working on atom integration
This commit is contained in:
parent
c203bfe5ad
commit
4d864d8cad
@ -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 = """
|
||||
<script type="text/javascript">
|
||||
require=requirejs=define=undefined;
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
$(_js_code)
|
||||
</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", """
|
||||
<script type="text/javascript">
|
||||
require=requirejs=define=undefined;
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
$(open(readall, _js_path, "r"))
|
||||
</script>
|
||||
""")
|
||||
display("text/html", _js_script)
|
||||
# display("text/html", "<p>Plotly javascript loaded.</p>")
|
||||
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})
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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))
|
||||
Base.extrema(plt::Plot) = (xmin(plt), xmax(plt))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user