make type recipe aware of current axis

This commit is contained in:
Daniel Schwabeneder 2020-03-23 23:12:13 +01:00
parent 2083af9257
commit b0548ffc14

View File

@ -175,9 +175,9 @@ end
@recipe f(::Type{V}, x, y, z) where {V<:Val} = error("The backend must not support the series type $V, and there isn't a series recipe defined.") @recipe f(::Type{V}, x, y, z) where {V<:Val} = error("The backend must not support the series type $V, and there isn't a series recipe defined.")
function _apply_type_recipe(plotattributes, v, letter) function _apply_type_recipe(plotattributes, v, letter)
_handle_axis_args!(plotattributes) _preprocess_axis_args!(plotattributes, letter)
rdvec = RecipesBase.apply_recipe(plotattributes, typeof(v), v) rdvec = RecipesBase.apply_recipe(plotattributes, typeof(v), v)
_handle_axis_args!(plotattributes, letter) _postprocess_axis_args!(plotattributes, letter)
return rdvec[1].args[1] return rdvec[1].args[1]
end end
@ -185,7 +185,7 @@ end
# This sort of recipe should return a pair of functions... one to convert to number, # This sort of recipe should return a pair of functions... one to convert to number,
# and one to format tick values. # and one to format tick values.
function _apply_type_recipe(plotattributes, v::AbstractArray, letter) function _apply_type_recipe(plotattributes, v::AbstractArray, letter)
_handle_axis_args!(plotattributes) _preprocess_axis_args!(plotattributes, letter)
# First we try to apply an array type recipe. # First we try to apply an array type recipe.
w = RecipesBase.apply_recipe(plotattributes, typeof(v), v)[1].args[1] w = RecipesBase.apply_recipe(plotattributes, typeof(v), v)[1].args[1]
# If the type did not change try it element-wise # If the type did not change try it element-wise
@ -193,7 +193,7 @@ function _apply_type_recipe(plotattributes, v::AbstractArray, letter)
isempty(skipmissing(v)) && return Float64[] isempty(skipmissing(v)) && return Float64[]
x = first(skipmissing(v)) x = first(skipmissing(v))
args = RecipesBase.apply_recipe(plotattributes, typeof(x), x)[1].args args = RecipesBase.apply_recipe(plotattributes, typeof(x), x)[1].args
_handle_axis_args!(plotattributes, letter) _postprocess_axis_args!(plotattributes, letter)
if length(args) == 2 && all(arg -> arg isa Function, args) if length(args) == 2 && all(arg -> arg isa Function, args)
numfunc, formatter = args numfunc, formatter = args
return Formatted(map(numfunc, v), formatter) return Formatted(map(numfunc, v), formatter)
@ -201,7 +201,7 @@ function _apply_type_recipe(plotattributes, v::AbstractArray, letter)
return v return v
end end
end end
_handle_axis_args!(plotattributes, letter) _postprocess_axis_args!(plotattributes, letter)
return w return w
end end
@ -225,7 +225,8 @@ end
_apply_type_recipe(plotattributes, v::AbstractArray{T}, letter) where {T<:Union{Integer,AbstractFloat}} = v _apply_type_recipe(plotattributes, v::AbstractArray{T}, letter) where {T<:Union{Integer,AbstractFloat}} = v
# axis args in type recipes should only be applied to the current axis # axis args in type recipes should only be applied to the current axis
function _handle_axis_args!(plotattributes, letter) function _postprocess_axis_args!(plotattributes, letter)
pop!(plotattributes, :letter)
if letter in (:x, :y, :z) if letter in (:x, :y, :z)
replaceAliases!(plotattributes, _keyAliases) replaceAliases!(plotattributes, _keyAliases)
for (k, v) in plotattributes for (k, v) in plotattributes
@ -239,13 +240,14 @@ function _handle_axis_args!(plotattributes, letter)
end end
# 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 _handle_axis_args!(plotattributes) function _preprocess_axis_args!(plotattributes, letter)
replaceAliases!(plotattributes, _keyAliases) replaceAliases!(plotattributes, _keyAliases)
plotattributes[:letter] = letter
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)
for letter in (:x, :y, :z) for l in (:x, :y, :z)
lk = Symbol(letter, k) lk = Symbol(l, k)
haskey(plotattributes, lk) || (plotattributes[lk] = v) haskey(plotattributes, lk) || (plotattributes[lk] = v)
end end
end end