a bunch of refactors

This commit is contained in:
Chris Rackauckas 2019-08-24 03:54:02 -04:00
parent db685b6ee0
commit 5a1fe30567
8 changed files with 591 additions and 554 deletions

View File

@ -879,9 +879,9 @@ function processFontArg!(plotattributes::KW, fontname::Symbol, arg)
end
end
_replace_markershape(shape::Symbol) = get(_markerAliases, shape, shape)
_replace_markershape(shapes::AVec) = map(_replace_markershape, shapes)
_replace_markershape(shape) = shape
@noinline _replace_markershape(shape::Symbol) = get(_markerAliases, shape, shape)
@noinline _replace_markershape(shapes::AVec) = map(_replace_markershape, shapes)
@noinline _replace_markershape(shape) = shape
function _add_markershape(plotattributes::KW)
# add the markershape if it needs to be added... hack to allow "m=10" to add a shape,

View File

@ -754,5 +754,5 @@ function axis_drawing_info(sp::Subplot)
end
end
xticks, yticks, xaxis_segs, yaxis_segs, xtick_segs, ytick_segs, xgrid_segs, ygrid_segs, xminorgrid_segs, yminorgrid_segs, xborder_segs, yborder_segs
Any[xticks, yticks, xaxis_segs, yaxis_segs, xtick_segs, ytick_segs, xgrid_segs, ygrid_segs, xminorgrid_segs, yminorgrid_segs, xborder_segs, yborder_segs]
end

View File

@ -47,17 +47,17 @@ end
# ---------------------------------------------------------
# don't do anything as a default
_create_backend_figure(plt::Plot) = nothing
_prepare_plot_object(plt::Plot) = nothing
_initialize_subplot(plt::Plot, sp::Subplot) = nothing
@noinline _create_backend_figure(plt::Plot) = nothing
@noinline _prepare_plot_object(plt::Plot) = nothing
@noinline _initialize_subplot(plt::Plot, sp::Subplot) = nothing
_series_added(plt::Plot, series::Series) = nothing
_series_updated(plt::Plot, series::Series) = nothing
@noinline _series_added(plt::Plot, series::Series) = nothing
@noinline _series_updated(plt::Plot, series::Series) = nothing
_before_layout_calcs(plt::Plot) = nothing
@noinline _before_layout_calcs(plt::Plot) = nothing
title_padding(sp::Subplot) = sp[:title] == "" ? 0mm : sp[:titlefontsize] * pt
guide_padding(axis::Axis) = axis[:guide] == "" ? 0mm : axis[:guidefontsize] * pt
@noinline title_padding(sp::Subplot) = sp[:title] == "" ? 0mm : sp[:titlefontsize] * pt
@noinline guide_padding(axis::Axis) = axis[:guide] == "" ? 0mm : axis[:guidefontsize] * pt
"Returns the (width,height) of a text label."
function text_size(lablen::Int, sz::Number, rot::Number = 0)
@ -123,7 +123,7 @@ function _update_min_padding!(sp::Subplot)
sp.minpad = (leftpad, toppad, rightpad, bottompad)
end
_update_plot_object(plt::Plot) = nothing
@noinline _update_plot_object(plt::Plot) = nothing
# ---------------------------------------------------------
@ -148,7 +148,7 @@ end
# ---------------------------------------------------------
_fallback_default_backend() = backend(GRBackend())
@noinline _fallback_default_backend() = backend(GRBackend())
function _pick_default_backend()
env_default = get(ENV, "PLOTS_DEFAULT_BACKEND", "")
@ -305,9 +305,8 @@ function _initialize_backend(pkg::AbstractBackend)
end
end
_initialize_backend(pkg::GRBackend) = nothing
_initialize_backend(pkg::PlotlyBackend) = nothing
@noinline _initialize_backend(pkg::GRBackend) = nothing
@noinline _initialize_backend(pkg::PlotlyBackend) = nothing
# ------------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

View File

