diff --git a/docs/readme_template.md b/docs/readme_template.md index 79ede85c..0d387774 100644 --- a/docs/readme_template.md +++ b/docs/readme_template.md @@ -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__: Call `gui()` to display the plot in a window. Interactivity depends on backend. Showing at the REPL implicitly calls this. + ## TODO features: - [x] Plot vectors/matrices/functions diff --git a/src/Plots.jl b/src/Plots.jl index 1e4858e7..dcef62e4 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -41,6 +41,7 @@ export ylabel!, savepng, + gui, backends, aliases, @@ -103,23 +104,18 @@ ylabel!(plt::Plot, s::AbstractString) = plot!(plt; ylabel = s) 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(::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) -# # print(io, "
")
-# png = MIME("image/png")
-# print(io, "")
-# end
+# override the REPL display to open a gui window
+Base.display(::Base.REPL.REPLDisplay, ::MIME"text/plain", plt::PlottingObject) = gui(plt)
-# override the REPL display
-Base.display(::Base.REPL.REPLDisplay, ::MIME"text/plain", plt::PlottingObject) = display(PlotsDisplay(), plt)
-
function __init__()
global const CURRENT_BACKEND = pickDefaultBackend()
diff --git a/src/args.jl b/src/args.jl
index 4af76fad..64497612 100644
--- a/src/args.jl
+++ b/src/args.jl
@@ -265,7 +265,8 @@ function getPlotArgs(pkg::PlottingPackage, kw, idx::Int)
end
# 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
delete!(d, :x)
diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl
index 8099597d..dbee457b 100644
--- a/src/backends/gadfly.jl
+++ b/src/backends/gadfly.jl
@@ -211,53 +211,35 @@ function plot!(::GadflyPackage, plt::Plot; kw...)
end
-function findGuideAndSet(plt::Plot, t::DataType, s::AbstractString)
- for guide in plt.o.guides
+function findGuideAndSet(gplt, t::DataType, s::AbstractString)
+ for (i,guide) in enumerate(gplt.guides)
if isa(guide, t)
- guide.label = s
+ gplt.guides[i] = t(s)
+ # guide.label = s
end
end
end
-function updatePlotItems(::GadflyPackage, plt::Plot, d::Dict)
- haskey(d, :title) && findGuideAndSet(plt, Gadfly.Guide.title, d[:title])
- haskey(d, :xlabel) && findGuideAndSet(plt, Gadfly.Guide.xlabel, d[:xlabel])
- haskey(d, :ylabel) && findGuideAndSet(plt, Gadfly.Guide.ylabel, d[:ylabel])
+function updateGadflyGuides(gplt, d::Dict)
+ haskey(d, :title) && findGuideAndSet(gplt, Gadfly.Guide.title, d[:title])
+ haskey(d, :xlabel) && findGuideAndSet(gplt, Gadfly.Guide.xlabel, d[:xlabel])
+ haskey(d, :ylabel) && findGuideAndSet(gplt, Gadfly.Guide.ylabel, d[:ylabel])
end
-function setGadflyDisplaySize(w,h)
- Compose.set_default_graphic_size(w * Compose.px, h * Compose.px)
+function updatePlotItems(plt::Plot{GadflyPackage}, d::Dict)
+ updateGadflyGuides(plt.o, d)
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]...)
- display(plt.o)
+
+# create the underlying object (each backend will do this differently)
+function buildSubplotObject!(subplt::Subplot{GadflyPackage})
+ subplt.o = nothing
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, subplt::Subplot) = buildGadflySubplotContext(subplt)
@@ -273,11 +255,21 @@ function buildGadflySubplotContext(subplt::Subplot)
Gadfly.vstack(rows...)
end
-# create the underlying object (each backend will do this differently)
-function buildSubplotObject!(subplt::Subplot{GadflyPackage})
- subplt.o = nothing
+function setGadflyDisplaySize(w,h)
+ Compose.set_default_graphic_size(w * Compose.px, h * Compose.px)
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})
setGadflyDisplaySize(plt.initargs[:size]...)
diff --git a/src/backends/immerse.jl b/src/backends/immerse.jl
index 1ff505d3..442df58a 100644
--- a/src/backends/immerse.jl
+++ b/src/backends/immerse.jl
@@ -43,36 +43,13 @@ function plot!(::ImmersePackage, plt::Plot; kw...)
plt
end
-function Base.display(::ImmersePackage, plt::Plot)
- fig, gplt = plt.o
- if fig == nothing
- 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
+function updatePlotItems(plt::Plot{ImmersePackage}, d::Dict)
+ updateGadflyGuides(plt.o[2], d)
end
-# -------------------------------
+# ----------------------------------------------------------------
function buildSubplotObject!(subplt::Subplot{ImmersePackage})
@@ -119,15 +96,37 @@ function buildSubplotObject!(subplt::Subplot{ImmersePackage})
subplt.o = win
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
for plt in subplt.plts
fig, gplt = plt.o
Immerse.figure(fig.figno; displayfig = false)
display(gplt)
- # display(Immerse.Figure(fig.canvas, gplt))
end
# o is the window... show it
diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl
index 8121039d..c4225e86 100644
--- a/src/backends/pyplot.jl
+++ b/src/backends/pyplot.jl
@@ -107,7 +107,7 @@ function updateAxisColors(ax, fgcolor)
ax[:title][:set_color](fgcolor)
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
# PyPlot.figure(num) # makes this current
- makePlotCurrent(plt)
+ makePyPlotCurrent(plt)
if !(d[:linetype] in 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
-function updatePlotItems(::PyPlotPackage, plt::Plot, d::Dict)
- makePlotCurrent(plt)
+function updatePlotItems(plt::Plot{PyPlotPackage}, d::Dict)
+ makePyPlotCurrent(plt)
haskey(d, :title) && PyPlot.title(d[:title])
haskey(d, :xlabel) && PyPlot.xlabel(d[:xlabel])
haskey(d, :ylabel) && PyPlot.ylabel(d[:ylabel])
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...)
- fig, num = plt.o
- addPyPlotLegend(plt)
- f = open(fn, "w")
- writemime(f, "image/png", fig)
- close(f)
-end
+# function savepng(::PyPlotPackage, plt::PlottingObject, fn::AbstractString, args...)
+# fig, num = plt.o
+# addPyPlotLegend(plt)
+# f = open(fn, "w")
+# writemime(f, "image/png", fig)
+# close(f)
+# end
-# -------------------------------
+
+# -----------------------------------------------------------------
# create the underlying object (each backend will do this differently)
function buildSubplotObject!(subplt::Subplot{PyPlotPackage})
error("unsupported")
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)
end
diff --git a/src/backends/qwt.jl b/src/backends/qwt.jl
index a5f1649f..8bf15897 100644
--- a/src/backends/qwt.jl
+++ b/src/backends/qwt.jl
@@ -57,20 +57,15 @@ function plot!(::QwtPackage, plt::Plot; kw...)
plt
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, :xlabel) && Qwt.xlabel(plt.o, d[:xlabel])
haskey(d, :ylabel) && Qwt.ylabel(plt.o, d[:ylabel])
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
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
Qwt.refresh(plt.o)
end
diff --git a/src/backends/template.jl b/src/backends/template.jl
index 794ac94c..2bf2a3e6 100644
--- a/src/backends/template.jl
+++ b/src/backends/template.jl
@@ -34,42 +34,27 @@ function plot!(::[PkgName]Package, plt::Plot; kw...)
plt
end
+# ----------------------------------------------------------------
# TODO: override this to update plot items (title, xlabel, etc) after creation
function updatePlotItems(plt::Plot{[PkgName]Package}, d::Dict)
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})
# TODO: build the underlying Subplot object. this is where you might layout the panes within a GUI window, for example
end
+# ----------------------------------------------------------------
-# function Base.display(::[PkgName]Package, subplt::Subplot)
-# # TODO: display/show the Subplot object
-# end
+function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{[PkgName]Package})
+ # TODO: write a png to io
+end
+
+function Base.display(::PlotsDisplay, plt::Plot{[PkgName]Package})
+ # TODO: display/show the plot
+end
function Base.display(::PlotsDisplay, plt::Subplot{[PkgName]Package})
# TODO: display/show the subplot
diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl
index f83aebf0..2b5382d9 100644
--- a/src/backends/unicodeplots.jl
+++ b/src/backends/unicodeplots.jl
@@ -92,6 +92,10 @@ function addUnicodeSeries!(o, d::Dict, addlegend::Bool)
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
end
-function Base.display(::UnicodePlotsPackage, plt::Plot)
- rebuildUnicodePlot!(plt)
- show(plt.o)
+
+function updatePlotItems(plt::Plot{UnicodePlotsPackage}, d::Dict)
+ for k in (:title, :xlabel, :ylabel)
+ if haskey(d, k)
+ plt.initargs[k] = d[k]
+ 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
println("\n\n\n\n\n\n")
- display(plt)
+ gui(plt)
@osx_only begin
# BEGIN HACK
@@ -156,14 +166,21 @@ end
# we don't do very much for subplots... just stack them vertically
-function buildSubplotObject!(::UnicodePlotsPackage, subplt::Subplot)
+function buildSubplotObject!(subplt::Subplot{UnicodePlotsPackage})
nothing
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
- display(UnicodePlotsPackage(), plt)
+ gui(plt)
end
end
diff --git a/src/backends/winston.jl b/src/backends/winston.jl
index a19ff600..5b913ada 100644
--- a/src/backends/winston.jl
+++ b/src/backends/winston.jl
@@ -33,8 +33,8 @@ const winston_marker = Dict(:none=>".",
supportedArgs(::WinstonPackage) = setdiff(_allArgs, [:heatmap_c, :fillto, :pos, :markercolor, :background_color])
supportedAxes(::WinstonPackage) = [:auto, :left]
supportedTypes(::WinstonPackage) = [:none, :line, :path, :sticks, :scatter, :hist, :bar]
-supportedStyles(::WinstonPackage) = intersect(_allStyles, collect(keys(winston_linestyle))) # [:auto, :solid, :dash, :dot, :dashdot]
-supportedMarkers(::WinstonPackage) = intersect(_allMarkers, collect(keys(winston_marker))) # [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1]
+supportedStyles(::WinstonPackage) = intersect(_allStyles, collect(keys(winston_linestyle)))
+supportedMarkers(::WinstonPackage) = intersect(_allMarkers, collect(keys(winston_marker)))
subplotSupported(::WinstonPackage) = false
# ---------------------------------------------------------------------------
@@ -51,42 +51,9 @@ subplotSupported(::WinstonPackage) = false
function plot(pkg::WinstonPackage; 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])
-
- # # 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((window, canvas, wplt), pkg, 0, d, Dict[])
- # Plot((fig, figidx), pkg, 0, d, Dict[])
end
copy_remove(d::Dict, s::Symbol) = delete!(copy(d), s)
@@ -203,14 +170,48 @@ function plot!(::WinstonPackage, plt::Plot; kw...)
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)
Winston.legend(wplt, [sd[:label] for sd in plt.seriesargs])
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
- # fig, figidx = plt.o
+
+function Base.display(::PlotsDisplay, plt::Plot{WinstonPackage})
window, canvas, wplt = getWinstonItems(plt)
@@ -219,45 +220,16 @@ function Base.display(::WinstonPackage, plt::Plot)
w,h = plt.initargs[:size]
canvas = Gtk.GtkCanvasLeaf()
window = Gtk.GtkWindowLeaf(canvas, plt.initargs[:windowtitle], w, h)
- # wplt = plt.o
plt.o = (window, canvas, wplt)
- # else
- # window, canvas, wplt = plt.o
end
addWinstonLegend(plt, wplt)
Winston.display(canvas, wplt)
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
-# -------------------------------
-
-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)
+function Base.display(::PlotsDisplay, subplt::Subplot{WinstonPackage})
# TODO: display/show the Subplot object
end
diff --git a/src/colors.jl b/src/colors.jl
index fafdb219..722dac20 100644
--- a/src/colors.jl
+++ b/src/colors.jl
@@ -136,7 +136,8 @@ end
# 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?
-function getBackgroundRGBColor(c, d::Dict)
+# function getBackgroundRGBColor(c, d::Dict)
+function handlePlotColors(::PlottingPackage, d::Dict)
if :background_color in supportedArgs()
bgcolor = convertColor(d[:background_color])
else
@@ -159,7 +160,8 @@ function getBackgroundRGBColor(c, d::Dict)
d[:foreground_color] = convertColor(d[:foreground_color])
end
- bgcolor
+ # bgcolor
+ d[:background_color] = bgcolor
end
# 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)
end
- # should be a RGB now... either it was passed in, generated automatically, or created from a string
- @assert isa(c, Colorant)
+ # # should be a RGB now... either it was passed in, generated automatically, or created from a string
+ # @assert isa(c, Colorant)
# return the RGB
c
diff --git a/src/plot.jl b/src/plot.jl
index 07e7c6c2..8bff8e5a 100644
--- a/src/plot.jl
+++ b/src/plot.jl
@@ -93,7 +93,7 @@ function plot!(plt::Plot, args...; kw...)
plot!(plt.plotter, plt; d...)
end
- updatePlotItems(plt.plotter, plt, d)
+ updatePlotItems(plt, d)
currentPlot!(plt)
# NOTE: lets ignore the show param and effectively use the semicolon at the end of the REPL statement