more display fun

This commit is contained in:
Thomas Breloff 2015-09-22 14:56:37 -04:00
parent eced15b712
commit ec939f9f9a
12 changed files with 206 additions and 226 deletions

View File

@ -185,6 +185,8 @@ plot(rand(100,4); color = [:red, RGB(0,0,1)], # lines 1 and 3 are red, lines
__Tip__: Not all features are supported for each backend, but you can see what's supported by calling the functions: `supportedAxes()`, `supportedTypes()`, `supportedStyles()`, `supportedMarkers()`, `subplotSupported()` __Tip__: Not all features are supported for each backend, but you can see what's supported by calling the functions: `supportedAxes()`, `supportedTypes()`, `supportedStyles()`, `supportedMarkers()`, `subplotSupported()`
__Tip__: Call `gui()` to display the plot in a window. Interactivity depends on backend. Showing at the REPL implicitly calls this.
## TODO features: ## TODO features:
- [x] Plot vectors/matrices/functions - [x] Plot vectors/matrices/functions

View File

@ -41,6 +41,7 @@ export
ylabel!, ylabel!,
savepng, savepng,
gui,
backends, backends,
aliases, aliases,
@ -103,23 +104,18 @@ ylabel!(plt::Plot, s::AbstractString) = plot!(plt; ylabel = s)
savepng(args...; kw...) = savepng(currentPlot(), args...; kw...) savepng(args...; kw...) = savepng(currentPlot(), args...; kw...)
savepng(plt::PlottingObject, fn::AbstractString; kw...) = (io = open(fn); writemime(io, MIME"image/png", plt); close(io)) savepng(plt::PlottingObject, fn::AbstractString; kw...) = (io = open(fn, "w"); writemime(io, MIME("image/png"), plt); close(io))
# savepng(plt::PlottingObject, args...; kw...) = savepng(plt.plotter, plt, args...; kw...) # savepng(plt::PlottingObject, args...; kw...) = savepng(plt.plotter, plt, args...; kw...)
# savepng(::PlottingPackage, plt::PlottingObject, fn::AbstractString, args...) = error("unsupported") # fallback so multiple dispatch doesn't get confused if it's missing # savepng(::PlottingPackage, plt::PlottingObject, fn::AbstractString, args...) = error("unsupported") # fallback so multiple dispatch doesn't get confused if it's missing
# function Base.writemime(io::IO, ::MIME"image/png", plt::Plot)
gui(plt::PlottingObject = currentPlot()) = display(PlotsDisplay(), plt)
# function Base.writemime(io::IO, ::MIME"text/html", plt::Plot) # override the REPL display to open a gui window
# # print(io, "<p>") Base.display(::Base.REPL.REPLDisplay, ::MIME"text/plain", plt::PlottingObject) = gui(plt)
# png = MIME("image/png")
# print(io, "<img src=\"data:image/png; base64,", base64encode(writemime, png), "\" />")
# end
# override the REPL display
Base.display(::Base.REPL.REPLDisplay, ::MIME"text/plain", plt::PlottingObject) = display(PlotsDisplay(), plt)
function __init__() function __init__()
global const CURRENT_BACKEND = pickDefaultBackend() global const CURRENT_BACKEND = pickDefaultBackend()

View File

@ -265,7 +265,8 @@ function getPlotArgs(pkg::PlottingPackage, kw, idx::Int)
end end
# convert color # convert color
d[:background_color] = getBackgroundRGBColor(d[:background_color], d) handlePlotColors(pkg, d)
# d[:background_color] = getBackgroundRGBColor(d[:background_color], d)
# no need for these # no need for these
delete!(d, :x) delete!(d, :x)

View File

@ -211,53 +211,35 @@ function plot!(::GadflyPackage, plt::Plot; kw...)
end end
function findGuideAndSet(plt::Plot, t::DataType, s::AbstractString) function findGuideAndSet(gplt, t::DataType, s::AbstractString)
for guide in plt.o.guides for (i,guide) in enumerate(gplt.guides)
if isa(guide, t) if isa(guide, t)
guide.label = s gplt.guides[i] = t(s)
# guide.label = s
end end
end end
end end
function updatePlotItems(::GadflyPackage, plt::Plot, d::Dict) function updateGadflyGuides(gplt, d::Dict)
haskey(d, :title) && findGuideAndSet(plt, Gadfly.Guide.title, d[:title]) haskey(d, :title) && findGuideAndSet(gplt, Gadfly.Guide.title, d[:title])
haskey(d, :xlabel) && findGuideAndSet(plt, Gadfly.Guide.xlabel, d[:xlabel]) haskey(d, :xlabel) && findGuideAndSet(gplt, Gadfly.Guide.xlabel, d[:xlabel])
haskey(d, :ylabel) && findGuideAndSet(plt, Gadfly.Guide.ylabel, d[:ylabel]) haskey(d, :ylabel) && findGuideAndSet(gplt, Gadfly.Guide.ylabel, d[:ylabel])
end end
function setGadflyDisplaySize(w,h) function updatePlotItems(plt::Plot{GadflyPackage}, d::Dict)
Compose.set_default_graphic_size(w * Compose.px, h * Compose.px) updateGadflyGuides(plt.o, d)
end end
# function Base.display(::GadflyPackage, plt::Plot) # ----------------------------------------------------------------
# # function Base.writemime(io::IO, ::MIME")
# setGadflyDisplaySize(plt.initargs[:size]...)
# display(plt.o)
# end
function Base.display(::PlotsDisplay, plt::Plot{GadflyPackage})
setGadflyDisplaySize(plt.initargs[:size]...) # create the underlying object (each backend will do this differently)
display(plt.o) function buildSubplotObject!(subplt::Subplot{GadflyPackage})
subplt.o = nothing
end end
# ------------------------------- # ----------------------------------------------------------------
# function savepng(::GadflyPackage, plt::PlottingObject, fn::AbstractString;
# w = plt.initargs[:size][1] * Gadfly.px, # 6 * Gadfly.inch,
# h = plt.initargs[:size][2] * Gadfly.px) # 4 * Gadfly.inch)
# o = getGadflyContext(plt.plotter, plt)
# Gadfly.draw(Gadfly.PNG(fn, w, h), o)
# end
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{GadflyPackage})
# w = plt.initargs[:size][1] * Gadfly.px, # 6 * Gadfly.inch,
# h = plt.initargs[:size][2] * Gadfly.px) # 4 * Gadfly.inch)
gplt = getGadflyContext(plt.plotter, plt)
setGadflyDisplaySize(plt.initargs[:size]...)
Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end
# -------------------------------
getGadflyContext(::GadflyPackage, plt::Plot) = plt.o getGadflyContext(::GadflyPackage, plt::Plot) = plt.o
getGadflyContext(::GadflyPackage, subplt::Subplot) = buildGadflySubplotContext(subplt) getGadflyContext(::GadflyPackage, subplt::Subplot) = buildGadflySubplotContext(subplt)
@ -273,11 +255,21 @@ function buildGadflySubplotContext(subplt::Subplot)
Gadfly.vstack(rows...) Gadfly.vstack(rows...)
end end
# create the underlying object (each backend will do this differently) function setGadflyDisplaySize(w,h)
function buildSubplotObject!(subplt::Subplot{GadflyPackage}) Compose.set_default_graphic_size(w * Compose.px, h * Compose.px)
subplt.o = nothing
end end
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{GadflyPackage})
gplt = getGadflyContext(plt.plotter, plt)
setGadflyDisplaySize(plt.initargs[:size]...)
Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end
function Base.display(::PlotsDisplay, plt::Plot{GadflyPackage})
setGadflyDisplaySize(plt.initargs[:size]...)
display(plt.o)
end
function Base.display(::PlotsDisplay, subplt::Subplot{GadflyPackage}) function Base.display(::PlotsDisplay, subplt::Subplot{GadflyPackage})
setGadflyDisplaySize(plt.initargs[:size]...) setGadflyDisplaySize(plt.initargs[:size]...)

