move replaceAliases! out of recipe processing

This commit is contained in:
Daniel Schwabeneder 2020-03-26 15:09:31 +01:00
parent c684213106
commit 932d0da73d
4 changed files with 9 additions and 10 deletions

View File

@ -916,8 +916,8 @@ function _add_markershape(plotattributes::AKW)
end end
"Handle all preprocessing of args... break out colors/sizes/etc and replace aliases." "Handle all preprocessing of args... break out colors/sizes/etc and replace aliases."
function preprocessArgs!(plotattributes::AKW) function preprocessArgs!(plotattributes::AKW, replace_aliases = true)
replaceAliases!(plotattributes, _keyAliases) replace_aliases && replaceAliases!(plotattributes, _keyAliases)
# clear all axis stuff # clear all axis stuff
# if haskey(plotattributes, :axis) && plotattributes[:axis] in (:none, nothing, false) # if haskey(plotattributes, :axis) && plotattributes[:axis] in (:none, nothing, false)

View File

@ -96,7 +96,7 @@ function _process_userrecipe(plt::Plot, kw_list::Vector{KW}, recipedata::RecipeD
# when the arg tuple is empty, that means there's nothing left to recursively # when the arg tuple is empty, that means there's nothing left to recursively
# process... finish up and add to the kw_list # process... finish up and add to the kw_list
kw = recipedata.plotattributes kw = recipedata.plotattributes
preprocessArgs!(kw) preprocessArgs!(kw, false)
_preprocess_userrecipe(kw) _preprocess_userrecipe(kw)
warnOnUnsupported_scales(plt.backend, kw) warnOnUnsupported_scales(plt.backend, kw)
@ -185,7 +185,7 @@ function _process_plotrecipe(plt::Plot, kw::AKW, kw_list::Vector{KW}, still_to_p
st = kw[:seriestype] = get(_typeAliases, st, st) st = kw[:seriestype] = get(_typeAliases, st, st)
datalist = RecipesBase.apply_recipe(kw, Val{st}, plt) datalist = RecipesBase.apply_recipe(kw, Val{st}, plt)
for data in datalist for data in datalist
preprocessArgs!(data.plotattributes) preprocessArgs!(data.plotattributes, false)
if data.plotattributes[:seriestype] == st if data.plotattributes[:seriestype] == st
error("Plot recipe $st returned the same seriestype: $(data.plotattributes)") error("Plot recipe $st returned the same seriestype: $(data.plotattributes)")
end end
@ -413,7 +413,7 @@ function _process_seriesrecipe(plt::Plot, plotattributes::AKW)
# assuming there was no error, recursively apply the series recipes # assuming there was no error, recursively apply the series recipes
for data in datalist for data in datalist
if isa(data, RecipeData) if isa(data, RecipeData)
preprocessArgs!(data.plotattributes) preprocessArgs!(data.plotattributes, false)
if data.plotattributes[:seriestype] == st if data.plotattributes[:seriestype] == st
error("The seriestype didn't change in series recipe $st. This will cause a StackOverflow.") error("The seriestype didn't change in series recipe $st. This will cause a StackOverflow.")
end end

View File

@ -227,7 +227,6 @@ _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)
replaceAliases!(plotattributes, _keyAliases)
for (k, v) in plotattributes for (k, v) in plotattributes
if haskey(_axis_defaults, k) if haskey(_axis_defaults, k)
pop!(plotattributes, k) pop!(plotattributes, k)
@ -247,7 +246,6 @@ end
function _postprocess_axis_args!(plotattributes, letter) function _postprocess_axis_args!(plotattributes, letter)
pop!(plotattributes, :letter) pop!(plotattributes, :letter)
if letter in (:x, :y, :z) if letter in (:x, :y, :z)
replaceAliases!(plotattributes, _keyAliases)
for (k, v) in plotattributes for (k, v) in plotattributes
if haskey(_axis_defaults, k) if haskey(_axis_defaults, k)
pop!(plotattributes, k) pop!(plotattributes, k)

View File

@ -26,8 +26,9 @@ struct Attr <: AbstractDict{Symbol,Any}
defaults::KW defaults::KW
end end
Base.getindex(attr::Attr, k) = haskey(attr.explicit,k) ? function Base.getindex(attr::Attr, k)
attr.explicit[k] : attr.defaults[k] return haskey(attr.explicit, k) ? attr.explicit[k] : attr.defaults[k]
end
Base.haskey(attr::Attr, k) = haskey(attr.explicit,k) || haskey(attr.defaults,k) Base.haskey(attr::Attr, k) = haskey(attr.explicit,k) || haskey(attr.defaults,k)
Base.get(attr::Attr, k, default) = haskey(attr, k) ? attr[k] : default Base.get(attr::Attr, k, default) = haskey(attr, k) ? attr[k] : default
function Base.get!(attr::Attr, k, default) function Base.get!(attr::Attr, k, default)