fix default with axis args

This commit is contained in:
Daniel Schwabeneder 2020-03-29 15:39:44 +02:00
parent a1116f8e3b
commit 076de033fd
4 changed files with 47 additions and 71 deletions

View File

@ -450,38 +450,33 @@ const _initial_fontsizes = Dict(:titlefontsize => _subplot_defaults[:titlefonts
:tickfontsize => _axis_defaults[:tickfontsize], :tickfontsize => _axis_defaults[:tickfontsize],
:guidefontsize => _axis_defaults[:guidefontsize]) :guidefontsize => _axis_defaults[:guidefontsize])
const _all_args = sort(collect(union(map(keys, _all_defaults)...)))
is_subplot_attr(k) = haskey(_subplot_defaults, k)
is_series_attr(k) = haskey(_series_defaults, k)
#is_axis_attr(k) = haskey(_axis_defaults_byletter, k)
is_axis_attr(k) = haskey(_axis_defaults, Symbol(chop(string(k); head=1, tail=0)))
is_axis_attr_noletter(k) = haskey(_axis_defaults, k)
RecipesBase.is_key_supported(k::Symbol) = is_attr_supported(k)
const _internal_args = const _internal_args =
[:plot_object, :series_plotindex, :markershape_to_add, :letter, :idxfilter] [:plot_object, :series_plotindex, :markershape_to_add, :letter, :idxfilter]
const _magic_axis_args = [:axis, :tickfont, :guidefont]
const _axis_args = sort(union(collect(keys(_axis_defaults))))
const _series_args = sort(union(collect(keys(_series_defaults))))
const _subplot_args = sort(union(collect(keys(_subplot_defaults))))
const _plot_args = sort(union(collect(keys(_plot_defaults))))
const _magic_axis_args = [:axis, :tickfont, :guidefont, :grid, :minorgrid]
const _magic_subplot_args = [:titlefont, :legendfont, :legendtitlefont, ] const _magic_subplot_args = [:titlefont, :legendfont, :legendtitlefont, ]
const _magic_series_args = [:line, :marker, :fill] const _magic_series_args = [:line, :marker, :fill]
function is_noletter_attribute(k) const _all_axis_args = sort(union([_axis_args; _magic_axis_args]))
is_axis_attr_noletter(k) && return true const _all_subplot_args = sort(union([_subplot_args; _magic_subplot_args]))
k in _magic_axis_args && return true const _all_series_args = sort(union([_series_args; _magic_series_args]))
return false const _all_plot_args = _plot_args
end
function is_default_attribute(k) const _all_args =
k in _internal_args && return true sort([_all_axis_args; _all_subplot_args; _all_series_args; _all_plot_args])
k in _all_args && return true
is_axis_attr(k) && return true is_subplot_attr(k) = k in _all_subplot_args
is_noletter_attribute(k) && return true is_series_attr(k) = k in _all_series_args
k in _magic_subplot_args && return true is_axis_attr(k) = Symbol(chop(string(k); head=1, tail=0)) in _all_axis_args
k in _magic_series_args && return true is_axis_attr_noletter(k) = k in _all_axis_args
Symbol(chop(string(k); head = 1, tail = 0)) in _magic_axis_args && return true
return false RecipesBase.is_key_supported(k::Symbol) = is_attr_supported(k)
end is_default_attribute(k) = k in _internal_args || k in _all_args || is_axis_attr_noletter(k)
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -942,22 +937,6 @@ end
function preprocessArgs!(plotattributes::AKW) function preprocessArgs!(plotattributes::AKW)
replaceAliases!(plotattributes, _keyAliases) replaceAliases!(plotattributes, _keyAliases)
# clear all axis stuff
# if haskey(plotattributes, :axis) && plotattributes[:axis] in (:none, nothing, false)
# plotattributes[:ticks] = nothing
# plotattributes[:foreground_color_border] = RGBA(0,0,0,0)
# plotattributes[:foreground_color_axis] = RGBA(0,0,0,0)
# plotattributes[:grid] = false
# delete!(plotattributes, :axis)
# end
# for letter in (:x, :y, :z)
# asym = Symbol(letter, :axis)
# if haskey(plotattributes, asym) || plotattributes[asym] in (:none, nothing, false)
# plotattributes[Symbol(letter, :ticks)] = nothing
# plotattributes[Symbol(letter, :foreground_color_border)] = RGBA(0,0,0,0)
# end
# end
# handle axis args common to all axis # handle axis args common to all axis
args = pop_kw!(plotattributes, :axis, ()) args = pop_kw!(plotattributes, :axis, ())
for arg in wraptuple(args) for arg in wraptuple(args)
@ -1015,13 +994,6 @@ function preprocessArgs!(plotattributes::AKW)
processMinorGridArg!(plotattributes, arg, letter) processMinorGridArg!(plotattributes, arg, letter)
end end
end end
# fonts
for fontname in (:titlefont, :legendfont, :legendtitlefont)
args = pop_kw!(plotattributes, fontname, ())
for arg in wraptuple(args)
processFontArg!(plotattributes, fontname, arg)
end
end
# handle font args common to all axes # handle font args common to all axes
for fontname in (:tickfont, :guidefont) for fontname in (:tickfont, :guidefont)
args = pop_kw!(plotattributes, fontname, ()) args = pop_kw!(plotattributes, fontname, ())
@ -1040,17 +1012,27 @@ function preprocessArgs!(plotattributes::AKW)
end end
end end
end end
# handle axes guides # handle axes args
if haskey(plotattributes, :guide) for k in _axis_args
guide = pop!(plotattributes, :guide) if haskey(plotattributes, k)
for letter in (:x, :y, :z) v = plotattributes[k]
guide_sym = Symbol(letter, :guide) for letter in (:x, :y, :z)
if !is_explicit(plotattributes, guide_sym) lk = Symbol(letter, k)
plotattributes[guide_sym] = guide if !is_explicit(plotattributes, lk)
plotattributes[lk] = v
end
end end
end end
end end
# fonts
for fontname in (:titlefont, :legendfont, :legendtitlefont)
args = pop_kw!(plotattributes, fontname, ())
for arg in wraptuple(args)
processFontArg!(plotattributes, fontname, arg)
end
end
# handle line args # handle line args
for arg in wraptuple(pop_kw!(plotattributes, :line, ())) for arg in wraptuple(pop_kw!(plotattributes, :line, ()))
processLineArg(plotattributes, arg) processLineArg(plotattributes, arg)
@ -1504,12 +1486,9 @@ function _update_axis(plt::Plot, sp::Subplot, plotattributes_in::AKW, letter::Sy
end end
function _update_axis(axis::Axis, plotattributes_in::AKW, letter::Symbol, subplot_index::Int) function _update_axis(axis::Axis, plotattributes_in::AKW, letter::Symbol, subplot_index::Int)
# grab magic args (for example `xaxis = (:flip, :log)`)
args = wraptuple(get(plotattributes_in, Symbol(letter, :axis), ()))
# build the KW of arguments from the letter version (i.e. xticks --> ticks) # build the KW of arguments from the letter version (i.e. xticks --> ticks)
kw = KW() kw = KW()
for k in keys(_axis_defaults) for k in _all_axis_args
# first get the args without the letter: `tickfont = font(10)` # first get the args without the letter: `tickfont = font(10)`
# note: we don't pop because we want this to apply to all axes! (delete after all have finished) # note: we don't pop because we want this to apply to all axes! (delete after all have finished)
if haskey(plotattributes_in, k) if haskey(plotattributes_in, k)
@ -1524,7 +1503,7 @@ function _update_axis(axis::Axis, plotattributes_in::AKW, letter::Symbol, subplo
end end
# update the axis # update the axis
attr!(axis, args...; kw...) attr!(axis; kw...)
return return
end end

View File

@ -84,6 +84,9 @@ function attr!(axis::Axis, args...; kw...)
process_axis_arg!(plotattributes, arg) process_axis_arg!(plotattributes, arg)
end end
# then preprocess keyword arguments
preprocessArgs!(KW(kw))
# then override for any keywords... only those keywords that already exists in plotattributes # then override for any keywords... only those keywords that already exists in plotattributes
for (k,v) in kw for (k,v) in kw
if haskey(plotattributes, k) if haskey(plotattributes, k)

View File

@ -62,14 +62,8 @@ function _preprocess_args(plotattributes::AKW, args, still_to_process::Vector{Re
# remove subplot and axis args from plotattributes... they will be passed through in the kw_list # remove subplot and axis args from plotattributes... they will be passed through in the kw_list
if !isempty(args) if !isempty(args)
for (k,v) in plotattributes for (k,v) in plotattributes
for defdict in (_subplot_defaults, if k in _all_subplot_args || k in _all_axis_args
_axis_defaults, reset_kw!(plotattributes, k)
_axis_defaults_byletter[:x],
_axis_defaults_byletter[:y],
_axis_defaults_byletter[:z])
if haskey(defdict, k)
reset_kw!(plotattributes, k)
end
end end
end end
end end

View File

@ -227,7 +227,7 @@ _apply_type_recipe(plotattributes, v::AbstractArray{<:DataPoint}, letter) = v
# axis args before type recipes should still be mapped to all axes # axis args before type recipes should still be mapped to all axes
function _preprocess_axis_args!(plotattributes) function _preprocess_axis_args!(plotattributes)
for (k, v) in plotattributes for (k, v) in plotattributes
if is_noletter_attribute(k) if is_axis_attr_noletter(k)
pop!(plotattributes, k) pop!(plotattributes, k)
for l in (:x, :y, :z) for l in (:x, :y, :z)
lk = Symbol(l, k) lk = Symbol(l, k)
@ -246,7 +246,7 @@ function _postprocess_axis_args!(plotattributes, letter)
pop!(plotattributes, :letter) pop!(plotattributes, :letter)
if letter in (:x, :y, :z) if letter in (:x, :y, :z)
for (k, v) in plotattributes for (k, v) in plotattributes
if is_noletter_attribute(k) if is_axis_attr_noletter(k)
pop!(plotattributes, k) pop!(plotattributes, k)
lk = Symbol(letter, k) lk = Symbol(letter, k)
haskey(plotattributes, lk) || (plotattributes[lk] = v) haskey(plotattributes, lk) || (plotattributes[lk] = v)