View File

@ -43,36 +43,13 @@ function plot!(::ImmersePackage, plt::Plot; kw...)
plt plt
end end
function Base.display(::ImmersePackage, plt::Plot)
fig, gplt = plt.o function updatePlotItems(plt::Plot{ImmersePackage}, d::Dict)
if fig == nothing updateGadflyGuides(plt.o[2], d)
fig = createImmerseFigure(plt.initargs)
plt.o = (fig, gplt)
end
# # display a new Figure object to force a redraw
# display(Immerse.Figure(fig.canvas, gplt))
Immerse.figure(fig.figno; displayfig = false)
display(gplt)
end
# -------------------------------
getGadflyContext(::ImmersePackage, plt::Plot) = plt.o[2]
getGadflyContext(::ImmersePackage, subplt::Subplot) = buildGadflySubplotContext(subplt)
function savepng(::ImmersePackage, plt::PlottingObject, fn::AbstractString;
w = 6 * Immerse.inch,
h = 4 * Immerse.inch)
gctx = getGadflyContext(plt.plotter, plt)
Gadfly.draw(Gadfly.PNG(fn, w, h), gctx)
nothing
end end
# ------------------------------- # ----------------------------------------------------------------
function buildSubplotObject!(subplt::Subplot{ImmersePackage}) function buildSubplotObject!(subplt::Subplot{ImmersePackage})
@ -119,15 +96,37 @@ function buildSubplotObject!(subplt::Subplot{ImmersePackage})
subplt.o = win subplt.o = win
end end
# ----------------------------------------------------------------
function Base.display(::ImmersePackage, subplt::Subplot) getGadflyContext(::ImmersePackage, plt::Plot) = plt.o[2]
getGadflyContext(::ImmersePackage, subplt::Subplot) = buildGadflySubplotContext(subplt)
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{ImmersePackage})
gplt = getGadflyContext(plt.plotter, plt)
setGadflyDisplaySize(plt.initargs[:size]...)
Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end
function Base.display(::PlotsDisplay, plt::Plot{ImmersePackage})
fig, gplt = plt.o
if fig == nothing
fig = createImmerseFigure(plt.initargs)
plt.o = (fig, gplt)
end
Immerse.figure(fig.figno; displayfig = false)
display(gplt)
end
function Base.display(::PlotsDisplay, subplt::Subplot{ImmersePackage})
# display the plots by creating a fresh Immerse.Figure object from the GtkCanvas and Gadfly.Plot # display the plots by creating a fresh Immerse.Figure object from the GtkCanvas and Gadfly.Plot
for plt in subplt.plts for plt in subplt.plts
fig, gplt = plt.o fig, gplt = plt.o
Immerse.figure(fig.figno; displayfig = false) Immerse.figure(fig.figno; displayfig = false)
display(gplt) display(gplt)
# display(Immerse.Figure(fig.canvas, gplt))
end end
# o is the window... show it # o is the window... show it

