start first time to plot investigation

This commit is contained in:
Chris Rackauckas 2019-08-21 09:02:10 -04:00
parent 648f26f075
commit 5dff00e2a3
6 changed files with 35 additions and 24 deletions

View File

@ -220,6 +220,7 @@ end
# --------------------------------------------------------- # ---------------------------------------------------------
const CURRENT_BACKEND = CurrentBackend(:none) const CURRENT_BACKEND = Plots.CurrentBackend(:gr)
gr()
end # module end # module

View File

@ -128,11 +128,23 @@ _update_plot_object(plt::Plot) = nothing
# --------------------------------------------------------- # ---------------------------------------------------------
mutable struct CurrentBackend mutable struct CurrentBackend{sym,T}
sym::Symbol pkg::T
pkg::AbstractBackend end
function CurrentBackend(sym::Symbol)
bkend = _backend_instance(sym)
CurrentBackend{sym,typeof(bkend)}(bkend)
end
function Base.getproperty(bkend::CurrentBackend{sym,T},x::Symbol) where {sym,T}
if x === :sym
return sym
elseif x === :pkg
return getfield(bkend,:pkg)
else
error("Must be sym or pkg")
end
end end
CurrentBackend(sym::Symbol) = CurrentBackend(sym, _backend_instance(sym))
# --------------------------------------------------------- # ---------------------------------------------------------
@ -177,8 +189,7 @@ function backend(pkg::AbstractBackend)
_initialize_backend(pkg) _initialize_backend(pkg)
push!(_initialized_backends, sym) push!(_initialized_backends, sym)
end end
CURRENT_BACKEND.sym = sym CURRENT_BACKEND = Plots.CurrentBackend(sym)
CURRENT_BACKEND.pkg = pkg
pkg pkg
end end

View File

@ -140,7 +140,7 @@ end
function Base.display(::PlotsDisplay, plt::Plot) function Base.display(::PlotsDisplay, plt::Plot)
prepare_output(plt) prepare_output(plt)
_display(plt) #_display(plt)
end end
_do_plot_show(plt, showval::Bool) = showval && gui(plt) _do_plot_show(plt, showval::Bool) = showval && gui(plt)

View File

@ -203,7 +203,7 @@ end
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# setup plot and subplot # setup plot and subplot
function _plot_setup(plt::Plot, plotattributes::KW, kw_list::Vector{KW}) function _plot_setup(plt::Plot{T}, plotattributes::KW, kw_list::Vector{KW}) where {T}
# merge in anything meant for the Plot # merge in anything meant for the Plot
for kw in kw_list, (k,v) in kw for kw in kw_list, (k,v) in kw
haskey(_plot_defaults, k) && (plotattributes[k] = pop!(kw, k)) haskey(_plot_defaults, k) && (plotattributes[k] = pop!(kw, k))
@ -252,18 +252,17 @@ function _plot_setup(plt::Plot, plotattributes::KW, kw_list::Vector{KW})
plt[:inset_subplots] = nothing plt[:inset_subplots] = nothing
end end
function _subplot_setup(plt::Plot, plotattributes::KW, kw_list::Vector{KW}) function _subplot_setup(plt::Plot{T}, plotattributes::KW, kw_list::Vector{KW}) where T
# we'll keep a map of subplot to an attribute override dict. # 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/Axis attributes set by a user/series recipe apply only to the
# Subplot object which they belong to. # Subplot object which they belong to.
# TODO: allow matrices to still apply to all subplots # TODO: allow matrices to still apply to all subplots
sp_attrs = Dict{Subplot,Any}() sp_attrs = Dict{Subplot{T},Any}()
for kw in kw_list for kw in kw_list
# get the Subplot object to which the series belongs. # get the Subplot object to which the series belongs.
sps = get(kw, :subplot, :auto) sps = get(kw, :subplot, :auto)
sp = get_subplot(plt, _cycle(sps == :auto ? plt.subplots : plt.subplots[sps], command_idx(kw_list,kw))) sp::Subplot{T} = get_subplot(plt, _cycle(sps == :auto ? plt.subplots : plt.subplots[sps], command_idx(kw_list,kw)))
kw[:subplot] = sp kw[:subplot] = sp
# extract subplot/axis attributes from kw and add to sp_attr # extract subplot/axis attributes from kw and add to sp_attr
attr = KW() attr = KW()
for (k,v) in collect(kw) for (k,v) in collect(kw)

