From 4d864d8cadab578183102608d592e2c38dee809c Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Mon, 14 Mar 2016 16:58:01 -0400 Subject: [PATCH] working on atom integration --- src/backends/plotly.jl | 33 ++++++++++++++++++++++++--------- src/output.jl | 7 ++++++- src/utils.jl | 3 ++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index b8cccbd7..583c2f8e 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -8,25 +8,34 @@ function _initialize_backend(::PlotlyBackend; kw...) ############################ # borrowed from https://github.com/spencerlyon2/Plotlyjs.jl/blob/master/src/display.jl - _js_path = joinpath(Pkg.dir("Plots"), "deps", "plotly-latest.min.js") + _js_path = Pkg.dir("Plots", "deps", "plotly-latest.min.js") + + _js_code = open(readall, _js_path, "r") + + _js_script = """ + + + """ # if we're in IJulia call setupnotebook to load js and css if isijulia() # the first script is some hack I needed to do in order for the notebook # to not complain about Plotly being undefined - display("text/html", """ - - - """) + display("text/html", _js_script) # display("text/html", "

Plotly javascript loaded.

") end # end borrowing (thanks :) ########################### + # if isatom() + # import Atom + # Atom.@msg evaljs(_js_code) + # end + end # TODO: other initialization end @@ -447,6 +456,12 @@ function html_body(plt::Plot{PlotlyBackend}, style = nothing) html end +function js_body(plt::Plot{PlotlyBackend}, uuid) + js = """ + PLOT = document.getElementById('$(uuid)'); + Plotly.plot(PLOT, $(get_series_json(plt)), $(get_plot_json(plt))); + """ +end function html_body(subplt::Subplot{PlotlyBackend}) diff --git a/src/output.jl b/src/output.jl index 4cc18bec..f3659a0d 100644 --- a/src/output.jl +++ b/src/output.jl @@ -128,7 +128,7 @@ function setup_atom() import Atom, Media # connects the render function - Media.media(Plot, Media.Plot) + Media.media{T <: Union{GadflyBackend,ImmerseBackend,PyPlotBackend,GRBackend}}(Plot{T}, Media.Plot) # Atom.displaysize(::AbstractPlot) = (535, 379) # Atom.displaytitle(plt::AbstractPlot) = "Plots.jl (backend: $(backend(plt)))" @@ -137,5 +137,10 @@ function setup_atom() function Media.render(pane::Atom.PlotPane, plt::Plot) Media.render(pane, Atom.div(Atom.d(), Atom.HTML(stringmime(MIME("text/html"), plt)))) end + + + # function Media.render(pane::Atom.PlotPane, plt::Plot{PlotlyBackend}) + # html = Media.render(pane, Atom.div(Atom.d(), Atom.HTML(stringmime(MIME("text/html"), plt)))) + # end end end diff --git a/src/utils.jl b/src/utils.jl index 3bdd2c2f..30ea6f99 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -198,6 +198,7 @@ function fakedata(sz...) end isijulia() = isdefined(Main, :IJulia) && Main.IJulia.inited +isatom() = isdefined(Main, :Atom) && Atom.isconnected() istuple(::Tuple) = true istuple(::Any) = false @@ -498,4 +499,4 @@ xmin(plt::Plot) = minimum([minimum(d[:x]) for d in plt.seriesargs]) xmax(plt::Plot) = maximum([maximum(d[:x]) for d in plt.seriesargs]) "Extrema of x-values in plot" -Base.extrema(plt::Plot) = (xmin(plt), xmax(plt)) \ No newline at end of file +Base.extrema(plt::Plot) = (xmin(plt), xmax(plt))