merge glvisualize
This commit is contained in:
commit
0487d7a058
90
src/backends/glvisualize.jl
Normal file
90
src/backends/glvisualize.jl
Normal file
@ -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
|
||||
@ -77,7 +77,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]
|
||||
@ -492,3 +492,68 @@ supportedScales(::PlotlyPackage) = [:identity, :log10] #, :ln, :log2, :log10, :a
|
||||
subplotSupported(::PlotlyPackage) = true
|
||||
stringsSupported(::PlotlyPackage) = true
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
|
||||
15
src/plot.jl
15
src/plot.jl
@ -94,7 +94,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)
|
||||
@ -388,6 +388,16 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat::
|
||||
createKWargsList(plt, x, y; d..., z = surf)
|
||||
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
|
||||
@ -431,7 +441,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
|
||||
@ -474,4 +484,3 @@ end
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -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) = :glvisualize
|
||||
backend_name(::NoPackage) = :none
|
||||
|
||||
include("backends/supported.jl")
|
||||
@ -53,6 +57,8 @@ include("backends/web.jl")
|
||||
include("backends/bokeh.jl")
|
||||
include("backends/plotly.jl")
|
||||
|
||||
include("backends/glvisualize.jl")
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
@ -85,9 +91,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
|
||||
@ -99,7 +106,7 @@ CurrentBackend(sym::Symbol) = CurrentBackend(sym, backendInstance(sym))
|
||||
# ---------------------------------------------------------
|
||||
|
||||
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
|
||||
@ -163,7 +170,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"
|
||||
@ -234,6 +241,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
|
||||
@ -263,7 +279,7 @@ function backend(pkg::PlottingPackage)
|
||||
end
|
||||
|
||||
function backend(modname)
|
||||
|
||||
|
||||
# set the PlottingPackage
|
||||
if modname == :qwt
|
||||
CURRENT_BACKEND.pkg = QwtPackage()
|
||||
@ -281,6 +297,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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user