Skip to content

Commit

Permalink
Fix generic aliases (#3824)
Browse files Browse the repository at this point in the history
  • Loading branch information
briederer authored Sep 17, 2021
1 parent e2539a3 commit 4f8a265
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/args.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ function add_aliases(sym::Symbol, aliases::Symbol...)
return nothing
end

function add_axes_aliases(sym::Symbol, aliases::Symbol...)
function add_axes_aliases(sym::Symbol, aliases::Symbol...; generic::Bool = true)
sym in keys(_axis_defaults) || throw(ArgumentError("Invalid `$sym`"))
generic && add_aliases(sym, aliases...)
for letter in (:x, :y, :z)
add_aliases(Symbol(letter, sym), (Symbol(letter, a) for a in aliases)...)
end
Expand Down Expand Up @@ -841,7 +842,7 @@ add_aliases(:markerstrokealpha, :msa, :msalpha, :msα, :markerstrokeopacity, :ms
add_aliases(:fillalpha, :fa, :falpha, :fα, :fillopacity, :fopacity)

# axes attributes
add_axes_aliases(:guide, :label, :lab, :l)
add_axes_aliases(:guide, :label, :lab, :l; generic = false)
add_axes_aliases(:lims, :lim, :limit, :limits, :range)
add_axes_aliases(:ticks, :tick)
add_axes_aliases(:rotation, :rot, :r)
Expand Down
32 changes: 31 additions & 1 deletion test/test_axes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end
@test twpl[:bottom_margin] == 2Plots.cm
end

@testset "aliases" begin
@testset "axis-aliases" begin
p = plot(1:2, xl = "x label")
@test p[1][:xaxis][:guide] === "x label"
p = plot(1:2, xrange = (0, 3))
Expand All @@ -88,3 +88,33 @@ end
p = plot(1:2, xtickor = :out)
@test p[1][:xaxis][:tick_direction] === :out
end

@testset "aliases" begin
compare(p::Plots.Plot, s::Symbol, val, op) =
op(p[1][:xaxis][s], val) && op(p[1][:yaxis][s], val) && op(p[1][:zaxis][s], val)
p = plot(1:2, guide = "all labels")
@test compare(p, :guide, "all labels", ===)
p = plot(1:2, label = "test")
@test compare(p, :guide, "", ===)
p = plot(1:2, lim = (0, 3))
@test xlims(p) === ylims(p) === zlims(p) === (0,3)
p = plot(1:2, tick = [1.25, 1.5, 1.75])
@test compare(p,:ticks,[1.25, 1.5, 1.75], ==)
p = plot(1:2, labelfontsize = 4)
@test compare(p,:guidefontsize,4, ==)
p = plot(1:2, gα = .07)
@test compare(p,:gridalpha,.07, )
p = plot(1:2, gridls = :dashdot)
@test compare(p,:gridstyle,:dashdot, ===)
p = plot(1:2, gridcolor = :red)
@test compare(p,:foreground_color_grid,RGBA{Float64}(1.,0.,0.,1.), ===)
p = plot(1:2, minorgridcolor = :red)
@test compare(p,:foreground_color_minor_grid,RGBA{Float64}(1.,0.,0.,1.), ===)
p = plot(1:2, grid_lw = .01)
@test compare(p,:gridlinewidth,.01, )
p = plot(1:2, minorgrid_lw = .01)
@test compare(p,:minorgridlinewidth,.01, )
p = plot(1:2, tickor = :out)
@test compare(p,:tick_direction,:out, ===)

end

0 comments on commit 4f8a265

Please sign in to comment.