@ -188,29 +188,29 @@ parent_bbox(layout::AbstractLayout) = bbox(parent(layout))
# padding_h(layout::AbstractLayout) = bottom_padding(layout) + top_padding(layout)
# padding(layout::AbstractLayout) = (padding_w(layout), padding_h(layout))
update_position!(layout::AbstractLayout) = nothing
update_child_bboxes!(layout::AbstractLayout, minimum_perimeter = [0mm,0mm,0mm,0mm]) = nothing
@noinline update_position!(layout::AbstractLayout) = nothing
@noinline update_child_bboxes!(layout::AbstractLayout, minimum_perimeter = [0mm,0mm,0mm,0mm]) = nothing
left(layout::AbstractLayout) = left(bbox(layout))
top(layout::AbstractLayout) = top(bbox(layout))
right(layout::AbstractLayout) = right(bbox(layout))
bottom(layout::AbstractLayout) = bottom(bbox(layout))
width(layout::AbstractLayout) = width(bbox(layout))
height(layout::AbstractLayout) = height(bbox(layout))
@noinline left(layout::AbstractLayout) = left(bbox(layout))
@noinline top(layout::AbstractLayout) = top(bbox(layout))
@noinline right(layout::AbstractLayout) = right(bbox(layout))
@noinline bottom(layout::AbstractLayout) = bottom(bbox(layout))
@noinline width(layout::AbstractLayout) = width(bbox(layout))
@noinline height(layout::AbstractLayout) = height(bbox(layout))
# pass these through to the bbox methods if there's no plotarea
plotarea(layout::AbstractLayout) = bbox(layout)
plotarea!(layout::AbstractLayout, bb::BoundingBox) = bbox!(layout, bb)
@noinline plotarea(layout::AbstractLayout) = bbox(layout)
@noinline plotarea!(layout::AbstractLayout, bb::BoundingBox) = bbox!(layout, bb)
attr(layout::AbstractLayout, k::Symbol) = layout.attr[k]
attr(layout::AbstractLayout, k::Symbol, v) = get(layout.attr, k, v)
attr!(layout::AbstractLayout, v, k::Symbol) = (layout.attr[k] = v)
hasattr(layout::AbstractLayout, k::Symbol) = haskey(layout.attr, k)
@noinline attr(layout::AbstractLayout, k::Symbol) = layout.attr[k]
@noinline attr(layout::AbstractLayout, k::Symbol, v) = get(layout.attr, k, v)
@noinline attr!(layout::AbstractLayout, v, k::Symbol) = (layout.attr[k] = v)
@noinline hasattr(layout::AbstractLayout, k::Symbol) = haskey(layout.attr, k)
leftpad(layout::AbstractLayout) = 0mm
toppad(layout::AbstractLayout) = 0mm
rightpad(layout::AbstractLayout) = 0mm
bottompad(layout::AbstractLayout) = 0mm
@noinline leftpad(layout::AbstractLayout) = 0mm
@noinline toppad(layout::AbstractLayout) = 0mm
@noinline rightpad(layout::AbstractLayout) = 0mm
@noinline bottompad(layout::AbstractLayout) = 0mm
# -----------------------------------------------------------
# RootLayout
@ -349,18 +349,18 @@ function update_child_bboxes!(layout::GridLayout, minimum_perimeter = [0mm,0mm,0
# # create a matrix for each minimum padding direction
# _update_min_padding!(layout)
minpad_left = map(leftpad, layout.grid)
minpad_top = map(toppad, layout.grid)
minpad_right = map(rightpad, layout.grid)
minpad_bottom = map(bottompad, layout.grid)
minpad_left::Matrix{AbsoluteLength} = map(leftpad, layout.grid)
minpad_top::Matrix{AbsoluteLength} = map(toppad, layout.grid)
minpad_right::Matrix{AbsoluteLength} = map(rightpad, layout.grid)
minpad_bottom::Matrix{AbsoluteLength} = map(bottompad, layout.grid)
# get the max horizontal (left and right) padding over columns,
# and max vertical (bottom and top) padding over rows
# TODO: add extra padding here
pad_left = maximum(minpad_left, dims = 1)
pad_top = maximum(minpad_top, dims = 2)
pad_right = maximum(minpad_right, dims = 1)
pad_bottom = maximum(minpad_bottom, dims = 2)
pad_left::Matrix{AbsoluteLength} = maximum(minpad_left, dims = 1)
pad_top::Matrix{AbsoluteLength} = maximum(minpad_top, dims = 2)
pad_right::Matrix{AbsoluteLength} = maximum(minpad_right, dims = 1)
pad_bottom::Matrix{AbsoluteLength} = maximum(minpad_bottom, dims = 2)
# make sure the perimeter match the parent
pad_left[1] = max(pad_left[1], minimum_perimeter[1])
@ -389,14 +389,14 @@ function update_child_bboxes!(layout::GridLayout, minimum_perimeter = [0mm,0mm,0
child = layout[r,c]
# get the top-left corner of this child... the first one is top-left of the parent (i.e. layout)
child_left = (c == 1 ? left(layout.bbox) : right(layout[r, c-1].bbox))
child_top = (r == 1 ? top(layout.bbox) : bottom(layout[r-1, c].bbox))
child_left::AbsoluteLength = (c == 1 ? left(layout.bbox) : right(layout[r, c-1].bbox))
child_top::AbsoluteLength = (r == 1 ? top(layout.bbox) : bottom(layout[r-1, c].bbox))
# compute plot area
plotarea_left = child_left + pad_left[c]
plotarea_top = child_top + pad_top[r]
plotarea_width = total_plotarea_horizontal * layout.widths[c]
plotarea_height = total_plotarea_vertical * layout.heights[r]
plotarea_left::AbsoluteLength = child_left + pad_left[c]
plotarea_top::AbsoluteLength = child_top + pad_top[r]
plotarea_width::AbsoluteLength = total_plotarea_horizontal * layout.widths[c]
plotarea_height::AbsoluteLength = total_plotarea_vertical * layout.heights[r]
plotarea!(child, BoundingBox(plotarea_left, plotarea_top, plotarea_width, plotarea_height))
# compute child bbox

View File

@ -228,7 +228,7 @@ closeall() = closeall(backend())
# ---------------------------------------------------------
# Atom PlotPane
# ---------------------------------------------------------
function showjuno(io::IO, m, plt)
@noinline function showjuno(io::IO, m, plt)
sz = plt[:size]
dpi = plt[:dpi]
thickness_scaling = plt[:thickness_scaling]
@ -250,7 +250,7 @@ function showjuno(io::IO, m, plt)
end
end
function _showjuno(io::IO, m::MIME"image/svg+xml", plt)
@noinline function _showjuno(io::IO, m::MIME"image/svg+xml", plt)
if Symbol(plt.attr[:html_output_format]) :svg
throw(MethodError(show, (typeof(m), typeof(plt))))
else
@ -258,4 +258,4 @@ function _showjuno(io::IO, m::MIME"image/svg+xml", plt)
end
end
_showjuno(io::IO, m, plt) = _show(io, m, plt)
@noinline _showjuno(io::IO, m, plt) = _show(io, m, plt)

View File

@ -23,7 +23,7 @@ end
end
end
function _preprocess_args(plotattributes::KW, args, still_to_process::Vector{RecipeData})
@noinline function _preprocess_args(plotattributes::KW, 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
@ -57,7 +57,7 @@ end
# user recipes
function _process_userrecipes(plt::Plot, plotattributes::KW, args)
@noinline function _process_userrecipes(plt::Plot, plotattributes::KW, args)
still_to_process = RecipeData[]
args = _preprocess_args(plotattributes, args, still_to_process)
@ -90,7 +90,7 @@ function _process_userrecipes(plt::Plot, plotattributes::KW, args)
kw_list
end
function _process_userrecipe(plt::Plot, kw_list::Vector{KW}, recipedata::RecipeData)
@noinline function _process_userrecipe(plt::Plot, kw_list::Vector{KW}, recipedata::RecipeData)
# when the arg tuple is empty, that means there's nothing left to recursively
# process... finish up and add to the kw_list
kw = recipedata.plotattributes
@ -108,7 +108,7 @@ function _process_userrecipe(plt::Plot, kw_list::Vector{KW}, recipedata::RecipeD
return
end
function _preprocess_userrecipe(kw::KW)
@noinline function _preprocess_userrecipe(kw::KW)
_add_markershape(kw)
# if there was a grouping, filter the data here
@ -302,7 +302,7 @@ end
# getting ready to add the series... last update to subplot from anything
# that might have been added during series recipes
function _prepare_subplot(plt::Plot{T}, plotattributes::KW) where T
@noinline function _prepare_subplot(plt::Plot{T}, plotattributes::KW) where T
st::Symbol = plotattributes[:seriestype]
sp::Subplot{T} = plotattributes[:subplot]
sp_idx = get_subplot_index(plt, sp)

View File

@ -16,7 +16,7 @@ Returns the Plot object for the current plot
end
CURRENT_PLOT.nullableplot
end
current(plot::AbstractPlot) = (CURRENT_PLOT.nullableplot = plot)
@noinline current(plot::AbstractPlot) = (CURRENT_PLOT.nullableplot = plot)
# ---------------------------------------------------------
@ -175,6 +175,7 @@ function _plot!(plt::Plot{T}, plotattributes::KW, args::Vector{Any}) where {T}
# "USER RECIPES"
# --------------------------------
# 1 second
kw_list = _process_userrecipes(plt, plotattributes, args)
# @info(1)
@ -189,6 +190,7 @@ function _plot!(plt::Plot{T}, plotattributes::KW, args::Vector{Any}) where {T}
# the plot layout is created, which allows for setting layouts and other plot-wide attributes.
# we get inputs which have been fully processed by "user recipes" and "type recipes",
# so we can expect standard vectors, surfaces, etc. No defaults have been set yet.
still_to_process = kw_list
kw_list = KW[]
while !isempty(still_to_process)
@ -203,11 +205,12 @@ function _plot!(plt::Plot{T}, plotattributes::KW, args::Vector{Any}) where {T}
# Plot/Subplot/Layout setup
# --------------------------------
# 2.5 seconds
_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. !!!
# !!! The next step is to recursively apply series recipes until the backend supports that series type !!!
@ -238,6 +241,7 @@ function _plot!(plt::Plot{T}, plotattributes::KW, args::Vector{Any}) where {T}
end
# --------------------------------
# 7 seconds
current(plt)
# do we want to force display?
@ -246,13 +250,13 @@ function _plot!(plt::Plot{T}, plotattributes::KW, args::Vector{Any}) where {T}
# end
_do_plot_show(plt, plt[:show])
plt
=#
end
# we're getting ready to display/output. prep for layout calcs, then update
# the plot object after
function prepare_output(plt::Plot)
@noinline function prepare_output(plt::Plot)
_before_layout_calcs(plt)
w, h = plt.attr[:size]
@ -273,9 +277,10 @@ function prepare_output(plt::Plot)
# the backend callback, to reposition subplots, etc
_update_plot_object(plt)
end
function backend_object(plt::Plot)
@noinline function backend_object(plt::Plot)
prepare_output(plt)
plt.o
end