View File

@ -107,7 +107,7 @@ function updateAxisColors(ax, fgcolor)
ax[:title][:set_color](fgcolor) ax[:title][:set_color](fgcolor)
end end
makePlotCurrent(plt::Plot) = PyPlot.figure(plt.o[1].o[:number]) makePyPlotCurrent(plt::Plot) = PyPlot.figure(plt.o[1].o[:number])
# ------------------------------------------------------------------ # ------------------------------------------------------------------
@ -139,7 +139,7 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
fig, num = plt.o fig, num = plt.o
# PyPlot.figure(num) # makes this current # PyPlot.figure(num) # makes this current
makePlotCurrent(plt) makePyPlotCurrent(plt)
if !(d[:linetype] in supportedTypes(pkg)) if !(d[:linetype] in supportedTypes(pkg))
error("linetype $(d[:linetype]) is unsupported in PyPlot. Choose from: $(supportedTypes(pkg))") error("linetype $(d[:linetype]) is unsupported in PyPlot. Choose from: $(supportedTypes(pkg))")
@ -217,57 +217,64 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
end end
function updatePlotItems(::PyPlotPackage, plt::Plot, d::Dict) function updatePlotItems(plt::Plot{PyPlotPackage}, d::Dict)
makePlotCurrent(plt) makePyPlotCurrent(plt)
haskey(d, :title) && PyPlot.title(d[:title]) haskey(d, :title) && PyPlot.title(d[:title])
haskey(d, :xlabel) && PyPlot.xlabel(d[:xlabel]) haskey(d, :xlabel) && PyPlot.xlabel(d[:xlabel])
haskey(d, :ylabel) && PyPlot.ylabel(d[:ylabel]) haskey(d, :ylabel) && PyPlot.ylabel(d[:ylabel])
end end
function addPyPlotLegend(plt::Plot)
# add a legend?
# try
if plt.initargs[:legend]
# gotta do this to ensure both axes are included
args = filter(x -> !(x[:linetype] in (:hist,:hexbin,:heatmap)), plt.seriesargs)
if length(args) > 0
PyPlot.legend([d[:serieshandle] for d in args], [d[:label] for d in args], loc="best")
end
end
# catch ex
# warn("Error adding PyPlot legend: ", ex)
# end
end
function Base.display(::PyPlotPackage, plt::Plot)
fig, num = plt.o
# PyPlot.figure(num) # makes this current
makePlotCurrent(plt)
addPyPlotLegend(plt)
ax = fig.o[:axes][1]
updateAxisColors(ax, getPyPlotColor(plt.initargs[:foreground_color]))
display(fig)
end
# ------------------------------- # -------------------------------
function savepng(::PyPlotPackage, plt::PlottingObject, fn::AbstractString, args...) # function savepng(::PyPlotPackage, plt::PlottingObject, fn::AbstractString, args...)
fig, num = plt.o # fig, num = plt.o
addPyPlotLegend(plt) # addPyPlotLegend(plt)
f = open(fn, "w") # f = open(fn, "w")
writemime(f, "image/png", fig) # writemime(f, "image/png", fig)
close(f) # close(f)
end # end
# -------------------------------
# -----------------------------------------------------------------
# create the underlying object (each backend will do this differently) # create the underlying object (each backend will do this differently)
function buildSubplotObject!(subplt::Subplot{PyPlotPackage}) function buildSubplotObject!(subplt::Subplot{PyPlotPackage})
error("unsupported") error("unsupported")
end end
# -----------------------------------------------------------------
function Base.display(::PyPlotPackage, subplt::Subplot) function addPyPlotLegend(plt::Plot)
if plt.initargs[:legend]
# gotta do this to ensure both axes are included
args = filter(x -> !(x[:linetype] in (:hist,:hexbin,:heatmap)), plt.seriesargs)
if length(args) > 0
PyPlot.legend([d[:serieshandle] for d in args], [d[:label] for d in args], loc="best")
end
end
end
function Base.writemime(io::IO, m::MIME"image/png", plt::PlottingObject{PyPlotPackage})
fig, num = plt.o
addPyPlotLegend(plt)
writemime(io, m, fig)
end
function Base.display(::PlotsDisplay, plt::Plot{PyPlotPackage})
fig, num = plt.o
# PyPlot.figure(num) # makes this current
makePyPlotCurrent(plt)
addPyPlotLegend(plt)
ax = fig.o[:axes][1]
updateAxisColors(ax, getPyPlotColor(plt.initargs[:foreground_color]))
display(fig)
end
function Base.display(::PlotsDisplay, subplt::Subplot{PyPlotPackage})
display(subplt.o) display(subplt.o)
end end

