replace d -> plotattributes in the rest of the files

This commit is contained in:
Michael Krabbe Borregaard 2018-08-19 22:09:32 +02:00
parent 2873685517
commit 7590c133fd
5 changed files with 141 additions and 141 deletions

View File

@ -8,7 +8,7 @@
function Axis(sp::Subplot, letter::Symbol, args...; kw...) function Axis(sp::Subplot, letter::Symbol, args...; kw...)
# init with values from _plot_defaults # init with values from _plot_defaults
d = KW( plotattributes = KW(
:letter => letter, :letter => letter,
# :extrema => (Inf, -Inf), # :extrema => (Inf, -Inf),
:extrema => Extrema(), :extrema => Extrema(),
@ -22,14 +22,14 @@ function Axis(sp::Subplot, letter::Symbol, args...; kw...)
for (k,v) in _axis_defaults for (k,v) in _axis_defaults
lk = Symbol(letter, k) lk = Symbol(letter, k)
lv = _axis_defaults_byletter[lk] lv = _axis_defaults_byletter[lk]
d[k] = (lv == :match ? v : lv) plotattributes[k] = (lv == :match ? v : lv)
end end
# merge!(d, _axis_defaults) # merge!(plotattributes, _axis_defaults)
d[:discrete_values] = [] plotattributes[:discrete_values] = []
# update the defaults # update the defaults
attr!(Axis([sp], d), args...; kw...) attr!(Axis([sp], plotattributes), args...; kw...)
end end
function get_axis(sp::Subplot, letter::Symbol) function get_axis(sp::Subplot, letter::Symbol)
@ -41,45 +41,45 @@ function get_axis(sp::Subplot, letter::Symbol)
end::Axis end::Axis
end end
function process_axis_arg!(d::KW, arg, letter = "") function process_axis_arg!(plotattributes::KW, arg, letter = "")
T = typeof(arg) T = typeof(arg)
arg = get(_scaleAliases, arg, arg) arg = get(_scaleAliases, arg, arg)
if typeof(arg) <: Font if typeof(arg) <: Font
d[Symbol(letter,:tickfont)] = arg plotattributes[Symbol(letter,:tickfont)] = arg
d[Symbol(letter,:guidefont)] = arg plotattributes[Symbol(letter,:guidefont)] = arg
elseif arg in _allScales elseif arg in _allScales
d[Symbol(letter,:scale)] = arg plotattributes[Symbol(letter,:scale)] = arg
elseif arg in (:flip, :invert, :inverted) elseif arg in (:flip, :invert, :inverted)
d[Symbol(letter,:flip)] = true plotattributes[Symbol(letter,:flip)] = true
elseif T <: AbstractString elseif T <: AbstractString
d[Symbol(letter,:guide)] = arg plotattributes[Symbol(letter,:guide)] = arg
# xlims/ylims # xlims/ylims
elseif (T <: Tuple || T <: AVec) && length(arg) == 2 elseif (T <: Tuple || T <: AVec) && length(arg) == 2
sym = typeof(arg[1]) <: Number ? :lims : :ticks sym = typeof(arg[1]) <: Number ? :lims : :ticks
d[Symbol(letter,sym)] = arg plotattributes[Symbol(letter,sym)] = arg
# xticks/yticks # xticks/yticks
elseif T <: AVec elseif T <: AVec
d[Symbol(letter,:ticks)] = arg plotattributes[Symbol(letter,:ticks)] = arg
elseif arg == nothing elseif arg == nothing
d[Symbol(letter,:ticks)] = [] plotattributes[Symbol(letter,:ticks)] = []
elseif T <: Bool || arg in _allShowaxisArgs elseif T <: Bool || arg in _allShowaxisArgs
d[Symbol(letter,:showaxis)] = showaxis(arg, letter) plotattributes[Symbol(letter,:showaxis)] = showaxis(arg, letter)
elseif typeof(arg) <: Number elseif typeof(arg) <: Number
d[Symbol(letter,:rotation)] = arg plotattributes[Symbol(letter,:rotation)] = arg
elseif typeof(arg) <: Function elseif typeof(arg) <: Function
d[Symbol(letter,:formatter)] = arg plotattributes[Symbol(letter,:formatter)] = arg
elseif !handleColors!(d, arg, Symbol(letter, :foreground_color_axis)) elseif !handleColors!(plotattributes, arg, Symbol(letter, :foreground_color_axis))
@warn("Skipped $(letter)axis arg $arg") @warn("Skipped $(letter)axis arg $arg")
end end
@ -88,28 +88,28 @@ end
# update an Axis object with magic args and keywords # update an Axis object with magic args and keywords
function attr!(axis::Axis, args...; kw...) function attr!(axis::Axis, args...; kw...)
# first process args # first process args
d = axis.d plotattributes = axis.plotattributes
for arg in args for arg in args
process_axis_arg!(d, arg) process_axis_arg!(plotattributes, arg)
end end
# then override for any keywords... only those keywords that already exists in d # then override for any keywords... only those keywords that already exists in plotattributes
for (k,v) in kw for (k,v) in kw
if haskey(d, k) if haskey(plotattributes, k)
if k == :discrete_values if k == :discrete_values
# add these discrete values to the axis # add these discrete values to the axis
for vi in v for vi in v
discrete_value!(axis, vi) discrete_value!(axis, vi)
end end
else else
d[k] = v plotattributes[k] = v
end end
end end
end end
# replace scale aliases # replace scale aliases
if haskey(_scaleAliases, d[:scale]) if haskey(_scaleAliases, plotattributes[:scale])
d[:scale] = _scaleAliases[d[:scale]] plotattributes[:scale] = _scaleAliases[plotattributes[:scale]]
end end
axis axis
@ -117,10 +117,10 @@ end
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
Base.show(io::IO, axis::Axis) = dumpdict(axis.d, "Axis", true) Base.show(io::IO, axis::Axis) = dumpdict(axis.plotattributes, "Axis", true)
# Base.getindex(axis::Axis, k::Symbol) = getindex(axis.d, k) # Base.getindex(axis::Axis, k::Symbol) = getindex(axis.plotattributes, k)
Base.setindex!(axis::Axis, v, ks::Symbol...) = setindex!(axis.d, v, ks...) Base.setindex!(axis::Axis, v, ks::Symbol...) = setindex!(axis.plotattributes, v, ks...)
Base.haskey(axis::Axis, k::Symbol) = haskey(axis.d, k) Base.haskey(axis::Axis, k::Symbol) = haskey(axis.plotattributes, k)
ignorenan_extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) ignorenan_extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax))
@ -290,9 +290,9 @@ function get_minor_ticks(axis,ticks)
axis[:minorticks] in (nothing, false) && !axis[:minorgrid] && return nothing axis[:minorticks] in (nothing, false) && !axis[:minorgrid] && return nothing
ticks = ticks[1] ticks = ticks[1]
length(ticks) < 2 && return nothing length(ticks) < 2 && return nothing
amin, amax = axis_limits(axis) amin, amax = axis_limits(axis)
#Add one phantom tick either side of the ticks to ensure minor ticks extend to the axis limits #Add one phantom tick either side of the ticks to ensure minor ticks extend to the axis limits
if length(ticks) > 2 if length(ticks) > 2
ratio = (ticks[3] - ticks[2])/(ticks[2] - ticks[1]) ratio = (ticks[3] - ticks[2])/(ticks[2] - ticks[1])
elseif axis[:scale] == :none elseif axis[:scale] == :none
@ -322,7 +322,7 @@ function reset_extrema!(sp::Subplot)
sp[Symbol(asym,:axis)][:extrema] = Extrema() sp[Symbol(asym,:axis)][:extrema] = Extrema()
end end
for series in sp.series_list for series in sp.series_list
expand_extrema!(sp, series.d) expand_extrema!(sp, series.plotattributes)
end end
end end
@ -357,17 +357,17 @@ function expand_extrema!(axis::Axis, v::AVec{N}) where N<:Number
end end
function expand_extrema!(sp::Subplot, d::KW) function expand_extrema!(sp::Subplot, plotattributes::KW)
vert = isvertical(d) vert = isvertical(plotattributes)
# first expand for the data # first expand for the data
for letter in (:x, :y, :z) for letter in (:x, :y, :z)
data = d[if vert data = plotattributes[if vert
letter letter
else else
letter == :x ? :y : letter == :y ? :x : :z letter == :x ? :y : letter == :y ? :x : :z
end] end]
if letter != :z && d[:seriestype] == :straightline && any(series[:seriestype] != :straightline for series in series_list(sp)) && data[1] != data[2] if letter != :z && plotattributes[:seriestype] == :straightline && any(series[:seriestype] != :straightline for series in series_list(sp)) && data[1] != data[2]
data = [NaN] data = [NaN]
end end
axis = sp[Symbol(letter, "axis")] axis = sp[Symbol(letter, "axis")]
@ -379,30 +379,30 @@ function expand_extrema!(sp::Subplot, d::KW)
elseif eltype(data) <: Number || (isa(data, Surface) && all(di -> isa(di, Number), data.surf)) elseif eltype(data) <: Number || (isa(data, Surface) && all(di -> isa(di, Number), data.surf))
if !(eltype(data) <: Number) if !(eltype(data) <: Number)
# huh... must have been a mis-typed surface? lets swap it out # huh... must have been a mis-typed surface? lets swap it out
data = d[letter] = Surface(Matrix{Float64}(data.surf)) data = plotattributes[letter] = Surface(Matrix{Float64}(data.surf))
end end
expand_extrema!(axis, data) expand_extrema!(axis, data)
elseif data != nothing elseif data != nothing
# TODO: need more here... gotta track the discrete reference value # TODO: need more here... gotta track the discrete reference value
# as well as any coord offset (think of boxplot shape coords... they all # as well as any coord offset (think of boxplot shape coords... they all
# correspond to the same x-value) # correspond to the same x-value)
d[letter], d[Symbol(letter,"_discrete_indices")] = discrete_value!(axis, data) plotattributes[letter], plotattributes[Symbol(letter,"_discrete_indices")] = discrete_value!(axis, data)
expand_extrema!(axis, d[letter]) expand_extrema!(axis, plotattributes[letter])
end end
end end
# # expand for fillrange/bar_width # # expand for fillrange/bar_width
# fillaxis, baraxis = sp.attr[:yaxis], sp.attr[:xaxis] # fillaxis, baraxis = sp.attr[:yaxis], sp.attr[:xaxis]
# if isvertical(d) # if isvertical(plotattributes)
# fillaxis, baraxis = baraxis, fillaxis # fillaxis, baraxis = baraxis, fillaxis
# end # end
# expand for fillrange # expand for fillrange
fr = d[:fillrange] fr = plotattributes[:fillrange]
if fr == nothing && d[:seriestype] == :bar if fr == nothing && plotattributes[:seriestype] == :bar
fr = 0.0 fr = 0.0
end end
if fr != nothing && !all3D(d) if fr != nothing && !all3D(plotattributes)
axis = sp.attr[vert ? :yaxis : :xaxis] axis = sp.attr[vert ? :yaxis : :xaxis]
if typeof(fr) <: Tuple if typeof(fr) <: Tuple
for fri in fr for fri in fr
@ -414,13 +414,13 @@ function expand_extrema!(sp::Subplot, d::KW)
end end
# expand for bar_width # expand for bar_width
if d[:seriestype] == :bar if plotattributes[:seriestype] == :bar
dsym = vert ? :x : :y dsym = vert ? :x : :y
data = d[dsym] data = plotattributes[dsym]
bw = d[:bar_width] bw = plotattributes[:bar_width]
if bw == nothing if bw == nothing
bw = d[:bar_width] = _bar_width * ignorenan_minimum(filter(x->x>0,diff(sort(data)))) bw = plotattributes[:bar_width] = _bar_width * ignorenan_minimum(filter(x->x>0,diff(sort(data))))
end end
axis = sp.attr[Symbol(dsym, :axis)] axis = sp.attr[Symbol(dsym, :axis)]
expand_extrema!(axis, ignorenan_maximum(data) + 0.5maximum(bw)) expand_extrema!(axis, ignorenan_maximum(data) + 0.5maximum(bw))
@ -428,11 +428,11 @@ function expand_extrema!(sp::Subplot, d::KW)
end end
# expand for heatmaps # expand for heatmaps
if d[:seriestype] == :heatmap if plotattributes[:seriestype] == :heatmap
for letter in (:x, :y) for letter in (:x, :y)
data = d[letter] data = plotattributes[letter]
axis = sp[Symbol(letter, "axis")] axis = sp[Symbol(letter, "axis")]
scale = get(d, Symbol(letter, "scale"), :identity) scale = get(plotattributes, Symbol(letter, "scale"), :identity)
expand_extrema!(axis, heatmap_edges(data, scale)) expand_extrema!(axis, heatmap_edges(data, scale))
end end
end end
@ -462,7 +462,7 @@ function default_should_widen(axis::Axis)
if !is_2tuple(axis[:lims]) if !is_2tuple(axis[:lims])
for sp in axis.sps for sp in axis.sps
for series in series_list(sp) for series in series_list(sp)
if series.d[:seriestype] in _widen_seriestypes if series.plotattributes[:seriestype] in _widen_seriestypes
should_widen = true should_widen = true
end end
end end
@ -572,12 +572,12 @@ end
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
function pie_labels(sp::Subplot, series::Series) function pie_labels(sp::Subplot, series::Series)
d = series.d plotattributes = series.plotattributes
if haskey(d,:x_discrete_indices) if haskey(plotattributes,:x_discrete_indices)
dvals = sp.attr[:xaxis].d[:discrete_values] dvals = sp.attr[:xaxis].plotattributes[:discrete_values]
[dvals[idx] for idx in d[:x_discrete_indices]] [dvals[idx] for idx in plotattributes[:x_discrete_indices]]
else else
d[:x] plotattributes[:x]
end end
end end

