better juno integration

This commit is contained in:
Sebastian Pfitzner 2017-06-08 15:23:39 +02:00
parent f4f2f09d17
commit d671ccd6ba
3 changed files with 39 additions and 39 deletions

View File

@ -11,3 +11,4 @@ Showoff
StatsBase 0.14.0 StatsBase 0.14.0
JSON JSON
NaNMath NaNMath
Requires

View File

@ -242,8 +242,10 @@ end
const CURRENT_BACKEND = CurrentBackend(:none) const CURRENT_BACKEND = CurrentBackend(:none)
function __init__() function __init__()
# for compatibility with Requires.jl:
@init
setup_ijulia() setup_ijulia()
setup_atom()
if isdefined(Main, :PLOTS_DEFAULTS) if isdefined(Main, :PLOTS_DEFAULTS)
for (k,v) in Main.PLOTS_DEFAULTS for (k,v) in Main.PLOTS_DEFAULTS

View File

@ -278,10 +278,9 @@ end
# --------------------------------------------------------- # ---------------------------------------------------------
# Atom PlotPane # Atom PlotPane
# --------------------------------------------------------- # ---------------------------------------------------------
using Requires
function setup_atom() @require Juno begin
if isatom() import Hiccup, Media
@eval import Atom, Media
Media.media(Plot, Media.Plot) Media.media(Plot, Media.Plot)
# default text/plain so it doesn't complain # default text/plain so it doesn't complain
@ -289,37 +288,35 @@ function setup_atom()
print(io, "Plot{$B}()") print(io, "Plot{$B}()")
end end
function Media.render(e::Atom.Editor, plt::Plot) function Juno.render(e::Juno.Editor, plt::Plot)
Media.render(e, nothing) Juno.render(e, nothing)
end end
if get(ENV, "PLOTS_USE_ATOM_PLOTPANE", true) in (true, 1, "1", "true", "yes") if get(ENV, "PLOTS_USE_ATOM_PLOTPANE", true) in (true, 1, "1", "true", "yes")
# this is like "display"... sends an html div with the plot to the PlotPane # this is like "display"... sends an html div with the plot to the PlotPane
function Media.render(pane::Atom.PlotPane, plt::Plot) function Juno.render(pane::Juno.PlotPane, plt::Plot)
# temporarily overwrite size to be Atom.plotsize # temporarily overwrite size to be Atom.plotsize
sz = plt[:size] sz = plt[:size]
plt[:size] = Juno.plotsize() plt[:size] = Juno.plotsize()
Media.render(pane, Atom.div(".fill", Atom.HTML(stringmime(MIME("text/html"), plt)))) Juno.render(pane, Hiccup.div(".fill", HTML(stringmime(MIME("text/html"), plt))))
plt[:size] = sz plt[:size] = sz
end end
# special handling for PlotlyJS # special handling for PlotlyJS
function Media.render(pane::Atom.PlotPane, plt::Plot{PlotlyJSBackend}) function Juno.render(pane::Juno.PlotPane, plt::Plot{PlotlyJSBackend})
display(Plots.PlotsDisplay(), plt) display(Plots.PlotsDisplay(), plt)
end end
else else
# function Juno.render(pane::Juno.PlotPane, plt::Plot)
function Media.render(pane::Atom.PlotPane, plt::Plot)
display(Plots.PlotsDisplay(), plt) display(Plots.PlotsDisplay(), plt)
s = "PlotPane turned off. Unset ENV[\"PLOTS_USE_ATOM_PLOTPANE\"] and restart Julia to enable it." s = "PlotPane turned off. Unset ENV[\"PLOTS_USE_ATOM_PLOTPANE\"] and restart Julia to enable it."
Media.render(pane, Atom.div(Atom.HTML(s))) Juno.render(pane, Hiccup.div(HTML(s)))
end end
end end
# special handling for plotly... use PlotsDisplay # special handling for plotly... use PlotsDisplay
function Media.render(pane::Atom.PlotPane, plt::Plot{PlotlyBackend}) function Juno.render(pane::Juno.PlotPane, plt::Plot{PlotlyBackend})
display(Plots.PlotsDisplay(), plt) display(Plots.PlotsDisplay(), plt)
s = "PlotPane turned off. The plotly backend cannot render in the PlotPane due to javascript issues. Plotlyjs is similar to plotly and is compatible with the plot pane." s = "PlotPane turned off. The plotly backend cannot render in the PlotPane due to javascript issues. Plotlyjs is similar to plotly and is compatible with the plot pane."
Media.render(pane, Atom.div(Atom.HTML(s))) Juno.render(pane, Hiccup.div(HTML(s)))
end
end end
end end