working on immerse

This commit is contained in:
Thomas Breloff 2015-09-14 13:44:58 -04:00
parent 2207ae6617
commit e6c8344970
4 changed files with 53 additions and 15 deletions

View File

@ -41,6 +41,7 @@ PLOT_DEFAULTS[:xticks] = true
PLOT_DEFAULTS[:yticks] = true PLOT_DEFAULTS[:yticks] = true
PLOT_DEFAULTS[:size] = (600,400) PLOT_DEFAULTS[:size] = (600,400)
PLOT_DEFAULTS[:windowtitle] = "Plots.jl" PLOT_DEFAULTS[:windowtitle] = "Plots.jl"
PLOT_DEFAULTS[:show] = true
PLOT_DEFAULTS[:args] = [] # additional args to pass to the backend PLOT_DEFAULTS[:args] = [] # additional args to pass to the backend
PLOT_DEFAULTS[:kwargs] = [] # additional keyword args to pass to the backend PLOT_DEFAULTS[:kwargs] = [] # additional keyword args to pass to the backend

View File

@ -6,6 +6,13 @@ immutable ImmersePackage <: PlottingPackage end
immerse!() = plotter!(:immerse) 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 # create a blank Gadfly.Plot object
function plot(pkg::ImmersePackage; kw...) function plot(pkg::ImmersePackage; kw...)
@ -14,10 +21,16 @@ function plot(pkg::ImmersePackage; kw...)
# create the underlying Gadfly.Plot object # create the underlying Gadfly.Plot object
gplt = createGadflyPlotObject(d) gplt = createGadflyPlotObject(d)
# create the figure. Immerse just returns the index of the Figure in the GadflyDisplay... call Figure(figidx) to get the object # create the figure (or not). Immerse just returns the index of the Figure in the GadflyDisplay... call Figure(figidx) to get the object
w,h = d[:size] fig = d[:show] ? createImmerseFigure(d) : nothing
figidx = Immerse.figure(; name = d[:windowtitle], width = w, height = h) # if d[:show]
fig = Immerse.Figure(figidx) # # 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 # save both the Immerse.Figure and the Gadfly.Plot
Plot((fig,gplt), pkg, 0, d, Dict[]) Plot((fig,gplt), pkg, 0, d, Dict[])
@ -27,13 +40,20 @@ end
# plot one data series # plot one data series
function plot!(::ImmersePackage, plt::Plot; kw...) function plot!(::ImmersePackage, plt::Plot; kw...)
d = Dict(kw) d = Dict(kw)
addGadflySeries!(plt.o[2], d) gplt = plt.o[2]
addGadflySeries!(gplt, d)
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt
end end
function Base.display(::ImmersePackage, plt::Plot) 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 end
# ------------------------------- # -------------------------------
@ -41,7 +61,8 @@ end
function savepng(::ImmersePackage, plt::PlottingObject, fn::String; function savepng(::ImmersePackage, plt::PlottingObject, fn::String;
w = 6 * Immerse.inch, w = 6 * Immerse.inch,
h = 4 * 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 end
@ -57,12 +78,22 @@ function buildSubplotObject!(::ImmersePackage, subplt::Subplot)
end end
gctx = Gadfly.vstack(rows...) gctx = Gadfly.vstack(rows...)
figidx = Immerse.figure() fig = subplt.initargs[:show] ? createImmerseFigure(subplt.initargs) : nothing
fig = Immerse.Figure(figidx) # fig = createImmerseFigure(subplt.initargs)
(fig, gctx)
subplt.o = (fig, gctx)
end end
function Base.display(::ImmersePackage, subplt::Subplot) 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 end

View File

@ -71,11 +71,14 @@ function subplot(args...; kw...)
# initialize the individual plots # initialize the individual plots
pkg = plotter() pkg = plotter()
kw0 = getPlotKeywordArgs(kw, 1, 0) tmpd = getPlotKeywordArgs(kw, 1, 0)
plts = Plot[plot(pkg; kw0..., show=false) for i in 1:length(layout)] 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 # 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...) subplot!(subplt, args...; kw...)
subplt subplt
@ -103,6 +106,7 @@ function subplot!(subplt::Subplot, args...; kw...)
for (i,d) in enumerate(kwList) for (i,d) in enumerate(kwList)
subplt.n += 1 subplt.n += 1
plt = getplot(subplt) # get the Plot object where this series will be drawn plt = getplot(subplt) # get the Plot object where this series will be drawn
d[:show] = false
plot!(plt; d...) plot!(plt; d...)
end end
@ -114,8 +118,9 @@ function subplot!(subplt::Subplot, args...; kw...)
# do we want to show it? # do we want to show it?
d = Dict(kw) d = Dict(kw)
@show d
if haskey(d, :show) && d[:show] if haskey(d, :show) && d[:show]
draw(subplt) display(subplt)
end end
subplt subplt

View File

@ -29,4 +29,5 @@ type Subplot <: PlottingObject
p::Int # number of plots p::Int # number of plots
n::Int # number of series n::Int # number of series
layout::SubplotLayout layout::SubplotLayout
initargs::Dict
end end