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

View File

@ -128,11 +128,23 @@ _update_plot_object(plt::Plot) = nothing
# ---------------------------------------------------------
mutable struct CurrentBackend
sym::Symbol
pkg::AbstractBackend
mutable struct CurrentBackend{sym,T}
pkg::T
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
CurrentBackend(sym::Symbol) = CurrentBackend(sym, _backend_instance(sym))
# ---------------------------------------------------------
@ -177,8 +189,7 @@ function backend(pkg::AbstractBackend)
_initialize_backend(pkg)
push!(_initialized_backends, sym)
end
CURRENT_BACKEND.sym = sym
CURRENT_BACKEND.pkg = pkg
CURRENT_BACKEND = Plots.CurrentBackend(sym)
pkg
end

View File

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

View File

@ -203,7 +203,7 @@ end
# ------------------------------------------------------------------
# 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
for kw in kw_list, (k,v) in kw
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
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.
# Subplot/Axis attributes set by a user/series recipe apply only to the
# Subplot object which they belong to.
# 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
# get the Subplot object to which the series belongs.
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
# extract subplot/axis attributes from kw and add to sp_attr
attr = 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
plotattributes = KW(kw)
preprocessArgs!(plotattributes)
# create an empty Plot then process
plt = Plot()
# plt.user_attr = plotattributes
@ -163,7 +162,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{T}, plotattributes::KW, args::Tuple) where {T}
plotattributes[:plot_object] = plt
if !isempty(args) && !isdefined(Main, :StatsPlots) &&
@ -202,7 +201,10 @@ function _plot!(plt::Plot, plotattributes::KW, args::Tuple)
# --------------------------------
# Plot/Subplot/Layout setup
# --------------------------------
_plot_setup(plt, plotattributes, kw_list)
# 6 seconds
_subplot_setup(plt, plotattributes, kw_list)
# !!! 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)
for kw in kw_list
sp::Subplot = kw[:subplot]
sp::Subplot{T} = kw[:subplot]
# idx = get_subplot_index(plt, sp)
# # 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).
_process_seriesrecipe(plt, kw)
end
# --------------------------------
current(plt)
@ -243,7 +244,6 @@ function _plot!(plt::Plot, plotattributes::KW, args::Tuple)
# gui(plt)
# end
_do_plot_show(plt, plt[:show])
plt
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!`
series_list::Vector{Series} # arguments for each series
o # the backend's plot object
subplots::Vector{Subplot}
subplots::Vector{Subplot{T}}
spmap::SubplotMap # provide any label as a map to a subplot
layout::AbstractLayout
inset_subplots::Vector{Subplot} # list of inset subplots
inset_subplots::Vector{Subplot{T}} # list of inset subplots
init::Bool
end
function Plot()
Plot(backend(), 0, KW(), KW(), Series[], nothing,
Subplot[], SubplotMap(), EmptyLayout(),
Subplot[], false)
function Plot(_backend = CURRENT_BACKEND)
Plot(_backend.pkg, 0, KW(), KW(), Series[], nothing,
Subplot{typeof(_backend.pkg)}[], SubplotMap(), EmptyLayout(),
Subplot{typeof(_backend.pkg)}[], false)
end
# -----------------------------------------------------------------------