From e6c8344970b1160dc53004b9ef13fab2c0568282 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Mon, 14 Sep 2015 13:44:58 -0400 Subject: [PATCH] working on immerse --- src/args.jl | 1 + src/backends/immerse.jl | 53 ++++++++++++++++++++++++++++++++--------- src/subplot.jl | 13 ++++++---- src/types.jl | 1 + 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/args.jl b/src/args.jl index 7626fcfc..7dd86a0b 100644 --- a/src/args.jl +++ b/src/args.jl @@ -41,6 +41,7 @@ PLOT_DEFAULTS[:xticks] = true PLOT_DEFAULTS[:yticks] = true PLOT_DEFAULTS[:size] = (600,400) PLOT_DEFAULTS[:windowtitle] = "Plots.jl" +PLOT_DEFAULTS[:show] = true PLOT_DEFAULTS[:args] = [] # additional args to pass to the backend PLOT_DEFAULTS[:kwargs] = [] # additional keyword args to pass to the backend diff --git a/src/backends/immerse.jl b/src/backends/immerse.jl index a4f45187..a3578a2b 100644 --- a/src/backends/immerse.jl +++ b/src/backends/immerse.jl @@ -6,6 +6,13 @@ immutable ImmersePackage <: PlottingPackage end immerse!() = plotter!(:immerse) +function createImmerseFigure(d::Dict) + # d[:show] || return # return nothing when we're not showing + w,h = d[:size] + figidx = Immerse.figure(; name = d[:windowtitle], width = w, height = h) + Immerse.Figure(figidx) +end + # create a blank Gadfly.Plot object function plot(pkg::ImmersePackage; kw...) @@ -14,10 +21,16 @@ function plot(pkg::ImmersePackage; kw...) # create the underlying Gadfly.Plot object gplt = createGadflyPlotObject(d) - # create the figure. Immerse just returns the index of the Figure in the GadflyDisplay... call Figure(figidx) to get the object - w,h = d[:size] - figidx = Immerse.figure(; name = d[:windowtitle], width = w, height = h) - fig = Immerse.Figure(figidx) + # create the figure (or not). Immerse just returns the index of the Figure in the GadflyDisplay... call Figure(figidx) to get the object + fig = d[:show] ? createImmerseFigure(d) : nothing + # if d[:show] + # # w,h = d[:size] + # # figidx = Immerse.figure(; name = d[:windowtitle], width = w, height = h) + # # fig = Immerse.Figure(figidx) + # fig = createImmerseFigure(d) + # else + # fig = nothing + # end # save both the Immerse.Figure and the Gadfly.Plot Plot((fig,gplt), pkg, 0, d, Dict[]) @@ -27,13 +40,20 @@ end # plot one data series function plot!(::ImmersePackage, plt::Plot; kw...) d = Dict(kw) - addGadflySeries!(plt.o[2], d) + gplt = plt.o[2] + addGadflySeries!(gplt, d) push!(plt.seriesargs, d) plt end function Base.display(::ImmersePackage, plt::Plot) - display(plt.o[2]) + println("disp1") + fig, gplt = plt.o + if fig == nothing + fig = createImmerseFigure(plt.initargs) + end + newfig = Immerse.Figure(fig.canvas, gplt) + display(newfig) end # ------------------------------- @@ -41,7 +61,8 @@ end function savepng(::ImmersePackage, plt::PlottingObject, fn::String; w = 6 * Immerse.inch, h = 4 * Immerse.inch) - Immerse.draw(Immerse.PNG(fn, w, h), plt.o) + gctx = plt.o[2] + Gadfly.draw(Gadfly.PNG(fn, w, h), gctx) end @@ -57,12 +78,22 @@ function buildSubplotObject!(::ImmersePackage, subplt::Subplot) end gctx = Gadfly.vstack(rows...) - figidx = Immerse.figure() - fig = Immerse.Figure(figidx) - (fig, gctx) + fig = subplt.initargs[:show] ? createImmerseFigure(subplt.initargs) : nothing + # fig = createImmerseFigure(subplt.initargs) + + subplt.o = (fig, gctx) end function Base.display(::ImmersePackage, subplt::Subplot) - display(subplt.o[2]) + println("disp2") + # display(subplt.o[1]) + fig, gctx = subplt.o + if fig == nothing + fig = createImmerseFigure(subplt.initargs) + end + # newfig = Immerse.Figure(fig.canvas, gctx) + fig.cc = gctx + # error(fig) + display(fig) end diff --git a/src/subplot.jl b/src/subplot.jl index 77e3d209..8685857c 100644 --- a/src/subplot.jl +++ b/src/subplot.jl @@ -71,11 +71,14 @@ function subplot(args...; kw...) # initialize the individual plots pkg = plotter() - kw0 = getPlotKeywordArgs(kw, 1, 0) - plts = Plot[plot(pkg; kw0..., show=false) for i in 1:length(layout)] + tmpd = getPlotKeywordArgs(kw, 1, 0) + shouldShow = tmpd[:show] + tmpd[:show] = false + plts = Plot[plot(pkg; tmpd...) for i in 1:length(layout)] + tmpd[:show] = shouldShow # create the object and do the plotting - subplt = Subplot(nothing, plts, pkg, length(layout), 0, layout) + subplt = Subplot(nothing, plts, pkg, length(layout), 0, layout, tmpd) subplot!(subplt, args...; kw...) subplt @@ -103,6 +106,7 @@ function subplot!(subplt::Subplot, args...; kw...) for (i,d) in enumerate(kwList) subplt.n += 1 plt = getplot(subplt) # get the Plot object where this series will be drawn + d[:show] = false plot!(plt; d...) end @@ -114,8 +118,9 @@ function subplot!(subplt::Subplot, args...; kw...) # do we want to show it? d = Dict(kw) + @show d if haskey(d, :show) && d[:show] - draw(subplt) + display(subplt) end subplt diff --git a/src/types.jl b/src/types.jl index a5b31b9f..d5d1c7e0 100644 --- a/src/types.jl +++ b/src/types.jl @@ -29,4 +29,5 @@ type Subplot <: PlottingObject p::Int # number of plots n::Int # number of series layout::SubplotLayout + initargs::Dict end \ No newline at end of file