View File

@ -57,20 +57,15 @@ function plot!(::QwtPackage, plt::Plot; kw...)
plt plt
end end
function updatePlotItems(::QwtPackage, plt::Plot, d::Dict) function updatePlotItems(plt::Plot{QwtPackage}, d::Dict)
haskey(d, :title) && Qwt.title(plt.o, d[:title]) haskey(d, :title) && Qwt.title(plt.o, d[:title])
haskey(d, :xlabel) && Qwt.xlabel(plt.o, d[:xlabel]) haskey(d, :xlabel) && Qwt.xlabel(plt.o, d[:xlabel])
haskey(d, :ylabel) && Qwt.ylabel(plt.o, d[:ylabel]) haskey(d, :ylabel) && Qwt.ylabel(plt.o, d[:ylabel])
end end
function Base.display(::QwtPackage, plt::Plot)
Qwt.refresh(plt.o)
Qwt.showwidget(plt.o)
end
# ------------------------------- # -------------------------------
savepng(::QwtPackage, plt::PlottingObject, fn::AbstractString, args...) = Qwt.savepng(plt.o, fn) # savepng(::QwtPackage, plt::PlottingObject, fn::AbstractString, args...) = Qwt.savepng(plt.o, fn)
# ------------------------------- # -------------------------------
@ -87,8 +82,20 @@ function buildSubplotObject!(subplt::Subplot{QwtPackage})
Qwt.moveToLastScreen(subplt.o) # hack so it goes to my center monitor... sorry Qwt.moveToLastScreen(subplt.o) # hack so it goes to my center monitor... sorry
end end
# ----------------------------------------------------------------
function Base.display(::QwtPackage, subplt::Subplot) function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{QwtPackage})
Qwt.savepng(plt.o, "/tmp/dfskjdhfkh.png")
write(io, readall("/tmp/dfskjdhfkh.png"))
end
function Base.display(::PlotsDisplay, plt::Plot{QwtPackage})
Qwt.refresh(plt.o)
Qwt.showwidget(plt.o)
end
function Base.display(::PlotsDisplay, subplt::Subplot{QwtPackage})
for plt in subplt.plts for plt in subplt.plts
Qwt.refresh(plt.o) Qwt.refresh(plt.o)
end end