View File

@ -7,7 +7,7 @@
const FuncOrFuncs = Union{Function, AVec{Function}} const FuncOrFuncs = Union{Function, AVec{Function}}
all3D(plotattributes::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image), get(d, :seriestype, :none)) all3D(plotattributes::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image), get(plotattributes, :seriestype, :none))
# missing # missing
convertToAnyVector(v::Nothing, plotattributes::KW) = Any[nothing], nothing convertToAnyVector(v::Nothing, plotattributes::KW) = Any[nothing], nothing
@ -22,7 +22,7 @@ convertToAnyVector(v::AVec{T}, plotattributes::KW) where {T<:Number} = Any[v], n
convertToAnyVector(v::AVec{T}, plotattributes::KW) where {T<:AbstractString} = Any[v], nothing convertToAnyVector(v::AVec{T}, plotattributes::KW) where {T<:AbstractString} = Any[v], nothing
function convertToAnyVector(v::AMat, plotattributes::KW) function convertToAnyVector(v::AMat, plotattributes::KW)
if all3D(d) if all3D(plotattributes)
Any[Surface(v)] Any[Surface(v)]
else else
Any[v[:,i] for i in 1:size(v,2)] Any[v[:,i] for i in 1:size(v,2)]
@ -48,7 +48,7 @@ function convertToAnyVector(v::AVec, plotattributes::KW)
Any[convert(Vector{Float64}, v)], nothing Any[convert(Vector{Float64}, v)], nothing
else else
# something else... treat each element as an item # something else... treat each element as an item
vcat(Any[convertToAnyVector(vi, d)[1] for vi in v]...), nothing vcat(Any[convertToAnyVector(vi, plotattributes)[1] for vi in v]...), nothing
# Any[vi for vi in v], nothing # Any[vi for vi in v], nothing
end end
end end

