Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Runic formatting on code base #329

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/runic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Runic formatting
on:
push:
branches:
- 'master'
- 'release-'
tags:
- '*'
pull_request:
jobs:
runic:
name: Runic
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# - uses: julia-actions/setup-julia@v2
# with:
# version: '1'
# - uses: julia-actions/cache@v2
- uses: fredrikekre/runic-action@v1
with:
version: '1.0.0'
14 changes: 8 additions & 6 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Documenter, PGFPlotsX
PGFPlotsX.latexengine!(PGFPlotsX.LUALATEX)
DocMeta.setdocmeta!(PGFPlotsX, :DocTestSetup, :(using PGFPlotsX); recursive=true)
DocMeta.setdocmeta!(PGFPlotsX, :DocTestSetup, :(using PGFPlotsX); recursive = true)
using Contour, Colors, DataFrames, Distributions

makedocs(
modules = [PGFPlotsX],
format = Documenter.HTML(; assets = ["assets/custom.css"],
prettyurls = get(ENV, "CI", nothing) == "true"),
format = Documenter.HTML(;
assets = ["assets/custom.css"],
prettyurls = get(ENV, "CI", nothing) == "true"
),
sitename = "PGFPlotsX.jl",
doctest = true,
strict = true,
Expand All @@ -22,7 +24,7 @@ makedocs(
"man/picdoc.md",
"man/save.md",
"man/internals.md",
],
],
"Examples" => [
"examples/coordinates.md",
"examples/tables.md",
Expand All @@ -31,13 +33,13 @@ makedocs(
"examples/juliatypes.md",
"examples/convenience.md",
"examples/latex.md",
]
],
]
)

@info "calling deploydocs"

deploydocs(
repo = "github.com/KristofferC/PGFPlotsX.jl.git",
push_preview=true,
push_preview = true,
)
24 changes: 16 additions & 8 deletions ext/ColorsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ PGFPlotsX.EXTENSIONS_SUPPORTED ? (using Colors) : (using ..Colors)
function _rgb_for_printing(c::Colors.Colorant)
rgb = convert(Colors.RGB{Float64}, c)
# round colors since pgfplots cannot parse scientific notation, eg 1e-10
round.((Colors.red(rgb), Colors.green(rgb), Colors.blue(rgb)); digits = 4)
return round.((Colors.red(rgb), Colors.green(rgb), Colors.blue(rgb)); digits = 4)
end

function PGFPlotsX.print_opt(io::IO, c::Colors.Colorant)
rgb_64 = _rgb_for_printing(c)
print(io, "rgb,1:",
"red," , rgb_64[1], ";",
"green,", rgb_64[2], ";",
"blue," , rgb_64[3])
print(
io, "rgb,1:",
"red,", rgb_64[1], ";",
"green,", rgb_64[2], ";",
"blue,", rgb_64[3]
)
return
end

# For printing surface plots with explicit color, pgfplots manual 4.6.7.
Expand All @@ -24,24 +27,29 @@ end
function PGFPlotsX.print_tex(io::IO, c::Colors.Colorant)
rgb_64 = _rgb_for_printing(c)
print(io, "rgb=", rgb_64[1], ",", rgb_64[2], ",", rgb_64[3])
return
end

function PGFPlotsX.print_tex(io::IO, c::Tuple{String, Colors.Colorant}, ::Any)
name, color = c
rgb_64 = _rgb_for_printing(color)
print(io, "\\definecolor{$name}{rgb}{$(rgb_64[1]), $(rgb_64[2]), $(rgb_64[3])}")
return
end

function PGFPlotsX.print_tex(io::IO,
c::Tuple{String, Vector{<:Colors.Colorant}},
::Any)
function PGFPlotsX.print_tex(
io::IO,
c::Tuple{String, Vector{<:Colors.Colorant}},
::Any
)
name, colors = c
println(io, "\\pgfplotsset{ colormap={$name}{")
for col in colors
rgb_64 = _rgb_for_printing(col)
println(io, "rgb=(", join(rgb_64, ","), ")")
end
println(io, "}}")
return
end