View File

@ -34,42 +34,27 @@ function plot!(::[PkgName]Package, plt::Plot; kw...)
plt plt
end end
# ----------------------------------------------------------------
# TODO: override this to update plot items (title, xlabel, etc) after creation # TODO: override this to update plot items (title, xlabel, etc) after creation
function updatePlotItems(plt::Plot{[PkgName]Package}, d::Dict) function updatePlotItems(plt::Plot{[PkgName]Package}, d::Dict)
end end
# ----------------------------------------------------------------
# function Base.display(::[PkgName]Package, plt::Plot)
# # TODO: display/show the plot
# end
function Base.display(::PlotsDisplay, plt::Plot{[PkgName]Package})
# TODO: display/show the plot
end
# -------------------------------
# function savepng(::[PkgName]Package, plt::PlottingObject, fn::AbstractString; kw...)
# # TODO: save a PNG of the underlying plot/subplot object
# end
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{[PkgName]Package})
# TODO: write a png to io
end
# -------------------------------
function buildSubplotObject!(subplt::Subplot{[PkgName]Package}) function buildSubplotObject!(subplt::Subplot{[PkgName]Package})
# TODO: build the underlying Subplot object. this is where you might layout the panes within a GUI window, for example # TODO: build the underlying Subplot object. this is where you might layout the panes within a GUI window, for example
end end
# ----------------------------------------------------------------
# function Base.display(::[PkgName]Package, subplt::Subplot) function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{[PkgName]Package})
# # TODO: display/show the Subplot object # TODO: write a png to io
# end end
function Base.display(::PlotsDisplay, plt::Plot{[PkgName]Package})
# TODO: display/show the plot
end
function Base.display(::PlotsDisplay, plt::Subplot{[PkgName]Package}) function Base.display(::PlotsDisplay, plt::Subplot{[PkgName]Package})
# TODO: display/show the subplot # TODO: display/show the subplot

View File

@ -92,6 +92,10 @@ function addUnicodeSeries!(o, d::Dict, addlegend::Bool)
end end
function handlePlotColors(::UnicodePlotsPackage, d::Dict)
# TODO: something special for unicodeplots, since it doesn't take kindly to people messing with its color palette
end
# ------------------------------- # -------------------------------
@ -117,18 +121,24 @@ function plot!(::UnicodePlotsPackage, plt::Plot; kw...)
plt plt
end end
function Base.display(::UnicodePlotsPackage, plt::Plot)
rebuildUnicodePlot!(plt) function updatePlotItems(plt::Plot{UnicodePlotsPackage}, d::Dict)
show(plt.o) for k in (:title, :xlabel, :ylabel)
if haskey(d, k)
plt.initargs[k] = d[k]
end
end
end end
# ------------------------------- # -------------------------------
function savepng(::UnicodePlotsPackage, plt::PlottingObject, fn::AbstractString, args...) # function savepng(::UnicodePlotsPackage, plt::PlottingObject, fn::AbstractString, args...)
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{UnicodePlotsPackage})
# make some whitespace and show the plot # make some whitespace and show the plot
println("\n\n\n\n\n\n") println("\n\n\n\n\n\n")
display(plt) gui(plt)
@osx_only begin @osx_only begin
# BEGIN HACK # BEGIN HACK
@ -156,14 +166,21 @@ end
# we don't do very much for subplots... just stack them vertically # we don't do very much for subplots... just stack them vertically
function buildSubplotObject!(::UnicodePlotsPackage, subplt::Subplot) function buildSubplotObject!(subplt::Subplot{UnicodePlotsPackage})
nothing nothing
end end
function Base.display(::UnicodePlotsPackage, subplt::Subplot) function Base.display(::PlotsDisplay, plt::Plot{UnicodePlotsPackage})
rebuildUnicodePlot!(plt)
show(plt.o)
end
function Base.display(::PlotsDisplay, subplt::Subplot{UnicodePlotsPackage})
for plt in subplt.plts for plt in subplt.plts
display(UnicodePlotsPackage(), plt) gui(plt)
end end
end end

