From 5af5ec73133609162eff1a2def212447d65dd673 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 8 Feb 2020 23:29:09 +0100 Subject: [PATCH 1/4] more AKWs --- src/args.jl | 10 +++++----- src/axes.jl | 2 +- src/layouts.jl | 4 ++-- src/pipeline.jl | 20 ++++++++++---------- src/plot.jl | 2 +- src/recipes.jl | 14 +++++++------- src/series.jl | 2 +- src/themes.jl | 2 +- src/utils.jl | 8 ++++---- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/args.jl b/src/args.jl index 47124693..f44f97b7 100644 --- a/src/args.jl +++ b/src/args.jl @@ -906,7 +906,7 @@ _replace_markershape(shape::Symbol) = get(_markerAliases, shape, shape) _replace_markershape(shapes::AVec) = map(_replace_markershape, shapes) _replace_markershape(shape) = shape -function _add_markershape(plotattributes::KW) +function _add_markershape(plotattributes::AKW) # add the markershape if it needs to be added... hack to allow "m=10" to add a shape, # and still allow overriding in _apply_recipe ms = pop!(plotattributes, :markershape_to_add, :none) @@ -1145,13 +1145,13 @@ end filter_data(v::AVec, idxfilter::AVec{Int}) = v[idxfilter] filter_data(v, idxfilter) = v -function filter_data!(plotattributes::KW, idxfilter) +function filter_data!(plotattributes::AKW, idxfilter) for s in (:x, :y, :z) plotattributes[s] = filter_data(get(plotattributes, s, nothing), idxfilter) end end -function _filter_input_data!(plotattributes::KW) +function _filter_input_data!(plotattributes::AKW) idxfilter = pop!(plotattributes, :idxfilter, nothing) if idxfilter !== nothing filter_data!(plotattributes, idxfilter) @@ -1200,7 +1200,7 @@ function warnOnUnsupported(pkg::AbstractBackend, plotattributes) end end -function warnOnUnsupported_scales(pkg::AbstractBackend, plotattributes::KW) +function warnOnUnsupported_scales(pkg::AbstractBackend, plotattributes::AKW) for k in (:xscale, :yscale, :zscale, :scale) if haskey(plotattributes, k) v = plotattributes[k] @@ -1267,7 +1267,7 @@ end # # if the value is `:match` then we take whatever match_color is. # # this is mainly used for cascading defaults for foreground and background colors -# function color_or_match!(plotattributes::KW, k::Symbol, match_color) +# function color_or_match!(plotattributes::AKW, k::Symbol, match_color) # v = plotattributes[k] # plotattributes[k] = if v == :match # match_color diff --git a/src/axes.jl b/src/axes.jl index 0b97e8c2..702ff5ba 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -32,7 +32,7 @@ function get_axis(sp::Subplot, letter::Symbol) end::Axis end -function process_axis_arg!(plotattributes::KW, arg, letter = "") +function process_axis_arg!(plotattributes::AKW, arg, letter = "") T = typeof(arg) arg = get(_scaleAliases, arg, arg) diff --git a/src/layouts.jl b/src/layouts.jl index 46ef19e7..941663ca 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -616,7 +616,7 @@ end # ---------------------------------------------------------------------- # @layout macro -function add_layout_pct!(kw::KW, v::Expr, idx::Integer, nidx::Integer) +function add_layout_pct!(kw::AKW, v::Expr, idx::Integer, nidx::Integer) # dump(v) # something like {0.2w}? if v.head == :call && v.args[1] == :* @@ -637,7 +637,7 @@ function add_layout_pct!(kw::KW, v::Expr, idx::Integer, nidx::Integer) error("Couldn't match layout curly (idx=$idx): $v") end -function add_layout_pct!(kw::KW, v::Number, idx::Integer) +function add_layout_pct!(kw::AKW, v::Number, idx::Integer) # kw[idx == 1 ? :w : :h] = v*pct idx == 1 && (kw[:w] = v*pct) (idx == 2 || nidx == 1) && (kw[:h] = v*pct) diff --git a/src/pipeline.jl b/src/pipeline.jl index 463aa26c..693e0b56 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -3,11 +3,11 @@ # ------------------------------------------------------------------ # preprocessing -function series_idx(kw_list::AVec{KW}, kw::KW) +function series_idx(kw_list::AVec{KW}, kw::AKW) Int(kw[:series_plotindex]) - Int(kw_list[1][:series_plotindex]) + 1 end -function _expand_seriestype_array(plotattributes::KW, args) +function _expand_seriestype_array(plotattributes::AKW, args) sts = get(plotattributes, :seriestype, :path) if typeof(sts) <: AbstractArray delete!(plotattributes, :seriestype) @@ -23,7 +23,7 @@ function _expand_seriestype_array(plotattributes::KW, args) end end -function _preprocess_args(plotattributes::KW, args, still_to_process::Vector{RecipeData}) +function _preprocess_args(plotattributes::AKW, args, still_to_process::Vector{RecipeData}) # the grouping mechanism is a recipe on a GroupBy object # we simply add the GroupBy object to the front of the args list to allow # the recipe to be applied @@ -59,7 +59,7 @@ end # user recipes -function _process_userrecipes(plt::Plot, plotattributes::KW, args) +function _process_userrecipes(plt::Plot, plotattributes::AKW, args) still_to_process = RecipeData[] args = _preprocess_args(plotattributes, args, still_to_process) @@ -110,7 +110,7 @@ function _process_userrecipe(plt::Plot, kw_list::Vector{KW}, recipedata::RecipeD return end -function _preprocess_userrecipe(kw::KW) +function _preprocess_userrecipe(kw::AKW) _add_markershape(kw) # if there was a grouping, filter the data here @@ -134,7 +134,7 @@ function _preprocess_userrecipe(kw::KW) return end -function _add_errorbar_kw(kw_list::Vector{KW}, kw::KW) +function _add_errorbar_kw(kw_list::Vector{KW}, kw::AKW) # handle error bars by creating new recipedata data... these will have # the same recipedata index as the recipedata they are copied from for esym in (:xerror, :yerror) @@ -149,7 +149,7 @@ function _add_errorbar_kw(kw_list::Vector{KW}, kw::KW) end end -function _add_smooth_kw(kw_list::Vector{KW}, kw::KW) +function _add_smooth_kw(kw_list::Vector{KW}, kw::AKW) # handle smoothing by adding a new series if get(kw, :smooth, false) x, y = kw[:x], kw[:y] @@ -174,7 +174,7 @@ end # to generate a list of RecipeData objects (data + attributes). # If we applied a "plot recipe" without error, then add the returned datalist's KWs, # otherwise we just add the original KW. -function _process_plotrecipe(plt::Plot, kw::KW, kw_list::Vector{KW}, still_to_process::Vector{KW}) +function _process_plotrecipe(plt::Plot, kw::AKW, kw_list::Vector{KW}, still_to_process::Vector{KW}) if !isa(get(kw, :seriestype, nothing), Symbol) # seriestype was never set, or it's not a Symbol, so it can't be a plot recipe push!(kw_list, kw) @@ -205,7 +205,7 @@ end # ------------------------------------------------------------------ # setup plot and subplot -function _plot_setup(plt::Plot, plotattributes::KW, kw_list::Vector{KW}) +function _plot_setup(plt::Plot, plotattributes::AKW, kw_list::Vector{KW}) # merge in anything meant for the Plot for kw in kw_list, (k,v) in kw haskey(_plot_defaults, k) && (plotattributes[k] = pop!(kw, k)) @@ -254,7 +254,7 @@ function _plot_setup(plt::Plot, plotattributes::KW, kw_list::Vector{KW}) plt[:inset_subplots] = nothing end -function _subplot_setup(plt::Plot, plotattributes::KW, kw_list::Vector{KW}) +function _subplot_setup(plt::Plot, plotattributes::AKW, kw_list::Vector{KW}) # we'll keep a map of subplot to an attribute override dict. # Subplot/Axis attributes set by a user/series recipe apply only to the # Subplot object which they belong to. diff --git a/src/plot.jl b/src/plot.jl index 1a7ddabb..7bd16693 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -163,7 +163,7 @@ end # this is the core plotting function. recursively apply recipes to build # a list of series KW dicts. # note: at entry, we only have those preprocessed args which were passed in... no default values yet -function _plot!(plt::Plot, plotattributes::KW, args::Tuple) +function _plot!(plt::Plot, plotattributes::AKW, args::Tuple) plotattributes[:plot_object] = plt if !isempty(args) && !isdefined(Main, :StatsPlots) && diff --git a/src/recipes.jl b/src/recipes.jl index 06215cd2..89343fd5 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -47,7 +47,7 @@ end num_series(x::AMat) = size(x,2) num_series(x) = 1 -RecipesBase.apply_recipe(plotattributes::KW, ::Type{T}, plt::AbstractPlot) where {T} = throw(MethodError(T, "Unmatched plot recipe: $T")) +RecipesBase.apply_recipe(plotattributes::AKW, ::Type{T}, plt::AbstractPlot) where {T} = throw(MethodError(T, "Unmatched plot recipe: $T")) # --------------------------------------------------------------------------- @@ -813,7 +813,7 @@ end # --------------------------------------------------------------------------- # Error Bars -function error_style!(plotattributes::KW) +function error_style!(plotattributes::AKW) plotattributes[:seriestype] = :path plotattributes[:linecolor] = plotattributes[:markerstrokecolor] plotattributes[:linewidth] = plotattributes[:markerstrokewidth] @@ -874,8 +874,8 @@ end # --------------------------------------------------------------------------- # quiver -# function apply_series_recipe(plotattributes::KW, ::Type{Val{:quiver}}) -function quiver_using_arrows(plotattributes::KW) +# function apply_series_recipe(plotattributes::AKW, ::Type{Val{:quiver}}) +function quiver_using_arrows(plotattributes::AKW) plotattributes[:label] = "" plotattributes[:seriestype] = :path if !isa(plotattributes[:arrow], Arrow) @@ -913,8 +913,8 @@ function quiver_using_arrows(plotattributes::KW) # KW[plotattributes] end -# function apply_series_recipe(plotattributes::KW, ::Type{Val{:quiver}}) -function quiver_using_hack(plotattributes::KW) +# function apply_series_recipe(plotattributes::AKW, ::Type{Val{:quiver}}) +function quiver_using_hack(plotattributes::AKW) plotattributes[:label] = "" plotattributes[:seriestype] = :shape @@ -959,7 +959,7 @@ function quiver_using_hack(plotattributes::KW) # KW[plotattributes] end -# function apply_series_recipe(plotattributes::KW, ::Type{Val{:quiver}}) +# function apply_series_recipe(plotattributes::AKW, ::Type{Val{:quiver}}) @recipe function f(::Type{Val{:quiver}}, x, y, z) if :arrow in supported_attrs() quiver_using_arrows(plotattributes) diff --git a/src/series.jl b/src/series.jl index 7ac9838a..6726de71 100644 --- a/src/series.jl +++ b/src/series.jl @@ -267,7 +267,7 @@ end # # -------------------------------------------------------------------- # helper function to ensure relevant attributes are wrapped by Surface -function wrap_surfaces(plotattributes::KW) +function wrap_surfaces(plotattributes::AKW) if haskey(plotattributes, :fill_z) v = plotattributes[:fill_z] if !isa(v, Surface) diff --git a/src/themes.jl b/src/themes.jl index 4f47039b..3b812ee8 100644 --- a/src/themes.jl +++ b/src/themes.jl @@ -8,7 +8,7 @@ function theme(s::Symbol; kw...) _theme(s, defaults; kw...) end -function _theme(s::Symbol, defaults::KW; kw...) +function _theme(s::Symbol, defaults::AKW; kw...) # Reset to defaults to overwrite active theme reset_defaults() diff --git a/src/utils.jl b/src/utils.jl index dd0e139b..c8c6bc62 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -129,7 +129,7 @@ function replace_image_with_heatmap(z::Array{T}) where T<:Colorant # newz, ColorGradient(colors) end -function imageHack(plotattributes::KW) +function imageHack(plotattributes::AKW) is_seriestype_supported(:heatmap) || error("Neither :image or :heatmap are supported!") plotattributes[:seriestype] = :heatmap plotattributes[:z], plotattributes[:fillcolor] = replace_image_with_heatmap(plotattributes[:z].surf) @@ -499,7 +499,7 @@ function make_fillrange_side(y, rib) end # turn a ribbon into a fillrange -function make_fillrange_from_ribbon(kw::KW) +function make_fillrange_from_ribbon(kw::AKW) y, rib = kw[:y], kw[:ribbon] rib = wraptuple(rib) rib1, rib2 = -first(rib), last(rib) @@ -842,8 +842,8 @@ function dumpdict(io::IO, plotattributes::AKW, prefix = "", alwaysshow = false) end println(io) end -DD(io::IO, plotattributes::KW, prefix = "") = dumpdict(io, plotattributes, prefix, true) -DD(plotattributes::KW, prefix = "") = DD(stdout, plotattributes, prefix) +DD(io::IO, plotattributes::AKW, prefix = "") = dumpdict(io, plotattributes, prefix, true) +DD(plotattributes::AKW, prefix = "") = DD(stdout, plotattributes, prefix) function dumpcallstack() error() # well... you wanted the stacktrace, didn't you?!? From 70d0d786e2f058f8bcb4a1a92d73ae6625c87876 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 8 Feb 2020 23:48:35 +0100 Subject: [PATCH 2/4] fix fg_color --- src/args.jl | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/args.jl b/src/args.jl index f44f97b7..231c143d 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1379,18 +1379,18 @@ Base.get(series::Series, k::Symbol, v) = get(series.plotattributes, k, v) # ----------------------------------------------------------------------------- -function fg_color(plotattributes::Attr) - fg = plotattributes[:foreground_color] +function fg_color(plotattributes::AKW) + fg = get(plotattributes, :foreground_color, :auto) if fg == :auto - bg = plot_color(plotattributes[:background_color]) + bg = plot_color(get(plotattributes, :background_color, :white)) fg = isdark(bg) ? colorant"white" : colorant"black" else plot_color(fg) end end -function fg_color_sp(plotattributes::Attr) - fgsp = plotattributes[:foreground_color_subplot] +function fg_color_sp(plotattributes::AWK) + fgsp = get(plotattributes, :foreground_color_subplot, :match) if fg == :match fg_color(plotattributes) else @@ -1402,11 +1402,9 @@ end # update attr from an input dictionary function _update_plot_args(plt::Plot, plotattributes_in::AKW) - # TODO do merged kws need to be removed from plotattributes_in? - merge!(plt.attr, plotattributes_in) - # for (k,v) in _plot_defaults - # slice_arg!(plotattributes_in, plt.attr, k, v, 1, true) - # end + for (k,v) in _plot_defaults + slice_arg!(plotattributes_in, plt.attr, k, 1, true) + end # handle colors plotattributes= plt.attr From 8554e632bdc57440ba6dc5a57f01c5d83533e15c Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 8 Feb 2020 23:49:50 +0100 Subject: [PATCH 3/4] more reset_kw!s --- src/pipeline.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pipeline.jl b/src/pipeline.jl index 693e0b56..1e9cd991 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -10,7 +10,7 @@ end function _expand_seriestype_array(plotattributes::AKW, args) sts = get(plotattributes, :seriestype, :path) if typeof(sts) <: AbstractArray - delete!(plotattributes, :seriestype) + reset_kw!(plotattributes, :seriestype) rd = Vector{RecipeData}(undef, size(sts, 1)) for r in axes(sts, 1) dc = copy(plotattributes) @@ -46,7 +46,7 @@ function _preprocess_args(plotattributes::AKW, args, still_to_process::Vector{Re _axis_defaults_byletter[:y], _axis_defaults_byletter[:z]) if haskey(defdict, k) - delete!(plotattributes, k) + reset_kw!(plotattributes, k) end end end From 31f54905172a1ccdc9bc0a369227894f9c9a2f62 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 8 Feb 2020 23:57:48 +0100 Subject: [PATCH 4/4] fix typo --- src/args.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index 231c143d..8c6b1f0a 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1389,7 +1389,7 @@ function fg_color(plotattributes::AKW) end end -function fg_color_sp(plotattributes::AWK) +function fg_color_sp(plotattributes::AKW) fgsp = get(plotattributes, :foreground_color_subplot, :match) if fg == :match fg_color(plotattributes)