better juno integration
This commit is contained in:
parent
f4f2f09d17
commit
d671ccd6ba
1
REQUIRE
1
REQUIRE
@ -11,3 +11,4 @@ Showoff
|
|||||||
StatsBase 0.14.0
|
StatsBase 0.14.0
|
||||||
JSON
|
JSON
|
||||||
NaNMath
|
NaNMath
|
||||||
|
Requires
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -278,48 +278,45 @@ end
|
|||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# Atom PlotPane
|
# Atom PlotPane
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
using Requires
|
||||||
|
@require Juno begin
|
||||||
|
import Hiccup, Media
|
||||||
|
Media.media(Plot, Media.Plot)
|
||||||
|
|
||||||
function setup_atom()
|
# default text/plain so it doesn't complain
|
||||||
if isatom()
|
function Base.show{B}(io::IO, ::MIME"text/plain", plt::Plot{B})
|
||||||
@eval import Atom, Media
|
print(io, "Plot{$B}()")
|
||||||
Media.media(Plot, Media.Plot)
|
end
|
||||||
|
|
||||||
# default text/plain so it doesn't complain
|
function Juno.render(e::Juno.Editor, plt::Plot)
|
||||||
function Base.show{B}(io::IO, ::MIME"text/plain", plt::Plot{B})
|
Juno.render(e, nothing)
|
||||||
print(io, "Plot{$B}()")
|
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 Juno.render(pane::Juno.PlotPane, plt::Plot)
|
||||||
|
# temporarily overwrite size to be Atom.plotsize
|
||||||
|
sz = plt[:size]
|
||||||
|
plt[:size] = Juno.plotsize()
|
||||||
|
Juno.render(pane, Hiccup.div(".fill", HTML(stringmime(MIME("text/html"), plt))))
|
||||||
|
plt[:size] = sz
|
||||||
end
|
end
|
||||||
|
# special handling for PlotlyJS
|
||||||
function Media.render(e::Atom.Editor, plt::Plot)
|
function Juno.render(pane::Juno.PlotPane, plt::Plot{PlotlyJSBackend})
|
||||||
Media.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)
|
|
||||||
# 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))))
|
|
||||||
plt[:size] = sz
|
|
||||||
end
|
|
||||||
# special handling for PlotlyJS
|
|
||||||
function Media.render(pane::Atom.PlotPane, plt::Plot{PlotlyJSBackend})
|
|
||||||
display(Plots.PlotsDisplay(), plt)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
#
|
|
||||||
function Media.render(pane::Atom.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)))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# special handling for plotly... use PlotsDisplay
|
|
||||||
function Media.render(pane::Atom.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."
|
end
|
||||||
Media.render(pane, Atom.div(Atom.HTML(s)))
|
else
|
||||||
|
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."
|
||||||
|
Juno.render(pane, Hiccup.div(HTML(s)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# special handling for plotly... use PlotsDisplay
|
||||||
|
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."
|
||||||
|
Juno.render(pane, Hiccup.div(HTML(s)))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user