View File

@ -33,8 +33,8 @@ const winston_marker = Dict(:none=>".",
supportedArgs(::WinstonPackage) = setdiff(_allArgs, [:heatmap_c, :fillto, :pos, :markercolor, :background_color]) supportedArgs(::WinstonPackage) = setdiff(_allArgs, [:heatmap_c, :fillto, :pos, :markercolor, :background_color])
supportedAxes(::WinstonPackage) = [:auto, :left] supportedAxes(::WinstonPackage) = [:auto, :left]
supportedTypes(::WinstonPackage) = [:none, :line, :path, :sticks, :scatter, :hist, :bar] supportedTypes(::WinstonPackage) = [:none, :line, :path, :sticks, :scatter, :hist, :bar]
supportedStyles(::WinstonPackage) = intersect(_allStyles, collect(keys(winston_linestyle))) # [:auto, :solid, :dash, :dot, :dashdot] supportedStyles(::WinstonPackage) = intersect(_allStyles, collect(keys(winston_linestyle)))
supportedMarkers(::WinstonPackage) = intersect(_allMarkers, collect(keys(winston_marker))) # [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1] supportedMarkers(::WinstonPackage) = intersect(_allMarkers, collect(keys(winston_marker)))
subplotSupported(::WinstonPackage) = false subplotSupported(::WinstonPackage) = false
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@ -51,42 +51,9 @@ subplotSupported(::WinstonPackage) = false
function plot(pkg::WinstonPackage; kw...) function plot(pkg::WinstonPackage; kw...)
d = Dict(kw) d = Dict(kw)
# bgcolor
# create a new window
# the call to figure does a few things here:
# get a new unique id
# create a new GtkWindow (or Tk?)
# w,h = d[:size]
# canvas = Gtk.GtkCanvasLeaf()
# window = Gtk.GtkWindowLeaf(canvas, d[:windowtitle], w, h)
# figidx = Winston.figure(; name = d[:windowtitle], width = w, height = h)
# # skip the current fig stuff... just grab the fig directly
# fig = Winston._display.figs[figidx]
# overwrite the placeholder FramedPlot with our own
# fig.plot = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel])
wplt = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel]) wplt = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel])
# # using the figure index returned from Winston.figure, make this plot current and get the
# # Figure object (fields: window::GtkWindow and plot::FramedPlot)
# Winston.switchfig(Winston._display, figidx)
# fig = Winston.curfig(Winston._display)
# Winston._pwinston = fig.plot
# Winston.setattr(fig.plot, "xlabel", d[:xlabel])
# Winston.setattr(fig.plot, "ylabel", d[:ylabel])
# Winston.setattr(fig.plot, "title", d[:title])
Plot(wplt, pkg, 0, d, Dict[]) Plot(wplt, pkg, 0, d, Dict[])
# Plot((window, canvas, wplt), pkg, 0, d, Dict[])
# Plot((fig, figidx), pkg, 0, d, Dict[])
end end
copy_remove(d::Dict, s::Symbol) = delete!(copy(d), s) copy_remove(d::Dict, s::Symbol) = delete!(copy(d), s)
@ -203,14 +170,48 @@ function plot!(::WinstonPackage, plt::Plot; kw...)
end end
function updatePlotItems(plt::Plot{WinstonPackage}, d::Dict)
window, canvas, wplt = getWinstonItems(plt)
for k in (:xlabel, :ylabel, :title)
if haskey(d, k)
Winston.setattr(wplt, string(k), d[k])
end
end
end
# -------------------------------
# function savepng(::WinstonPackage, plt::PlottingObject, fn::AbstractString; kw...)
# f = open(fn, "w")
# window, canvas, wplt = getWinstonItems(plt)
# addWinstonLegend(plt, wplt)
# writemime(f, "image/png", wplt)
# close(f)
# end
# -------------------------------
function buildSubplotObject!(subplt::Subplot{WinstonPackage})
# TODO: build the underlying Subplot object. this is where you might layout the panes within a GUI window, for example
end
# ----------------------------------------------------------------
function addWinstonLegend(plt::Plot, wplt) function addWinstonLegend(plt::Plot, wplt)
Winston.legend(wplt, [sd[:label] for sd in plt.seriesargs]) Winston.legend(wplt, [sd[:label] for sd in plt.seriesargs])
end end
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{WinstonPackage})
window, canvas, wplt = getWinstonItems(plt)
addWinstonLegend(plt, wplt)
writemime(io, "image/png", wplt)
end
function Base.display(::WinstonPackage, plt::Plot)
# recreate the legend function Base.display(::PlotsDisplay, plt::Plot{WinstonPackage})
# fig, figidx = plt.o
window, canvas, wplt = getWinstonItems(plt) window, canvas, wplt = getWinstonItems(plt)
@ -219,45 +220,16 @@ function Base.display(::WinstonPackage, plt::Plot)
w,h = plt.initargs[:size] w,h = plt.initargs[:size]
canvas = Gtk.GtkCanvasLeaf() canvas = Gtk.GtkCanvasLeaf()
window = Gtk.GtkWindowLeaf(canvas, plt.initargs[:windowtitle], w, h) window = Gtk.GtkWindowLeaf(canvas, plt.initargs[:windowtitle], w, h)
# wplt = plt.o
plt.o = (window, canvas, wplt) plt.o = (window, canvas, wplt)
# else
# window, canvas, wplt = plt.o
end end
addWinstonLegend(plt, wplt) addWinstonLegend(plt, wplt)
Winston.display(canvas, wplt) Winston.display(canvas, wplt)
Gtk.showall(window) Gtk.showall(window)
# # display the Figure
# display(fig)
# display(plt.o.window)
# # show it
# Winston.display(plt.o.plot)
end
# -------------------------------
function savepng(::WinstonPackage, plt::PlottingObject, fn::AbstractString; kw...)
f = open(fn, "w")
window, canvas, wplt = getWinstonItems(plt)
addWinstonLegend(plt, wplt)
writemime(f, "image/png", wplt)
close(f)
end end
# ------------------------------- function Base.display(::PlotsDisplay, subplt::Subplot{WinstonPackage})
function buildSubplotObject!(::WinstonPackage, subplt::Subplot)
# TODO: build the underlying Subplot object. this is where you might layout the panes within a GUI window, for example
end
function Base.display(::WinstonPackage, subplt::Subplot)
# TODO: display/show the Subplot object # TODO: display/show the Subplot object
end end

