Merge pull request #2388 from daschw/akw
Some fixes for KW -> Attr transition
This commit is contained in:
commit
20a290792f
28
src/args.jl
28
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
|
||||
@ -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::AKW)
|
||||
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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -3,14 +3,14 @@
|
||||
# ------------------------------------------------------------------
|
||||
# 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)
|
||||
reset_kw!(plotattributes, :seriestype)
|
||||
rd = Vector{RecipeData}(undef, size(sts, 1))
|
||||
for r in axes(sts, 1)
|
||||
dc = copy(plotattributes)
|
||||
@ -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
|
||||
@ -46,7 +46,7 @@ function _preprocess_args(plotattributes::KW, args, still_to_process::Vector{Rec
|
||||
_axis_defaults_byletter[:y],
|
||||
_axis_defaults_byletter[:z])
|
||||
if haskey(defdict, k)
|
||||
delete!(plotattributes, k)
|
||||
reset_kw!(plotattributes, k)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -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.
|
||||
|
||||
@ -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) &&
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
@ -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?!?
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user