From b0548ffc14342136f1828f3db0239d60bc5d0d18 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 23 Mar 2020 23:12:13 +0100 Subject: [PATCH 1/3] make type recipe aware of current axis --- src/series.jl | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/series.jl b/src/series.jl index 3a79d478..32982d13 100644 --- a/src/series.jl +++ b/src/series.jl @@ -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.") function _apply_type_recipe(plotattributes, v, letter) - _handle_axis_args!(plotattributes) + _preprocess_axis_args!(plotattributes, letter) rdvec = RecipesBase.apply_recipe(plotattributes, typeof(v), v) - _handle_axis_args!(plotattributes, letter) + _postprocess_axis_args!(plotattributes, letter) return rdvec[1].args[1] end @@ -185,7 +185,7 @@ end # This sort of recipe should return a pair of functions... one to convert to number, # and one to format tick values. 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. w = RecipesBase.apply_recipe(plotattributes, typeof(v), v)[1].args[1] # 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[] x = first(skipmissing(v)) 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) numfunc, formatter = args return Formatted(map(numfunc, v), formatter) @@ -201,7 +201,7 @@ function _apply_type_recipe(plotattributes, v::AbstractArray, letter) return v end end - _handle_axis_args!(plotattributes, letter) + _postprocess_axis_args!(plotattributes, letter) return w end @@ -225,7 +225,8 @@ end _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 -function _handle_axis_args!(plotattributes, letter) +function _postprocess_axis_args!(plotattributes, letter) + pop!(plotattributes, :letter) if letter in (:x, :y, :z) replaceAliases!(plotattributes, _keyAliases) for (k, v) in plotattributes @@ -239,13 +240,14 @@ function _handle_axis_args!(plotattributes, letter) end # 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) + plotattributes[:letter] = letter for (k, v) in plotattributes if haskey(_axis_defaults, k) pop!(plotattributes, k) - for letter in (:x, :y, :z) - lk = Symbol(letter, k) + for l in (:x, :y, :z) + lk = Symbol(l, k) haskey(plotattributes, lk) || (plotattributes[lk] = v) end end From 17db6c01b4fdb763ca58d902ace9ffe97b51d03c Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 25 Mar 2020 12:51:49 +0100 Subject: [PATCH 2/3] keep no-letter version of `_preprocess_axis_args!` --- src/series.jl | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/series.jl b/src/series.jl index 32982d13..ac5f9213 100644 --- a/src/series.jl +++ b/src/series.jl @@ -224,6 +224,24 @@ end # don't do anything for ints or floats _apply_type_recipe(plotattributes, v::AbstractArray{T}, letter) where {T<:Union{Integer,AbstractFloat}} = v +# axis args before type recipes should still be mapped to all axes +function _preprocess_axis_args!(plotattributes) + replaceAliases!(plotattributes, _keyAliases) + for (k, v) in plotattributes + if haskey(_axis_defaults, k) + pop!(plotattributes, k) + for l in (:x, :y, :z) + lk = Symbol(l, k) + haskey(plotattributes, lk) || (plotattributes[lk] = v) + end + end + end +end +function _preprocess_axis_args!(plotattributes, letter) + plotattributes[:letter] = letter + _preprocess_axis_args!(plotattributes) +end + # axis args in type recipes should only be applied to the current axis function _postprocess_axis_args!(plotattributes, letter) pop!(plotattributes, :letter) @@ -239,21 +257,6 @@ function _postprocess_axis_args!(plotattributes, letter) end end -# axis args before type recipes should still be mapped to all axes -function _preprocess_axis_args!(plotattributes, letter) - replaceAliases!(plotattributes, _keyAliases) - plotattributes[:letter] = letter - for (k, v) in plotattributes - if haskey(_axis_defaults, k) - pop!(plotattributes, k) - for l in (:x, :y, :z) - lk = Symbol(l, k) - haskey(plotattributes, lk) || (plotattributes[lk] = v) - end - end - end -end - # handle "type recipes" by converting inputs, and then either re-calling or slicing @recipe function f(x, y, z) did_replace = false From c684213106e5ec43cd6626f63c73185d09185154 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 25 Mar 2020 15:04:39 +0100 Subject: [PATCH 3/3] fix `AbstractArray{<:Missing}` --- src/series.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/series.jl b/src/series.jl index ac5f9213..afebde8e 100644 --- a/src/series.jl +++ b/src/series.jl @@ -20,6 +20,7 @@ function prepareSeriesData(a::AbstractArray{<:MaybeNumber}) f = isimmutable(a) ? replace : replace! a = f(x -> ismissing(x) || isinf(x) ? NaN : x, map(float, a)) end +prepareSeriesData(a::AbstractArray{<:Missing}) = fill(NaN, axes(a)) prepareSeriesData(a::AbstractArray{<:MaybeString}) = replace(x -> ismissing(x) ? "" : x, a) prepareSeriesData(s::Surface{<:AMat{<:MaybeNumber}}) = Surface(prepareSeriesData(s.surf)) prepareSeriesData(s::Surface) = s # non-numeric Surface, such as an image @@ -222,7 +223,7 @@ end # end # don't do anything for ints or floats -_apply_type_recipe(plotattributes, v::AbstractArray{T}, letter) where {T<:Union{Integer,AbstractFloat}} = v +_apply_type_recipe(plotattributes, v::AbstractArray{<:DataPoint}, letter) = v # axis args before type recipes should still be mapped to all axes function _preprocess_axis_args!(plotattributes)