added series_list to Subplot object to improve performance

This commit is contained in:
Thomas Breloff 2016-09-22 19:36:25 -04:00
parent c58de34e63
commit 755a70bf77
5 changed files with 20 additions and 14 deletions

View File

@ -1143,7 +1143,8 @@ function _add_defaults!(d::KW, plt::Plot, sp::Subplot, commandIndex::Int)
end end
# this is how many series belong to this subplot # this is how many series belong to this subplot
plotIndex = count(series -> series.d[:subplot] === sp && series.d[:primary], plt.series_list) # plotIndex = count(series -> series.d[:subplot] === sp && series.d[:primary], plt.series_list)
plotIndex = count(series -> series[:primary], sp.series_list)
if get(d, :primary, true) if get(d, :primary, true)
plotIndex += 1 plotIndex += 1
end end

View File

@ -684,9 +684,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end end
GR.restorestate() GR.restorestate()
# TODO: can we remove?
gr_set_font(xaxis[:tickfont]) gr_set_font(xaxis[:tickfont])
# GR.setcolormap(1000 + GR.COLORMAP_COOLWARM)
# this needs to be here to point the colormap to the right indices
GR.setcolormap(1000 + GR.COLORMAP_COOLWARM)
for (idx, series) in enumerate(series_list(sp)) for (idx, series) in enumerate(series_list(sp))
st = series[:seriestype] st = series[:seriestype]

View File

@ -355,11 +355,12 @@ function _expand_subplot_extrema(sp::Subplot, d::KW, st::Symbol)
end end
end end
function _add_the_series(plt, d) function _add_the_series(plt, sp, d)
warnOnUnsupported_args(plt.backend, d) warnOnUnsupported_args(plt.backend, d)
warnOnUnsupported(plt.backend, d) warnOnUnsupported(plt.backend, d)
series = Series(d) series = Series(d)
push!(plt.series_list, series) push!(plt.series_list, series)
push!(sp.series_list, series)
_series_added(plt, series) _series_added(plt, series)
end end
@ -382,7 +383,7 @@ function _process_seriesrecipe(plt::Plot, d::KW)
sp = _prepare_subplot(plt, d) sp = _prepare_subplot(plt, d)
_prepare_annotations(sp, d) _prepare_annotations(sp, d)
_expand_subplot_extrema(sp, d, st) _expand_subplot_extrema(sp, d, st)
_add_the_series(plt, d) _add_the_series(plt, sp, d)
else else
# get a sub list of series for this seriestype # get a sub list of series for this seriestype

View File

@ -3,6 +3,7 @@
function Subplot{T<:AbstractBackend}(::T; parent = RootLayout()) function Subplot{T<:AbstractBackend}(::T; parent = RootLayout())
Subplot{T}( Subplot{T}(
parent, parent,
Series[],
(20mm, 5mm, 2mm, 10mm), (20mm, 5mm, 2mm, 10mm),
defaultbox, defaultbox,
defaultbox, defaultbox,
@ -33,7 +34,7 @@ get_subplot(series::Series) = series.d[:subplot]
get_subplot_index(plt::Plot, idx::Integer) = Int(idx) get_subplot_index(plt::Plot, idx::Integer) = Int(idx)
get_subplot_index(plt::Plot, sp::Subplot) = findfirst(_ -> _ === sp, plt.subplots) get_subplot_index(plt::Plot, sp::Subplot) = findfirst(_ -> _ === sp, plt.subplots)
series_list(sp::Subplot) = filter(series -> series.d[:subplot] === sp, sp.plt.series_list) series_list(sp::Subplot) = sp.series_list # filter(series -> series.d[:subplot] === sp, sp.plt.series_list)
function should_add_to_legend(series::Series) function should_add_to_legend(series::Series)
series.d[:primary] && series.d[:label] != "" && series.d[:primary] && series.d[:label] != "" &&

View File

@ -21,11 +21,21 @@ wrap{T}(obj::T) = InputWrapper{T}(obj)
Base.isempty(wrapper::InputWrapper) = false Base.isempty(wrapper::InputWrapper) = false
# -----------------------------------------------------------
type Series
d::KW
end
attr(series::Series, k::Symbol) = series.d[k]
attr!(series::Series, v, k::Symbol) = (series.d[k] = v)
# ----------------------------------------------------------- # -----------------------------------------------------------
# a single subplot # a single subplot
type Subplot{T<:AbstractBackend} <: AbstractLayout type Subplot{T<:AbstractBackend} <: AbstractLayout
parent::AbstractLayout parent::AbstractLayout
series_list::Vector{Series} # arguments for each series
minpad::Tuple # leftpad, toppad, rightpad, bottompad minpad::Tuple # leftpad, toppad, rightpad, bottompad
bbox::BoundingBox # the canvas area which is available to this subplot bbox::BoundingBox # the canvas area which is available to this subplot
plotarea::BoundingBox # the part where the data goes plotarea::BoundingBox # the part where the data goes
@ -56,14 +66,6 @@ typealias SubplotMap Dict{Any, Subplot}
# ----------------------------------------------------------- # -----------------------------------------------------------
type Series
d::KW
end
attr(series::Series, k::Symbol) = series.d[k]
attr!(series::Series, v, k::Symbol) = (series.d[k] = v)
# -----------------------------------------------------------
type Plot{T<:AbstractBackend} <: AbstractPlot{T} type Plot{T<:AbstractBackend} <: AbstractPlot{T}
backend::T # the backend type backend::T # the backend type