end
2 changes: 1 addition & 1 deletion ext/ContourExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function PGFPlotsX.TableData(c::Contour.ContourCollection; kwargs...)
push!(ns, n)
end
end
PGFPlotsX.TableData(hcat(colx, coly, colz); colnames=["x", "y", "z"], scanlines=cumsum(ns), kwargs...)
return PGFPlotsX.TableData(hcat(colx, coly, colz); colnames = ["x", "y", "z"], scanlines = cumsum(ns), kwargs...)
end

end
36 changes: 24 additions & 12 deletions ext/MeasurementsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,35 @@ import PGFPlotsX

PGFPlotsX.EXTENSIONS_SUPPORTED ? (using Measurements) : (using ..Measurements)

function PGFPlotsX.Coordinates(x::AbstractVector{T}, y::AbstractVector;
kwargs...) where T <: Measurements.Measurement{<:Real}
PGFPlotsX.Coordinates(Measurements.value.(x), y;
xerror = Measurements.uncertainty.(x), kwargs...)
function PGFPlotsX.Coordinates(
x::AbstractVector{T}, y::AbstractVector;
kwargs...
) where {T <: Measurements.Measurement{<:Real}}
return PGFPlotsX.Coordinates(
Measurements.value.(x), y;
xerror = Measurements.uncertainty.(x), kwargs...
)
end

function PGFPlotsX.Coordinates(x::AbstractVector, y::AbstractVector{T};
kwargs...) where T <: Measurements.Measurement{<:Real}
PGFPlotsX.Coordinates(x, Measurements.value.(y);
yerror = Measurements.uncertainty.(y), kwargs...)
function PGFPlotsX.Coordinates(
x::AbstractVector, y::AbstractVector{T};
kwargs...
) where {T <: Measurements.Measurement{<:Real}}
return PGFPlotsX.Coordinates(
x, Measurements.value.(y);
yerror = Measurements.uncertainty.(y), kwargs...
)
end

function PGFPlotsX.Coordinates(x::AbstractVector{T}, y::AbstractVector{T};
kwargs...) where T <: Measurements.Measurement{<:Real}
PGFPlotsX.Coordinates(Measurements.value.(x), Measurements.value.(y);
function PGFPlotsX.Coordinates(
x::AbstractVector{T}, y::AbstractVector{T};
kwargs...
) where {T <: Measurements.Measurement{<:Real}}
return PGFPlotsX.Coordinates(
Measurements.value.(x), Measurements.value.(y);
xerror = Measurements.uncertainty.(x),
yerror = Measurements.uncertainty.(y), kwargs...)
yerror = Measurements.uncertainty.(y), kwargs...
)
end

end
34 changes: 21 additions & 13 deletions ext/StatsBaseExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,35 @@ import PGFPlotsX

PGFPlotsX.EXTENSIONS_SUPPORTED ? (using StatsBase) : (using ..StatsBase)

function PGFPlotsX.TableData(h::StatsBase.Histogram{T, 1};
kwargs...) where T
PGFPlotsX.TableData(hcat(h.edges[1], vcat(h.weights, 0)); kwargs...)
function PGFPlotsX.TableData(
h::StatsBase.Histogram{T, 1};
kwargs...
) where {T}
return PGFPlotsX.TableData(hcat(h.edges[1], vcat(h.weights, 0)); kwargs...)
end

function PGFPlotsX.TableData(histogram::StatsBase.Histogram{T, 2};
kwargs...) where T
PGFPlotsX.TableData(StatsBase.midpoints(histogram.edges[1]),
StatsBase.midpoints(histogram.edges[2]),
histogram.weights; kwargs...)
function PGFPlotsX.TableData(
histogram::StatsBase.Histogram{T, 2};
kwargs...
) where {T}
return PGFPlotsX.TableData(
StatsBase.midpoints(histogram.edges[1]),
StatsBase.midpoints(histogram.edges[2]),
histogram.weights; kwargs...
)
end

