working on subplots
This commit is contained in:
parent
7917397bf3
commit
51e8f3ff6e
File diff suppressed because one or more lines are too long
@ -250,20 +250,6 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
|
||||
push!(gfargs, Gadfly.Geom.ribbon)
|
||||
end
|
||||
|
||||
# # fillto and ribbon
|
||||
# yminmax = Any[]
|
||||
# fillto, ribbon = d[:fill], d[:ribbon]
|
||||
|
||||
# if fillto != nothing
|
||||
# if ribbon != nothing
|
||||
# warn("Ignoring ribbon arg since fillto is set!")
|
||||
# end
|
||||
# fillto = makevec(fillto)
|
||||
# n = length(fillto)
|
||||
# push!(yminmax, (:ymin, Float64[min(y, fillto[mod1(i,n)]) for (i,y) in enumerate(d[:y])]))
|
||||
# push!(yminmax, (:ymax, Float64[max(y, fillto[mod1(i,n)]) for (i,y) in enumerate(d[:y])]))
|
||||
# push!(gfargs, Gadfly.Geom.ribbon)
|
||||
|
||||
# elseif ribbon != nothing
|
||||
# ribbon = makevec(ribbon)
|
||||
# n = length(ribbon)
|
||||
@ -490,52 +476,68 @@ function buildSubplotObject!(subplt::Subplot{GadflyPackage})
|
||||
end
|
||||
|
||||
|
||||
# link the subplots together to share axes... useful for facet plots, cross-scatters, etc
|
||||
function linkXAxis(subplt::Subplot{GadflyPackage})
|
||||
|
||||
for (i,(r,c)) in enumerate(subplt.layout)
|
||||
gplt = subplt.plts[i].o
|
||||
if r < nrows(subplt.layout)
|
||||
addOrReplace(gplt.guides, Gadfly.Guide.xticks; label=false)
|
||||
addOrReplace(gplt.guides, Gadfly.Guide.xlabel, "")
|
||||
end
|
||||
end
|
||||
|
||||
lims = [Inf,-Inf]
|
||||
for plt in subplt.plts
|
||||
for l in plt.o.layers
|
||||
expandLimits!(lims, l.mapping[:x])
|
||||
end
|
||||
end
|
||||
for plt in subplt.plts
|
||||
xlims!(plt, lims...)
|
||||
end
|
||||
|
||||
function handleLinkInner(plt::Plot{GadflyPackage}, isx::Bool)
|
||||
gplt = getGadflyContext(plt)
|
||||
# addOrReplace(gplt.guides, Gadfly.Guide.xticks; label=false)
|
||||
# addOrReplace(gplt.guides, Gadfly.Guide.xlabel, "")
|
||||
addOrReplace(gplt.guides, isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks; label=false)
|
||||
addOrReplace(gplt.guides, isx ? Gadfly.Guide.xlabel : Gadfly.Guide.ylabel, "")
|
||||
end
|
||||
|
||||
# link the subplots together to share axes... useful for facet plots, cross-scatters, etc
|
||||
function linkYAxis(subplt::Subplot{GadflyPackage})
|
||||
|
||||
for (i,(r,c)) in enumerate(subplt.layout)
|
||||
gplt = subplt.plts[i].o
|
||||
if c > 1
|
||||
addOrReplace(gplt.guides, Gadfly.Guide.yticks; label=false)
|
||||
addOrReplace(gplt.guides, Gadfly.Guide.ylabel, "")
|
||||
end
|
||||
end
|
||||
|
||||
lims = [Inf,-Inf]
|
||||
for plt in subplt.plts
|
||||
for l in plt.o.layers
|
||||
expandLimits!(lims, l.mapping[:y])
|
||||
end
|
||||
end
|
||||
for plt in subplt.plts
|
||||
ylims!(plt, lims...)
|
||||
end
|
||||
|
||||
function expandLimits!(lims, plt::Plot{GadflyPackage}, isx::Bool)
|
||||
for l in getGadflyContext(plt).layers
|
||||
expandLimits!(lims, l.mapping[isx ? :x : :y])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# # link the subplots together to share axes... useful for facet plots, cross-scatters, etc
|
||||
# function linkXAxis{T<:@compat(Union{GadflyPackage,ImmersePackage})}(subplt::Subplot{T})
|
||||
|
||||
|
||||
# for (i,(r,c)) in enumerate(subplt.layout)
|
||||
# gplt = getGadflyContext(subplt.plts[i])
|
||||
# if r < nrows(subplt.layout)
|
||||
# addOrReplace(gplt.guides, Gadfly.Guide.xticks; label=false)
|
||||
# addOrReplace(gplt.guides, Gadfly.Guide.xlabel, "")
|
||||
# end
|
||||
# end
|
||||
|
||||
# lims = [Inf,-Inf]
|
||||
# for plt in subplt.plts
|
||||
# for l in getGadflyContext(plt).layers
|
||||
# expandLimits!(lims, l.mapping[:x])
|
||||
# end
|
||||
# end
|
||||
# for plt in subplt.plts
|
||||
# xlims!(plt, lims...)
|
||||
# end
|
||||
|
||||
# end
|
||||
|
||||
# # link the subplots together to share axes... useful for facet plots, cross-scatters, etc
|
||||
# function linkYAxis{T<:@compat(Union{GadflyPackage,ImmersePackage})}(subplt::Subplot{T})
|
||||
|
||||
# for (i,(r,c)) in enumerate(subplt.layout)
|
||||
# gplt = getGadflyContext(subplt.plts[i])
|
||||
# if c > 1
|
||||
# addOrReplace(gplt.guides, Gadfly.Guide.yticks; label=false)
|
||||
# addOrReplace(gplt.guides, Gadfly.Guide.ylabel, "")
|
||||
# end
|
||||
# end
|
||||
|
||||
# lims = [Inf,-Inf]
|
||||
# for plt in subplt.plts
|
||||
# for l in getGadflyContext(plt).layers
|
||||
# expandLimits!(lims, l.mapping[:y])
|
||||
# end
|
||||
# end
|
||||
# for plt in subplt.plts
|
||||
# ylims!(plt, lims...)
|
||||
# end
|
||||
|
||||
# end
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
@ -87,42 +87,82 @@ function buildSubplotObject!(subplt::Subplot{ImmersePackage})
|
||||
vsep = Gtk.GtkBoxLeaf(:v)
|
||||
win = Gtk.GtkWindowLeaf(vsep, d[:windowtitle], w, h)
|
||||
|
||||
# add the plot boxes
|
||||
i = 0
|
||||
rows = []
|
||||
figindices = []
|
||||
for rowcnt in subplt.layout.rowcounts
|
||||
row = Gtk.GtkBoxLeaf(:h)
|
||||
push!(vsep, row)
|
||||
for (i,(r,c)) in enumerate(subplt.layout)
|
||||
plt = subplt.plts[i]
|
||||
|
||||
# create a new row and add it to the main Box vsep
|
||||
row = Gtk.GtkBoxLeaf(:h)
|
||||
push!(vsep, row)
|
||||
# get the components... box is the main plot GtkBox, and canvas is the GtkCanvas where it's plotted
|
||||
box, toolbar, canvas = Immerse.createPlotGuiComponents()
|
||||
|
||||
# now add the plot components to the row
|
||||
for plt in subplt.plts[(1:rowcnt) + i]
|
||||
# add the plot's box to the row
|
||||
push!(row, box)
|
||||
|
||||
# get the components... box is the main plot GtkBox, and canvas is the GtkCanvas where it's plotted
|
||||
box, toolbar, canvas = Immerse.createPlotGuiComponents()
|
||||
# create the figure and store the index returned for destruction later
|
||||
figidx = Immerse.figure(canvas)
|
||||
push!(figindices, figidx)
|
||||
|
||||
# add the plot's box to the row
|
||||
push!(row, box)
|
||||
fig = Immerse.figure(figidx)
|
||||
plt.o = (fig, plt.o[2])
|
||||
|
||||
# create the figure and store the index returned for destruction later
|
||||
figidx = Immerse.figure(canvas)
|
||||
push!(figindices, figidx)
|
||||
|
||||
fig = Immerse.figure(figidx)
|
||||
plt.o = (fig, plt.o[2])
|
||||
# add the row
|
||||
if c == ncols(subplt.layout, r)
|
||||
row = Gtk.GtkBoxLeaf(:h)
|
||||
push!(vsep, row)
|
||||
end
|
||||
|
||||
i += rowcnt
|
||||
end
|
||||
|
||||
# # add the plot boxes
|
||||
# i = 0
|
||||
# figindices = []
|
||||
# for rowcnt in subplt.layout.rowcounts
|
||||
|
||||
# # create a new row and add it to the main Box vsep
|
||||
# row = Gtk.GtkBoxLeaf(:h)
|
||||
# push!(vsep, row)
|
||||
|
||||
# # now add the plot components to the row
|
||||
# for plt in subplt.plts[(1:rowcnt) + i]
|
||||
|
||||
# # get the components... box is the main plot GtkBox, and canvas is the GtkCanvas where it's plotted
|
||||
# box, toolbar, canvas = Immerse.createPlotGuiComponents()
|
||||
|
||||
# # add the plot's box to the row
|
||||
# push!(row, box)
|
||||
|
||||
# # create the figure and store the index returned for destruction later
|
||||
# figidx = Immerse.figure(canvas)
|
||||
# push!(figindices, figidx)
|
||||
|
||||
# fig = Immerse.figure(figidx)
|
||||
# plt.o = (fig, plt.o[2])
|
||||
# end
|
||||
|
||||
# i += rowcnt
|
||||
# end
|
||||
|
||||
# destructor... clean up plots
|
||||
Gtk.on_signal_destroy((x...) -> [Immerse.dropfig(Immerse._display,i) for i in figindices], win)
|
||||
|
||||
subplt.o = win
|
||||
end
|
||||
|
||||
|
||||
function handleLinkInner(plt::Plot{ImmersePackage}, isx::Bool)
|
||||
gplt = getGadflyContext(plt)
|
||||
addOrReplace(gplt.guides, isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks; label=false)
|
||||
addOrReplace(gplt.guides, isx ? Gadfly.Guide.xlabel : Gadfly.Guide.ylabel, "")
|
||||
end
|
||||
|
||||
function expandLimits!(lims, plt::Plot{ImmersePackage}, isx::Bool)
|
||||
for l in getGadflyContext(plt).layers
|
||||
expandLimits!(lims, l.mapping[isx ? :x : :y])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
getGadflyContext(plt::Plot{ImmersePackage}) = plt.o[2]
|
||||
|
||||
@ -38,7 +38,7 @@ function subplotlayout(numplts::Int, nr::Int, nc::Int)
|
||||
i += cnt
|
||||
end
|
||||
|
||||
SubplotLayout(numplts, rowcounts)
|
||||
FlexLayout(numplts, rowcounts)
|
||||
end
|
||||
|
||||
# # create a layout directly
|
||||
@ -110,7 +110,23 @@ ncols(layout::GridLayout, row::Int) = layout.nc
|
||||
# get the plot index given row and column
|
||||
Base.getindex(layout::GridLayout, r::Int, c::Int) = (r-1) * layout.nc + c
|
||||
|
||||
# handle "linking" the subplot axes together
|
||||
# each backend should implement the handleLinkInner and expandLimits! methods
|
||||
function linkAxis(subplt::Subplot, isx::Bool)
|
||||
lims = [Inf, -Inf]
|
||||
for (i,(r,c)) in enumerate(subplt.layout)
|
||||
plt = subplt.plts[i]
|
||||
if (isx && r < nrows(subplt.layout)) || (!isx && c > 1)
|
||||
handleLinkInner(plt, isx)
|
||||
end
|
||||
expandLimits!(lims, plt, isx)
|
||||
end
|
||||
|
||||
for plt in subplt.plts
|
||||
(isx ? xlims! : ylims!)(plt, lims...)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
|
||||
@ -174,7 +190,7 @@ function subplot(args...; kw...)
|
||||
# # tmpd[:show] = shouldShow
|
||||
|
||||
# create the object and do the plotting
|
||||
subplt = Subplot(nothing, plts, pkg, length(layout), 0, layout, ds, false, get(d, :linkx, false), get(d, :linky, false))
|
||||
subplt = Subplot(nothing, plts, pkg, length(layout), 0, layout, ds, false, false, false)
|
||||
subplot!(subplt, args...; kw...)
|
||||
|
||||
subplt
|
||||
@ -206,11 +222,11 @@ function subplot!(subplt::Subplot, args...; kw...)
|
||||
|
||||
d = Dict(kw)
|
||||
preprocessArgs!(d)
|
||||
# for k in keys(_plotDefaults)
|
||||
# delete!(d, k)
|
||||
# end
|
||||
dumpdict(d, "After subplot! preprocessing")
|
||||
|
||||
haskey(d, :linkx) && (subplt.linkx = d[:linkx])
|
||||
haskey(d, :linky) && (subplt.linky = d[:linky])
|
||||
|
||||
kwList, xmeta, ymeta = createKWargsList(subplt, args...; d...)
|
||||
|
||||
# TODO: something useful with meta info?
|
||||
@ -242,12 +258,8 @@ function subplot!(subplt::Subplot, args...; kw...)
|
||||
updatePlotItems(plt, di)
|
||||
end
|
||||
|
||||
if subplt.linkx
|
||||
linkXAxis(subplt)
|
||||
end
|
||||
if subplt.linky
|
||||
linkYAxis(subplt)
|
||||
end
|
||||
subplt.linkx && linkAxis(subplt, true)
|
||||
subplt.linky && linkAxis(subplt, false)
|
||||
|
||||
# set this to be current
|
||||
current(subplt)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user