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)
|
push!(gfargs, Gadfly.Geom.ribbon)
|
||||||
end
|
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
|
# elseif ribbon != nothing
|
||||||
# ribbon = makevec(ribbon)
|
# ribbon = makevec(ribbon)
|
||||||
# n = length(ribbon)
|
# n = length(ribbon)
|
||||||
@ -490,52 +476,68 @@ function buildSubplotObject!(subplt::Subplot{GadflyPackage})
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# link the subplots together to share axes... useful for facet plots, cross-scatters, etc
|
function handleLinkInner(plt::Plot{GadflyPackage}, isx::Bool)
|
||||||
function linkXAxis(subplt::Subplot{GadflyPackage})
|
gplt = getGadflyContext(plt)
|
||||||
|
# addOrReplace(gplt.guides, Gadfly.Guide.xticks; label=false)
|
||||||
for (i,(r,c)) in enumerate(subplt.layout)
|
# addOrReplace(gplt.guides, Gadfly.Guide.xlabel, "")
|
||||||
gplt = subplt.plts[i].o
|
addOrReplace(gplt.guides, isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks; label=false)
|
||||||
if r < nrows(subplt.layout)
|
addOrReplace(gplt.guides, isx ? Gadfly.Guide.xlabel : Gadfly.Guide.ylabel, "")
|
||||||
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
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# link the subplots together to share axes... useful for facet plots, cross-scatters, etc
|
function expandLimits!(lims, plt::Plot{GadflyPackage}, isx::Bool)
|
||||||
function linkYAxis(subplt::Subplot{GadflyPackage})
|
for l in getGadflyContext(plt).layers
|
||||||
|
expandLimits!(lims, l.mapping[isx ? :x : :y])
|
||||||
for (i,(r,c)) in enumerate(subplt.layout)
|
end
|
||||||
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
|
|
||||||
|
|
||||||
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)
|
vsep = Gtk.GtkBoxLeaf(:v)
|
||||||
win = Gtk.GtkWindowLeaf(vsep, d[:windowtitle], w, h)
|
win = Gtk.GtkWindowLeaf(vsep, d[:windowtitle], w, h)
|
||||||
|
|
||||||
# add the plot boxes
|
|
||||||
i = 0
|
|
||||||
rows = []
|
|
||||||
figindices = []
|
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
|
# get the components... box is the main plot GtkBox, and canvas is the GtkCanvas where it's plotted
|
||||||
row = Gtk.GtkBoxLeaf(:h)
|
box, toolbar, canvas = Immerse.createPlotGuiComponents()
|
||||||
push!(vsep, row)
|
|
||||||
|
|
||||||
# now add the plot components to the row
|
# add the plot's box to the row
|
||||||
for plt in subplt.plts[(1:rowcnt) + i]
|
push!(row, box)
|
||||||
|
|
||||||
# get the components... box is the main plot GtkBox, and canvas is the GtkCanvas where it's plotted
|
# create the figure and store the index returned for destruction later
|
||||||
box, toolbar, canvas = Immerse.createPlotGuiComponents()
|
figidx = Immerse.figure(canvas)
|
||||||
|
push!(figindices, figidx)
|
||||||
|
|
||||||
# add the plot's box to the row
|
fig = Immerse.figure(figidx)
|
||||||
push!(row, box)
|
plt.o = (fig, plt.o[2])
|
||||||
|
|
||||||
# create the figure and store the index returned for destruction later
|
# add the row
|
||||||
figidx = Immerse.figure(canvas)
|
if c == ncols(subplt.layout, r)
|
||||||
push!(figindices, figidx)
|
row = Gtk.GtkBoxLeaf(:h)
|
||||||
|
push!(vsep, row)
|
||||||
fig = Immerse.figure(figidx)
|
|
||||||
plt.o = (fig, plt.o[2])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
i += rowcnt
|
|
||||||
end
|
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
|
# destructor... clean up plots
|
||||||
Gtk.on_signal_destroy((x...) -> [Immerse.dropfig(Immerse._display,i) for i in figindices], win)
|
Gtk.on_signal_destroy((x...) -> [Immerse.dropfig(Immerse._display,i) for i in figindices], win)
|
||||||
|
|
||||||
subplt.o = win
|
subplt.o = win
|
||||||
end
|
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]
|
getGadflyContext(plt::Plot{ImmersePackage}) = plt.o[2]
|
||||||
|
|||||||
@ -38,7 +38,7 @@ function subplotlayout(numplts::Int, nr::Int, nc::Int)
|
|||||||
i += cnt
|
i += cnt
|
||||||
end
|
end
|
||||||
|
|
||||||
SubplotLayout(numplts, rowcounts)
|
FlexLayout(numplts, rowcounts)
|
||||||
end
|
end
|
||||||
|
|
||||||
# # create a layout directly
|
# # create a layout directly
|
||||||
@ -110,7 +110,23 @@ ncols(layout::GridLayout, row::Int) = layout.nc
|
|||||||
# get the plot index given row and column
|
# get the plot index given row and column
|
||||||
Base.getindex(layout::GridLayout, r::Int, c::Int) = (r-1) * layout.nc + c
|
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
|
# # tmpd[:show] = shouldShow
|
||||||
|
|
||||||
# create the object and do the plotting
|
# 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...)
|
subplot!(subplt, args...; kw...)
|
||||||
|
|
||||||
subplt
|
subplt
|
||||||
@ -206,11 +222,11 @@ function subplot!(subplt::Subplot, args...; kw...)
|
|||||||
|
|
||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
preprocessArgs!(d)
|
preprocessArgs!(d)
|
||||||
# for k in keys(_plotDefaults)
|
|
||||||
# delete!(d, k)
|
|
||||||
# end
|
|
||||||
dumpdict(d, "After subplot! preprocessing")
|
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...)
|
kwList, xmeta, ymeta = createKWargsList(subplt, args...; d...)
|
||||||
|
|
||||||
# TODO: something useful with meta info?
|
# TODO: something useful with meta info?
|
||||||
@ -242,12 +258,8 @@ function subplot!(subplt::Subplot, args...; kw...)
|
|||||||
updatePlotItems(plt, di)
|
updatePlotItems(plt, di)
|
||||||
end
|
end
|
||||||
|
|
||||||
if subplt.linkx
|
subplt.linkx && linkAxis(subplt, true)
|
||||||
linkXAxis(subplt)
|
subplt.linky && linkAxis(subplt, false)
|
||||||
end
|
|
||||||
if subplt.linky
|
|
||||||
linkYAxis(subplt)
|
|
||||||
end
|
|
||||||
|
|
||||||
# set this to be current
|
# set this to be current
|
||||||
current(subplt)
|
current(subplt)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user