function PGFPlotsX.TableData(e::StatsBase.ECDF; n = 100, kwargs...)
x = range(extrema(e)...; length = n)
PGFPlotsX.TableData(hcat(x, map(e, x)); kwargs...)
return PGFPlotsX.TableData(hcat(x, map(e, x)); kwargs...)
end

function PGFPlotsX.Coordinates(histogram::StatsBase.Histogram{T, 2}) where T
PGFPlotsX.Coordinates(StatsBase.midpoints(histogram.edges[1]),
StatsBase.midpoints(histogram.edges[2]),
histogram.weights)
function PGFPlotsX.Coordinates(histogram::StatsBase.Histogram{T, 2}) where {T}
return PGFPlotsX.Coordinates(
StatsBase.midpoints(histogram.edges[1]),
StatsBase.midpoints(histogram.edges[2]),
histogram.weights
)
end

end
39 changes: 24 additions & 15 deletions src/PGFPlotsX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ print_tex(a) = print_tex(stdout, a)
function print_tex(::Type{String}, args...)
io = IOBuffer()
print_tex(io, args...)
String(take!(io))
return String(take!(io))
end

include("options.jl")
Expand Down Expand Up @@ -89,6 +89,7 @@ function print_tex(io::IO, x::Real)
else
throw(ArgumentError("Don't know how to print $x for LaTeX."))
end
return
end

print_tex(io::IO, ::Missing) = print(io, "nan")
Expand All @@ -97,9 +98,15 @@ print_tex(io::IO, dt::Date) = Dates.format(io, dt, dateformat"YYYY-mm-dd")

print_tex(io::IO, dt::DateTime) = Dates.format(io, dt, dateformat"YYYY-mm-dd HH:MM")

print_tex(io::IO, v) = throw(ArgumentError(string("No tex function available for data of type $(typeof(v)). ",
"Define one by overloading print_tex(io::IO, data::T) ",
"where T is the type of the data to dispatch on.")))
print_tex(io::IO, v) = throw(
ArgumentError(
string(
"No tex function available for data of type $(typeof(v)). ",
"Define one by overloading print_tex(io::IO, data::T) ",
"where T is the type of the data to dispatch on."
)
)
)


"""
Expand Down Expand Up @@ -130,18 +137,20 @@ end

function __init__()
pushdisplay(PGFPlotsXDisplay())
atreplinit(i -> begin
if PlotDisplay() in Base.Multimedia.displays
popdisplay(PGFPlotsXDisplay())
atreplinit(
i -> begin
if PlotDisplay() in Base.Multimedia.displays
popdisplay(PGFPlotsXDisplay())
end
pushdisplay(PGFPlotsXDisplay())
end
pushdisplay(PGFPlotsXDisplay())
end)

@static if !EXTENSIONS_SUPPORTED
@require Colors="5ae59095-9a9b-59fe-a467-6f913c188581" include("../ext/ColorsExt.jl")
@require Contour="d38c429a-6771-53c6-b99e-75d170b6e991" include("../ext/ContourExt.jl")
@require StatsBase="2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" include("../ext/StatsBaseExt.jl")
@require Measurements="eff96d63-e80a-5855-80a2-b1b0885c5ab7" include("../ext/MeasurementsExt.jl")
)

return @static if !EXTENSIONS_SUPPORTED
@require Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" include("../ext/ColorsExt.jl")
@require Contour = "d38c429a-6771-53c6-b99e-75d170b6e991" include("../ext/ContourExt.jl")
@require StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" include("../ext/StatsBaseExt.jl")
@require Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" include("../ext/MeasurementsExt.jl")
end
end

Expand Down
Loading
Loading