implement showaxis attribute for gr
This commit is contained in:
parent
bcc2f089be
commit
18188516ec
@ -115,5 +115,6 @@ const _arg_desc = KW(
|
|||||||
:gridalpha => "Number in [0,1]. The alpha/opacity override for the grid lines.",
|
:gridalpha => "Number in [0,1]. The alpha/opacity override for the grid lines.",
|
||||||
:gridstyle => "Symbol. Style of the grid lines. Choose from $(_allStyles)",
|
:gridstyle => "Symbol. Style of the grid lines. Choose from $(_allStyles)",
|
||||||
:gridlinewidth => "Number. Width of the grid lines (in pixels)",
|
:gridlinewidth => "Number. Width of the grid lines (in pixels)",
|
||||||
:tick_direction => "Symbol. Direction of the ticks. `:in` or `:out`"
|
:tick_direction => "Symbol. Direction of the ticks. `:in` or `:out`",
|
||||||
|
:showaxis => "Bool, Symbol or String. Show the axis. `true`, `false`, `:show`, `:hide`, `:yes`, `:no`, `:x`, `:y`, `:z`, `:xy`, ..., `:all`, `:none`, `:off`"
|
||||||
)
|
)
|
||||||
|
|||||||
22
src/args.jl
22
src/args.jl
@ -170,8 +170,8 @@ const _scaleAliases = Dict{Symbol,Symbol}(
|
|||||||
const _allGridSyms = [:x, :y, :z,
|
const _allGridSyms = [:x, :y, :z,
|
||||||
:xy, :xz, :yx, :yz, :zx, :zy,
|
:xy, :xz, :yx, :yz, :zx, :zy,
|
||||||
:xyz, :xzy, :yxz, :yzx, :zxy, :zyx,
|
:xyz, :xzy, :yxz, :yzx, :zxy, :zyx,
|
||||||
:all, :both, :on,
|
:all, :both, :on, :yes,
|
||||||
:none, :off,]
|
:none, :off, :no]
|
||||||
const _allGridArgs = [_allGridSyms; string.(_allGridSyms); nothing]
|
const _allGridArgs = [_allGridSyms; string.(_allGridSyms); nothing]
|
||||||
hasgrid(arg::Void, letter) = false
|
hasgrid(arg::Void, letter) = false
|
||||||
hasgrid(arg::Bool, letter) = arg
|
hasgrid(arg::Bool, letter) = arg
|
||||||
@ -185,6 +185,24 @@ function hasgrid(arg::Symbol, letter)
|
|||||||
end
|
end
|
||||||
hasgrid(arg::AbstractString, letter) = hasgrid(Symbol(arg), letter)
|
hasgrid(arg::AbstractString, letter) = hasgrid(Symbol(arg), letter)
|
||||||
|
|
||||||
|
const _allShowaxisSyms = [:x, :y, :z,
|
||||||
|
:xy, :xz, :yx, :yz, :zx, :zy,
|
||||||
|
:xyz, :xzy, :yxz, :yzx, :zxy, :zyx,
|
||||||
|
:all, :both, :on, :yes,
|
||||||
|
:none, :off, :no]
|
||||||
|
const _allShowaxisArgs = [_allGridSyms; string.(_allGridSyms)]
|
||||||
|
showaxis(arg::Void, letter) = false
|
||||||
|
showaxis(arg::Bool, letter) = arg
|
||||||
|
function hasgrid(arg::Symbol, letter)
|
||||||
|
if arg in _allGridSyms
|
||||||
|
arg in (:all, :both, :on, :yes) || contains(string(arg), string(letter))
|
||||||
|
else
|
||||||
|
warn("Unknown showaxis argument $arg; $(Symbol(letter, :showaxis)) was set to `true` instead.")
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
showaxis(arg::AbstractString, letter) = hasgrid(Symbol(arg), letter)
|
||||||
|
|
||||||
const _allFramestyles = [:box, :semi, :axes, :origin, :zerolines, :grid, :none]
|
const _allFramestyles = [:box, :semi, :axes, :origin, :zerolines, :grid, :none]
|
||||||
const _framestyleAliases = Dict{Symbol, Symbol}(
|
const _framestyleAliases = Dict{Symbol, Symbol}(
|
||||||
:frame => :box,
|
:frame => :box,
|
||||||
|
|||||||
11
src/axes.jl
11
src/axes.jl
@ -70,6 +70,9 @@ function process_axis_arg!(d::KW, arg, letter = "")
|
|||||||
elseif arg == nothing
|
elseif arg == nothing
|
||||||
d[Symbol(letter,:ticks)] = []
|
d[Symbol(letter,:ticks)] = []
|
||||||
|
|
||||||
|
elseif arg in _allShowaxisArgs
|
||||||
|
d[Symbol(letter,:showaxis)] = showaxis(arg, letter)
|
||||||
|
|
||||||
elseif typeof(arg) <: Number
|
elseif typeof(arg) <: Number
|
||||||
d[Symbol(letter,:rotation)] = arg
|
d[Symbol(letter,:rotation)] = arg
|
||||||
|
|
||||||
@ -517,6 +520,7 @@ function axis_drawing_info(sp::Subplot)
|
|||||||
|
|
||||||
if !(sp[:framestyle] == :none)
|
if !(sp[:framestyle] == :none)
|
||||||
# xaxis
|
# xaxis
|
||||||
|
if xaxis[:showaxis]
|
||||||
sp[:framestyle] in (:grid, :origin, :zerolines) || push!(xaxis_segs, (xmin,ymin), (xmax,ymin)) # bottom spine / xaxis
|
sp[:framestyle] in (:grid, :origin, :zerolines) || push!(xaxis_segs, (xmin,ymin), (xmax,ymin)) # bottom spine / xaxis
|
||||||
if sp[:framestyle] in (:origin, :zerolines)
|
if sp[:framestyle] in (:origin, :zerolines)
|
||||||
push!(xaxis_segs, (xmin, 0.0), (xmax, 0.0))
|
push!(xaxis_segs, (xmin, 0.0), (xmax, 0.0))
|
||||||
@ -527,6 +531,7 @@ function axis_drawing_info(sp::Subplot)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
sp[:framestyle] in (:semi, :box) && push!(xborder_segs, (xmin,ymax), (xmax,ymax)) # top spine
|
sp[:framestyle] in (:semi, :box) && push!(xborder_segs, (xmin,ymax), (xmax,ymax)) # top spine
|
||||||
|
end
|
||||||
if !(xaxis[:ticks] in (nothing, false))
|
if !(xaxis[:ticks] in (nothing, false))
|
||||||
f = scalefunc(yaxis[:scale])
|
f = scalefunc(yaxis[:scale])
|
||||||
invf = invscalefunc(yaxis[:scale])
|
invf = invscalefunc(yaxis[:scale])
|
||||||
@ -536,18 +541,21 @@ function axis_drawing_info(sp::Subplot)
|
|||||||
t3 = invf(f(0) + 0.015 * (f(ymax) - f(ymin)) * ticks_in)
|
t3 = invf(f(0) + 0.015 * (f(ymax) - f(ymin)) * ticks_in)
|
||||||
|
|
||||||
for xtick in xticks[1]
|
for xtick in xticks[1]
|
||||||
|
if xaxis[:showaxis]
|
||||||
tick_start, tick_stop = if sp[:framestyle] == :origin
|
tick_start, tick_stop = if sp[:framestyle] == :origin
|
||||||
(0, t3)
|
(0, t3)
|
||||||
else
|
else
|
||||||
xaxis[:mirror] ? (ymax, t2) : (ymin, t1)
|
xaxis[:mirror] ? (ymax, t2) : (ymin, t1)
|
||||||
end
|
end
|
||||||
push!(xtick_segs, (xtick, tick_start), (xtick, tick_stop)) # bottom tick
|
push!(xtick_segs, (xtick, tick_start), (xtick, tick_stop)) # bottom tick
|
||||||
|
end
|
||||||
# sp[:draw_axes_border] && push!(xaxis_segs, (xtick, ymax), (xtick, t2)) # top tick
|
# sp[:draw_axes_border] && push!(xaxis_segs, (xtick, ymax), (xtick, t2)) # top tick
|
||||||
xaxis[:grid] && push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid
|
xaxis[:grid] && push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# yaxis
|
# yaxis
|
||||||
|
if yaxis[:showaxis]
|
||||||
sp[:framestyle] in (:grid, :origin, :zerolines) || push!(yaxis_segs, (xmin,ymin), (xmin,ymax)) # left spine / yaxis
|
sp[:framestyle] in (:grid, :origin, :zerolines) || push!(yaxis_segs, (xmin,ymin), (xmin,ymax)) # left spine / yaxis
|
||||||
if sp[:framestyle] in (:origin, :zerolines)
|
if sp[:framestyle] in (:origin, :zerolines)
|
||||||
push!(yaxis_segs, (0.0, ymin), (0.0, ymax))
|
push!(yaxis_segs, (0.0, ymin), (0.0, ymax))
|
||||||
@ -558,6 +566,7 @@ function axis_drawing_info(sp::Subplot)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
sp[:framestyle] in (:semi, :box) && push!(yborder_segs, (xmax,ymin), (xmax,ymax)) # right spine
|
sp[:framestyle] in (:semi, :box) && push!(yborder_segs, (xmax,ymin), (xmax,ymax)) # right spine
|
||||||
|
end
|
||||||
if !(yaxis[:ticks] in (nothing, false))
|
if !(yaxis[:ticks] in (nothing, false))
|
||||||
f = scalefunc(xaxis[:scale])
|
f = scalefunc(xaxis[:scale])
|
||||||
invf = invscalefunc(xaxis[:scale])
|
invf = invscalefunc(xaxis[:scale])
|
||||||
@ -567,12 +576,14 @@ function axis_drawing_info(sp::Subplot)
|
|||||||
t3 = invf(f(0) + 0.015 * (f(xmax) - f(xmin)) * ticks_in)
|
t3 = invf(f(0) + 0.015 * (f(xmax) - f(xmin)) * ticks_in)
|
||||||
|
|
||||||
for ytick in yticks[1]
|
for ytick in yticks[1]
|
||||||
|
if yaxis[:showaxis]
|
||||||
tick_start, tick_stop = if sp[:framestyle] == :origin
|
tick_start, tick_stop = if sp[:framestyle] == :origin
|
||||||
(0, t3)
|
(0, t3)
|
||||||
else
|
else
|
||||||
yaxis[:mirror] ? (xmax, t2) : (xmin, t1)
|
yaxis[:mirror] ? (xmax, t2) : (xmin, t1)
|
||||||
end
|
end
|
||||||
push!(ytick_segs, (tick_start, ytick), (tick_stop, ytick)) # left tick
|
push!(ytick_segs, (tick_start, ytick), (tick_stop, ytick)) # left tick
|
||||||
|
end
|
||||||
# sp[:draw_axes_border] && push!(yaxis_segs, (xmax, ytick), (t2, ytick)) # right tick
|
# sp[:draw_axes_border] && push!(yaxis_segs, (xmax, ytick), (t2, ytick)) # right tick
|
||||||
yaxis[:grid] && push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid
|
yaxis[:grid] && push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid
|
||||||
end
|
end
|
||||||
|
|||||||
@ -793,15 +793,20 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
GR.settransparency(1.0)
|
GR.settransparency(1.0)
|
||||||
|
|
||||||
# axis lines
|
# axis lines
|
||||||
|
if xaxis[:showaxis]
|
||||||
gr_set_line(1, :solid, xaxis[:foreground_color_axis])
|
gr_set_line(1, :solid, xaxis[:foreground_color_axis])
|
||||||
GR.setclip(0)
|
GR.setclip(0)
|
||||||
gr_polyline(coords(xspine_segs)...)
|
gr_polyline(coords(xspine_segs)...)
|
||||||
|
end
|
||||||
|
if yaxis[:showaxis]
|
||||||
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
||||||
GR.setclip(0)
|
GR.setclip(0)
|
||||||
gr_polyline(coords(yspine_segs)...)
|
gr_polyline(coords(yspine_segs)...)
|
||||||
|
end
|
||||||
GR.setclip(1)
|
GR.setclip(1)
|
||||||
|
|
||||||
# axis ticks
|
# axis ticks
|
||||||
|
if xaxis[:showaxis]
|
||||||
if sp[:framestyle] in (:zerolines, :grid)
|
if sp[:framestyle] in (:zerolines, :grid)
|
||||||
gr_set_line(1, :solid, xaxis[:foreground_color_grid])
|
gr_set_line(1, :solid, xaxis[:foreground_color_grid])
|
||||||
GR.settransparency(xaxis[:gridalpha])
|
GR.settransparency(xaxis[:gridalpha])
|
||||||
@ -810,6 +815,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
end
|
end
|
||||||
GR.setclip(0)
|
GR.setclip(0)
|
||||||
gr_polyline(coords(xtick_segs)...)
|
gr_polyline(coords(xtick_segs)...)
|
||||||
|
end
|
||||||
|
if yaxis[:showaxis]
|
||||||
if sp[:framestyle] in (:zerolines, :grid)
|
if sp[:framestyle] in (:zerolines, :grid)
|
||||||
gr_set_line(1, :solid, yaxis[:foreground_color_grid])
|
gr_set_line(1, :solid, yaxis[:foreground_color_grid])
|
||||||
GR.settransparency(yaxis[:gridalpha])
|
GR.settransparency(yaxis[:gridalpha])
|
||||||
@ -818,10 +825,11 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
end
|
end
|
||||||
GR.setclip(0)
|
GR.setclip(0)
|
||||||
gr_polyline(coords(ytick_segs)...)
|
gr_polyline(coords(ytick_segs)...)
|
||||||
|
end
|
||||||
GR.setclip(1)
|
GR.setclip(1)
|
||||||
|
|
||||||
# tick marks
|
# tick marks
|
||||||
if !(xticks in (:none, nothing, false))
|
if !(xticks in (:none, nothing, false)) && xaxis[:showaxis]
|
||||||
# x labels
|
# x labels
|
||||||
flip, mirror = gr_set_xticks_font(sp)
|
flip, mirror = gr_set_xticks_font(sp)
|
||||||
for (cv, dv) in zip(xticks...)
|
for (cv, dv) in zip(xticks...)
|
||||||
@ -832,7 +840,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if !(yticks in (:none, nothing, false))
|
if !(yticks in (:none, nothing, false)) && yaxis[:showaxis]
|
||||||
# y labels
|
# y labels
|
||||||
flip, mirror = gr_set_yticks_font(sp)
|
flip, mirror = gr_set_yticks_font(sp)
|
||||||
for (cv, dv) in zip(yticks...)
|
for (cv, dv) in zip(yticks...)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user