renaming: AbstractPlot and AbstractBackend

This commit is contained in:
Thomas Breloff 2016-03-10 23:08:04 -05:00
parent 5501605a1f
commit b5f08838b3
26 changed files with 539 additions and 538 deletions

View File

@ -10,6 +10,7 @@ using Requires
using FixedSizeArrays using FixedSizeArrays
export export
AbstractPlot,
Plot, Plot,
Subplot, Subplot,
SubplotLayout, SubplotLayout,
@ -185,18 +186,18 @@ scatter3d(args...; kw...) = plot(args...; kw..., linetype = :scatter3d)
scatter3d!(args...; kw...) = plot!(args...; kw..., linetype = :scatter3d) scatter3d!(args...; kw...) = plot!(args...; kw..., linetype = :scatter3d)
title!(s::@compat(AbstractString); kw...) = plot!(; title = s, kw...) title!(s::AbstractString; kw...) = plot!(; title = s, kw...)
xlabel!(s::@compat(AbstractString); kw...) = plot!(; xlabel = s, kw...) xlabel!(s::AbstractString; kw...) = plot!(; xlabel = s, kw...)
ylabel!(s::@compat(AbstractString); kw...) = plot!(; ylabel = s, kw...) ylabel!(s::AbstractString; kw...) = plot!(; ylabel = s, kw...)
xlims!{T<:Real,S<:Real}(lims::@compat(Tuple{T,S}); kw...) = plot!(; xlims = lims, kw...) xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}; kw...) = plot!(; xlims = lims, kw...)
ylims!{T<:Real,S<:Real}(lims::@compat(Tuple{T,S}); kw...) = plot!(; ylims = lims, kw...) ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}; kw...) = plot!(; ylims = lims, kw...)
xlims!(xmin::Real, xmax::Real; kw...) = plot!(; xlims = (xmin,xmax), kw...) xlims!(xmin::Real, xmax::Real; kw...) = plot!(; xlims = (xmin,xmax), kw...)
ylims!(ymin::Real, ymax::Real; kw...) = plot!(; ylims = (ymin,ymax), kw...) ylims!(ymin::Real, ymax::Real; kw...) = plot!(; ylims = (ymin,ymax), kw...)
xticks!{T<:Real}(v::AVec{T}; kw...) = plot!(; xticks = v, kw...) xticks!{T<:Real}(v::AVec{T}; kw...) = plot!(; xticks = v, kw...)
yticks!{T<:Real}(v::AVec{T}; kw...) = plot!(; yticks = v, kw...) yticks!{T<:Real}(v::AVec{T}; kw...) = plot!(; yticks = v, kw...)
xticks!{T<:Real,S<:@compat(AbstractString)}( xticks!{T<:Real,S<:AbstractString}(
ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(; xticks = (ticks,labels), kw...) ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(; xticks = (ticks,labels), kw...)
yticks!{T<:Real,S<:@compat(AbstractString)}( yticks!{T<:Real,S<:AbstractString}(
ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(; yticks = (ticks,labels), kw...) ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(; yticks = (ticks,labels), kw...)
annotate!(anns...; kw...) = plot!(; annotation = anns, kw...) annotate!(anns...; kw...) = plot!(; annotation = anns, kw...)
annotate!{T<:Tuple}(anns::AVec{T}; kw...) = plot!(; annotation = anns, kw...) annotate!{T<:Tuple}(anns::AVec{T}; kw...) = plot!(; annotation = anns, kw...)
@ -205,18 +206,18 @@ yflip!(flip::Bool = true; kw...) = plot!(; yflip = flip
xaxis!(args...; kw...) = plot!(; xaxis = args, kw...) xaxis!(args...; kw...) = plot!(; xaxis = args, kw...)
yaxis!(args...; kw...) = plot!(; yaxis = args, kw...) yaxis!(args...; kw...) = plot!(; yaxis = args, kw...)
title!(plt::Plot, s::@compat(AbstractString); kw...) = plot!(plt; title = s, kw...) title!(plt::Plot, s::AbstractString; kw...) = plot!(plt; title = s, kw...)
xlabel!(plt::Plot, s::@compat(AbstractString); kw...) = plot!(plt; xlabel = s, kw...) xlabel!(plt::Plot, s::AbstractString; kw...) = plot!(plt; xlabel = s, kw...)
ylabel!(plt::Plot, s::@compat(AbstractString); kw...) = plot!(plt; ylabel = s, kw...) ylabel!(plt::Plot, s::AbstractString; kw...) = plot!(plt; ylabel = s, kw...)
xlims!{T<:Real,S<:Real}(plt::Plot, lims::@compat(Tuple{T,S}); kw...) = plot!(plt; xlims = lims, kw...) xlims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}; kw...) = plot!(plt; xlims = lims, kw...)
ylims!{T<:Real,S<:Real}(plt::Plot, lims::@compat(Tuple{T,S}); kw...) = plot!(plt; ylims = lims, kw...) ylims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}; kw...) = plot!(plt; ylims = lims, kw...)
xlims!(plt::Plot, xmin::Real, xmax::Real; kw...) = plot!(plt; xlims = (xmin,xmax), kw...) xlims!(plt::Plot, xmin::Real, xmax::Real; kw...) = plot!(plt; xlims = (xmin,xmax), kw...)
ylims!(plt::Plot, ymin::Real, ymax::Real; kw...) = plot!(plt; ylims = (ymin,ymax), kw...) ylims!(plt::Plot, ymin::Real, ymax::Real; kw...) = plot!(plt; ylims = (ymin,ymax), kw...)
xticks!{T<:Real}(plt::Plot, ticks::AVec{T}; kw...) = plot!(plt; xticks = ticks, kw...) xticks!{T<:Real}(plt::Plot, ticks::AVec{T}; kw...) = plot!(plt; xticks = ticks, kw...)
yticks!{T<:Real}(plt::Plot, ticks::AVec{T}; kw...) = plot!(plt; yticks = ticks, kw...) yticks!{T<:Real}(plt::Plot, ticks::AVec{T}; kw...) = plot!(plt; yticks = ticks, kw...)
xticks!{T<:Real,S<:@compat(AbstractString)}(plt::Plot, xticks!{T<:Real,S<:AbstractString}(plt::Plot,
ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(plt; xticks = (ticks,labels), kw...) ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(plt; xticks = (ticks,labels), kw...)
yticks!{T<:Real,S<:@compat(AbstractString)}(plt::Plot, yticks!{T<:Real,S<:AbstractString}(plt::Plot,
ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(plt; yticks = (ticks,labels), kw...) ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(plt; yticks = (ticks,labels), kw...)
annotate!(plt::Plot, anns...; kw...) = plot!(plt; annotation = anns, kw...) annotate!(plt::Plot, anns...; kw...) = plot!(plt; annotation = anns, kw...)
annotate!{T<:Tuple}(plt::Plot, anns::AVec{T}; kw...) = plot!(plt; annotation = anns, kw...) annotate!{T<:Tuple}(plt::Plot, anns::AVec{T}; kw...) = plot!(plt; annotation = anns, kw...)
@ -236,7 +237,7 @@ function __init__()
# override IJulia inline display # override IJulia inline display
if isijulia() if isijulia()
@eval import IJulia @eval import IJulia
IJulia.display_dict(plt::PlottingObject) = Dict{ASCIIString, ByteString}("text/html" => sprint(writemime, "text/html", plt)) IJulia.display_dict(plt::AbstractPlot) = Dict{ASCIIString, ByteString}("text/html" => sprint(writemime, "text/html", plt))
end end
end end

View File

@ -9,7 +9,7 @@ function Animation()
Animation(tmpdir, ASCIIString[]) Animation(tmpdir, ASCIIString[])
end end
function frame{P<:PlottingObject}(anim::Animation, plt::P=current()) function frame{P<:AbstractPlot}(anim::Animation, plt::P=current())
i = length(anim.frames) + 1 i = length(anim.frames) + 1
filename = @sprintf("%06d.png", i) filename = @sprintf("%06d.png", i)
png(plt, joinpath(anim.dir, filename)) png(plt, joinpath(anim.dir, filename))

View File

@ -185,7 +185,7 @@ _plotDefaults[:overwrite_figure] = false
# TODO: x/y scales # TODO: x/y scales
const _allArgs = sort(collect(union(keys(_seriesDefaults), keys(_plotDefaults)))) const _allArgs = sort(collect(union(keys(_seriesDefaults), keys(_plotDefaults))))
supportedArgs(::PlottingPackage) = error("supportedArgs not defined") #_allArgs supportedArgs(::AbstractBackend) = error("supportedArgs not defined") #_allArgs
supportedArgs() = supportedArgs(backend()) supportedArgs() = supportedArgs(backend())
@ -632,7 +632,7 @@ end
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
function warnOnUnsupportedArgs(pkg::PlottingPackage, d::Dict) function warnOnUnsupportedArgs(pkg::AbstractBackend, d::Dict)
for k in sortedkeys(d) for k in sortedkeys(d)
if (!(k in supportedArgs(pkg)) if (!(k in supportedArgs(pkg))
&& k != :subplot && k != :subplot
@ -642,11 +642,11 @@ function warnOnUnsupportedArgs(pkg::PlottingPackage, d::Dict)
end end
end end
_markershape_supported(pkg::PlottingPackage, shape::Symbol) = shape in supportedMarkers(pkg) _markershape_supported(pkg::AbstractBackend, shape::Symbol) = shape in supportedMarkers(pkg)
_markershape_supported(pkg::PlottingPackage, shape::Shape) = Shape in supportedMarkers(pkg) _markershape_supported(pkg::AbstractBackend, shape::Shape) = Shape in supportedMarkers(pkg)
_markershape_supported(pkg::PlottingPackage, shapes::AVec) = all([_markershape_supported(pkg, shape) for shape in shapes]) _markershape_supported(pkg::AbstractBackend, shapes::AVec) = all([_markershape_supported(pkg, shape) for shape in shapes])
function warnOnUnsupported(pkg::PlottingPackage, d::Dict) function warnOnUnsupported(pkg::AbstractBackend, d::Dict)
(d[:axis] in supportedAxes(pkg) (d[:axis] in supportedAxes(pkg)
|| warn("axis $(d[:axis]) is unsupported with $pkg. Choose from: $(supportedAxes(pkg))")) || warn("axis $(d[:axis]) is unsupported with $pkg. Choose from: $(supportedAxes(pkg))"))
(d[:linetype] == :none (d[:linetype] == :none
@ -661,7 +661,7 @@ function warnOnUnsupported(pkg::PlottingPackage, d::Dict)
|| warn("markershape $(d[:markershape]) is unsupported with $pkg. Choose from: $(supportedMarkers(pkg))")) || warn("markershape $(d[:markershape]) is unsupported with $pkg. Choose from: $(supportedMarkers(pkg))"))
end end
function warnOnUnsupportedScales(pkg::PlottingPackage, d::Dict) function warnOnUnsupportedScales(pkg::AbstractBackend, d::Dict)
for k in (:xscale, :yscale) for k in (:xscale, :yscale)
if haskey(d, k) if haskey(d, k)
d[k] in supportedScales(pkg) || warn("scale $(d[k]) is unsupported with $pkg. Choose from: $(supportedScales(pkg))") d[k] in supportedScales(pkg) || warn("scale $(d[k]) is unsupported with $pkg. Choose from: $(supportedScales(pkg))")
@ -709,7 +709,7 @@ convertLegendValue(val::Bool) = val ? :best : :none
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# build the argument dictionary for the plot # build the argument dictionary for the plot
function getPlotArgs(pkg::PlottingPackage, kw, idx::Int; set_defaults = true) function getPlotArgs(pkg::AbstractBackend, kw, idx::Int; set_defaults = true)
kwdict = Dict(kw) kwdict = Dict(kw)
d = Dict() d = Dict()
@ -746,7 +746,7 @@ end
# build the argument dictionary for a series # build the argument dictionary for a series
function getSeriesArgs(pkg::PlottingPackage, plotargs::Dict, kw, commandIndex::Int, plotIndex::Int, globalIndex::Int) # TODO, pass in plotargs, not plt function getSeriesArgs(pkg::AbstractBackend, plotargs::Dict, kw, commandIndex::Int, plotIndex::Int, globalIndex::Int) # TODO, pass in plotargs, not plt
kwdict = Dict(kw) kwdict = Dict(kw)
d = Dict() d = Dict()

View File

@ -1,8 +1,8 @@
immutable NoPackage <: PlottingPackage end immutable NoBackend <: AbstractBackend end
const _backendType = Dict{Symbol, DataType}(:none => NoPackage) const _backendType = Dict{Symbol, DataType}(:none => NoBackend)
const _backendSymbol = Dict{DataType, Symbol}(NoPackage => :none) const _backendSymbol = Dict{DataType, Symbol}(NoBackend => :none)
const _backends = Symbol[] const _backends = Symbol[]
const _initialized_backends = Set{Symbol}() const _initialized_backends = Set{Symbol}()
@ -10,12 +10,12 @@ backends() = _backends
backend_name() = CURRENT_BACKEND.sym backend_name() = CURRENT_BACKEND.sym
_backend_instance(sym::Symbol) = haskey(_backendType, sym) ? _backendType[sym]() : error("Unsupported backend $sym") _backend_instance(sym::Symbol) = haskey(_backendType, sym) ? _backendType[sym]() : error("Unsupported backend $sym")
macro init_plotting_pkg(s) macro init_backend(s)
str = lowercase(string(s)) str = lowercase(string(s))
sym = symbol(str) sym = symbol(str)
T = symbol(string(s) * "Package") T = symbol(string(s) * "Backend")
esc(quote esc(quote
immutable $T <: PlottingPackage end immutable $T <: AbstractBackend end
export $sym export $sym
$sym(; kw...) = (default(; kw...); backend(symbol($str))) $sym(; kw...) = (default(; kw...); backend(symbol($str)))
backend_name(::$T) = symbol($str) backend_name(::$T) = symbol($str)
@ -26,18 +26,18 @@ macro init_plotting_pkg(s)
end) end)
end end
@init_plotting_pkg Immerse @init_backend Immerse
@init_plotting_pkg Gadfly @init_backend Gadfly
@init_plotting_pkg PyPlot @init_backend PyPlot
@init_plotting_pkg Qwt @init_backend Qwt
@init_plotting_pkg UnicodePlots @init_backend UnicodePlots
@init_plotting_pkg Winston @init_backend Winston
@init_plotting_pkg Bokeh @init_backend Bokeh
@init_plotting_pkg Plotly @init_backend Plotly
@init_plotting_pkg PlotlyJS @init_backend PlotlyJS
@init_plotting_pkg GR @init_backend GR
@init_plotting_pkg GLVisualize @init_backend GLVisualize
@init_plotting_pkg PGFPlots @init_backend PGFPlots
include("backends/web.jl") include("backends/web.jl")
include("backends/supported.jl") include("backends/supported.jl")
@ -45,19 +45,19 @@ include("backends/supported.jl")
# --------------------------------------------------------- # ---------------------------------------------------------
plot(pkg::PlottingPackage; kw...) = error("plot($pkg; kw...) is not implemented") plot(pkg::AbstractBackend; kw...) = error("plot($pkg; kw...) is not implemented")
plot!(pkg::PlottingPackage, plt::Plot; kw...) = error("plot!($pkg, plt; kw...) is not implemented") plot!(pkg::AbstractBackend, plt::Plot; kw...) = error("plot!($pkg, plt; kw...) is not implemented")
_update_plot(pkg::PlottingPackage, plt::Plot, d::Dict) = error("_update_plot($pkg, plt, d) is not implemented") _update_plot(pkg::AbstractBackend, plt::Plot, d::Dict) = error("_update_plot($pkg, plt, d) is not implemented")
_update_plot_pos_size{P<:PlottingPackage}(plt::PlottingObject{P}, d::Dict) = nothing _update_plot_pos_size{P<:AbstractBackend}(plt::AbstractPlot{P}, d::Dict) = nothing
subplot(pkg::PlottingPackage; kw...) = error("subplot($pkg; kw...) is not implemented") subplot(pkg::AbstractBackend; kw...) = error("subplot($pkg; kw...) is not implemented")
subplot!(pkg::PlottingPackage, subplt::Subplot; kw...) = error("subplot!($pkg, subplt; kw...) is not implemented") subplot!(pkg::AbstractBackend, subplt::Subplot; kw...) = error("subplot!($pkg, subplt; kw...) is not implemented")
# --------------------------------------------------------- # ---------------------------------------------------------
type CurrentBackend type CurrentBackend
sym::Symbol sym::Symbol
pkg::PlottingPackage pkg::AbstractBackend
end end
CurrentBackend(sym::Symbol) = CurrentBackend(sym, _backend_instance(sym)) CurrentBackend(sym::Symbol) = CurrentBackend(sym, _backend_instance(sym))
@ -110,7 +110,7 @@ end
""" """
Set the plot backend. Set the plot backend.
""" """
function backend(pkg::PlottingPackage) function backend(pkg::AbstractBackend)
CURRENT_BACKEND.sym = backend_name(pkg) CURRENT_BACKEND.sym = backend_name(pkg)
CURRENT_BACKEND.pkg = pkg CURRENT_BACKEND.pkg = pkg
end end

View File

@ -2,7 +2,7 @@
# https://github.com/bokeh/Bokeh.jl # https://github.com/bokeh/Bokeh.jl
function _initialize_backend(::BokehPackage; kw...) function _initialize_backend(::BokehBackend; kw...)
@eval begin @eval begin
warn("Bokeh is no longer supported... many features will likely be broken.") warn("Bokeh is no longer supported... many features will likely be broken.")
import Bokeh import Bokeh
@ -64,7 +64,7 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::BokehPackage; kw...) function _create_plot(pkg::BokehBackend; kw...)
d = Dict(kw) d = Dict(kw)
# dumpdict(d, "plot", true) # dumpdict(d, "plot", true)
@ -88,7 +88,7 @@ function _create_plot(pkg::BokehPackage; kw...)
end end
function _add_series(::BokehPackage, plt::Plot; kw...) function _add_series(::BokehBackend, plt::Plot; kw...)
d = Dict(kw) d = Dict(kw)
# dumpdict(d, "plot!", true) # dumpdict(d, "plot!", true)
@ -114,22 +114,22 @@ 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 _update_plot(plt::Plot{BokehPackage}, d::Dict) function _update_plot(plt::Plot{BokehBackend}, d::Dict)
end end
function _update_plot_pos_size(plt::PlottingObject{BokehPackage}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{BokehBackend}, d::Dict)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# accessors for x/y data # accessors for x/y data
function Base.getindex(plt::Plot{BokehPackage}, i::Int) function Base.getindex(plt::Plot{BokehBackend}, i::Int)
series = plt.o.datacolumns[i].data series = plt.o.datacolumns[i].data
series[:x], series[:y] series[:x], series[:y]
end end
function Base.setindex!(plt::Plot{BokehPackage}, xy::Tuple, i::Integer) function Base.setindex!(plt::Plot{BokehBackend}, xy::Tuple, i::Integer)
series = plt.o.datacolumns[i].data series = plt.o.datacolumns[i].data
series[:x], series[:y] = xy series[:x], series[:y] = xy
plt plt
@ -138,7 +138,7 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _add_annotations{X,Y,V}(plt::Plot{BokehPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) function _add_annotations{X,Y,V}(plt::Plot{BokehBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
for ann in anns for ann in anns
# TODO: add the annotation to the plot # TODO: add the annotation to the plot
end end
@ -146,31 +146,31 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _create_subplot(subplt::Subplot{BokehPackage}, isbefore::Bool) function _create_subplot(subplt::Subplot{BokehBackend}, isbefore::Bool)
# 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 _expand_limits(lims, plt::Plot{BokehPackage}, isx::Bool) function _expand_limits(lims, plt::Plot{BokehBackend}, isx::Bool)
# TODO: call expand limits for each plot data # TODO: call expand limits for each plot data
end end
function _remove_axis(plt::Plot{BokehPackage}, isx::Bool) function _remove_axis(plt::Plot{BokehBackend}, isx::Bool)
# TODO: if plot is inner subplot, might need to remove ticks or axis labels # TODO: if plot is inner subplot, might need to remove ticks or axis labels
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{BokehPackage}) function Base.writemime(io::IO, ::MIME"image/png", plt::AbstractPlot{BokehBackend})
# TODO: write a png to io # TODO: write a png to io
warn("mime png not implemented") warn("mime png not implemented")
end end
function Base.display(::PlotsDisplay, plt::Plot{BokehPackage}) function Base.display(::PlotsDisplay, plt::Plot{BokehBackend})
Bokeh.showplot(plt.o) Bokeh.showplot(plt.o)
end end
function Base.display(::PlotsDisplay, plt::Subplot{BokehPackage}) function Base.display(::PlotsDisplay, plt::Subplot{BokehBackend})
# TODO: display/show the subplot # TODO: display/show the subplot
end end

View File

@ -2,7 +2,7 @@
# https://github.com/dcjones/Gadfly.jl # https://github.com/dcjones/Gadfly.jl
function _initialize_backend(::GadflyPackage; kw...) function _initialize_backend(::GadflyBackend; kw...)
@eval begin @eval begin
import Gadfly, Compose import Gadfly, Compose
export Gadfly, Compose export Gadfly, Compose
@ -205,7 +205,7 @@ function getGadflyMarkerTheme(d::Dict, plotargs::Dict)
) )
end end
function addGadflyContColorScale(plt::Plot{GadflyPackage}, c) function addGadflyContColorScale(plt::Plot{GadflyBackend}, c)
plt.plotargs[:colorbar] == :none && return plt.plotargs[:colorbar] == :none && return
if !isa(c, ColorGradient) if !isa(c, ColorGradient)
c = colorscheme(:bluesreds) c = colorscheme(:bluesreds)
@ -557,7 +557,7 @@ function createGadflyAnnotationObject(x, y, txt::PlotText)
)) ))
end end
function _add_annotations{X,Y,V}(plt::Plot{GadflyPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) function _add_annotations{X,Y,V}(plt::Plot{GadflyBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
for ann in anns for ann in anns
push!(plt.o.guides, createGadflyAnnotationObject(ann...)) push!(plt.o.guides, createGadflyAnnotationObject(ann...))
end end
@ -567,7 +567,7 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# create a blank Gadfly.Plot object # create a blank Gadfly.Plot object
function _create_plot(pkg::GadflyPackage; kw...) function _create_plot(pkg::GadflyBackend; kw...)
d = Dict(kw) d = Dict(kw)
gplt = createGadflyPlotObject(d) gplt = createGadflyPlotObject(d)
Plot(gplt, pkg, 0, d, Dict[]) Plot(gplt, pkg, 0, d, Dict[])
@ -575,7 +575,7 @@ end
# plot one data series # plot one data series
function _add_series(::GadflyPackage, plt::Plot; kw...) function _add_series(::GadflyBackend, plt::Plot; kw...)
# first clear out the temporary layer # first clear out the temporary layer
gplt = getGadflyContext(plt) gplt = getGadflyContext(plt)
@ -591,7 +591,7 @@ end
function _update_plot(plt::Plot{GadflyPackage}, d::Dict) function _update_plot(plt::Plot{GadflyBackend}, d::Dict)
updateGadflyGuides(plt, d) updateGadflyGuides(plt, d)
updateGadflyPlotTheme(plt, d) updateGadflyPlotTheme(plt, d)
end end
@ -607,12 +607,12 @@ function getGadflyMappings(plt::Plot, i::Integer)
mappings = [l.mapping for l in plt.seriesargs[i][:gadflylayers]] mappings = [l.mapping for l in plt.seriesargs[i][:gadflylayers]]
end end
function Base.getindex(plt::Plot{GadflyPackage}, i::Integer) function Base.getindex(plt::Plot{GadflyBackend}, i::Integer)
mapping = getGadflyMappings(plt, i)[1] mapping = getGadflyMappings(plt, i)[1]
mapping[:x], mapping[:y] mapping[:x], mapping[:y]
end end
function Base.setindex!(plt::Plot{GadflyPackage}, xy::Tuple, i::Integer) function Base.setindex!(plt::Plot{GadflyBackend}, xy::Tuple, i::Integer)
for mapping in getGadflyMappings(plt, i) for mapping in getGadflyMappings(plt, i)
mapping[:x], mapping[:y] = xy mapping[:x], mapping[:y] = xy
end end
@ -623,20 +623,20 @@ end
# create the underlying object (each backend will do this differently) # create the underlying object (each backend will do this differently)
function _create_subplot(subplt::Subplot{GadflyPackage}, isbefore::Bool) function _create_subplot(subplt::Subplot{GadflyBackend}, isbefore::Bool)
isbefore && return false # wait until after plotting to create the subplots isbefore && return false # wait until after plotting to create the subplots
subplt.o = nothing subplt.o = nothing
true true
end end
function _remove_axis(plt::Plot{GadflyPackage}, isx::Bool) function _remove_axis(plt::Plot{GadflyBackend}, isx::Bool)
gplt = getGadflyContext(plt) gplt = getGadflyContext(plt)
addOrReplace(gplt.guides, isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks; label=false) addOrReplace(gplt.guides, isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks; label=false)
addOrReplace(gplt.guides, isx ? Gadfly.Guide.xlabel : Gadfly.Guide.ylabel, "") addOrReplace(gplt.guides, isx ? Gadfly.Guide.xlabel : Gadfly.Guide.ylabel, "")
end end
function _expand_limits(lims, plt::Plot{GadflyPackage}, isx::Bool) function _expand_limits(lims, plt::Plot{GadflyBackend}, isx::Bool)
for l in getGadflyContext(plt).layers for l in getGadflyContext(plt).layers
_expand_limits(lims, l.mapping[isx ? :x : :y]) _expand_limits(lims, l.mapping[isx ? :x : :y])
end end
@ -646,8 +646,8 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
getGadflyContext(plt::Plot{GadflyPackage}) = plt.o getGadflyContext(plt::Plot{GadflyBackend}) = plt.o
getGadflyContext(subplt::Subplot{GadflyPackage}) = buildGadflySubplotContext(subplt) getGadflyContext(subplt::Subplot{GadflyBackend}) = buildGadflySubplotContext(subplt)
# create my Compose.Context grid by hstacking and vstacking the Gadfly.Plot objects # create my Compose.Context grid by hstacking and vstacking the Gadfly.Plot objects
function buildGadflySubplotContext(subplt::Subplot) function buildGadflySubplotContext(subplt::Subplot)
@ -675,7 +675,7 @@ setGadflyDisplaySize(subplt::Subplot) = setGadflyDisplaySize(getplotargs(subplt,
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
function dowritemime{P<:Union{GadflyPackage,ImmersePackage}}(io::IO, func, plt::PlottingObject{P}) function dowritemime{P<:Union{GadflyBackend,ImmerseBackend}}(io::IO, func, plt::AbstractPlot{P})
gplt = getGadflyContext(plt) gplt = getGadflyContext(plt)
setGadflyDisplaySize(plt) setGadflyDisplaySize(plt)
Gadfly.draw(func(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt) Gadfly.draw(func(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
@ -690,7 +690,7 @@ getGadflyWriteFunc(::MIME"application/x-tex") = Gadfly.PGF
getGadflyWriteFunc(m::MIME) = error("Unsupported in Gadfly/Immerse: ", m) getGadflyWriteFunc(m::MIME) = error("Unsupported in Gadfly/Immerse: ", m)
for mime in (MIME"image/png", MIME"image/svg+xml", MIME"application/pdf", MIME"application/postscript", MIME"application/x-tex") for mime in (MIME"image/png", MIME"image/svg+xml", MIME"application/pdf", MIME"application/postscript", MIME"application/x-tex")
@eval function Base.writemime{P<:Union{GadflyPackage,ImmersePackage}}(io::IO, ::$mime, plt::PlottingObject{P}) @eval function Base.writemime{P<:Union{GadflyBackend,ImmerseBackend}}(io::IO, ::$mime, plt::AbstractPlot{P})
func = getGadflyWriteFunc($mime()) func = getGadflyWriteFunc($mime())
dowritemime(io, func, plt) dowritemime(io, func, plt)
end end
@ -698,14 +698,14 @@ end
function Base.display(::PlotsDisplay, plt::Plot{GadflyPackage}) function Base.display(::PlotsDisplay, plt::Plot{GadflyBackend})
setGadflyDisplaySize(plt.plotargs[:size]...) setGadflyDisplaySize(plt.plotargs[:size]...)
display(plt.o) display(plt.o)
end end
function Base.display(::PlotsDisplay, subplt::Subplot{GadflyPackage}) function Base.display(::PlotsDisplay, subplt::Subplot{GadflyBackend})
setGadflyDisplaySize(getplotargs(subplt,1)[:size]...) setGadflyDisplaySize(getplotargs(subplt,1)[:size]...)
ctx = buildGadflySubplotContext(subplt) ctx = buildGadflySubplotContext(subplt)

View File

@ -2,7 +2,7 @@
# [WEBSITE] # [WEBSITE]
function _initialize_backend(::GLVisualizePackage; kw...) function _initialize_backend(::GLVisualizeBackend; kw...)
@eval begin @eval begin
import GLVisualize import GLVisualize
export GLVisualize export GLVisualize
@ -15,7 +15,7 @@ immutable GLScreenWrapper
window window
end end
function _create_plot(pkg::GLVisualizePackage; kw...) function _create_plot(pkg::GLVisualizeBackend; kw...)
d = Dict(kw) d = Dict(kw)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`) # TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc # TODO: initialize the plot... title, xlabel, bgcolor, etc
@ -27,7 +27,7 @@ function _create_plot(pkg::GLVisualizePackage; kw...)
end end
function _add_series(::GLVisualizePackage, plt::Plot; kw...) function _add_series(::GLVisualizeBackend, plt::Plot; kw...)
d = Dict(kw) d = Dict(kw)
# TODO: add one series to the underlying package # TODO: add one series to the underlying package
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
@ -37,7 +37,7 @@ function _add_series(::GLVisualizePackage, plt::Plot; kw...)
plt plt
end end
function _add_annotations{X,Y,V}(plt::Plot{GLVisualizePackage}, anns::AVec{@compat(Tuple{X,Y,V})}) function _add_annotations{X,Y,V}(plt::Plot{GLVisualizeBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
for ann in anns for ann in anns
# TODO: add the annotation to the plot # TODO: add the annotation to the plot
end end
@ -45,28 +45,28 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _before_update_plot(plt::Plot{GLVisualizePackage}) function _before_update_plot(plt::Plot{GLVisualizeBackend})
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 _update_plot(plt::Plot{GLVisualizePackage}, d::Dict) function _update_plot(plt::Plot{GLVisualizeBackend}, d::Dict)
end end
function _update_plot_pos_size(plt::PlottingObject{GLVisualizePackage}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{GLVisualizeBackend}, d::Dict)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# accessors for x/y data # accessors for x/y data
function Base.getindex(plt::Plot{GLVisualizePackage}, i::Int) function Base.getindex(plt::Plot{GLVisualizeBackend}, i::Int)
# TODO: # TODO:
# series = plt.o.lines[i] # series = plt.o.lines[i]
# series.x, series.y # series.x, series.y
nothing, nothing nothing, nothing
end end
function Base.setindex!(plt::Plot{GLVisualizePackage}, xy::Tuple, i::Integer) function Base.setindex!(plt::Plot{GLVisualizeBackend}, xy::Tuple, i::Integer)
# TODO: # TODO:
# series = plt.o.lines[i] # series = plt.o.lines[i]
# series.x, series.y = xy # series.x, series.y = xy
@ -75,25 +75,25 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _create_subplot(subplt::Subplot{GLVisualizePackage}) function _create_subplot(subplt::Subplot{GLVisualizeBackend})
# 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 _expand_limits(lims, plt::Plot{GLVisualizePackage}, isx::Bool) function _expand_limits(lims, plt::Plot{GLVisualizeBackend}, isx::Bool)
# TODO: call expand limits for each plot data # TODO: call expand limits for each plot data
end end
function _remove_axis(plt::Plot{GLVisualizePackage}, isx::Bool) function _remove_axis(plt::Plot{GLVisualizeBackend}, isx::Bool)
# TODO: if plot is inner subplot, might need to remove ticks or axis labels # TODO: if plot is inner subplot, might need to remove ticks or axis labels
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{GLVisualizePackage}) function Base.writemime(io::IO, ::MIME"image/png", plt::AbstractPlot{GLVisualizeBackend})
# TODO: write a png to io # TODO: write a png to io
end end
function Base.display(::PlotsDisplay, plt::Plot{GLVisualizePackage}) function Base.display(::PlotsDisplay, plt::Plot{GLVisualizeBackend})
# TODO: display/show the plot # TODO: display/show the plot
# NOTE: I think maybe this should be empty? We can start with the assumption that creating # NOTE: I think maybe this should be empty? We can start with the assumption that creating
@ -101,6 +101,6 @@ function Base.display(::PlotsDisplay, plt::Plot{GLVisualizePackage})
# wouldn't actually need to do anything # wouldn't actually need to do anything
end end
function Base.display(::PlotsDisplay, plt::Subplot{GLVisualizePackage}) function Base.display(::PlotsDisplay, plt::Subplot{GLVisualizeBackend})
# TODO: display/show the subplot # TODO: display/show the subplot
end end

View File

@ -1,7 +1,7 @@
# https://github.com/jheinen/GR.jl # https://github.com/jheinen/GR.jl
function _initialize_backend(::GRPackage; kw...) function _initialize_backend(::GRBackend; kw...)
@eval begin @eval begin
import GR import GR
export GR export GR
@ -89,7 +89,7 @@ function gr_polyline(x, y)
end end
end end
function gr_display(plt::Plot{GRPackage}, clear=true, update=true, function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
subplot=[0, 1, 0, 1]) subplot=[0, 1, 0, 1])
d = plt.plotargs d = plt.plotargs
@ -666,7 +666,7 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
update && GR.updatews() update && GR.updatews()
end end
function gr_display(subplt::Subplot{GRPackage}) function gr_display(subplt::Subplot{GRBackend})
clear = true clear = true
update = false update = false
l = enumerate(subplt.layout) l = enumerate(subplt.layout)
@ -682,18 +682,18 @@ function gr_display(subplt::Subplot{GRPackage})
end end
end end
function _create_plot(pkg::GRPackage; kw...) function _create_plot(pkg::GRBackend; kw...)
d = Dict(kw) d = Dict(kw)
Plot(nothing, pkg, 0, d, Dict[]) Plot(nothing, pkg, 0, d, Dict[])
end end
function _add_series(::GRPackage, plt::Plot; kw...) function _add_series(::GRBackend, plt::Plot; kw...)
d = Dict(kw) d = Dict(kw)
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt
end end
function _add_annotations{X,Y,V}(plt::Plot{GRPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) function _add_annotations{X,Y,V}(plt::Plot{GRBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
if haskey(plt.plotargs, :anns) if haskey(plt.plotargs, :anns)
append!(plt.plotargs[:anns], anns) append!(plt.plotargs[:anns], anns)
else else
@ -703,26 +703,26 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _before_update_plot(plt::Plot{GRPackage}) function _before_update_plot(plt::Plot{GRBackend})
end end
function _update_plot(plt::Plot{GRPackage}, d::Dict) function _update_plot(plt::Plot{GRBackend}, d::Dict)
for k in (:title, :xlabel, :ylabel) for k in (:title, :xlabel, :ylabel)
haskey(d, k) && (plt.plotargs[k] = d[k]) haskey(d, k) && (plt.plotargs[k] = d[k])
end end
end end
function _update_plot_pos_size(plt::PlottingObject{GRPackage}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{GRBackend}, d::Dict)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function Base.getindex(plt::Plot{GRPackage}, i::Int) function Base.getindex(plt::Plot{GRBackend}, i::Int)
d = plt.seriesargs[i] d = plt.seriesargs[i]
d[:x], d[:y] d[:x], d[:y]
end end
function Base.setindex!(plt::Plot{GRPackage}, xy::Tuple, i::Integer) function Base.setindex!(plt::Plot{GRBackend}, xy::Tuple, i::Integer)
d = plt.seriesargs[i] d = plt.seriesargs[i]
d[:x], d[:y] = xy d[:x], d[:y] = xy
plt plt
@ -730,21 +730,21 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _create_subplot(subplt::Subplot{GRPackage}, isbefore::Bool) function _create_subplot(subplt::Subplot{GRBackend}, isbefore::Bool)
true true
end end
function _expand_limits(lims, plt::Plot{GRPackage}, isx::Bool) function _expand_limits(lims, plt::Plot{GRBackend}, isx::Bool)
# TODO: call expand limits for each plot data # TODO: call expand limits for each plot data
end end
function _remove_axis(plt::Plot{GRPackage}, isx::Bool) function _remove_axis(plt::Plot{GRBackend}, isx::Bool)
# TODO: if plot is inner subplot, might need to remove ticks or axis labels # TODO: if plot is inner subplot, might need to remove ticks or axis labels
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function Base.writemime(io::IO, m::MIME"image/png", plt::PlottingObject{GRPackage}) function Base.writemime(io::IO, m::MIME"image/png", plt::AbstractPlot{GRBackend})
GR.emergencyclosegks() GR.emergencyclosegks()
ENV["GKS_WSTYPE"] = "png" ENV["GKS_WSTYPE"] = "png"
gr_display(plt) gr_display(plt)
@ -752,7 +752,7 @@ function Base.writemime(io::IO, m::MIME"image/png", plt::PlottingObject{GRPackag
write(io, readall("gks.png")) write(io, readall("gks.png"))
end end
function Base.writemime(io::IO, m::MIME"image/svg+xml", plt::PlottingObject{GRPackage}) function Base.writemime(io::IO, m::MIME"image/svg+xml", plt::AbstractPlot{GRBackend})
GR.emergencyclosegks() GR.emergencyclosegks()
ENV["GKS_WSTYPE"] = "svg" ENV["GKS_WSTYPE"] = "svg"
gr_display(plt) gr_display(plt)
@ -760,11 +760,11 @@ function Base.writemime(io::IO, m::MIME"image/svg+xml", plt::PlottingObject{GRPa
write(io, readall("gks.svg")) write(io, readall("gks.svg"))
end end
function Base.writemime(io::IO, m::MIME"text/html", plt::PlottingObject{GRPackage}) function Base.writemime(io::IO, m::MIME"text/html", plt::AbstractPlot{GRBackend})
writemime(io, MIME("image/svg+xml"), plt) writemime(io, MIME("image/svg+xml"), plt)
end end
function Base.writemime(io::IO, m::MIME"application/pdf", plt::PlottingObject{GRPackage}) function Base.writemime(io::IO, m::MIME"application/pdf", plt::AbstractPlot{GRBackend})
GR.emergencyclosegks() GR.emergencyclosegks()
ENV["GKS_WSTYPE"] = "pdf" ENV["GKS_WSTYPE"] = "pdf"
gr_display(plt) gr_display(plt)
@ -772,7 +772,7 @@ function Base.writemime(io::IO, m::MIME"application/pdf", plt::PlottingObject{GR
write(io, readall("gks.pdf")) write(io, readall("gks.pdf"))
end end
function Base.writemime(io::IO, m::MIME"application/postscript", plt::PlottingObject{GRPackage}) function Base.writemime(io::IO, m::MIME"application/postscript", plt::AbstractPlot{GRBackend})
GR.emergencyclosegks() GR.emergencyclosegks()
ENV["GKS_WSTYPE"] = "ps" ENV["GKS_WSTYPE"] = "ps"
gr_display(plt) gr_display(plt)
@ -780,11 +780,11 @@ function Base.writemime(io::IO, m::MIME"application/postscript", plt::PlottingOb
write(io, readall("gks.ps")) write(io, readall("gks.ps"))
end end
function Base.display(::PlotsDisplay, plt::Plot{GRPackage}) function Base.display(::PlotsDisplay, plt::Plot{GRBackend})
gr_display(plt) gr_display(plt)
end end
function Base.display(::PlotsDisplay, plt::Subplot{GRPackage}) function Base.display(::PlotsDisplay, plt::Subplot{GRBackend})
gr_display(plt) gr_display(plt)
true true
end end

View File

@ -1,7 +1,7 @@
# https://github.com/JuliaGraphics/Immerse.jl # https://github.com/JuliaGraphics/Immerse.jl
function _initialize_backend(::ImmersePackage; kw...) function _initialize_backend(::ImmerseBackend; kw...)
@eval begin @eval begin
import Immerse, Gadfly, Compose, Gtk import Immerse, Gadfly, Compose, Gtk
export Immerse, Gadfly, Compose, Gtk export Immerse, Gadfly, Compose, Gtk
@ -19,7 +19,7 @@ end
# create a blank Gadfly.Plot object # create a blank Gadfly.Plot object
function _create_plot(pkg::ImmersePackage; kw...) function _create_plot(pkg::ImmerseBackend; kw...)
d = Dict(kw) d = Dict(kw)
# create the underlying Gadfly.Plot object # create the underlying Gadfly.Plot object
@ -31,7 +31,7 @@ end
# plot one data series # plot one data series
function _add_series(::ImmersePackage, plt::Plot; kw...) function _add_series(::ImmerseBackend, plt::Plot; kw...)
d = Dict(kw) d = Dict(kw)
addGadflySeries!(plt, d) addGadflySeries!(plt, d)
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
@ -39,7 +39,7 @@ function _add_series(::ImmersePackage, plt::Plot; kw...)
end end
function _update_plot(plt::Plot{ImmersePackage}, d::Dict) function _update_plot(plt::Plot{ImmerseBackend}, d::Dict)
updateGadflyGuides(plt, d) updateGadflyGuides(plt, d)
updateGadflyPlotTheme(plt, d) updateGadflyPlotTheme(plt, d)
end end
@ -48,7 +48,7 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _add_annotations{X,Y,V}(plt::Plot{ImmersePackage}, anns::AVec{@compat(Tuple{X,Y,V})}) function _add_annotations{X,Y,V}(plt::Plot{ImmerseBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
for ann in anns for ann in anns
push!(getGadflyContext(plt).guides, createGadflyAnnotationObject(ann...)) push!(getGadflyContext(plt).guides, createGadflyAnnotationObject(ann...))
end end
@ -58,12 +58,12 @@ end
# accessors for x/y data # accessors for x/y data
function Base.getindex(plt::Plot{ImmersePackage}, i::Integer) function Base.getindex(plt::Plot{ImmerseBackend}, i::Integer)
mapping = getGadflyMappings(plt, i)[1] mapping = getGadflyMappings(plt, i)[1]
mapping[:x], mapping[:y] mapping[:x], mapping[:y]
end end
function Base.setindex!(plt::Plot{ImmersePackage}, xy::Tuple, i::Integer) function Base.setindex!(plt::Plot{ImmerseBackend}, xy::Tuple, i::Integer)
for mapping in getGadflyMappings(plt, i) for mapping in getGadflyMappings(plt, i)
mapping[:x], mapping[:y] = xy mapping[:x], mapping[:y] = xy
end end
@ -74,12 +74,12 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _create_subplot(subplt::Subplot{ImmersePackage}, isbefore::Bool) function _create_subplot(subplt::Subplot{ImmerseBackend}, isbefore::Bool)
return false return false
# isbefore && return false # isbefore && return false
end end
function showSubplotObject(subplt::Subplot{ImmersePackage}) function showSubplotObject(subplt::Subplot{ImmerseBackend})
# create the Gtk window with vertical box vsep # create the Gtk window with vertical box vsep
d = getplotargs(subplt,1) d = getplotargs(subplt,1)
w,h = d[:size] w,h = d[:size]
@ -121,13 +121,13 @@ function showSubplotObject(subplt::Subplot{ImmersePackage})
end end
function _remove_axis(plt::Plot{ImmersePackage}, isx::Bool) function _remove_axis(plt::Plot{ImmerseBackend}, isx::Bool)
gplt = getGadflyContext(plt) gplt = getGadflyContext(plt)
addOrReplace(gplt.guides, isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks; label=false) addOrReplace(gplt.guides, isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks; label=false)
addOrReplace(gplt.guides, isx ? Gadfly.Guide.xlabel : Gadfly.Guide.ylabel, "") addOrReplace(gplt.guides, isx ? Gadfly.Guide.xlabel : Gadfly.Guide.ylabel, "")
end end
function _expand_limits(lims, plt::Plot{ImmersePackage}, isx::Bool) function _expand_limits(lims, plt::Plot{ImmerseBackend}, isx::Bool)
for l in getGadflyContext(plt).layers for l in getGadflyContext(plt).layers
_expand_limits(lims, l.mapping[isx ? :x : :y]) _expand_limits(lims, l.mapping[isx ? :x : :y])
end end
@ -136,11 +136,11 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
getGadflyContext(plt::Plot{ImmersePackage}) = plt.o[2] getGadflyContext(plt::Plot{ImmerseBackend}) = plt.o[2]
getGadflyContext(subplt::Subplot{ImmersePackage}) = buildGadflySubplotContext(subplt) getGadflyContext(subplt::Subplot{ImmerseBackend}) = buildGadflySubplotContext(subplt)
function Base.display(::PlotsDisplay, plt::Plot{ImmersePackage}) function Base.display(::PlotsDisplay, plt::Plot{ImmerseBackend})
fig, gplt = plt.o fig, gplt = plt.o
if fig == nothing if fig == nothing
@ -154,7 +154,7 @@ function Base.display(::PlotsDisplay, plt::Plot{ImmersePackage})
end end
function Base.display(::PlotsDisplay, subplt::Subplot{ImmersePackage}) function Base.display(::PlotsDisplay, subplt::Subplot{ImmerseBackend})
# if we haven't created the window yet, do it # if we haven't created the window yet, do it
if subplt.o == nothing if subplt.o == nothing

View File

@ -1,7 +1,7 @@
# https://github.com/sisl/PGFPlots.jl # https://github.com/sisl/PGFPlots.jl
function _initialize_backend(::PGFPlotsPackage; kw...) function _initialize_backend(::PGFPlotsBackend; kw...)
@eval begin @eval begin
import PGFPlots import PGFPlots
export PGFPlots export PGFPlots
@ -12,7 +12,7 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::PGFPlotsPackage; kw...) function _create_plot(pkg::PGFPlotsBackend; kw...)
d = Dict{Symbol,Any}(kw) d = Dict{Symbol,Any}(kw)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`) # TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc # TODO: initialize the plot... title, xlabel, bgcolor, etc
@ -20,14 +20,14 @@ function _create_plot(pkg::PGFPlotsPackage; kw...)
end end
function _add_series(::PGFPlotsPackage, plt::Plot; kw...) function _add_series(::PGFPlotsBackend, plt::Plot; kw...)
d = Dict{Symbol,Any}(kw) d = Dict{Symbol,Any}(kw)
# TODO: add one series to the underlying package # TODO: add one series to the underlying package
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt
end end
function _add_annotations{X,Y,V}(plt::Plot{PGFPlotsPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) function _add_annotations{X,Y,V}(plt::Plot{PGFPlotsBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
# set or add to the annotation_list # set or add to the annotation_list
if haskey(plt.plotargs, :annotation_list) if haskey(plt.plotargs, :annotation_list)
append!(plt.plotargs[:annotation_list], anns) append!(plt.plotargs[:annotation_list], anns)
@ -38,26 +38,26 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _before_update_plot(plt::Plot{PGFPlotsPackage}) function _before_update_plot(plt::Plot{PGFPlotsBackend})
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 _update_plot(plt::Plot{PGFPlotsPackage}, d::Dict) function _update_plot(plt::Plot{PGFPlotsBackend}, d::Dict)
end end
function _update_plot_pos_size(plt::PlottingObject{PGFPlotsPackage}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{PGFPlotsBackend}, d::Dict)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# accessors for x/y data # accessors for x/y data
function Base.getindex(plt::Plot{PGFPlotsPackage}, i::Int) function Base.getindex(plt::Plot{PGFPlotsBackend}, i::Int)
d = plt.seriesargs[i] d = plt.seriesargs[i]
d[:x], d[:y] d[:x], d[:y]
end end
function Base.setindex!(plt::Plot{PGFPlotsPackage}, xy::Tuple, i::Integer) function Base.setindex!(plt::Plot{PGFPlotsBackend}, xy::Tuple, i::Integer)
d = plt.seriesargs[i] d = plt.seriesargs[i]
d[:x], d[:y] = xy d[:x], d[:y] = xy
plt plt
@ -65,16 +65,16 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _create_subplot(subplt::Subplot{PGFPlotsPackage}, isbefore::Bool) function _create_subplot(subplt::Subplot{PGFPlotsBackend}, isbefore::Bool)
# 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
true true
end end
function _expand_limits(lims, plt::Plot{PGFPlotsPackage}, isx::Bool) function _expand_limits(lims, plt::Plot{PGFPlotsBackend}, isx::Bool)
# TODO: call expand limits for each plot data # TODO: call expand limits for each plot data
end end
function _remove_axis(plt::Plot{PGFPlotsPackage}, isx::Bool) function _remove_axis(plt::Plot{PGFPlotsBackend}, isx::Bool)
# TODO: if plot is inner subplot, might need to remove ticks or axis labels # TODO: if plot is inner subplot, might need to remove ticks or axis labels
end end
@ -84,24 +84,24 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
################# This is the important method to implement!!! ################# ################# This is the important method to implement!!! #################
function _make_pgf_plot(plt::Plot{PGFPlotsPackage}) function _make_pgf_plot(plt::Plot{PGFPlotsBackend})
# TODO: convert plt.plotargs and plt.seriesargs into PGFPlots calls # TODO: convert plt.plotargs and plt.seriesargs into PGFPlots calls
# TODO: return the PGFPlots object # TODO: return the PGFPlots object
end end
function Base.writemime(io::IO, mime::MIME"image/png", plt::PlottingObject{PGFPlotsPackage}) function Base.writemime(io::IO, mime::MIME"image/png", plt::AbstractPlot{PGFPlotsBackend})
plt.o = _make_pgf_plot(plt) plt.o = _make_pgf_plot(plt)
writemime(io, mime, plt.o) writemime(io, mime, plt.o)
end end
# function Base.writemime(io::IO, ::MIME"text/html", plt::PlottingObject{PGFPlotsPackage}) # function Base.writemime(io::IO, ::MIME"text/html", plt::AbstractPlot{PGFPlotsBackend})
# end # end
function Base.display(::PlotsDisplay, plt::PlottingObject{PGFPlotsPackage}) function Base.display(::PlotsDisplay, plt::AbstractPlot{PGFPlotsBackend})
plt.o = _make_pgf_plot(plt) plt.o = _make_pgf_plot(plt)
display(plt.o) display(plt.o)
end end
# function Base.display(::PlotsDisplay, plt::Subplot{PGFPlotsPackage}) # function Base.display(::PlotsDisplay, plt::Subplot{PGFPlotsBackend})
# # TODO: display/show the subplot # # TODO: display/show the subplot
# end # end

View File

@ -1,7 +1,7 @@
# https://plot.ly/javascript/getting-started # https://plot.ly/javascript/getting-started
function _initialize_backend(::PlotlyPackage; kw...) function _initialize_backend(::PlotlyBackend; kw...)
@eval begin @eval begin
import JSON import JSON
JSON._print(io::IO, state::JSON.State, dt::Union{Date,DateTime}) = print(io, '"', dt, '"') JSON._print(io::IO, state::JSON.State, dt::Union{Date,DateTime}) = print(io, '"', dt, '"')
@ -33,7 +33,7 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::PlotlyPackage; kw...) function _create_plot(pkg::PlotlyBackend; kw...)
d = Dict{Symbol,Any}(kw) d = Dict{Symbol,Any}(kw)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`) # TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc # TODO: initialize the plot... title, xlabel, bgcolor, etc
@ -41,14 +41,14 @@ function _create_plot(pkg::PlotlyPackage; kw...)
end end
function _add_series(::PlotlyPackage, plt::Plot; kw...) function _add_series(::PlotlyBackend, plt::Plot; kw...)
d = Dict{Symbol,Any}(kw) d = Dict{Symbol,Any}(kw)
# TODO: add one series to the underlying package # TODO: add one series to the underlying package
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt
end end
function _add_annotations{X,Y,V}(plt::Plot{PlotlyPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) function _add_annotations{X,Y,V}(plt::Plot{PlotlyBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
# set or add to the annotation_list # set or add to the annotation_list
if haskey(plt.plotargs, :annotation_list) if haskey(plt.plotargs, :annotation_list)
append!(plt.plotargs[:annotation_list], anns) append!(plt.plotargs[:annotation_list], anns)
@ -59,26 +59,26 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _before_update_plot(plt::Plot{PlotlyPackage}) function _before_update_plot(plt::Plot{PlotlyBackend})
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 _update_plot(plt::Plot{PlotlyPackage}, d::Dict) function _update_plot(plt::Plot{PlotlyBackend}, d::Dict)
end end
function _update_plot_pos_size(plt::PlottingObject{PlotlyPackage}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{PlotlyBackend}, d::Dict)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# accessors for x/y data # accessors for x/y data
function Base.getindex(plt::Plot{PlotlyPackage}, i::Int) function Base.getindex(plt::Plot{PlotlyBackend}, i::Int)
d = plt.seriesargs[i] d = plt.seriesargs[i]
d[:x], d[:y] d[:x], d[:y]
end end
function Base.setindex!(plt::Plot{PlotlyPackage}, xy::Tuple, i::Integer) function Base.setindex!(plt::Plot{PlotlyBackend}, xy::Tuple, i::Integer)
d = plt.seriesargs[i] d = plt.seriesargs[i]
d[:x], d[:y] = xy d[:x], d[:y] = xy
plt plt
@ -86,16 +86,16 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _create_subplot(subplt::Subplot{PlotlyPackage}, isbefore::Bool) function _create_subplot(subplt::Subplot{PlotlyBackend}, isbefore::Bool)
# 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
true true
end end
function _expand_limits(lims, plt::Plot{PlotlyPackage}, isx::Bool) function _expand_limits(lims, plt::Plot{PlotlyBackend}, isx::Bool)
# TODO: call expand limits for each plot data # TODO: call expand limits for each plot data
end end
function _remove_axis(plt::Plot{PlotlyPackage}, isx::Bool) function _remove_axis(plt::Plot{PlotlyBackend}, isx::Bool)
# TODO: if plot is inner subplot, might need to remove ticks or axis labels # TODO: if plot is inner subplot, might need to remove ticks or axis labels
end end
@ -206,7 +206,7 @@ function plotlyaxis(d::Dict, isx::Bool)
ax ax
end end
# function get_plot_json(plt::Plot{PlotlyPackage}) # function get_plot_json(plt::Plot{PlotlyBackend})
# d = plt.plotargs # d = plt.plotargs
function plotly_layout(d::Dict) function plotly_layout(d::Dict)
d_out = Dict{Symbol,Any}() d_out = Dict{Symbol,Any}()
@ -244,7 +244,7 @@ function plotly_layout(d::Dict)
d_out d_out
end end
function get_plot_json(plt::Plot{PlotlyPackage}) function get_plot_json(plt::Plot{PlotlyBackend})
JSON.json(plotly_layout(plt.plotargs)) JSON.json(plotly_layout(plt.plotargs))
end end
@ -410,11 +410,11 @@ function plotly_series(d::Dict; plot_index = nothing)
end end
# get a list of dictionaries, each representing the series params # get a list of dictionaries, each representing the series params
function get_series_json(plt::Plot{PlotlyPackage}) function get_series_json(plt::Plot{PlotlyBackend})
JSON.json(map(plotly_series, plt.seriesargs)) JSON.json(map(plotly_series, plt.seriesargs))
end end
function get_series_json(subplt::Subplot{PlotlyPackage}) function get_series_json(subplt::Subplot{PlotlyBackend})
ds = Dict[] ds = Dict[]
for (i,plt) in enumerate(subplt.plts) for (i,plt) in enumerate(subplt.plts)
for d in plt.seriesargs for d in plt.seriesargs
@ -426,11 +426,11 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function html_head(plt::PlottingObject{PlotlyPackage}) function html_head(plt::AbstractPlot{PlotlyBackend})
"<script src=\"$(Pkg.dir("Plots","deps","plotly-latest.min.js"))\"></script>" "<script src=\"$(Pkg.dir("Plots","deps","plotly-latest.min.js"))\"></script>"
end end
function html_body(plt::Plot{PlotlyPackage}, style = nothing) function html_body(plt::Plot{PlotlyBackend}, style = nothing)
if style == nothing if style == nothing
w, h = plt.plotargs[:size] w, h = plt.plotargs[:size]
style = "width:$(w)px;height:$(h)px;" style = "width:$(w)px;height:$(h)px;"
@ -447,7 +447,7 @@ end
function html_body(subplt::Subplot{PlotlyPackage}) function html_body(subplt::Subplot{PlotlyBackend})
w, h = subplt.plts[1].plotargs[:size] w, h = subplt.plts[1].plotargs[:size]
html = ["<div style=\"width:$(w)px;height:$(h)px;\">"] html = ["<div style=\"width:$(w)px;height:$(h)px;\">"]
nr = nrows(subplt.layout) nr = nrows(subplt.layout)
@ -474,18 +474,18 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{PlotlyPackage}) function Base.writemime(io::IO, ::MIME"image/png", plt::AbstractPlot{PlotlyBackend})
warn("todo: png") warn("todo: png")
end end
function Base.writemime(io::IO, ::MIME"text/html", plt::PlottingObject{PlotlyPackage}) function Base.writemime(io::IO, ::MIME"text/html", plt::AbstractPlot{PlotlyBackend})
write(io, html_head(plt) * html_body(plt)) write(io, html_head(plt) * html_body(plt))
end end
function Base.display(::PlotsDisplay, plt::PlottingObject{PlotlyPackage}) function Base.display(::PlotsDisplay, plt::AbstractPlot{PlotlyBackend})
standalone_html_window(plt) standalone_html_window(plt)
end end
# function Base.display(::PlotsDisplay, plt::Subplot{PlotlyPackage}) # function Base.display(::PlotsDisplay, plt::Subplot{PlotlyBackend})
# # TODO: display/show the subplot # # TODO: display/show the subplot
# end # end

View File

@ -1,25 +1,25 @@
# https://github.com/spencerlyon2/PlotlyJS.jl # https://github.com/spencerlyon2/PlotlyJS.jl
function _initialize_backend(::PlotlyJSPackage; kw...) function _initialize_backend(::PlotlyJSBackend; kw...)
@eval begin @eval begin
import PlotlyJS import PlotlyJS
export PlotlyJS export PlotlyJS
end end
for (mime, fmt) in PlotlyJS._mimeformats for (mime, fmt) in PlotlyJS._mimeformats
@eval Base.writemime(io::IO, m::MIME{symbol($mime)}, p::Plot{PlotlyJSPackage}) = writemime(io, m, p.o) @eval Base.writemime(io::IO, m::MIME{symbol($mime)}, p::Plot{PlotlyJSBackend}) = writemime(io, m, p.o)
end end
# override IJulia inline display # override IJulia inline display
if isijulia() if isijulia()
IJulia.display_dict(plt::PlottingObject{PlotlyJSPackage}) = IJulia.display_dict(plt.o) IJulia.display_dict(plt::AbstractPlot{PlotlyJSBackend}) = IJulia.display_dict(plt.o)
end end
end end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::PlotlyJSPackage; kw...) function _create_plot(pkg::PlotlyJSBackend; kw...)
d = Dict(kw) d = Dict(kw)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`) # TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc # TODO: initialize the plot... title, xlabel, bgcolor, etc
@ -33,7 +33,7 @@ function _create_plot(pkg::PlotlyJSPackage; kw...)
end end
function _add_series(::PlotlyJSPackage, plt::Plot; kw...) function _add_series(::PlotlyJSBackend, plt::Plot; kw...)
d = Dict(kw) d = Dict(kw)
syncplot = plt.o syncplot = plt.o
@ -53,7 +53,7 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _add_annotations{X,Y,V}(plt::Plot{PlotlyJSPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) function _add_annotations{X,Y,V}(plt::Plot{PlotlyJSBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
# set or add to the annotation_list # set or add to the annotation_list
if !haskey(plt.plotargs, :annotation_list) if !haskey(plt.plotargs, :annotation_list)
plt.plotargs[:annotation_list] = Any[] plt.plotargs[:annotation_list] = Any[]
@ -63,11 +63,11 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _before_update_plot(plt::Plot{PlotlyJSPackage}) function _before_update_plot(plt::Plot{PlotlyJSBackend})
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 _update_plot(plt::Plot{PlotlyJSPackage}, d::Dict) function _update_plot(plt::Plot{PlotlyJSBackend}, d::Dict)
pdict = plotly_layout(d) pdict = plotly_layout(d)
# dumpdict(pdict, "pdict updateplot", true) # dumpdict(pdict, "pdict updateplot", true)
syncplot = plt.o syncplot = plt.o
@ -76,19 +76,19 @@ function _update_plot(plt::Plot{PlotlyJSPackage}, d::Dict)
end end
function _update_plot_pos_size(plt::PlottingObject{PlotlyJSPackage}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{PlotlyJSBackend}, d::Dict)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# accessors for x/y data # accessors for x/y data
function Base.getindex(plt::Plot{PlotlyJSPackage}, i::Int) function Base.getindex(plt::Plot{PlotlyJSBackend}, i::Int)
d = plt.seriesargs[i] d = plt.seriesargs[i]
d[:x], d[:y] d[:x], d[:y]
end end
function Base.setindex!(plt::Plot{PlotlyJSPackage}, xy::Tuple, i::Integer) function Base.setindex!(plt::Plot{PlotlyJSBackend}, xy::Tuple, i::Integer)
d = plt.seriesargs[i] d = plt.seriesargs[i]
d[:x], d[:y] = xy d[:x], d[:y] = xy
# TODO: this is likely ineffecient... we should make a call that ONLY changes the plot data # TODO: this is likely ineffecient... we should make a call that ONLY changes the plot data
@ -99,30 +99,30 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _create_subplot(subplt::Subplot{PlotlyJSPackage}, isbefore::Bool) function _create_subplot(subplt::Subplot{PlotlyJSBackend}, isbefore::Bool)
# 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
true true
end end
function _expand_limits(lims, plt::Plot{PlotlyJSPackage}, isx::Bool) function _expand_limits(lims, plt::Plot{PlotlyJSBackend}, isx::Bool)
# TODO: call expand limits for each plot data # TODO: call expand limits for each plot data
end end
function _remove_axis(plt::Plot{PlotlyJSPackage}, isx::Bool) function _remove_axis(plt::Plot{PlotlyJSBackend}, isx::Bool)
# TODO: if plot is inner subplot, might need to remove ticks or axis labels # TODO: if plot is inner subplot, might need to remove ticks or axis labels
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function Base.writemime(io::IO, m::MIME"text/html", plt::PlottingObject{PlotlyJSPackage}) function Base.writemime(io::IO, m::MIME"text/html", plt::AbstractPlot{PlotlyJSBackend})
Base.writemime(io, m, plt.o) Base.writemime(io, m, plt.o)
end end
function Base.display(::PlotsDisplay, plt::Plot{PlotlyJSPackage}) function Base.display(::PlotsDisplay, plt::Plot{PlotlyJSBackend})
display(plt.o) display(plt.o)
end end
function Base.display(::PlotsDisplay, plt::Subplot{PlotlyJSPackage}) function Base.display(::PlotsDisplay, plt::Subplot{PlotlyJSBackend})
error() error()
end end

View File

@ -1,7 +1,7 @@
# https://github.com/stevengj/PyPlot.jl # https://github.com/stevengj/PyPlot.jl
function _initialize_backend(::PyPlotPackage) function _initialize_backend(::PyPlotBackend)
@eval begin @eval begin
import PyPlot import PyPlot
export PyPlot export PyPlot
@ -149,9 +149,9 @@ function getRightAxis(wrap::PyPlotAxisWrapper)
wrap.rightax wrap.rightax
end end
getLeftAxis(plt::Plot{PyPlotPackage}) = getLeftAxis(plt.o) getLeftAxis(plt::Plot{PyPlotBackend}) = getLeftAxis(plt.o)
getRightAxis(plt::Plot{PyPlotPackage}) = getRightAxis(plt.o) getRightAxis(plt::Plot{PyPlotBackend}) = getRightAxis(plt.o)
getAxis(plt::Plot{PyPlotPackage}, axis::Symbol) = (axis == :right ? getRightAxis : getLeftAxis)(plt) getAxis(plt::Plot{PyPlotBackend}, axis::Symbol) = (axis == :right ? getRightAxis : getLeftAxis)(plt)
# left axis is PyPlot.<func>, right axis is "f.axes[0].twinx().<func>" # left axis is PyPlot.<func>, right axis is "f.axes[0].twinx().<func>"
function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol) function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
@ -196,7 +196,7 @@ function updateAxisColors(ax, fgcolor)
end end
function handleSmooth(plt::Plot{PyPlotPackage}, ax, d::Dict, smooth::Bool) function handleSmooth(plt::Plot{PyPlotBackend}, ax, d::Dict, smooth::Bool)
if smooth if smooth
xs, ys = regressionXY(d[:x], d[:y]) xs, ys = regressionXY(d[:x], d[:y])
ax[:plot](xs, ys, ax[:plot](xs, ys,
@ -206,7 +206,7 @@ function handleSmooth(plt::Plot{PyPlotPackage}, ax, d::Dict, smooth::Bool)
) )
end end
end end
handleSmooth(plt::Plot{PyPlotPackage}, ax, d::Dict, smooth::Real) = handleSmooth(plt, ax, d, true) handleSmooth(plt::Plot{PyPlotBackend}, ax, d::Dict, smooth::Real) = handleSmooth(plt, ax, d, true)
@ -214,10 +214,10 @@ handleSmooth(plt::Plot{PyPlotPackage}, ax, d::Dict, smooth::Real) = handleSmooth
# makePyPlotCurrent(wrap::PyPlotFigWrapper) = PyPlot.figure(wrap.fig.o[:number]) # makePyPlotCurrent(wrap::PyPlotFigWrapper) = PyPlot.figure(wrap.fig.o[:number])
# makePyPlotCurrent(wrap::PyPlotAxisWrapper) = nothing #PyPlot.sca(wrap.ax.o) # makePyPlotCurrent(wrap::PyPlotAxisWrapper) = nothing #PyPlot.sca(wrap.ax.o)
makePyPlotCurrent(wrap::PyPlotAxisWrapper) = wrap.ax == nothing ? PyPlot.figure(wrap.fig.o[:number]) : nothing makePyPlotCurrent(wrap::PyPlotAxisWrapper) = wrap.ax == nothing ? PyPlot.figure(wrap.fig.o[:number]) : nothing
makePyPlotCurrent(plt::Plot{PyPlotPackage}) = plt.o == nothing ? nothing : makePyPlotCurrent(plt.o) makePyPlotCurrent(plt::Plot{PyPlotBackend}) = plt.o == nothing ? nothing : makePyPlotCurrent(plt.o)
function _before_add_series(plt::Plot{PyPlotPackage}) function _before_add_series(plt::Plot{PyPlotBackend})
makePyPlotCurrent(plt) makePyPlotCurrent(plt)
end end
@ -267,7 +267,7 @@ end
# screen # Integer, move enclosing window to this screen number (for multiscreen desktops) # screen # Integer, move enclosing window to this screen number (for multiscreen desktops)
# show # true or false, show the plot (in case you don't want the window to pop up right away) # show # true or false, show the plot (in case you don't want the window to pop up right away)
function _create_plot(pkg::PyPlotPackage; kw...) function _create_plot(pkg::PyPlotBackend; kw...)
# create the figure # create the figure
d = Dict(kw) d = Dict(kw)
@ -289,7 +289,7 @@ function _create_plot(pkg::PyPlotPackage; kw...)
end end
function _add_series(pkg::PyPlotPackage, plt::Plot; kw...) function _add_series(pkg::PyPlotBackend, plt::Plot; kw...)
d = Dict(kw) d = Dict(kw)
# 3D plots have a different underlying Axes object in PyPlot # 3D plots have a different underlying Axes object in PyPlot
@ -508,7 +508,7 @@ end
# ----------------------------------------------------------------- # -----------------------------------------------------------------
function Base.getindex(plt::Plot{PyPlotPackage}, i::Integer) function Base.getindex(plt::Plot{PyPlotBackend}, i::Integer)
series = plt.seriesargs[i][:serieshandle] series = plt.seriesargs[i][:serieshandle]
try try
return series[:get_data]() return series[:get_data]()
@ -540,7 +540,7 @@ function minmaxseries(ds, vec, axis)
end end
# TODO: this needs to handle one-sided fixed limits # TODO: this needs to handle one-sided fixed limits
function set_lims!(plt::Plot{PyPlotPackage}, axis::Symbol) function set_lims!(plt::Plot{PyPlotBackend}, axis::Symbol)
ax = getAxis(plt, axis) ax = getAxis(plt, axis)
if plt.plotargs[:xlims] == :auto if plt.plotargs[:xlims] == :auto
ax[:set_xlim](minmaxseries(plt.seriesargs, :x, axis)...) ax[:set_xlim](minmaxseries(plt.seriesargs, :x, axis)...)
@ -550,7 +550,7 @@ function set_lims!(plt::Plot{PyPlotPackage}, axis::Symbol)
end end
end end
function Base.setindex!{X,Y}(plt::Plot{PyPlotPackage}, xy::Tuple{X,Y}, i::Integer) function Base.setindex!{X,Y}(plt::Plot{PyPlotBackend}, xy::Tuple{X,Y}, i::Integer)
d = plt.seriesargs[i] d = plt.seriesargs[i]
series = d[:serieshandle] series = d[:serieshandle]
x, y = xy x, y = xy
@ -565,7 +565,7 @@ function Base.setindex!{X,Y}(plt::Plot{PyPlotPackage}, xy::Tuple{X,Y}, i::Intege
plt plt
end end
function Base.setindex!{X,Y,Z}(plt::Plot{PyPlotPackage}, xyz::Tuple{X,Y,Z}, i::Integer) function Base.setindex!{X,Y,Z}(plt::Plot{PyPlotBackend}, xyz::Tuple{X,Y,Z}, i::Integer)
warn("setindex not implemented for xyz") warn("setindex not implemented for xyz")
plt plt
end end
@ -605,9 +605,9 @@ function addPyPlotTicks(ax, ticks, isx::Bool)
end end
end end
usingRightAxis(plt::Plot{PyPlotPackage}) = any(args -> args[:axis] in (:right,:auto), plt.seriesargs) usingRightAxis(plt::Plot{PyPlotBackend}) = any(args -> args[:axis] in (:right,:auto), plt.seriesargs)
function _update_plot(plt::Plot{PyPlotPackage}, d::Dict) function _update_plot(plt::Plot{PyPlotBackend}, d::Dict)
figorax = plt.o figorax = plt.o
ax = getLeftAxis(figorax) ax = getLeftAxis(figorax)
# PyPlot.sca(ax) # PyPlot.sca(ax)
@ -686,13 +686,13 @@ end
# ----------------------------------------------------------------- # -----------------------------------------------------------------
function createPyPlotAnnotationObject(plt::Plot{PyPlotPackage}, x, y, val::@compat(AbstractString)) function createPyPlotAnnotationObject(plt::Plot{PyPlotBackend}, x, y, val::@compat(AbstractString))
ax = getLeftAxis(plt) ax = getLeftAxis(plt)
ax[:annotate](val, xy = (x,y)) ax[:annotate](val, xy = (x,y))
end end
function createPyPlotAnnotationObject(plt::Plot{PyPlotPackage}, x, y, val::PlotText) function createPyPlotAnnotationObject(plt::Plot{PyPlotBackend}, x, y, val::PlotText)
ax = getLeftAxis(plt) ax = getLeftAxis(plt)
ax[:annotate](val.str, ax[:annotate](val.str,
xy = (x,y), xy = (x,y),
@ -705,7 +705,7 @@ function createPyPlotAnnotationObject(plt::Plot{PyPlotPackage}, x, y, val::PlotT
) )
end end
function _add_annotations{X,Y,V}(plt::Plot{PyPlotPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) function _add_annotations{X,Y,V}(plt::Plot{PyPlotBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
for ann in anns for ann in anns
createPyPlotAnnotationObject(plt, ann...) createPyPlotAnnotationObject(plt, ann...)
end end
@ -714,7 +714,7 @@ end
# ----------------------------------------------------------------- # -----------------------------------------------------------------
# NOTE: pyplot needs to build before # NOTE: pyplot needs to build before
function _create_subplot(subplt::Subplot{PyPlotPackage}, isbefore::Bool) function _create_subplot(subplt::Subplot{PyPlotBackend}, isbefore::Bool)
l = subplt.layout l = subplt.layout
# w,h = map(px2inch, getplotargs(subplt,1)[:size]) # w,h = map(px2inch, getplotargs(subplt,1)[:size])
@ -743,16 +743,16 @@ end
# this will be called internally, when creating a subplot from existing plots # this will be called internally, when creating a subplot from existing plots
# NOTE: if I ever need to "Rebuild a "ubplot from individual Plot's"... this is what I should use! # NOTE: if I ever need to "Rebuild a "ubplot from individual Plot's"... this is what I should use!
function subplot(plts::AVec{Plot{PyPlotPackage}}, layout::SubplotLayout, d::Dict) function subplot(plts::AVec{Plot{PyPlotBackend}}, layout::SubplotLayout, d::Dict)
validateSubplotSupported() validateSubplotSupported()
p = length(layout) p = length(layout)
n = sum([plt.n for plt in plts]) n = sum([plt.n for plt in plts])
pkg = PyPlotPackage() pkg = PyPlotBackend()
newplts = Plot{PyPlotPackage}[_create_plot(pkg; subplot=true, plt.plotargs...) for plt in plts] newplts = Plot{PyPlotBackend}[_create_plot(pkg; subplot=true, plt.plotargs...) for plt in plts]
subplt = Subplot(nothing, newplts, PyPlotPackage(), p, n, layout, d, true, false, false, (r,c) -> (nothing,nothing)) subplt = Subplot(nothing, newplts, PyPlotBackend(), p, n, layout, d, true, false, false, (r,c) -> (nothing,nothing))
_preprocess_subplot(subplt, d) _preprocess_subplot(subplt, d)
_create_subplot(subplt, true) _create_subplot(subplt, true)
@ -769,7 +769,7 @@ function subplot(plts::AVec{Plot{PyPlotPackage}}, layout::SubplotLayout, d::Dict
end end
function _remove_axis(plt::Plot{PyPlotPackage}, isx::Bool) function _remove_axis(plt::Plot{PyPlotBackend}, isx::Bool)
if isx if isx
plot!(plt, xticks=zeros(0), xlabel="") plot!(plt, xticks=zeros(0), xlabel="")
else else
@ -777,7 +777,7 @@ function _remove_axis(plt::Plot{PyPlotPackage}, isx::Bool)
end end
end end
function _expand_limits(lims, plt::Plot{PyPlotPackage}, isx::Bool) function _expand_limits(lims, plt::Plot{PyPlotBackend}, isx::Bool)
pltlims = plt.o.ax[isx ? :get_xbound : :get_ybound]() pltlims = plt.o.ax[isx ? :get_xbound : :get_ybound]()
_expand_limits(lims, pltlims) _expand_limits(lims, pltlims)
end end
@ -810,14 +810,14 @@ function addPyPlotLegend(plt::Plot, ax)
end end
end end
function finalizePlot(plt::Plot{PyPlotPackage}) function finalizePlot(plt::Plot{PyPlotBackend})
ax = getLeftAxis(plt) ax = getLeftAxis(plt)
addPyPlotLegend(plt, ax) addPyPlotLegend(plt, ax)
updateAxisColors(ax, getPyPlotColor(plt.plotargs[:foreground_color])) updateAxisColors(ax, getPyPlotColor(plt.plotargs[:foreground_color]))
PyPlot.draw() PyPlot.draw()
end end
function finalizePlot(subplt::Subplot{PyPlotPackage}) function finalizePlot(subplt::Subplot{PyPlotBackend})
fig = subplt.o.fig fig = subplt.o.fig
for (i,plt) in enumerate(subplt.plts) for (i,plt) in enumerate(subplt.plts)
ax = getLeftAxis(plt) ax = getLeftAxis(plt)
@ -830,20 +830,20 @@ end
# # allow for writing any supported mime # # allow for writing any supported mime
# for mime in keys(PyPlot.aggformats) # for mime in keys(PyPlot.aggformats)
# @eval function Base.writemime(io::IO, m::MIME{symbol{$mime}}, plt::Plot{PyPlotPackage}) # @eval function Base.writemime(io::IO, m::MIME{symbol{$mime}}, plt::Plot{PyPlotBackend})
# finalizePlot(plt) # finalizePlot(plt)
# writemime(io, m, getfig(plt.o)) # writemime(io, m, getfig(plt.o))
# end # end
# end # end
# function Base.writemime(io::IO, m::@compat(Union{MIME"image/svg+xml", MIME"image/png"}, plt::Plot{PyPlotPackage}) # function Base.writemime(io::IO, m::@compat(Union{MIME"image/svg+xml", MIME"image/png"}, plt::Plot{PyPlotBackend})
# finalizePlot(plt) # finalizePlot(plt)
# writemime(io, m, getfig(plt.o)) # writemime(io, m, getfig(plt.o))
# end # end
# NOTE: to bring up a GUI window in IJulia, need some extra steps # NOTE: to bring up a GUI window in IJulia, need some extra steps
function Base.display(::PlotsDisplay, plt::PlottingObject{PyPlotPackage}) function Base.display(::PlotsDisplay, plt::AbstractPlot{PyPlotBackend})
finalizePlot(plt) finalizePlot(plt)
if isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay) if isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay)
display(getfig(plt.o)) display(getfig(plt.o))
@ -858,7 +858,7 @@ function Base.display(::PlotsDisplay, plt::PlottingObject{PyPlotPackage})
end end
# function Base.display(::PlotsDisplay, subplt::Subplot{PyPlotPackage}) # function Base.display(::PlotsDisplay, subplt::Subplot{PyPlotBackend})
# finalizePlot(subplt) # finalizePlot(subplt)
# PyPlot.ion() # PyPlot.ion()
# PyPlot.figure(getfig(subplt.o).o[:number]) # PyPlot.figure(getfig(subplt.o).o[:number])
@ -869,7 +869,7 @@ end
# # allow for writing any supported mime # # allow for writing any supported mime
# for mime in (MIME"image/png", MIME"application/pdf", MIME"application/postscript") # for mime in (MIME"image/png", MIME"application/pdf", MIME"application/postscript")
# @eval function Base.writemime(io::IO, ::$mime, plt::PlottingObject{PyPlotPackage}) # @eval function Base.writemime(io::IO, ::$mime, plt::AbstractPlot{PyPlotBackend})
# finalizePlot(plt) # finalizePlot(plt)
# writemime(io, $mime(), getfig(plt.o)) # writemime(io, $mime(), getfig(plt.o))
# end # end
@ -886,7 +886,7 @@ const _pyplot_mimeformats = @compat Dict(
for (mime, fmt) in _pyplot_mimeformats for (mime, fmt) in _pyplot_mimeformats
@eval function Base.writemime(io::IO, ::MIME{symbol($mime)}, plt::PlottingObject{PyPlotPackage}) @eval function Base.writemime(io::IO, ::MIME{symbol($mime)}, plt::AbstractPlot{PyPlotBackend})
finalizePlot(plt) finalizePlot(plt)
fig = getfig(plt.o) fig = getfig(plt.o)
fig.o["canvas"][:print_figure](io, fig.o["canvas"][:print_figure](io,
@ -901,7 +901,7 @@ for (mime, fmt) in _pyplot_mimeformats
end end
# function Base.writemime(io::IO, m::MIME"image/png", subplt::Subplot{PyPlotPackage}) # function Base.writemime(io::IO, m::MIME"image/png", subplt::Subplot{PyPlotBackend})
# finalizePlot(subplt) # finalizePlot(subplt)
# writemime(io, m, getfig(subplt.o)) # writemime(io, m, getfig(subplt.o))
# end # end

View File

@ -1,7 +1,7 @@
# https://github.com/tbreloff/Qwt.jl # https://github.com/tbreloff/Qwt.jl
function _initialize_backend(::QwtPackage; kw...) function _initialize_backend(::QwtBackend; kw...)
@eval begin @eval begin
warn("Qwt is no longer supported... many features will likely be broken.") warn("Qwt is no longer supported... many features will likely be broken.")
import Qwt import Qwt
@ -38,7 +38,7 @@ function replaceQwtAliases(d, s)
end end
end end
function adjustQwtKeywords(plt::Plot{QwtPackage}, iscreating::Bool; kw...) function adjustQwtKeywords(plt::Plot{QwtBackend}, iscreating::Bool; kw...)
d = Dict(kw) d = Dict(kw)
lt = d[:linetype] lt = d[:linetype]
if lt == :scatter if lt == :scatter
@ -77,7 +77,7 @@ function adjustQwtKeywords(plt::Plot{QwtPackage}, iscreating::Bool; kw...)
d d
end end
function _create_plot(pkg::QwtPackage; kw...) function _create_plot(pkg::QwtBackend; kw...)
d = Dict(kw) d = Dict(kw)
fixcolors(d) fixcolors(d)
dumpdict(d,"\n\n!!! plot") dumpdict(d,"\n\n!!! plot")
@ -86,7 +86,7 @@ function _create_plot(pkg::QwtPackage; kw...)
plt plt
end end
function _add_series(::QwtPackage, plt::Plot; kw...) function _add_series(::QwtBackend, plt::Plot; kw...)
d = adjustQwtKeywords(plt, false; kw...) d = adjustQwtKeywords(plt, false; kw...)
fixcolors(d) fixcolors(d)
dumpdict(d,"\n\n!!! plot!") dumpdict(d,"\n\n!!! plot!")
@ -98,7 +98,7 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function updateLimsAndTicks(plt::Plot{QwtPackage}, d::Dict, isx::Bool) function updateLimsAndTicks(plt::Plot{QwtBackend}, d::Dict, isx::Bool)
lims = get(d, isx ? :xlims : :ylims, nothing) lims = get(d, isx ? :xlims : :ylims, nothing)
ticks = get(d, isx ? :xticks : :yticks, nothing) ticks = get(d, isx ? :xticks : :yticks, nothing)
w = plt.o.widget w = plt.o.widget
@ -138,7 +138,7 @@ function updateLimsAndTicks(plt::Plot{QwtPackage}, d::Dict, isx::Bool)
end end
function _update_plot(plt::Plot{QwtPackage}, d::Dict) function _update_plot(plt::Plot{QwtBackend}, 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])
@ -146,7 +146,7 @@ function _update_plot(plt::Plot{QwtPackage}, d::Dict)
updateLimsAndTicks(plt, d, false) updateLimsAndTicks(plt, d, false)
end end
function _update_plot_pos_size(plt::PlottingObject{QwtPackage}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{QwtBackend}, d::Dict)
haskey(d, :size) && Qwt.resizewidget(plt.o, d[:size]...) haskey(d, :size) && Qwt.resizewidget(plt.o, d[:size]...)
haskey(d, :pos) && Qwt.movewidget(plt.o, d[:pos]...) haskey(d, :pos) && Qwt.movewidget(plt.o, d[:pos]...)
end end
@ -155,7 +155,7 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# curve.setPen(Qt.QPen(Qt.QColor(color), linewidth, self.getLineStyle(linestyle))) # curve.setPen(Qt.QPen(Qt.QColor(color), linewidth, self.getLineStyle(linestyle)))
function addLineMarker(plt::Plot{QwtPackage}, d::Dict) function addLineMarker(plt::Plot{QwtBackend}, d::Dict)
for yi in d[:y] for yi in d[:y]
marker = Qwt.QWT.QwtPlotMarker() marker = Qwt.QWT.QwtPlotMarker()
ishorizontal = (d[:linetype] == :hline) ishorizontal = (d[:linetype] == :hline)
@ -189,7 +189,7 @@ function createQwtAnnotation(plt::Plot, x, y, val::@compat(AbstractString))
marker[:attach](plt.o.widget) marker[:attach](plt.o.widget)
end end
function _add_annotations{X,Y,V}(plt::Plot{QwtPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) function _add_annotations{X,Y,V}(plt::Plot{QwtBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
for ann in anns for ann in anns
createQwtAnnotation(plt, ann...) createQwtAnnotation(plt, ann...)
end end
@ -199,12 +199,12 @@ end
# accessors for x/y data # accessors for x/y data
function Base.getindex(plt::Plot{QwtPackage}, i::Int) function Base.getindex(plt::Plot{QwtBackend}, i::Int)
series = plt.o.lines[i] series = plt.o.lines[i]
series.x, series.y series.x, series.y
end end
function Base.setindex!(plt::Plot{QwtPackage}, xy::Tuple, i::Integer) function Base.setindex!(plt::Plot{QwtBackend}, xy::Tuple, i::Integer)
series = plt.o.lines[i] series = plt.o.lines[i]
series.x, series.y = xy series.x, series.y = xy
plt plt
@ -213,12 +213,12 @@ end
# ------------------------------- # -------------------------------
# savepng(::QwtPackage, plt::PlottingObject, fn::@compat(AbstractString), args...) = Qwt.savepng(plt.o, fn) # savepng(::QwtBackend, plt::AbstractPlot, fn::@compat(AbstractString), args...) = Qwt.savepng(plt.o, fn)
# ------------------------------- # -------------------------------
# create the underlying object (each backend will do this differently) # create the underlying object (each backend will do this differently)
function _create_subplot(subplt::Subplot{QwtPackage}, isbefore::Bool) function _create_subplot(subplt::Subplot{QwtBackend}, isbefore::Bool)
isbefore && return false isbefore && return false
i = 0 i = 0
rows = Any[] rows = Any[]
@ -240,26 +240,26 @@ function _create_subplot(subplt::Subplot{QwtPackage}, isbefore::Bool)
true true
end end
function _expand_limits(lims, plt::Plot{QwtPackage}, isx::Bool) function _expand_limits(lims, plt::Plot{QwtBackend}, isx::Bool)
for series in plt.o.lines for series in plt.o.lines
_expand_limits(lims, isx ? series.x : series.y) _expand_limits(lims, isx ? series.x : series.y)
end end
end end
function _remove_axis(plt::Plot{QwtPackage}, isx::Bool) function _remove_axis(plt::Plot{QwtBackend}, isx::Bool)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function Base.writemime(io::IO, ::MIME"image/png", plt::Plot{QwtPackage}) function Base.writemime(io::IO, ::MIME"image/png", plt::Plot{QwtBackend})
Qwt.refresh(plt.o) Qwt.refresh(plt.o)
Qwt.savepng(plt.o, "/tmp/dfskjdhfkh.png") Qwt.savepng(plt.o, "/tmp/dfskjdhfkh.png")
write(io, readall("/tmp/dfskjdhfkh.png")) write(io, readall("/tmp/dfskjdhfkh.png"))
end end
function Base.writemime(io::IO, ::MIME"image/png", subplt::Subplot{QwtPackage}) function Base.writemime(io::IO, ::MIME"image/png", subplt::Subplot{QwtBackend})
for plt in subplt.plts for plt in subplt.plts
Qwt.refresh(plt.o) Qwt.refresh(plt.o)
end end
@ -268,12 +268,12 @@ function Base.writemime(io::IO, ::MIME"image/png", subplt::Subplot{QwtPackage})
end end
function Base.display(::PlotsDisplay, plt::Plot{QwtPackage}) function Base.display(::PlotsDisplay, plt::Plot{QwtBackend})
Qwt.refresh(plt.o) Qwt.refresh(plt.o)
Qwt.showwidget(plt.o) Qwt.showwidget(plt.o)
end end
function Base.display(::PlotsDisplay, subplt::Subplot{QwtPackage}) function Base.display(::PlotsDisplay, subplt::Subplot{QwtBackend})
for plt in subplt.plts for plt in subplt.plts
Qwt.refresh(plt.o) Qwt.refresh(plt.o)
end end

View File

@ -1,11 +1,11 @@
supportedAxes(::PlottingPackage) = [:left] supportedAxes(::AbstractBackend) = [:left]
supportedTypes(::PlottingPackage) = [] supportedTypes(::AbstractBackend) = []
supportedStyles(::PlottingPackage) = [:solid] supportedStyles(::AbstractBackend) = [:solid]
supportedMarkers(::PlottingPackage) = [:none] supportedMarkers(::AbstractBackend) = [:none]
supportedScales(::PlottingPackage) = [:identity] supportedScales(::AbstractBackend) = [:identity]
subplotSupported(::PlottingPackage) = false subplotSupported(::AbstractBackend) = false
stringsSupported(::PlottingPackage) = false stringsSupported(::AbstractBackend) = false
supportedAxes() = supportedAxes(backend()) supportedAxes() = supportedAxes(backend())
supportedTypes() = supportedTypes(backend()) supportedTypes() = supportedTypes(backend())
@ -19,7 +19,7 @@ stringsSupported() = stringsSupported(backend())
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
supportedArgs(::GadflyPackage) = [ supportedArgs(::GadflyBackend) = [
:annotation, :annotation,
# :axis, # :axis,
:background_color, :background_color,
@ -78,32 +78,32 @@ supportedArgs(::GadflyPackage) = [
# :surface, # :surface,
:levels, :levels,
] ]
supportedAxes(::GadflyPackage) = [:auto, :left] supportedAxes(::GadflyBackend) = [:auto, :left]
supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, supportedTypes(::GadflyBackend) = [:none, :line, :path, :steppre, :steppost, :sticks,
:scatter, :hist2d, :hexbin, :hist, :bar, :scatter, :hist2d, :hexbin, :hist, :bar,
:hline, :vline, :contour] :hline, :vline, :contour]
supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] supportedStyles(::GadflyBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::GadflyPackage) = vcat(_allMarkers, Shape) supportedMarkers(::GadflyBackend) = vcat(_allMarkers, Shape)
supportedScales(::GadflyPackage) = [:identity, :ln, :log2, :log10, :asinh, :sqrt] supportedScales(::GadflyBackend) = [:identity, :ln, :log2, :log10, :asinh, :sqrt]
subplotSupported(::GadflyPackage) = true subplotSupported(::GadflyBackend) = true
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
supportedArgs(::ImmersePackage) = supportedArgs(GadflyPackage()) supportedArgs(::ImmerseBackend) = supportedArgs(GadflyBackend())
supportedAxes(::ImmersePackage) = supportedAxes(GadflyPackage()) supportedAxes(::ImmerseBackend) = supportedAxes(GadflyBackend())
supportedTypes(::ImmersePackage) = supportedTypes(GadflyPackage()) supportedTypes(::ImmerseBackend) = supportedTypes(GadflyBackend())
supportedStyles(::ImmersePackage) = supportedStyles(GadflyPackage()) supportedStyles(::ImmerseBackend) = supportedStyles(GadflyBackend())
supportedMarkers(::ImmersePackage) = supportedMarkers(GadflyPackage()) supportedMarkers(::ImmerseBackend) = supportedMarkers(GadflyBackend())
supportedScales(::ImmersePackage) = supportedScales(GadflyPackage()) supportedScales(::ImmerseBackend) = supportedScales(GadflyBackend())
subplotSupported(::ImmersePackage) = true subplotSupported(::ImmerseBackend) = true
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
supportedArgs(::PyPlotPackage) = [ supportedArgs(::PyPlotBackend) = [
:annotation, :annotation,
:axis, :axis,
:background_color, :background_color,
@ -164,22 +164,22 @@ supportedArgs(::PyPlotPackage) = [
:markeralpha, :markeralpha,
:overwrite_figure, :overwrite_figure,
] ]
supportedAxes(::PyPlotPackage) = _allAxes supportedAxes(::PyPlotBackend) = _allAxes
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, #:sticks, supportedTypes(::PyPlotBackend) = [:none, :line, :path, :steppre, :steppost, #:sticks,
:scatter, :hist2d, :hexbin, :hist, :density, :bar, :scatter, :hist2d, :hexbin, :hist, :density, :bar,
:hline, :vline, :contour, :path3d, :scatter3d, :surface, :wireframe, :heatmap] :hline, :vline, :contour, :path3d, :scatter3d, :surface, :wireframe, :heatmap]
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot] supportedStyles(::PyPlotBackend) = [:auto, :solid, :dash, :dot, :dashdot]
# supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon] # supportedMarkers(::PyPlotBackend) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon]
supportedMarkers(::PyPlotPackage) = vcat(_allMarkers, Shape) supportedMarkers(::PyPlotBackend) = vcat(_allMarkers, Shape)
supportedScales(::PyPlotPackage) = [:identity, :ln, :log2, :log10] supportedScales(::PyPlotBackend) = [:identity, :ln, :log2, :log10]
subplotSupported(::PyPlotPackage) = true subplotSupported(::PyPlotBackend) = true
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
supportedArgs(::GRPackage) = [ supportedArgs(::GRBackend) = [
:annotation, :annotation,
:axis, :axis,
:background_color, :background_color,
@ -238,22 +238,22 @@ supportedArgs(::GRPackage) = [
:linealpha, :linealpha,
:markeralpha, :markeralpha,
] ]
supportedAxes(::GRPackage) = _allAxes supportedAxes(::GRBackend) = _allAxes
supportedTypes(::GRPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, supportedTypes(::GRBackend) = [:none, :line, :path, :steppre, :steppost, :sticks,
:scatter, :hist2d, :hexbin, :hist, :density, :bar, :scatter, :hist2d, :hexbin, :hist, :density, :bar,
:hline, :vline, :contour, :path3d, :scatter3d, :surface, :hline, :vline, :contour, :path3d, :scatter3d, :surface,
:wireframe, :ohlc, :pie] :wireframe, :ohlc, :pie]
supportedStyles(::GRPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] supportedStyles(::GRBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::GRPackage) = vcat(_allMarkers, Shape) supportedMarkers(::GRBackend) = vcat(_allMarkers, Shape)
supportedScales(::GRPackage) = [:identity, :log10] supportedScales(::GRBackend) = [:identity, :log10]
subplotSupported(::GRPackage) = true subplotSupported(::GRBackend) = true
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
supportedArgs(::QwtPackage) = [ supportedArgs(::QwtBackend) = [
:annotation, :annotation,
# :args, # :args,
:axis, :axis,
@ -304,16 +304,16 @@ supportedArgs(::QwtPackage) = [
# :yflip, # :yflip,
# :z, # :z,
] ]
supportedTypes(::QwtPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :hist2d, :hexbin, :hist, :bar, :hline, :vline] supportedTypes(::QwtBackend) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :hist2d, :hexbin, :hist, :bar, :hline, :vline]
supportedMarkers(::QwtPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :star8, :hexagon] supportedMarkers(::QwtBackend) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :star8, :hexagon]
supportedScales(::QwtPackage) = [:identity, :log10] supportedScales(::QwtBackend) = [:identity, :log10]
subplotSupported(::QwtPackage) = true subplotSupported(::QwtBackend) = true
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
supportedArgs(::UnicodePlotsPackage) = [ supportedArgs(::UnicodePlotsBackend) = [
# :annotation, # :annotation,
# :args, # :args,
# :axis, # :axis,
@ -362,12 +362,12 @@ supportedArgs(::UnicodePlotsPackage) = [
# :yflip, # :yflip,
# :z, # :z,
] ]
supportedAxes(::UnicodePlotsPackage) = [:auto, :left] supportedAxes(::UnicodePlotsBackend) = [:auto, :left]
supportedTypes(::UnicodePlotsPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :hist2d, :hexbin, :hist, :bar, :hline, :vline] supportedTypes(::UnicodePlotsBackend) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :hist2d, :hexbin, :hist, :bar, :hline, :vline]
supportedStyles(::UnicodePlotsPackage) = [:auto, :solid] supportedStyles(::UnicodePlotsBackend) = [:auto, :solid]
supportedMarkers(::UnicodePlotsPackage) = [:none, :auto, :ellipse] supportedMarkers(::UnicodePlotsBackend) = [:none, :auto, :ellipse]
supportedScales(::UnicodePlotsPackage) = [:identity] supportedScales(::UnicodePlotsBackend) = [:identity]
subplotSupported(::UnicodePlotsPackage) = true subplotSupported(::UnicodePlotsBackend) = true
@ -375,7 +375,7 @@ subplotSupported(::UnicodePlotsPackage) = true
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
supportedArgs(::WinstonPackage) = [ supportedArgs(::WinstonBackend) = [
:annotation, :annotation,
# :args, # :args,
# :axis, # :axis,
@ -426,19 +426,19 @@ supportedArgs(::WinstonPackage) = [
# :yflip, # :yflip,
# :z, # :z,
] ]
supportedAxes(::WinstonPackage) = [:auto, :left] supportedAxes(::WinstonBackend) = [:auto, :left]
supportedTypes(::WinstonPackage) = [:none, :line, :path, :sticks, :scatter, :hist, :bar] supportedTypes(::WinstonBackend) = [:none, :line, :path, :sticks, :scatter, :hist, :bar]
supportedStyles(::WinstonPackage) = [:auto, :solid, :dash, :dot, :dashdot] supportedStyles(::WinstonBackend) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::WinstonPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] supportedMarkers(::WinstonBackend) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5]
supportedScales(::WinstonPackage) = [:identity, :log10] supportedScales(::WinstonBackend) = [:identity, :log10]
subplotSupported(::WinstonPackage) = false subplotSupported(::WinstonBackend) = false
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
supportedArgs(::BokehPackage) = [ supportedArgs(::BokehBackend) = [
# :annotation, # :annotation,
# :axis, # :axis,
# :background_color, # :background_color,
@ -494,17 +494,17 @@ supportedArgs(::BokehPackage) = [
# :surface, # :surface,
# :levels, # :levels,
] ]
supportedAxes(::BokehPackage) = [:auto, :left] supportedAxes(::BokehBackend) = [:auto, :left]
supportedTypes(::BokehPackage) = [:none, :path, :scatter] #,:steppre, :steppost, :sticks, :hist2d, :hexbin, :hist, :bar, :hline, :vline, :contour] supportedTypes(::BokehBackend) = [:none, :path, :scatter] #,:steppre, :steppost, :sticks, :hist2d, :hexbin, :hist, :bar, :hline, :vline, :contour]
supportedStyles(::BokehPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] supportedStyles(::BokehBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::BokehPackage) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape) supportedMarkers(::BokehBackend) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape)
supportedScales(::BokehPackage) = [:identity, :ln] #, :ln, :log2, :log10, :asinh, :sqrt] supportedScales(::BokehBackend) = [:identity, :ln] #, :ln, :log2, :log10, :asinh, :sqrt]
subplotSupported(::BokehPackage) = false subplotSupported(::BokehBackend) = false
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
supportedArgs(::PlotlyPackage) = [ supportedArgs(::PlotlyBackend) = [
:annotation, :annotation,
# :axis, # :axis,
:background_color, :background_color,
@ -560,21 +560,21 @@ supportedArgs(::PlotlyPackage) = [
:grid, :grid,
:levels, :levels,
] ]
supportedAxes(::PlotlyPackage) = [:auto, :left] supportedAxes(::PlotlyBackend) = [:auto, :left]
supportedTypes(::PlotlyPackage) = [:none, :line, :path, :scatter, :steppre, :steppost, supportedTypes(::PlotlyBackend) = [:none, :line, :path, :scatter, :steppre, :steppost,
:hist2d, :hist, :density, :bar, :contour, :surface, :path3d, :scatter3d, :hist2d, :hist, :density, :bar, :contour, :surface, :path3d, :scatter3d,
:pie, :heatmap] #,, :sticks, :hexbin, :hline, :vline] :pie, :heatmap] #,, :sticks, :hexbin, :hline, :vline]
supportedStyles(::PlotlyPackage) = [:auto, :solid, :dash, :dot, :dashdot] supportedStyles(::PlotlyBackend) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::PlotlyPackage) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, supportedMarkers(::PlotlyBackend) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross,
:pentagon, :hexagon, :octagon, :vline, :hline] #vcat(_allMarkers, Shape) :pentagon, :hexagon, :octagon, :vline, :hline] #vcat(_allMarkers, Shape)
supportedScales(::PlotlyPackage) = [:identity, :log10] #, :ln, :log2, :log10, :asinh, :sqrt] supportedScales(::PlotlyBackend) = [:identity, :log10] #, :ln, :log2, :log10, :asinh, :sqrt]
subplotSupported(::PlotlyPackage) = true subplotSupported(::PlotlyBackend) = true
stringsSupported(::PlotlyPackage) = true stringsSupported(::PlotlyBackend) = true
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
supportedArgs(::PlotlyJSPackage) = [ supportedArgs(::PlotlyJSBackend) = [
:annotation, :annotation,
# :axis, # :axis,
:background_color, :background_color,
@ -630,20 +630,20 @@ supportedArgs(::PlotlyJSPackage) = [
:grid, :grid,
:levels, :levels,
] ]
supportedAxes(::PlotlyJSPackage) = [:auto, :left] supportedAxes(::PlotlyJSBackend) = [:auto, :left]
supportedTypes(::PlotlyJSPackage) = [:none, :line, :path, :scatter, :steppre, :steppost, supportedTypes(::PlotlyJSBackend) = [:none, :line, :path, :scatter, :steppre, :steppost,
:hist2d, :hist, :density, :bar, :contour, :surface, :path3d, :scatter3d, :hist2d, :hist, :density, :bar, :contour, :surface, :path3d, :scatter3d,
:pie, :heatmap] #,, :sticks, :hexbin, :hline, :vline] :pie, :heatmap] #,, :sticks, :hexbin, :hline, :vline]
supportedStyles(::PlotlyJSPackage) = [:auto, :solid, :dash, :dot, :dashdot] supportedStyles(::PlotlyJSBackend) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::PlotlyJSPackage) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, supportedMarkers(::PlotlyJSBackend) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross,
:pentagon, :hexagon, :octagon, :vline, :hline] #vcat(_allMarkers, Shape) :pentagon, :hexagon, :octagon, :vline, :hline] #vcat(_allMarkers, Shape)
supportedScales(::PlotlyJSPackage) = [:identity, :log10] #, :ln, :log2, :log10, :asinh, :sqrt] supportedScales(::PlotlyJSBackend) = [:identity, :log10] #, :ln, :log2, :log10, :asinh, :sqrt]
subplotSupported(::PlotlyJSPackage) = true subplotSupported(::PlotlyJSBackend) = true
stringsSupported(::PlotlyJSPackage) = true stringsSupported(::PlotlyJSBackend) = true
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
supportedArgs(::GLVisualizePackage) = [ supportedArgs(::GLVisualizeBackend) = [
# :annotation, # :annotation,
# :axis, # :axis,
# :background_color, # :background_color,
@ -699,16 +699,16 @@ supportedArgs(::GLVisualizePackage) = [
# :surface # :surface
# :levels, # :levels,
] ]
supportedAxes(::GLVisualizePackage) = [:auto, :left] supportedAxes(::GLVisualizeBackend) = [:auto, :left]
supportedTypes(::GLVisualizePackage) = [:surface] #, :path, :scatter ,:steppre, :steppost, :sticks, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour] supportedTypes(::GLVisualizeBackend) = [:surface] #, :path, :scatter ,:steppre, :steppost, :sticks, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour]
supportedStyles(::GLVisualizePackage) = [:auto, :solid] #, :dash, :dot, :dashdot, :dashdotdot] supportedStyles(::GLVisualizeBackend) = [:auto, :solid] #, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::GLVisualizePackage) = [:none, :auto, :ellipse] #, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape) supportedMarkers(::GLVisualizeBackend) = [:none, :auto, :ellipse] #, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape)
supportedScales(::GLVisualizePackage) = [:identity] #, :log, :log2, :log10, :asinh, :sqrt] supportedScales(::GLVisualizeBackend) = [:identity] #, :log, :log2, :log10, :asinh, :sqrt]
subplotSupported(::GLVisualizePackage) = false subplotSupported(::GLVisualizeBackend) = false
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
supportedArgs(::PGFPlotsPackage) = [ supportedArgs(::PGFPlotsBackend) = [
# :annotation, # :annotation,
# :axis, # :axis,
# :background_color, # :background_color,
@ -764,10 +764,10 @@ supportedArgs(::PGFPlotsPackage) = [
# :surface # :surface
# :levels, # :levels,
] ]
supportedAxes(::PGFPlotsPackage) = [:auto, :left] supportedAxes(::PGFPlotsBackend) = [:auto, :left]
supportedTypes(::PGFPlotsPackage) = [:contour] #, :path, :scatter ,:steppre, :steppost, :sticks, :hist2d, :hexbin, :hist, :bar, :hline, :vline, :contour] supportedTypes(::PGFPlotsBackend) = [:contour] #, :path, :scatter ,:steppre, :steppost, :sticks, :hist2d, :hexbin, :hist, :bar, :hline, :vline, :contour]
supportedStyles(::PGFPlotsPackage) = [:auto, :solid] #, :dash, :dot, :dashdot, :dashdotdot] supportedStyles(::PGFPlotsBackend) = [:auto, :solid] #, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::PGFPlotsPackage) = [:none, :auto, :ellipse] #, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape) supportedMarkers(::PGFPlotsBackend) = [:none, :auto, :ellipse] #, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape)
supportedScales(::PGFPlotsPackage) = [:identity] #, :log, :log2, :log10, :asinh, :sqrt] supportedScales(::PGFPlotsBackend) = [:identity] #, :log, :log2, :log10, :asinh, :sqrt]
subplotSupported(::PGFPlotsPackage) = false subplotSupported(::PGFPlotsBackend) = false

View File

@ -3,7 +3,7 @@
# [WEBSITE] # [WEBSITE]
function _initialize_backend(::[PkgName]Package; kw...) function _initialize_backend(::[PkgName]AbstractBackend; kw...)
@eval begin @eval begin
import [PkgName] import [PkgName]
export [PkgName] export [PkgName]
@ -14,7 +14,7 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::[PkgName]Package; kw...) function _create_plot(pkg::[PkgName]AbstractBackend; kw...)
d = Dict(kw) d = Dict(kw)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`) # TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc # TODO: initialize the plot... title, xlabel, bgcolor, etc
@ -22,14 +22,14 @@ function _create_plot(pkg::[PkgName]Package; kw...)
end end
function _add_series(::[PkgName]Package, plt::Plot; kw...) function _add_series(::[PkgName]AbstractBackend, plt::Plot; kw...)
d = Dict(kw) d = Dict(kw)
# TODO: add one series to the underlying package # TODO: add one series to the underlying package
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt
end end
function _add_annotations{X,Y,V}(plt::Plot{[PkgName]Package}, anns::AVec{@compat(Tuple{X,Y,V})}) function _add_annotations{X,Y,V}(plt::Plot{[PkgName]AbstractBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
for ann in anns for ann in anns
# TODO: add the annotation to the plot # TODO: add the annotation to the plot
end end
@ -37,53 +37,53 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _before_update_plot(plt::Plot{[PkgName]Package}) function _before_update_plot(plt::Plot{[PkgName]AbstractBackend})
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 _update_plot(plt::Plot{[PkgName]Package}, d::Dict) function _update_plot(plt::Plot{[PkgName]AbstractBackend}, d::Dict)
end end
function _update_plot_pos_size(plt::PlottingObject{[PkgName]Package}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{[PkgName]AbstractBackend}, d::Dict)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# accessors for x/y data # accessors for x/y data
function Base.getindex(plt::Plot{[PkgName]Package}, i::Int) function Base.getindex(plt::Plot{[PkgName]AbstractBackend}, i::Int)
# TODO: return a tuple of (x, y) vectors # TODO: return a tuple of (x, y) vectors
end end
function Base.setindex!(plt::Plot{[PkgName]Package}, xy::Tuple, i::Integer) function Base.setindex!(plt::Plot{[PkgName]AbstractBackend}, xy::Tuple, i::Integer)
# TODO: set the plot data from the (x,y) tuple # TODO: set the plot data from the (x,y) tuple
plt plt
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _create_subplot(subplt::Subplot{[PkgName]Package}, isbefore::Bool) function _create_subplot(subplt::Subplot{[PkgName]AbstractBackend}, isbefore::Bool)
# 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 _expand_limits(lims, plt::Plot{[PkgName]Package}, isx::Bool) function _expand_limits(lims, plt::Plot{[PkgName]AbstractBackend}, isx::Bool)
# TODO: call expand limits for each plot data # TODO: call expand limits for each plot data
end end
function _remove_axis(plt::Plot{[PkgName]Package}, isx::Bool) function _remove_axis(plt::Plot{[PkgName]AbstractBackend}, isx::Bool)
# TODO: if plot is inner subplot, might need to remove ticks or axis labels # TODO: if plot is inner subplot, might need to remove ticks or axis labels
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{[PkgName]Package}) function Base.writemime(io::IO, ::MIME"image/png", plt::AbstractPlot{[PkgName]AbstractBackend})
# TODO: write a png to io # TODO: write a png to io
end end
function Base.display(::PlotsDisplay, plt::Plot{[PkgName]Package}) function Base.display(::PlotsDisplay, plt::Plot{[PkgName]AbstractBackend})
# TODO: display/show the plot # TODO: display/show the plot
end end
function Base.display(::PlotsDisplay, plt::Subplot{[PkgName]Package}) function Base.display(::PlotsDisplay, plt::Subplot{[PkgName]AbstractBackend})
# TODO: display/show the subplot # TODO: display/show the subplot
end end

View File

@ -1,7 +1,7 @@
# https://github.com/Evizero/UnicodePlots.jl # https://github.com/Evizero/UnicodePlots.jl
function _initialize_backend(::UnicodePlotsPackage; kw...) function _initialize_backend(::UnicodePlotsBackend; kw...)
@eval begin @eval begin
import UnicodePlots import UnicodePlots
export UnicodePlots export UnicodePlots
@ -111,7 +111,7 @@ function addUnicodeSeries!(o, d::Dict, addlegend::Bool, xlim, ylim)
end end
function handlePlotColors(::UnicodePlotsPackage, d::Dict) function handlePlotColors(::UnicodePlotsBackend, d::Dict)
# TODO: something special for unicodeplots, since it doesn't take kindly to people messing with its color palette # TODO: something special for unicodeplots, since it doesn't take kindly to people messing with its color palette
d[:color_palette] = [RGB(0,0,0)] d[:color_palette] = [RGB(0,0,0)]
end end
@ -119,7 +119,7 @@ end
# ------------------------------- # -------------------------------
function _create_plot(pkg::UnicodePlotsPackage; kw...) function _create_plot(pkg::UnicodePlotsBackend; kw...)
plt = Plot(nothing, pkg, 0, Dict(kw), Dict[]) plt = Plot(nothing, pkg, 0, Dict(kw), Dict[])
# do we want to give a new default size? # do we want to give a new default size?
@ -130,7 +130,7 @@ function _create_plot(pkg::UnicodePlotsPackage; kw...)
plt plt
end end
function _add_series(::UnicodePlotsPackage, plt::Plot; kw...) function _add_series(::UnicodePlotsBackend, plt::Plot; kw...)
d = Dict(kw) d = Dict(kw)
if d[:linetype] in (:sticks, :bar) if d[:linetype] in (:sticks, :bar)
d = barHack(; d...) d = barHack(; d...)
@ -142,7 +142,7 @@ function _add_series(::UnicodePlotsPackage, plt::Plot; kw...)
end end
function _update_plot(plt::Plot{UnicodePlotsPackage}, d::Dict) function _update_plot(plt::Plot{UnicodePlotsBackend}, d::Dict)
for k in (:title, :xlabel, :ylabel, :xlims, :ylims) for k in (:title, :xlabel, :ylabel, :xlims, :ylims)
if haskey(d, k) if haskey(d, k)
plt.plotargs[k] = d[k] plt.plotargs[k] = d[k]
@ -154,7 +154,7 @@ end
# ------------------------------- # -------------------------------
# since this is such a hack, it's only callable using `png`... should error during normal `writemime` # since this is such a hack, it's only callable using `png`... should error during normal `writemime`
function png(plt::PlottingObject{UnicodePlotsPackage}, fn::@compat(AbstractString)) function png(plt::AbstractPlot{UnicodePlotsBackend}, fn::@compat(AbstractString))
fn = addExtension(fn, "png") fn = addExtension(fn, "png")
# make some whitespace and show the plot # make some whitespace and show the plot
@ -182,20 +182,20 @@ 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 _create_subplot(subplt::Subplot{UnicodePlotsPackage}, isbefore::Bool) function _create_subplot(subplt::Subplot{UnicodePlotsBackend}, isbefore::Bool)
isbefore && return false isbefore && return false
true true
end end
function Base.display(::PlotsDisplay, plt::Plot{UnicodePlotsPackage}) function Base.display(::PlotsDisplay, plt::Plot{UnicodePlotsBackend})
rebuildUnicodePlot!(plt) rebuildUnicodePlot!(plt)
show(plt.o) show(plt.o)
end end
function Base.display(::PlotsDisplay, subplt::Subplot{UnicodePlotsPackage}) function Base.display(::PlotsDisplay, subplt::Subplot{UnicodePlotsBackend})
for plt in subplt.plts for plt in subplt.plts
gui(plt) gui(plt)
end end

View File

@ -4,7 +4,7 @@
# CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl # CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl
function standalone_html(plt::PlottingObject; title::AbstractString = get(plt.plotargs, :window_title, "Plots.jl")) function standalone_html(plt::AbstractPlot; title::AbstractString = get(plt.plotargs, :window_title, "Plots.jl"))
""" """
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -26,7 +26,7 @@ function open_browser_window(filename::AbstractString)
warn("Unknown OS... cannot open browser window.") warn("Unknown OS... cannot open browser window.")
end end
function standalone_html_window(plt::PlottingObject; kw...) function standalone_html_window(plt::AbstractPlot; kw...)
html = standalone_html(plt; kw...) html = standalone_html(plt; kw...)
# println(html) # println(html)
filename = string(tempname(), ".html") filename = string(tempname(), ".html")

View File

@ -3,7 +3,7 @@
# credit goes to https://github.com/jverzani for contributing to the first draft of this backend implementation # credit goes to https://github.com/jverzani for contributing to the first draft of this backend implementation
function _initialize_backend(::WinstonPackage; kw...) function _initialize_backend(::WinstonBackend; kw...)
@eval begin @eval begin
# ENV["WINSTON_OUTPUT"] = "gtk" # ENV["WINSTON_OUTPUT"] = "gtk"
warn("Winston is no longer supported... many features will likely be broken.") warn("Winston is no longer supported... many features will likely be broken.")
@ -33,14 +33,14 @@ end
:star5 => "asterisk" :star5 => "asterisk"
) )
function _before_add_series(plt::Plot{WinstonPackage}) function _before_add_series(plt::Plot{WinstonBackend})
Winston.ghf(plt.o) Winston.ghf(plt.o)
end end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::WinstonPackage; kw...) function _create_plot(pkg::WinstonBackend; kw...)
d = Dict(kw) d = Dict(kw)
wplt = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel]) wplt = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel])
@ -64,7 +64,7 @@ function getWinstonItems(plt::Plot)
window, canvas, wplt window, canvas, wplt
end end
function _add_series(::WinstonPackage, plt::Plot; kw...) function _add_series(::WinstonBackend, plt::Plot; kw...)
d = Dict(kw) d = Dict(kw)
window, canvas, wplt = getWinstonItems(plt) window, canvas, wplt = getWinstonItems(plt)
@ -165,7 +165,7 @@ end
:yscale => :ylog, :yscale => :ylog,
) )
function _update_plot(plt::Plot{WinstonPackage}, d::Dict) function _update_plot(plt::Plot{WinstonBackend}, d::Dict)
window, canvas, wplt = getWinstonItems(plt) window, canvas, wplt = getWinstonItems(plt)
for k in (:xlabel, :ylabel, :title, :xlims, :ylims) for k in (:xlabel, :ylabel, :title, :xlims, :ylims)
if haskey(d, k) if haskey(d, k)
@ -186,11 +186,11 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function createWinstonAnnotationObject(plt::Plot{WinstonPackage}, x, y, val::@compat(AbstractString)) function createWinstonAnnotationObject(plt::Plot{WinstonBackend}, x, y, val::@compat(AbstractString))
Winston.text(x, y, val) Winston.text(x, y, val)
end end
function _add_annotations{X,Y,V}(plt::Plot{WinstonPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) function _add_annotations{X,Y,V}(plt::Plot{WinstonBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
for ann in anns for ann in anns
createWinstonAnnotationObject(plt, ann...) createWinstonAnnotationObject(plt, ann...)
end end
@ -199,7 +199,7 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _create_subplot(subplt::Subplot{WinstonPackage}, isbefore::Bool) function _create_subplot(subplt::Subplot{WinstonBackend}, isbefore::Bool)
# 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
@ -211,14 +211,14 @@ function addWinstonLegend(plt::Plot, wplt)
end end
end end
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{WinstonPackage}) function Base.writemime(io::IO, ::MIME"image/png", plt::AbstractPlot{WinstonBackend})
window, canvas, wplt = getWinstonItems(plt) window, canvas, wplt = getWinstonItems(plt)
addWinstonLegend(plt, wplt) addWinstonLegend(plt, wplt)
writemime(io, "image/png", wplt) writemime(io, "image/png", wplt)
end end
function Base.display(::PlotsDisplay, plt::Plot{WinstonPackage}) function Base.display(::PlotsDisplay, plt::Plot{WinstonBackend})
window, canvas, wplt = getWinstonItems(plt) window, canvas, wplt = getWinstonItems(plt)
@ -240,6 +240,6 @@ function Base.display(::PlotsDisplay, plt::Plot{WinstonPackage})
end end
function Base.display(::PlotsDisplay, subplt::Subplot{WinstonPackage}) function Base.display(::PlotsDisplay, subplt::Subplot{WinstonBackend})
# TODO: display/show the Subplot object # TODO: display/show the Subplot object
end end

View File

@ -354,7 +354,7 @@ webcolor(c, α) = webcolor(convertColor(getColor(c), α))
# 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) function handlePlotColors(::AbstractBackend, d::Dict)
if :background_color in supportedArgs() if :background_color in supportedArgs()
bgcolor = convertColor(d[:background_color]) bgcolor = convertColor(d[:background_color])
else else

View File

@ -1,8 +1,8 @@
defaultOutputFormat(plt::PlottingObject) = "png" defaultOutputFormat(plt::AbstractPlot) = "png"
function png(plt::PlottingObject, fn::@compat(AbstractString)) function png(plt::AbstractPlot, fn::@compat(AbstractString))
fn = addExtension(fn, "png") fn = addExtension(fn, "png")
io = open(fn, "w") io = open(fn, "w")
writemime(io, MIME("image/png"), plt) writemime(io, MIME("image/png"), plt)
@ -10,7 +10,7 @@ function png(plt::PlottingObject, fn::@compat(AbstractString))
end end
png(fn::@compat(AbstractString)) = png(current(), fn) png(fn::@compat(AbstractString)) = png(current(), fn)
function svg(plt::PlottingObject, fn::@compat(AbstractString)) function svg(plt::AbstractPlot, fn::@compat(AbstractString))
fn = addExtension(fn, "svg") fn = addExtension(fn, "svg")
io = open(fn, "w") io = open(fn, "w")
writemime(io, MIME("image/svg+xml"), plt) writemime(io, MIME("image/svg+xml"), plt)
@ -19,7 +19,7 @@ end
svg(fn::@compat(AbstractString)) = svg(current(), fn) svg(fn::@compat(AbstractString)) = svg(current(), fn)
function pdf(plt::PlottingObject, fn::@compat(AbstractString)) function pdf(plt::AbstractPlot, fn::@compat(AbstractString))
fn = addExtension(fn, "pdf") fn = addExtension(fn, "pdf")
io = open(fn, "w") io = open(fn, "w")
writemime(io, MIME("application/pdf"), plt) writemime(io, MIME("application/pdf"), plt)
@ -28,7 +28,7 @@ end
pdf(fn::@compat(AbstractString)) = pdf(current(), fn) pdf(fn::@compat(AbstractString)) = pdf(current(), fn)
function ps(plt::PlottingObject, fn::@compat(AbstractString)) function ps(plt::AbstractPlot, fn::@compat(AbstractString))
fn = addExtension(fn, "ps") fn = addExtension(fn, "ps")
io = open(fn, "w") io = open(fn, "w")
writemime(io, MIME("application/postscript"), plt) writemime(io, MIME("application/postscript"), plt)
@ -37,7 +37,7 @@ end
ps(fn::@compat(AbstractString)) = ps(current(), fn) ps(fn::@compat(AbstractString)) = ps(current(), fn)
function tex(plt::PlottingObject, fn::@compat(AbstractString)) function tex(plt::AbstractPlot, fn::@compat(AbstractString))
fn = addExtension(fn, "tex") fn = addExtension(fn, "tex")
io = open(fn, "w") io = open(fn, "w")
writemime(io, MIME("application/x-tex"), plt) writemime(io, MIME("application/x-tex"), plt)
@ -78,7 +78,7 @@ function addExtension(fn::@compat(AbstractString), ext::@compat(AbstractString))
end end
end end
function savefig(plt::PlottingObject, fn::@compat(AbstractString)) function savefig(plt::AbstractPlot, fn::@compat(AbstractString))
# get the extension # get the extension
local ext local ext
@ -100,20 +100,20 @@ savefig(fn::@compat(AbstractString)) = savefig(current(), fn)
# savepng(args...; kw...) = savepng(current(), args...; kw...) # savepng(args...; kw...) = savepng(current(), args...; kw...)
# savepng(plt::PlottingObject, fn::@compat(AbstractString); kw...) = (io = open(fn, "w"); writemime(io, MIME("image/png"), plt); close(io)) # savepng(plt::AbstractPlot, fn::@compat(AbstractString); kw...) = (io = open(fn, "w"); writemime(io, MIME("image/png"), plt); close(io))
# --------------------------------------------------------- # ---------------------------------------------------------
gui(plt::PlottingObject = current()) = display(PlotsDisplay(), plt) gui(plt::AbstractPlot = current()) = display(PlotsDisplay(), plt)
# override the REPL display to open a gui window # override the REPL display to open a gui window
Base.display(::Base.REPL.REPLDisplay, ::MIME"text/plain", plt::PlottingObject) = gui(plt) Base.display(::Base.REPL.REPLDisplay, ::MIME"text/plain", plt::AbstractPlot) = gui(plt)
# a backup for html... passes to svg # a backup for html... passes to svg
function Base.writemime(io::IO, ::MIME"text/html", plt::PlottingObject) function Base.writemime(io::IO, ::MIME"text/html", plt::AbstractPlot)
writemime(io, MIME("image/svg+xml"), plt) writemime(io, MIME("image/svg+xml"), plt)
end end

View File

@ -1,8 +1,8 @@
type CurrentPlot type CurrentPlot
nullableplot::Nullable{PlottingObject} nullableplot::Nullable{AbstractPlot}
end end
const CURRENT_PLOT = CurrentPlot(Nullable{PlottingObject}()) const CURRENT_PLOT = CurrentPlot(Nullable{AbstractPlot}())
isplotnull() = isnull(CURRENT_PLOT.nullableplot) isplotnull() = isnull(CURRENT_PLOT.nullableplot)
@ -12,7 +12,7 @@ function current()
end end
get(CURRENT_PLOT.nullableplot) get(CURRENT_PLOT.nullableplot)
end end
current(plot::PlottingObject) = (CURRENT_PLOT.nullableplot = Nullable(plot)) current(plot::AbstractPlot) = (CURRENT_PLOT.nullableplot = Nullable(plot))
# --------------------------------------------------------- # ---------------------------------------------------------
@ -69,11 +69,6 @@ function plot!(args...; kw...)
plot!(current(), args...; kw...) plot!(current(), args...; kw...)
end end
# not allowed:
function plot!(subplt::Subplot, args...; kw...)
error("Can't call plot! on a Subplot!")
end
# this adds to a specific plot... most plot commands will flow through here # this adds to a specific plot... most plot commands will flow through here
function plot!(plt::Plot, args...; kw...) function plot!(plt::Plot, args...; kw...)
d = Dict(kw) d = Dict(kw)
@ -298,7 +293,7 @@ end
# create n=max(mx,my) series arguments. the shorter list is cycled through # create n=max(mx,my) series arguments. the shorter list is cycled through
# note: everything should flow through this # note: everything should flow through this
function createKWargsList(plt::PlottingObject, x, y; kw...) function createKWargsList(plt::AbstractPlot, x, y; kw...)
kwdict = Dict(kw) kwdict = Dict(kw)
xs, xmeta = convertToAnyVector(x, kwdict) xs, xmeta = convertToAnyVector(x, kwdict)
ys, ymeta = convertToAnyVector(y, kwdict) ys, ymeta = convertToAnyVector(y, kwdict)
@ -370,7 +365,7 @@ function createKWargsList(plt::PlottingObject, x, y; kw...)
end end
# handle grouping # handle grouping
function createKWargsList(plt::PlottingObject, groupby::GroupBy, args...; kw...) function createKWargsList(plt::AbstractPlot, groupby::GroupBy, args...; kw...)
ret = Any[] ret = Any[]
for (i,glab) in enumerate(groupby.groupLabels) for (i,glab) in enumerate(groupby.groupLabels)
# TODO: don't automatically overwrite labels # TODO: don't automatically overwrite labels
@ -384,12 +379,12 @@ function createKWargsList(plt::PlottingObject, groupby::GroupBy, args...; kw...)
end end
# pass it off to the x/y version # pass it off to the x/y version
function createKWargsList(plt::PlottingObject, y; kw...) function createKWargsList(plt::AbstractPlot, y; kw...)
createKWargsList(plt, nothing, y; kw...) createKWargsList(plt, nothing, y; kw...)
end end
# 3d line or scatter # 3d line or scatter
function createKWargsList(plt::PlottingObject, x::AVec, y::AVec, zvec::AVec; kw...) function createKWargsList(plt::AbstractPlot, x::AVec, y::AVec, zvec::AVec; kw...)
d = Dict(kw) d = Dict(kw)
if !(get(d, :linetype, :none) in _3dTypes) if !(get(d, :linetype, :none) in _3dTypes)
d[:linetype] = :path3d d[:linetype] = :path3d
@ -397,7 +392,7 @@ function createKWargsList(plt::PlottingObject, x::AVec, y::AVec, zvec::AVec; kw.
createKWargsList(plt, x, y; z=zvec, d...) createKWargsList(plt, x, y; z=zvec, d...)
end end
function createKWargsList{T<:Real}(plt::PlottingObject, z::AMat{T}; kw...) function createKWargsList{T<:Real}(plt::AbstractPlot, z::AMat{T}; kw...)
d = Dict(kw) d = Dict(kw)
if all3D(d) if all3D(d)
n,m = size(z) n,m = size(z)
@ -408,7 +403,7 @@ function createKWargsList{T<:Real}(plt::PlottingObject, z::AMat{T}; kw...)
end end
# contours or surfaces... function grid # contours or surfaces... function grid
function createKWargsList(plt::PlottingObject, x::AVec, y::AVec, zf::Function; kw...) function createKWargsList(plt::AbstractPlot, x::AVec, y::AVec, zf::Function; kw...)
# only allow sorted x/y for now # only allow sorted x/y for now
# TODO: auto sort x/y/z properly # TODO: auto sort x/y/z properly
@assert x == sort(x) @assert x == sort(x)
@ -418,7 +413,7 @@ function createKWargsList(plt::PlottingObject, x::AVec, y::AVec, zf::Function; k
end end
# contours or surfaces... matrix grid # contours or surfaces... matrix grid
function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat::AMat{T}; kw...) function createKWargsList{T<:Real}(plt::AbstractPlot, x::AVec, y::AVec, zmat::AMat{T}; kw...)
# only allow sorted x/y for now # only allow sorted x/y for now
# TODO: auto sort x/y/z properly # TODO: auto sort x/y/z properly
@assert x == sort(x) @assert x == sort(x)
@ -436,7 +431,7 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat::
end end
# contours or surfaces... general x, y grid # contours or surfaces... general x, y grid
function createKWargsList{T<:Real}(plt::PlottingObject, x::AMat{T}, y::AMat{T}, zmat::AMat{T}; kw...) function createKWargsList{T<:Real}(plt::AbstractPlot, x::AMat{T}, y::AMat{T}, zmat::AMat{T}; kw...)
@assert size(zmat) == size(x) == size(y) @assert size(zmat) == size(x) == size(y)
surf = Surface(convert(Matrix{Float64}, zmat)) surf = Surface(convert(Matrix{Float64}, zmat))
# surf = Array(Any,1,1) # surf = Array(Any,1,1)
@ -450,26 +445,26 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AMat{T}, y::AMat{T},
end end
function createKWargsList(plt::PlottingObject, surf::Surface; kw...) function createKWargsList(plt::AbstractPlot, surf::Surface; kw...)
createKWargsList(plt, 1:size(surf.surf,1), 1:size(surf.surf,2), convert(Matrix{Float64}, surf.surf); kw...) createKWargsList(plt, 1:size(surf.surf,1), 1:size(surf.surf,2), convert(Matrix{Float64}, surf.surf); kw...)
end end
function createKWargsList(plt::PlottingObject, x::AVec, y::AVec, surf::Surface; kw...) function createKWargsList(plt::AbstractPlot, x::AVec, y::AVec, surf::Surface; kw...)
createKWargsList(plt, x, y, convert(Matrix{Float64}, surf.surf); kw...) createKWargsList(plt, x, y, convert(Matrix{Float64}, surf.surf); kw...)
end end
function createKWargsList(plt::PlottingObject, f::FuncOrFuncs; kw...) function createKWargsList(plt::AbstractPlot, f::FuncOrFuncs; kw...)
createKWargsList(plt, f, xmin(plt), xmax(plt); kw...) createKWargsList(plt, f, xmin(plt), xmax(plt); kw...)
end end
# list of functions # list of functions
function createKWargsList(plt::PlottingObject, f::FuncOrFuncs, x; kw...) function createKWargsList(plt::AbstractPlot, f::FuncOrFuncs, x; kw...)
@assert !(typeof(x) <: FuncOrFuncs) # otherwise we'd hit infinite recursion here @assert !(typeof(x) <: FuncOrFuncs) # otherwise we'd hit infinite recursion here
createKWargsList(plt, x, f; kw...) createKWargsList(plt, x, f; kw...)
end end
# special handling... xmin/xmax with function(s) # special handling... xmin/xmax with function(s)
function createKWargsList(plt::PlottingObject, f::FuncOrFuncs, xmin::Real, xmax::Real; kw...) function createKWargsList(plt::AbstractPlot, f::FuncOrFuncs, xmin::Real, xmax::Real; kw...)
width = get(plt.plotargs, :size, (100,))[1] width = get(plt.plotargs, :size, (100,))[1]
x = collect(linspace(xmin, xmax, width)) # we don't need more than the width x = collect(linspace(xmin, xmax, width)) # we don't need more than the width
createKWargsList(plt, x, f; kw...) createKWargsList(plt, x, f; kw...)
@ -479,27 +474,27 @@ mapFuncOrFuncs(f::Function, u::AVec) = map(f, u)
mapFuncOrFuncs(fs::AVec{Function}, u::AVec) = [map(f, u) for f in fs] mapFuncOrFuncs(fs::AVec{Function}, u::AVec) = [map(f, u) for f in fs]
# special handling... xmin/xmax with parametric function(s) # special handling... xmin/xmax with parametric function(s)
createKWargsList{T<:Real}(plt::PlottingObject, fx::FuncOrFuncs, fy::FuncOrFuncs, u::AVec{T}; kw...) = createKWargsList(plt, mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u); kw...) createKWargsList{T<:Real}(plt::AbstractPlot, fx::FuncOrFuncs, fy::FuncOrFuncs, u::AVec{T}; kw...) = createKWargsList(plt, mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u); kw...)
createKWargsList{T<:Real}(plt::PlottingObject, u::AVec{T}, fx::FuncOrFuncs, fy::FuncOrFuncs; kw...) = createKWargsList(plt, mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u); kw...) createKWargsList{T<:Real}(plt::AbstractPlot, u::AVec{T}, fx::FuncOrFuncs, fy::FuncOrFuncs; kw...) = createKWargsList(plt, mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u); kw...)
createKWargsList(plt::PlottingObject, fx::FuncOrFuncs, fy::FuncOrFuncs, umin::Real, umax::Real, numPoints::Int = 1000; kw...) = createKWargsList(plt, fx, fy, linspace(umin, umax, numPoints); kw...) createKWargsList(plt::AbstractPlot, fx::FuncOrFuncs, fy::FuncOrFuncs, umin::Real, umax::Real, numPoints::Int = 1000; kw...) = createKWargsList(plt, fx, fy, linspace(umin, umax, numPoints); kw...)
# special handling... 3D parametric function(s) # special handling... 3D parametric function(s)
createKWargsList{T<:Real}(plt::PlottingObject, fx::FuncOrFuncs, fy::FuncOrFuncs, fz::FuncOrFuncs, u::AVec{T}; kw...) = createKWargsList(plt, mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u), mapFuncOrFuncs(fz, u); kw...) createKWargsList{T<:Real}(plt::AbstractPlot, fx::FuncOrFuncs, fy::FuncOrFuncs, fz::FuncOrFuncs, u::AVec{T}; kw...) = createKWargsList(plt, mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u), mapFuncOrFuncs(fz, u); kw...)
createKWargsList{T<:Real}(plt::PlottingObject, u::AVec{T}, fx::FuncOrFuncs, fy::FuncOrFuncs, fz::FuncOrFuncs; kw...) = createKWargsList(plt, mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u), mapFuncOrFuncs(fz, u); kw...) createKWargsList{T<:Real}(plt::AbstractPlot, u::AVec{T}, fx::FuncOrFuncs, fy::FuncOrFuncs, fz::FuncOrFuncs; kw...) = createKWargsList(plt, mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u), mapFuncOrFuncs(fz, u); kw...)
createKWargsList(plt::PlottingObject, fx::FuncOrFuncs, fy::FuncOrFuncs, fz::FuncOrFuncs, umin::Real, umax::Real, numPoints::Int = 1000; kw...) = createKWargsList(plt, fx, fy, fz, linspace(umin, umax, numPoints); kw...) createKWargsList(plt::AbstractPlot, fx::FuncOrFuncs, fy::FuncOrFuncs, fz::FuncOrFuncs, umin::Real, umax::Real, numPoints::Int = 1000; kw...) = createKWargsList(plt, fx, fy, fz, linspace(umin, umax, numPoints); kw...)
# (x,y) tuples # (x,y) tuples
function createKWargsList{R1<:Real,R2<:Real}(plt::PlottingObject, xy::AVec{Tuple{R1,R2}}; kw...) function createKWargsList{R1<:Real,R2<:Real}(plt::AbstractPlot, xy::AVec{Tuple{R1,R2}}; kw...)
createKWargsList(plt, unzip(xy)...; kw...) createKWargsList(plt, unzip(xy)...; kw...)
end end
function createKWargsList{R1<:Real,R2<:Real}(plt::PlottingObject, xy::Tuple{R1,R2}; kw...) function createKWargsList{R1<:Real,R2<:Real}(plt::AbstractPlot, xy::Tuple{R1,R2}; kw...)
createKWargsList(plt, [xy[1]], [xy[2]]; kw...) createKWargsList(plt, [xy[1]], [xy[2]]; kw...)
end end
# special handling... no args... 1 series # special handling... no args... 1 series
function createKWargsList(plt::PlottingObject; kw...) function createKWargsList(plt::AbstractPlot; kw...)
d = Dict(kw) d = Dict(kw)
if !haskey(d, :y) if !haskey(d, :y)
# assume we just want to create an empty plot object which can be added to later # assume we just want to create an empty plot object which can be added to later
@ -522,11 +517,11 @@ end
unzip{T}(x::AVec{FixedSizeArrays.Vec{2,T}}) = T[xi[1] for xi in x], T[xi[2] for xi in x] unzip{T}(x::AVec{FixedSizeArrays.Vec{2,T}}) = T[xi[1] for xi in x], T[xi[2] for xi in x]
unzip{T}(x::FixedSizeArrays.Vec{2,T}) = T[x[1]], T[x[2]] unzip{T}(x::FixedSizeArrays.Vec{2,T}) = T[x[1]], T[x[2]]
function createKWargsList{T<:Real}(plt::PlottingObject, xy::AVec{FixedSizeArrays.Vec{2,T}}; kw...) function createKWargsList{T<:Real}(plt::AbstractPlot, xy::AVec{FixedSizeArrays.Vec{2,T}}; kw...)
createKWargsList(plt, unzip(xy)...; kw...) createKWargsList(plt, unzip(xy)...; kw...)
end end
function createKWargsList{T<:Real}(plt::PlottingObject, xy::FixedSizeArrays.Vec{2,T}; kw...) function createKWargsList{T<:Real}(plt::AbstractPlot, xy::FixedSizeArrays.Vec{2,T}; kw...)
createKWargsList(plt, [xy[1]], [xy[2]]; kw...) createKWargsList(plt, [xy[1]], [xy[2]]; kw...)
end end
@ -538,7 +533,7 @@ end
@require DataFrames begin @require DataFrames begin
function createKWargsList(plt::PlottingObject, df::DataFrames.AbstractDataFrame, args...; kw...) function createKWargsList(plt::AbstractPlot, df::DataFrames.AbstractDataFrame, args...; kw...)
createKWargsList(plt, args...; kw..., dataframe = df) createKWargsList(plt, args...; kw..., dataframe = df)
end end

View File

@ -3,7 +3,7 @@
# TODO: there should be a distinction between an object that will manage a full plot, vs a component of a plot. # TODO: there should be a distinction between an object that will manage a full plot, vs a component of a plot.
# the PlotRecipe as currently implemented is more of a "custom component" # the PlotRecipe as currently implemented is more of a "custom component"
# a recipe should fully describe the plotting command(s) and call them, likewise for updating. # a recipe should fully describe the plotting command(s) and call them, likewise for updating.
# actually... maybe those should explicitly derive from PlottingObject??? # actually... maybe those should explicitly derive from AbstractPlot???
abstract PlotRecipe abstract PlotRecipe

View File

@ -127,7 +127,7 @@ function subplot{P,I<:Integer}(pltsPerRow::AVec{I}, plt1::Plot{P}, plts::Plot{P}
end end
# this will be called internally # this will be called internally
function subplot{P<:PlottingPackage}(plts::AVec{Plot{P}}, layout::SubplotLayout, d::Dict) function subplot{P<:AbstractBackend}(plts::AVec{Plot{P}}, layout::SubplotLayout, d::Dict)
validateSubplotSupported() validateSubplotSupported()
p = length(layout) p = length(layout)
n = sum([plt.n for plt in plts]) n = sum([plt.n for plt in plts])
@ -279,6 +279,11 @@ function subplot!(subplt::Subplot, args...; kw...)
end end
# not allowed:
function plot!(subplt::Subplot, args...; kw...)
error("Can't call plot! on a Subplot!")
end
function _add_series_subplot(plt::Plot, args...; kw...) function _add_series_subplot(plt::Plot, args...; kw...)
d = Dict(kw) d = Dict(kw)

View File

@ -4,14 +4,14 @@ typealias AMat AbstractMatrix
immutable PlotsDisplay <: Display end immutable PlotsDisplay <: Display end
abstract PlottingPackage abstract AbstractBackend
abstract PlottingObject{T<:PlottingPackage} abstract AbstractPlot{T<:AbstractBackend}
# ----------------------------------------------------------- # -----------------------------------------------------------
# Plot # Plot
# ----------------------------------------------------------- # -----------------------------------------------------------
type Plot{T<:PlottingPackage} <: PlottingObject{T} type Plot{T<:AbstractBackend} <: AbstractPlot{T}
o # the backend's plot object o # the backend's plot object
backend::T # the backend type backend::T # the backend type
n::Int # number of series n::Int # number of series
@ -58,7 +58,7 @@ typealias IntOrFlex Union{Int,FlexLayout}
# Subplot # Subplot
# ----------------------------------------------------------- # -----------------------------------------------------------
type Subplot{T<:PlottingPackage, L<:SubplotLayout} <: PlottingObject{T} type Subplot{T<:AbstractBackend, L<:SubplotLayout} <: AbstractPlot{T}
o # the underlying object o # the underlying object
plts::Vector{Plot{T}} # the individual plots plts::Vector{Plot{T}} # the individual plots
backend::T backend::T

View File

@ -8,10 +8,10 @@ default(show=false)
img_eps = 5e-2 img_eps = 5e-2
facts("Gadfly") do facts("Gadfly") do
@fact gadfly() --> Plots.GadflyPackage() @fact gadfly() --> Plots.GadflyBackend()
@fact backend() --> Plots.GadflyPackage() @fact backend() --> Plots.GadflyBackend()
@fact typeof(plot(1:10)) --> Plots.Plot{Plots.GadflyPackage} @fact typeof(plot(1:10)) --> Plots.Plot{Plots.GadflyBackend}
@fact plot(Int[1,2,3], rand(3)) --> not(nothing) @fact plot(Int[1,2,3], rand(3)) --> not(nothing)
@fact plot(sort(rand(10)), rand(Int, 10, 3)) --> not(nothing) @fact plot(sort(rand(10)), rand(Int, 10, 3)) --> not(nothing)
@fact plot!(rand(10,3), rand(10,3)) --> not(nothing) @fact plot!(rand(10,3), rand(10,3)) --> not(nothing)
@ -20,15 +20,15 @@ facts("Gadfly") do
end end
facts("PyPlot") do facts("PyPlot") do
@fact pyplot() --> Plots.PyPlotPackage() @fact pyplot() --> Plots.PyPlotBackend()
@fact backend() --> Plots.PyPlotPackage() @fact backend() --> Plots.PyPlotBackend()
image_comparison_facts(:pyplot, skip=[4,10,13,19,21,23], eps=img_eps) image_comparison_facts(:pyplot, skip=[4,10,13,19,21,23], eps=img_eps)
end end
facts("GR") do facts("GR") do
@fact gr() --> Plots.GRPackage() @fact gr() --> Plots.GRBackend()
@fact backend() --> Plots.GRPackage() @fact backend() --> Plots.GRBackend()
# image_comparison_facts(:gr, only=[1], eps=img_eps) # image_comparison_facts(:gr, only=[1], eps=img_eps)
end end