started work on plotly
This commit is contained in:
parent
be5c3fb55c
commit
a8c40a5493
41
src/backends/plotly-latest.min.js
vendored
Executable file
41
src/backends/plotly-latest.min.js
vendored
Executable file
File diff suppressed because one or more lines are too long
126
src/backends/plotly.jl
Normal file
126
src/backends/plotly.jl
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
|
||||||
|
# https://plot.ly/javascript/getting-started
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function _create_plot(pkg::PlotlyPackage; 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
|
||||||
|
Plot(nothing, pkg, 0, d, Dict[])
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function _add_series(::PlotlyPackage, plt::Plot; kw...)
|
||||||
|
d = Dict(kw)
|
||||||
|
# TODO: add one series to the underlying package
|
||||||
|
push!(plt.seriesargs, d)
|
||||||
|
plt
|
||||||
|
end
|
||||||
|
|
||||||
|
function _add_annotations{X,Y,V}(plt::Plot{PlotlyPackage}, 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{PlotlyPackage})
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: override this to update plot items (title, xlabel, etc) after creation
|
||||||
|
function _update_plot(plt::Plot{PlotlyPackage}, d::Dict)
|
||||||
|
end
|
||||||
|
|
||||||
|
function _update_plot_pos_size(plt::PlottingObject{PlotlyPackage}, d::Dict)
|
||||||
|
end
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
|
# accessors for x/y data
|
||||||
|
|
||||||
|
function Base.getindex(plt::Plot{PlotlyPackage}, i::Int)
|
||||||
|
series = plt.o.lines[i]
|
||||||
|
series.x, series.y
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.setindex!(plt::Plot{PlotlyPackage}, xy::Tuple, i::Integer)
|
||||||
|
series = plt.o.lines[i]
|
||||||
|
series.x, series.y = xy
|
||||||
|
plt
|
||||||
|
end
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function _create_subplot(subplt::Subplot{PlotlyPackage})
|
||||||
|
# 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{PlotlyPackage}, isx::Bool)
|
||||||
|
# TODO: call expand limits for each plot data
|
||||||
|
end
|
||||||
|
|
||||||
|
function _remove_axis(plt::Plot{PlotlyPackage}, 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{PlotlyPackage})
|
||||||
|
# TODO: write a png to io
|
||||||
|
end
|
||||||
|
|
||||||
|
function open_browser_window(filename::AbstractString)
|
||||||
|
@osx_only return run(`open $(filename)`)
|
||||||
|
@linux_only return run(`xdg-open $(filename)`)
|
||||||
|
@windows_only return run(`$(ENV["COMSPEC"]) /c start $(filename)`)
|
||||||
|
warn("Unknown OS... cannot open browser window.")
|
||||||
|
end
|
||||||
|
|
||||||
|
function build_plotly_json()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.display(::PlotsDisplay, plt::Plot{PlotlyPackage})
|
||||||
|
|
||||||
|
filename = string(tempname(), ".html")
|
||||||
|
output = open(filename, "w")
|
||||||
|
w, h = plt.plotargs[:size]
|
||||||
|
|
||||||
|
write(output,
|
||||||
|
"""
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Plots.jl (Plotly)</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<script src="$(Pkg.dir("Plots"))/src/backends/plotly-latest.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="myplot" style="width:$(w)px;height:$(h)px;"></div>
|
||||||
|
<script charset="utf-8">
|
||||||
|
PLOT = document.getElementById('myplot');
|
||||||
|
Plotly.plot(PLOT, [{
|
||||||
|
x: [1, 2, 3, 4, 5],
|
||||||
|
y: [1, 2, 4, 8, 16]
|
||||||
|
}],
|
||||||
|
{margin: { t: 0 }});
|
||||||
|
""")
|
||||||
|
|
||||||
|
# build_plotly_json(plt)
|
||||||
|
# print(output, json)
|
||||||
|
|
||||||
|
write(output,
|
||||||
|
"""
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
""")
|
||||||
|
close(output)
|
||||||
|
|
||||||
|
open_browser_window(filename)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.display(::PlotsDisplay, plt::Subplot{PlotlyPackage})
|
||||||
|
# TODO: display/show the subplot
|
||||||
|
end
|
||||||
@ -9,7 +9,7 @@ function _create_plot(pkg::[PkgName]Package; 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
|
||||||
Plot(o, pkg, 0, d, Dict[])
|
Plot(nothing, pkg, 0, d, Dict[])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
|
|
||||||
|
|
||||||
immutable GadflyPackage <: PlottingPackage end
|
immutable GadflyPackage <: PlottingPackage end
|
||||||
immutable ImmersePackage <: PlottingPackage end
|
immutable ImmersePackage <: PlottingPackage end
|
||||||
immutable PyPlotPackage <: PlottingPackage end
|
immutable PyPlotPackage <: PlottingPackage end
|
||||||
immutable QwtPackage <: PlottingPackage end
|
immutable QwtPackage <: PlottingPackage end
|
||||||
immutable UnicodePlotsPackage <: PlottingPackage end
|
immutable UnicodePlotsPackage <: PlottingPackage end
|
||||||
immutable WinstonPackage <: PlottingPackage end
|
immutable WinstonPackage <: PlottingPackage end
|
||||||
immutable BokehPackage <: PlottingPackage end
|
immutable BokehPackage <: PlottingPackage end
|
||||||
|
immutable PlotlyPackage <: PlottingPackage end
|
||||||
|
|
||||||
typealias GadflyOrImmerse @compat(Union{GadflyPackage, ImmersePackage})
|
typealias GadflyOrImmerse @compat(Union{GadflyPackage, ImmersePackage})
|
||||||
|
|
||||||
@ -16,16 +17,18 @@ export
|
|||||||
pyplot,
|
pyplot,
|
||||||
qwt,
|
qwt,
|
||||||
unicodeplots,
|
unicodeplots,
|
||||||
bokeh
|
bokeh,
|
||||||
|
plotly
|
||||||
# winston
|
# winston
|
||||||
|
|
||||||
gadfly() = backend(:gadfly)
|
gadfly() = backend(:gadfly)
|
||||||
immerse() = backend(:immerse)
|
immerse() = backend(:immerse)
|
||||||
pyplot() = backend(:pyplot)
|
pyplot() = backend(:pyplot)
|
||||||
qwt() = backend(:qwt)
|
qwt() = backend(:qwt)
|
||||||
unicodeplots() = backend(:unicodeplots)
|
unicodeplots() = backend(:unicodeplots)
|
||||||
bokeh() = backend(:bokeh)
|
bokeh() = backend(:bokeh)
|
||||||
# winston() = backend(:winston)
|
plotly() = backend(:plotly)
|
||||||
|
# winston() = backend(:winston)
|
||||||
|
|
||||||
backend_name(::GadflyPackage) = :gadfly
|
backend_name(::GadflyPackage) = :gadfly
|
||||||
backend_name(::ImmersePackage) = :immerse
|
backend_name(::ImmersePackage) = :immerse
|
||||||
@ -33,6 +36,7 @@ backend_name(::PyPlotPackage) = :pyplot
|
|||||||
backend_name(::UnicodePlotsPackage) = :unicodeplots
|
backend_name(::UnicodePlotsPackage) = :unicodeplots
|
||||||
backend_name(::QwtPackage) = :qwt
|
backend_name(::QwtPackage) = :qwt
|
||||||
backend_name(::BokehPackage) = :bokeh
|
backend_name(::BokehPackage) = :bokeh
|
||||||
|
backend_name(::PlotlyPackage) = :plotly
|
||||||
|
|
||||||
include("backends/supported.jl")
|
include("backends/supported.jl")
|
||||||
|
|
||||||
@ -43,6 +47,7 @@ include("backends/pyplot.jl")
|
|||||||
include("backends/immerse.jl")
|
include("backends/immerse.jl")
|
||||||
include("backends/winston.jl")
|
include("backends/winston.jl")
|
||||||
include("backends/bokeh.jl")
|
include("backends/bokeh.jl")
|
||||||
|
include("backends/plotly.jl")
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
@ -62,7 +67,7 @@ subplot!(pkg::PlottingPackage, subplt::Subplot; kw...) = error("subplot!($pkg, s
|
|||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
const BACKENDS = [:qwt, :gadfly, :unicodeplots, :pyplot, :immerse, :bokeh]
|
const BACKENDS = [:qwt, :gadfly, :unicodeplots, :pyplot, :immerse, :bokeh, :plotly]
|
||||||
const INITIALIZED_BACKENDS = Set{Symbol}()
|
const INITIALIZED_BACKENDS = Set{Symbol}()
|
||||||
backends() = BACKENDS
|
backends() = BACKENDS
|
||||||
|
|
||||||
@ -75,6 +80,7 @@ function backendInstance(sym::Symbol)
|
|||||||
sym == :immerse && return ImmersePackage()
|
sym == :immerse && return ImmersePackage()
|
||||||
sym == :winston && return WinstonPackage()
|
sym == :winston && return WinstonPackage()
|
||||||
sym == :bokeh && return BokehPackage()
|
sym == :bokeh && return BokehPackage()
|
||||||
|
sym == :plotly && return PlotlyPackage()
|
||||||
error("Unsupported backend $sym")
|
error("Unsupported backend $sym")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -118,13 +124,8 @@ function pickDefaultBackend()
|
|||||||
return CurrentBackend(:bokeh)
|
return CurrentBackend(:bokeh)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
try
|
# warn("You don't have any of the supported backends installed! Chose from ", backends())
|
||||||
if Pkg.installed("Winston") != nothing
|
return CurrentBackend(:plotly)
|
||||||
return CurrentBackend(:winston)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
warn("You don't have any of the supported backends installed! Chose from ", backends())
|
|
||||||
return CurrentBackend(:gadfly)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -216,6 +217,14 @@ function backend()
|
|||||||
rethrow(err)
|
rethrow(err)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elseif currentBackendSymbol == :plotly
|
||||||
|
try
|
||||||
|
# TODO: any setup
|
||||||
|
catch err
|
||||||
|
warn("Couldn't setup Plotly")
|
||||||
|
rethrow(err)
|
||||||
|
end
|
||||||
|
|
||||||
elseif currentBackendSymbol == :winston
|
elseif currentBackendSymbol == :winston
|
||||||
warn("Winston support is deprecated and broken. Try another backend: $BACKENDS")
|
warn("Winston support is deprecated and broken. Try another backend: $BACKENDS")
|
||||||
try
|
try
|
||||||
@ -262,6 +271,8 @@ function backend(modname)
|
|||||||
CURRENT_BACKEND.pkg = WinstonPackage()
|
CURRENT_BACKEND.pkg = WinstonPackage()
|
||||||
elseif modname == :bokeh
|
elseif modname == :bokeh
|
||||||
CURRENT_BACKEND.pkg = BokehPackage()
|
CURRENT_BACKEND.pkg = BokehPackage()
|
||||||
|
elseif modname == :plotly
|
||||||
|
CURRENT_BACKEND.pkg = PlotlyPackage()
|
||||||
else
|
else
|
||||||
error("Unknown backend $modname. Choose from: $BACKENDS")
|
error("Unknown backend $modname. Choose from: $BACKENDS")
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user