View File

@ -50,7 +50,6 @@ 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
plotattributes = KW(kw) plotattributes = KW(kw)
preprocessArgs!(plotattributes) preprocessArgs!(plotattributes)
# create an empty Plot then process # create an empty Plot then process
plt = Plot() plt = Plot()
# plt.user_attr = plotattributes # plt.user_attr = plotattributes
@ -163,7 +162,7 @@ end
# this is the core plotting function. recursively apply recipes to build # this is the core plotting function. recursively apply recipes to build
# 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{T}, plotattributes::KW, args::Tuple) where {T}
plotattributes[:plot_object] = plt plotattributes[:plot_object] = plt
if !isempty(args) && !isdefined(Main, :StatsPlots) && if !isempty(args) && !isdefined(Main, :StatsPlots) &&
@ -202,7 +201,10 @@ function _plot!(plt::Plot, plotattributes::KW, args::Tuple)
# -------------------------------- # --------------------------------
# Plot/Subplot/Layout setup # Plot/Subplot/Layout setup
# -------------------------------- # --------------------------------
_plot_setup(plt, plotattributes, kw_list) _plot_setup(plt, plotattributes, kw_list)
# 6 seconds
_subplot_setup(plt, plotattributes, 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. !!!
@ -216,7 +218,7 @@ function _plot!(plt::Plot, plotattributes::KW, args::Tuple)
# map(DD, kw_list) # map(DD, kw_list)
for kw in kw_list for kw in kw_list
sp::Subplot = kw[:subplot] sp::Subplot{T} = kw[:subplot]
# idx = get_subplot_index(plt, sp) # idx = get_subplot_index(plt, sp)
# # we update subplot args in case something like the color palatte is part of the recipe # # we update subplot args in case something like the color palatte is part of the recipe
@ -233,7 +235,6 @@ function _plot!(plt::Plot, plotattributes::KW, args::Tuple)
# be able to support step, bar, and histogram plots (and any recipes that use those components). # be able to support step, bar, and histogram plots (and any recipes that use those components).
_process_seriesrecipe(plt, kw) _process_seriesrecipe(plt, kw)
end end
# -------------------------------- # --------------------------------
current(plt) current(plt)
@ -243,7 +244,6 @@ function _plot!(plt::Plot, plotattributes::KW, args::Tuple)
# gui(plt) # gui(plt)
# end # end
_do_plot_show(plt, plt[:show]) _do_plot_show(plt, plt[:show])
plt plt
end end

View File

@ -71,17 +71,17 @@ mutable struct Plot{T<:AbstractBackend} <: AbstractPlot{T}
user_attr::KW # raw arg inputs (after aliases). these are used as the input dict in `_plot!` user_attr::KW # raw arg inputs (after aliases). these are used as the input dict in `_plot!`
series_list::Vector{Series} # arguments for each series series_list::Vector{Series} # arguments for each series
o # the backend's plot object o # the backend's plot object
subplots::Vector{Subplot} subplots::Vector{Subplot{T}}
spmap::SubplotMap # provide any label as a map to a subplot spmap::SubplotMap # provide any label as a map to a subplot
layout::AbstractLayout layout::AbstractLayout
inset_subplots::Vector{Subplot} # list of inset subplots inset_subplots::Vector{Subplot{T}} # list of inset subplots
init::Bool init::Bool
end end
function Plot() function Plot(_backend = CURRENT_BACKEND)
Plot(backend(), 0, KW(), KW(), Series[], nothing, Plot(_backend.pkg, 0, KW(), KW(), Series[], nothing,
Subplot[], SubplotMap(), EmptyLayout(), Subplot{typeof(_backend.pkg)}[], SubplotMap(), EmptyLayout(),
Subplot[], false) Subplot{typeof(_backend.pkg)}[], false)
end end
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------