View File

@ -465,11 +465,11 @@ end
# pass the layout arg through # pass the layout arg through
function layout_args(plotattributes::KW) function layout_args(plotattributes::KW)
layout_args(get(d, :layout, default(:layout))) layout_args(get(plotattributes, :layout, default(:layout)))
end end
function layout_args(plotattributes::KW, n_override::Integer) function layout_args(plotattributes::KW, n_override::Integer)
layout, n = layout_args(get(d, :layout, n_override)) layout, n = layout_args(get(plotattributes, :layout, n_override))
if n != n_override if n != n_override
error("When doing layout, n ($n) != n_override ($(n_override)). You're probably trying to force existing plots into a layout that doesn't fit them.") error("When doing layout, n ($n) != n_override ($(n_override)). You're probably trying to force existing plots into a layout that doesn't fit them.")
end end

View File

@ -48,20 +48,20 @@ as a String to look up its docstring; e.g. `plotattr("seriestype")`.
""" """
function plot(args...; kw...) function plot(args...; kw...)
# this creates a new plot with args/kw and sets it to be the current plot # this creates a new plot with args/kw and sets it to be the current plot
d = KW(kw) plotattributes = KW(kw)
preprocessArgs!(d) preprocessArgs!(plotattributes)
# create an empty Plot then process # create an empty Plot then process
plt = Plot() plt = Plot()
# plt.user_attr = d # plt.user_attr = plotattributes
_plot!(plt, d, args) _plot!(plt, plotattributes, args)
end end
# build a new plot from existing plots # build a new plot from existing plots
# note: we split into plt1 and plts_tail so we can dispatch correctly # note: we split into plt1 and plts_tail so we can dispatch correctly
function plot(plt1::Plot, plts_tail::Plot...; kw...) function plot(plt1::Plot, plts_tail::Plot...; kw...)
d = KW(kw) plotattributes = KW(kw)
preprocessArgs!(d) preprocessArgs!(plotattributes)
# build our plot vector from the args # build our plot vector from the args
n = length(plts_tail) + 1 n = length(plts_tail) + 1
@ -72,7 +72,7 @@ function plot(plt1::Plot, plts_tail::Plot...; kw...)
end end
# compute the layout # compute the layout
layout = layout_args(d, n)[1] layout = layout_args(plotattributes, n)[1]
num_sp = sum([length(p.subplots) for p in plts]) num_sp = sum([length(p.subplots) for p in plts])
# create a new plot object, with subplot list/map made of existing subplots. # create a new plot object, with subplot list/map made of existing subplots.
@ -83,21 +83,21 @@ function plot(plt1::Plot, plts_tail::Plot...; kw...)
# TODO: build the user_attr dict by creating "Any matrices" for the args of each subplot # TODO: build the user_attr dict by creating "Any matrices" for the args of each subplot
# TODO: replace this with proper processing from a merged user_attr KW # TODO: replace this with proper processing from a merged user_attr KW
# update plot args, first with existing plots, then override with d # update plot args, first with existing plots, then override with plotattributes
for p in plts for p in plts
_update_plot_args(plt, copy(p.attr)) _update_plot_args(plt, copy(p.attr))
plt.n += p.n plt.n += p.n
end end
_update_plot_args(plt, d) _update_plot_args(plt, plotattributes)
# pass new plot to the backend # pass new plot to the backend
plt.o = _create_backend_figure(plt) plt.o = _create_backend_figure(plt)
plt.init = true plt.init = true
series_attr = KW() series_attr = KW()
for (k,v) in d for (k,v) in plotattributes
if haskey(_series_defaults, k) if haskey(_series_defaults, k)
series_attr[k] = pop!(d,k) series_attr[k] = pop!(plotattributes,k)
end end
end end
@ -118,8 +118,8 @@ function plot(plt1::Plot, plts_tail::Plot...; kw...)
sp.plt = plt sp.plt = plt
sp.attr[:subplot_index] = idx sp.attr[:subplot_index] = idx
for series in serieslist for series in serieslist
merge!(series.d, series_attr) merge!(series.plotattributes, series_attr)
_add_defaults!(series.d, plt, sp, cmdidx) _add_defaults!(series.plotattributes, plt, sp, cmdidx)
push!(plt.series_list, series) push!(plt.series_list, series)
_series_added(plt, series) _series_added(plt, series)
cmdidx += 1 cmdidx += 1
@ -128,12 +128,12 @@ function plot(plt1::Plot, plts_tail::Plot...; kw...)
# first apply any args for the subplots # first apply any args for the subplots
for (idx,sp) in enumerate(plt.subplots) for (idx,sp) in enumerate(plt.subplots)
_update_subplot_args(plt, sp, d, idx, false) _update_subplot_args(plt, sp, plotattributes, idx, false)
end end
# finish up # finish up
current(plt) current(plt)
_do_plot_show(plt, get(d, :show, default(:show))) _do_plot_show(plt, get(plotattributes, :show, default(:show)))
plt plt
end end
@ -152,10 +152,10 @@ end
# this adds to a specific plot... most plot commands will flow through here # this adds to a specific plot... most plot commands will flow through here
function plot!(plt::Plot, args...; kw...) function plot!(plt::Plot, args...; kw...)
d = KW(kw) plotattributes = KW(kw)
preprocessArgs!(d) preprocessArgs!(plotattributes)
# merge!(plt.user_attr, d) # merge!(plt.user_attr, plotattributes)
_plot!(plt, d, args) _plot!(plt, plotattributes, args)
end end
# ------------------------------------------------------------------------------- # -------------------------------------------------------------------------------
@ -164,7 +164,7 @@ end
# a list of series KW dicts. # a list of series KW dicts.
# note: at entry, we only have those preprocessed args which were passed in... no default values yet # 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::KW, args::Tuple)
d[:plot_object] = plt plotattributes[:plot_object] = plt
if !isempty(args) && !isdefined(Main, :StatPlots) && if !isempty(args) && !isdefined(Main, :StatPlots) &&
first(split(string(typeof(args[1])), ".")) == "DataFrames" first(split(string(typeof(args[1])), ".")) == "DataFrames"
@ -175,7 +175,7 @@ function _plot!(plt::Plot, plotattributes::KW, args::Tuple)
# "USER RECIPES" # "USER RECIPES"
# -------------------------------- # --------------------------------
kw_list = _process_userrecipes(plt, d, args) kw_list = _process_userrecipes(plt, plotattributes, args)
# @info(1) # @info(1)
# map(DD, kw_list) # map(DD, kw_list)
@ -202,8 +202,8 @@ function _plot!(plt::Plot, plotattributes::KW, args::Tuple)
# -------------------------------- # --------------------------------
# Plot/Subplot/Layout setup # Plot/Subplot/Layout setup
# -------------------------------- # --------------------------------
_plot_setup(plt, d, kw_list) _plot_setup(plt, plotattributes, kw_list)
_subplot_setup(plt, d, kw_list) _subplot_setup(plt, plotattributes, kw_list)
# !!! note: At this point, kw_list is fully decomposed into individual series... one KW per series. !!! # !!! note: At this point, kw_list is fully decomposed into individual series... one KW per series. !!!
# !!! The next step is to recursively apply series recipes until the backend supports that series type !!! # !!! The next step is to recursively apply series recipes until the backend supports that series type !!!