View File

@ -136,7 +136,8 @@ end
# TODO: try to use the algorithms from https://github.com/timothyrenner/ColorBrewer.jl # TODO: try to use the algorithms from https://github.com/timothyrenner/ColorBrewer.jl
# TODO: allow the setting of the algorithm, either by passing a symbol (:colordiff, :fixed, etc) or a function? # TODO: allow the setting of the algorithm, either by passing a symbol (:colordiff, :fixed, etc) or a function?
function getBackgroundRGBColor(c, d::Dict) # function getBackgroundRGBColor(c, d::Dict)
function handlePlotColors(::PlottingPackage, d::Dict)
if :background_color in supportedArgs() if :background_color in supportedArgs()
bgcolor = convertColor(d[:background_color]) bgcolor = convertColor(d[:background_color])
else else
@ -159,7 +160,8 @@ function getBackgroundRGBColor(c, d::Dict)
d[:foreground_color] = convertColor(d[:foreground_color]) d[:foreground_color] = convertColor(d[:foreground_color])
end end
bgcolor # bgcolor
d[:background_color] = bgcolor
end end
# converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically # converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically
@ -171,8 +173,8 @@ function getSeriesRGBColor(c, d::Dict, n::Int)
c = convertColor(c) c = convertColor(c)
end end
# should be a RGB now... either it was passed in, generated automatically, or created from a string # # should be a RGB now... either it was passed in, generated automatically, or created from a string
@assert isa(c, Colorant) # @assert isa(c, Colorant)
# return the RGB # return the RGB
c c

View File

@ -93,7 +93,7 @@ function plot!(plt::Plot, args...; kw...)
plot!(plt.plotter, plt; d...) plot!(plt.plotter, plt; d...)
end end
updatePlotItems(plt.plotter, plt, d) updatePlotItems(plt, d)
currentPlot!(plt) currentPlot!(plt)
# NOTE: lets ignore the show param and effectively use the semicolon at the end of the REPL statement # NOTE: lets ignore the show param and effectively use the semicolon at the end of the REPL statement