diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl new file mode 100644 index 00000000..c42848ec --- /dev/null +++ b/src/backends/glvisualize.jl @@ -0,0 +1,90 @@ + + +# [WEBSITE] + +# --------------------------------------------------------------------------- + +immutable GLScreenWrapper + window + render +end + +function _create_plot(pkg::GLVisualizePackage; kw...) + d = Dict(kw) + # TODO: create the window/canvas/context that is the plot within the backend (call it `o`) + # TODO: initialize the plot... title, xlabel, bgcolor, etc + w,r=GLVisualize.glscreen() + @async r() + Plot(GLScreenWrapper(w,r), pkg, 0, d, Dict[]) +end + + +function _add_series(::GLVisualizePackage, plt::Plot; kw...) + d = Dict(kw) + # TODO: add one series to the underlying package + push!(plt.seriesargs, d) + x,y,z=map(Float32,d[:x]), map(Float32,d[:y]), map(Float32,d[:surface].surf) + GLVisualize.view(GLVisualize.visualize(x*ones(y)', ones(x)*y', z, :surface)) + plt +end + +function _add_annotations{X,Y,V}(plt::Plot{GLVisualizePackage}, anns::AVec{@compat(Tuple{X,Y,V})}) + for ann in anns + # TODO: add the annotation to the plot + end +end + +# ---------------------------------------------------------------- + +function _before_update_plot(plt::Plot{GLVisualizePackage}) +end + +# TODO: override this to update plot items (title, xlabel, etc) after creation +function _update_plot(plt::Plot{GLVisualizePackage}, d::Dict) +end + +function _update_plot_pos_size(plt::PlottingObject{GLVisualizePackage}, d::Dict) +end + +# ---------------------------------------------------------------- + +# accessors for x/y data + +function Base.getindex(plt::Plot{GLVisualizePackage}, i::Int) + series = plt.o.lines[i] + series.x, series.y +end + +function Base.setindex!(plt::Plot{GLVisualizePackage}, xy::Tuple, i::Integer) + series = plt.o.lines[i] + series.x, series.y = xy + plt +end + +# ---------------------------------------------------------------- + +function _create_subplot(subplt::Subplot{GLVisualizePackage}) + # TODO: build the underlying Subplot object. this is where you might layout the panes within a GUI window, for example +end + +function _expand_limits(lims, plt::Plot{GLVisualizePackage}, isx::Bool) + # TODO: call expand limits for each plot data +end + +function _remove_axis(plt::Plot{GLVisualizePackage}, isx::Bool) + # TODO: if plot is inner subplot, might need to remove ticks or axis labels +end + +# ---------------------------------------------------------------- + +function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{GLVisualizePackage}) + # TODO: write a png to io +end + +function Base.display(::PlotsDisplay, plt::Plot{GLVisualizePackage}) + # TODO: display/show the plot +end + +function Base.display(::PlotsDisplay, plt::Subplot{GLVisualizePackage}) + # TODO: display/show the subplot +end diff --git a/src/backends/supported.jl b/src/backends/supported.jl index a6926f8e..eb3d3aa7 100644 --- a/src/backends/supported.jl +++ b/src/backends/supported.jl @@ -75,7 +75,7 @@ supportedArgs(::GadflyPackage) = [ :nlevels, ] supportedAxes(::GadflyPackage) = [:auto, :left] -supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, +supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour] supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] @@ -487,3 +487,68 @@ supportedScales(::PlotlyPackage) = [:identity, :log] #, :log, :log2, :log10, :as subplotSupported(::PlotlyPackage) = false + +# -------------------------------------------------------------------------------------- + +supportedArgs(::GLVisualizePackage) = [ + # :annotation, + # :axis, + # :background_color, + # :color_palette, + # :fillrange, + # :fillcolor, + # :fillalpha, + # :foreground_color, + # :group, + # :label, + # :layout, + # :legend, + # :linecolor, + # :linestyle, + # :linetype, + # :linewidth, + # :linealpha, + # :markershape, + # :markercolor, + # :markersize, + # :markeralpha, + # :markerstrokewidth, + # :markerstrokecolor, + # :markerstrokestyle, + # :n, + # :nbins, + # :nc, + # :nr, + # :pos, + # :smooth, + # :show, + # :size, + # :title, + # :windowtitle, + # :x, + # :xlabel, + # :xlims, + # :xticks, + # :y, + # :ylabel, + # :ylims, + # :yrightlabel, + # :yticks, + # :xscale, + # :yscale, + # :xflip, + # :yflip, + # :z, + # :tickfont, + # :guidefont, + # :legendfont, + # :grid, + # :surface + # :nlevels, + ] +supportedAxes(::GLVisualizePackage) = [:auto, :left] +supportedTypes(::GLVisualizePackage) = [:contour] #, :path, :scatter ,:steppre, :steppost, :sticks, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour] +supportedStyles(::GLVisualizePackage) = [:auto, :solid] #, :dash, :dot, :dashdot, :dashdotdot] +supportedMarkers(::GLVisualizePackage) = [:none, :auto, :ellipse] #, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape) +supportedScales(::GLVisualizePackage) = [:identity] #, :log, :log2, :log10, :asinh, :sqrt] +subplotSupported(::GLVisualizePackage) = false diff --git a/src/plot.jl b/src/plot.jl index e65556d1..1bd42872 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -91,7 +91,7 @@ function plot!(plt::Plot, args...; kw...) # get the list of dictionaries, one per series seriesArgList, xmeta, ymeta = createKWargsList(plt, groupargs..., args...; d...) - + # if we were able to extract guide information from the series inputs, then update the plot # @show xmeta, ymeta updateDictWithMeta(d, plt.plotargs, xmeta, true) @@ -372,6 +372,16 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat:: createKWargsList(plt, x, y; kw..., surface = surf, linetype = :contour) end +# contours or surfaces... general x, y grid +function createKWargsList{T<:Real}(plt::PlottingObject, x::AMat{T}, y::AMat{T}, zmat::AMat{T}; kw...) + @assert size(zmat) == size(x) == size(y) + surf = Surface(convert(Matrix{Float64}, zmat)) + # surf = Array(Any,1,1) + # surf[1,1] = convert(Matrix{Float64}, zmat) + createKWargsList(plt, x, y; kw..., surface = surf, linetype = :contour) +end + + function createKWargsList(plt::PlottingObject, surf::Surface; kw...) createKWargsList(plt, 1:size(surf.surf,1), 1:size(surf.surf,2), convert(Matrix{Float64}, surf.surf); kw...) end @@ -411,7 +421,7 @@ function createKWargsList(plt::PlottingObject; kw...) return [], nothing, nothing # error("Called plot/subplot without args... must set y in the keyword args. Example: plot(; y=rand(10))") end - + if haskey(d, :x) return createKWargsList(plt, d[:x], d[:y]; kw...) else @@ -454,4 +464,3 @@ end # -------------------------------------------------------------------- - diff --git a/src/plotter.jl b/src/plotter.jl index 261cfe03..a47e8332 100644 --- a/src/plotter.jl +++ b/src/plotter.jl @@ -8,6 +8,7 @@ immutable UnicodePlotsPackage <: PlottingPackage end immutable WinstonPackage <: PlottingPackage end immutable BokehPackage <: PlottingPackage end immutable PlotlyPackage <: PlottingPackage end +immutable GLVisualizePackage <: PlottingPackage end immutable NoPackage <: PlottingPackage end typealias GadflyOrImmerse @compat(Union{GadflyPackage, ImmersePackage}) @@ -19,7 +20,8 @@ export qwt, unicodeplots, bokeh, - plotly + plotly, + glvisualize # winston gadfly() = backend(:gadfly) @@ -29,6 +31,7 @@ qwt() = backend(:qwt) unicodeplots() = backend(:unicodeplots) bokeh() = backend(:bokeh) plotly() = backend(:plotly) +glvisualize() = backend(:glvisualize) # winston() = backend(:winston) backend_name(::GadflyPackage) = :gadfly @@ -38,6 +41,7 @@ backend_name(::UnicodePlotsPackage) = :unicodeplots backend_name(::QwtPackage) = :qwt backend_name(::BokehPackage) = :bokeh backend_name(::PlotlyPackage) = :plotly +backend_name(::GLVisualizePackage) = :plotly backend_name(::NoPackage) = :none include("backends/supported.jl") @@ -49,6 +53,7 @@ include("backends/pyplot.jl") include("backends/immerse.jl") include("backends/winston.jl") include("backends/bokeh.jl") +include("backends/glvisualize.jl") # include("backends/plotly.jl") @@ -83,9 +88,10 @@ function backendInstance(sym::Symbol) sym == :winston && return WinstonPackage() sym == :bokeh && return BokehPackage() sym == :plotly && return PlotlyPackage() + sym == :glvisualize && return GLVisualizePackage() sym == :none && return NoPackage() error("Unsupported backend $sym") -end +end type CurrentBackend @@ -132,7 +138,7 @@ CurrentBackend(sym::Symbol) = CurrentBackend(sym, backendInstance(sym)) # end function pickDefaultBackend() - for pkgstr in ("PyPlot", "Immerse", "Qwt", "Gadfly", "UnicodePlots", "Bokeh") + for pkgstr in ("PyPlot", "Immerse", "Qwt", "Gadfly", "UnicodePlots", "Bokeh", "GLVisualize") if Pkg.installed(pkgstr) != nothing return backend(symbol(lowercase(pkgstr))) end @@ -196,7 +202,7 @@ function backend() # @eval const pycolorbar = PyPlot.pywrap(PyPlot.pyimport("matplotlib.colorbar")) if !isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay) PyPlot.ioff() # stops wierd behavior of displaying incomplete graphs in IJulia - + # # TODO: how the hell can I use PyQt4?? # "pyqt4"=>:qt_pyqt4 # PyPlot.backend[1] = "pyqt4" @@ -243,6 +249,15 @@ function backend() rethrow(err) end + elseif currentBackendSymbol == :glvisualize + try + @eval import GLVisualize + @eval export GLVisualize + catch err + warn("Couldn't setup GLVisualize") + rethrow(err) + end + elseif currentBackendSymbol == :winston warn("Winston support is deprecated and broken. Try another backend: $BACKENDS") try @@ -272,7 +287,7 @@ function backend(pkg::PlottingPackage) end function backend(modname) - + # set the PlottingPackage if modname == :qwt CURRENT_BACKEND.pkg = QwtPackage() @@ -290,6 +305,8 @@ function backend(modname) CURRENT_BACKEND.pkg = BokehPackage() elseif modname == :plotly CURRENT_BACKEND.pkg = PlotlyPackage() +elseif modname == :glvisualize + CURRENT_BACKEND.pkg = GLVisualizePackage() else error("Unknown backend $modname. Choose from: $BACKENDS") end