View File

@ -19,15 +19,15 @@ A hacky replacement for a histogram when the backend doesn't support histograms
Convert it into a bar chart with the appropriate x/y values. Convert it into a bar chart with the appropriate x/y values.
""" """
function histogramHack(; kw...) function histogramHack(; kw...)
d = KW(kw) plotattributes = KW(kw)
# we assume that the y kwarg is set with the data to be binned, and nbins is also defined # we assume that the y kwarg is set with the data to be binned, and nbins is also defined
edges, midpoints, buckets, counts = binData(d[:y], d[:bins]) edges, midpoints, buckets, counts = binData(plotattributes[:y], plotattributes[:bins])
d[:x] = midpoints plotattributes[:x] = midpoints
d[:y] = float(counts) plotattributes[:y] = float(counts)
d[:seriestype] = :bar plotattributes[:seriestype] = :bar
d[:fillrange] = d[:fillrange] == nothing ? 0.0 : d[:fillrange] plotattributes[:fillrange] = plotattributes[:fillrange] == nothing ? 0.0 : plotattributes[:fillrange]
d plotattributes
end end
""" """
@ -35,10 +35,10 @@ A hacky replacement for a bar graph when the backend doesn't support bars direct
Convert it into a line chart with fillrange set. Convert it into a line chart with fillrange set.
""" """
function barHack(; kw...) function barHack(; kw...)
d = KW(kw) plotattributes = KW(kw)
midpoints = d[:x] midpoints = plotattributes[:x]
heights = d[:y] heights = plotattributes[:y]
fillrange = d[:fillrange] == nothing ? 0.0 : d[:fillrange] fillrange = plotattributes[:fillrange] == nothing ? 0.0 : plotattributes[:fillrange]
# estimate the edges # estimate the edges
dists = diff(midpoints) * 0.5 dists = diff(midpoints) * 0.5
@ -62,11 +62,11 @@ function barHack(; kw...)
append!(y, [fillrange, heights[i], heights[i], fillrange]) append!(y, [fillrange, heights[i], heights[i], fillrange])
end end
d[:x] = x plotattributes[:x] = x
d[:y] = y plotattributes[:y] = y
d[:seriestype] = :path plotattributes[:seriestype] = :path
d[:fillrange] = fillrange plotattributes[:fillrange] = fillrange
d plotattributes
end end
@ -75,33 +75,33 @@ A hacky replacement for a sticks graph when the backend doesn't support sticks d
Convert it into a line chart that traces the sticks, and a scatter that sets markers at the points. Convert it into a line chart that traces the sticks, and a scatter that sets markers at the points.
""" """
function sticksHack(; kw...) function sticksHack(; kw...)
dLine = KW(kw) plotattributesLine = KW(kw)
dScatter = copy(dLine) plotattributesScatter = copy(plotattributesLine)
# these are the line vertices # these are the line vertices
x = Float64[] x = Float64[]
y = Float64[] y = Float64[]
fillrange = dLine[:fillrange] == nothing ? 0.0 : dLine[:fillrange] fillrange = plotattributesLine[:fillrange] == nothing ? 0.0 : plotattributesLine[:fillrange]
# calculate the vertices # calculate the vertices
yScatter = dScatter[:y] yScatter = plotattributesScatter[:y]
for (i,xi) in enumerate(dScatter[:x]) for (i,xi) in enumerate(plotattributesScatter[:x])
yi = yScatter[i] yi = yScatter[i]
for j in 1:3 push!(x, xi) end for j in 1:3 push!(x, xi) end
append!(y, [fillrange, yScatter[i], fillrange]) append!(y, [fillrange, yScatter[i], fillrange])
end end
# change the line args # change the line args
dLine[:x] = x plotattributesLine[:x] = x
dLine[:y] = y plotattributesLine[:y] = y
dLine[:seriestype] = :path plotattributesLine[:seriestype] = :path
dLine[:markershape] = :none plotattributesLine[:markershape] = :none
dLine[:fillrange] = nothing plotattributesLine[:fillrange] = nothing
# change the scatter args # change the scatter args
dScatter[:seriestype] = :none plotattributesScatter[:seriestype] = :none
dLine, dScatter plotattributesLine, plotattributesScatter
end end
function regressionXY(x, y) function regressionXY(x, y)
@ -132,8 +132,8 @@ end
function imageHack(plotattributes::KW) function imageHack(plotattributes::KW)
is_seriestype_supported(:heatmap) || error("Neither :image or :heatmap are supported!") is_seriestype_supported(:heatmap) || error("Neither :image or :heatmap are supported!")
d[:seriestype] = :heatmap plotattributes[:seriestype] = :heatmap
d[:z], d[:fillcolor] = replace_image_with_heatmap(d[:z].surf) plotattributes[:z], plotattributes[:fillcolor] = replace_image_with_heatmap(plotattributes[:z].surf)
end end
# --------------------------------------------------------------- # ---------------------------------------------------------------
@ -330,14 +330,14 @@ end
function replaceAlias!(plotattributes::KW, k::Symbol, aliases::Dict{Symbol,Symbol}) function replaceAlias!(plotattributes::KW, k::Symbol, aliases::Dict{Symbol,Symbol})
if haskey(aliases, k) if haskey(aliases, k)
d[aliases[k]] = pop!(d, k) plotattributes[aliases[k]] = pop!(plotattributes, k)
end end
end end
function replaceAliases!(plotattributes::KW, aliases::Dict{Symbol,Symbol}) function replaceAliases!(plotattributes::KW, aliases::Dict{Symbol,Symbol})
ks = collect(keys(d)) ks = collect(keys(plotattributes))
for k in ks for k in ks
replaceAlias!(d, k, aliases) replaceAlias!(plotattributes, k, aliases)
end end
end end
@ -347,7 +347,7 @@ Base.first(c::Colorant) = c
Base.first(x::Symbol) = x Base.first(x::Symbol) = x
sortedkeys(d::Dict) = sort(collect(keys(d))) sortedkeys(plotattributes::Dict) = sort(collect(keys(plotattributes)))
const _scale_base = Dict{Symbol, Real}( const _scale_base = Dict{Symbol, Real}(
@ -432,8 +432,8 @@ isscalar(::Any) = false
is_2tuple(v) = typeof(v) <: Tuple && length(v) == 2 is_2tuple(v) = typeof(v) <: Tuple && length(v) == 2
isvertical(plotattributes::KW) = get(d, :orientation, :vertical) in (:vertical, :v, :vert) isvertical(plotattributes::KW) = get(plotattributes, :orientation, :vertical) in (:vertical, :v, :vert)
isvertical(series::Series) = isvertical(series.d) isvertical(series::Series) = isvertical(series.plotattributes)
ticksType(ticks::AVec{T}) where {T<:Real} = :ticks ticksType(ticks::AVec{T}) where {T<:Real} = :ticks
@ -492,8 +492,8 @@ end
# this is a helper function to determine whether we need to transpose a surface matrix. # this is a helper function to determine whether we need to transpose a surface matrix.
# it depends on whether the backend matches rows to x (transpose_on_match == true) or vice versa # it depends on whether the backend matches rows to x (transpose_on_match == true) or vice versa
# for example: PyPlot sends rows to y, so transpose_on_match should be true # for example: PyPlot sends rows to y, so transpose_on_match should be true
function transpose_z(d, z, transpose_on_match::Bool = true) function transpose_z(plotattributes, z, transpose_on_match::Bool = true)
if d[:match_dimensions] == transpose_on_match if plotattributes[:match_dimensions] == transpose_on_match
# z' # z'
permutedims(z, [2,1]) permutedims(z, [2,1])
else else
@ -812,14 +812,14 @@ function dumpdict(plotattributes::KW, prefix = "", alwaysshow = false)
if prefix != "" if prefix != ""
println(prefix, ":") println(prefix, ":")
end end
for k in sort(collect(keys(d))) for k in sort(collect(keys(plotattributes)))
@printf("%14s: ", k) @printf("%14s: ", k)
debugshow(d[k]) debugshow(plotattributes[k])
println() println()
end end
println() println()
end end
DD(plotattributes::KW, prefix = "") = dumpdict(d, prefix, true) DD(plotattributes::KW, prefix = "") = dumpdict(plotattributes, prefix, true)
function dumpcallstack() function dumpcallstack()
@ -845,25 +845,25 @@ tovec(v::AbstractVector) = v
tovec(v::Nothing) = zeros(0) tovec(v::Nothing) = zeros(0)
function getxy(plt::Plot, i::Integer) function getxy(plt::Plot, i::Integer)
d = plt.series_list[i].d plotattributes = plt.series_list[i].plotattributes
tovec(d[:x]), tovec(d[:y]) tovec(plotattributes[:x]), tovec(plotattributes[:y])
end end
function getxyz(plt::Plot, i::Integer) function getxyz(plt::Plot, i::Integer)
d = plt.series_list[i].d plotattributes = plt.series_list[i].plotattributes
tovec(d[:x]), tovec(d[:y]), tovec(d[:z]) tovec(plotattributes[:x]), tovec(plotattributes[:y]), tovec(plotattributes[:z])
end end
function setxy!(plt::Plot, xy::Tuple{X,Y}, i::Integer) where {X,Y} function setxy!(plt::Plot, xy::Tuple{X,Y}, i::Integer) where {X,Y}
series = plt.series_list[i] series = plt.series_list[i]
series.d[:x], series.d[:y] = xy series.plotattributes[:x], series.plotattributes[:y] = xy
sp = series.d[:subplot] sp = series.plotattributes[:subplot]
reset_extrema!(sp) reset_extrema!(sp)
_series_updated(plt, series) _series_updated(plt, series)
end end
function setxyz!(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) where {X,Y,Z} function setxyz!(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) where {X,Y,Z}
series = plt.series_list[i] series = plt.series_list[i]
series.d[:x], series.d[:y], series.d[:z] = xyz series.plotattributes[:x], series.plotattributes[:y], series.plotattributes[:z] = xyz
sp = series.d[:subplot] sp = series.plotattributes[:subplot]
reset_extrema!(sp) reset_extrema!(sp)
_series_updated(plt, series) _series_updated(plt, series)
end end
@ -912,9 +912,9 @@ Base.push!(series::Series, xi, yi, zi) = (push_x!(series,xi); push_y!(series,yi)
# ------------------------------------------------------- # -------------------------------------------------------
function attr!(series::Series; kw...) function attr!(series::Series; kw...)
d = KW(kw) plotattributes = KW(kw)
preprocessArgs!(d) preprocessArgs!(plotattributes)
for (k,v) in d for (k,v) in plotattributes
if haskey(_series_defaults, k) if haskey(_series_defaults, k)
series[k] = v series[k] = v
else else
@ -926,9 +926,9 @@ function attr!(series::Series; kw...)
end end
function attr!(sp::Subplot; kw...) function attr!(sp::Subplot; kw...)
d = KW(kw) plotattributes = KW(kw)
preprocessArgs!(d) preprocessArgs!(plotattributes)
for (k,v) in d for (k,v) in plotattributes
if haskey(_subplot_defaults, k) if haskey(_subplot_defaults, k)
sp[k] = v sp[k] = v
else else
@ -1057,9 +1057,9 @@ mm2px(mm::Real) = float(px / MM_PER_PX)
"Smallest x in plot" "Smallest x in plot"
xmin(plt::Plot) = ignorenan_minimum([ignorenan_minimum(series.d[:x]) for series in plt.series_list]) xmin(plt::Plot) = ignorenan_minimum([ignorenan_minimum(series.plotattributes[:x]) for series in plt.series_list])
"Largest x in plot" "Largest x in plot"
xmax(plt::Plot) = ignorenan_maximum([ignorenan_maximum(series.d[:x]) for series in plt.series_list]) xmax(plt::Plot) = ignorenan_maximum([ignorenan_maximum(series.plotattributes[:x]) for series in plt.series_list])
"Extrema of x-values in plot" "Extrema of x-values in plot"
ignorenan_extrema(plt::Plot) = (xmin(plt), xmax(plt)) ignorenan_extrema(plt::Plot) = (xmin(plt), xmax(plt))