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
JSON
NaNMath
Requires

View File

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

View File

@ -278,10 +278,9 @@ end
# ---------------------------------------------------------
# Atom PlotPane
# ---------------------------------------------------------
function setup_atom()
if isatom()
@eval import Atom, Media
using Requires
@require Juno begin
import Hiccup, Media
Media.media(Plot, Media.Plot)
# default text/plain so it doesn't complain
@ -289,37 +288,35 @@ function setup_atom()
print(io, "Plot{$B}()")
end
function Media.render(e::Atom.Editor, plt::Plot)
Media.render(e, nothing)
function Juno.render(e::Juno.Editor, plt::Plot)
Juno.render(e, nothing)
end
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
function Media.render(pane::Atom.PlotPane, plt::Plot)
function Juno.render(pane::Juno.PlotPane, plt::Plot)
# temporarily overwrite size to be Atom.plotsize
sz = plt[:size]
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
end
# 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)
end
else
#
function Media.render(pane::Atom.PlotPane, plt::Plot)
function Juno.render(pane::Juno.PlotPane, plt::Plot)
display(Plots.PlotsDisplay(), plt)
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
# 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)
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)))
end
Juno.render(pane, Hiccup.div(HTML(s)))
end
end