handle ijulia with requires
and properly check if juno/ijulia are actually used and not just loaded
This commit is contained in:
parent
5e5f23b5e5
commit
c385035ac5
@ -245,8 +245,6 @@ function __init__()
|
|||||||
# for compatibility with Requires.jl:
|
# for compatibility with Requires.jl:
|
||||||
@init
|
@init
|
||||||
|
|
||||||
setup_ijulia()
|
|
||||||
|
|
||||||
if isdefined(Main, :PLOTS_DEFAULTS)
|
if isdefined(Main, :PLOTS_DEFAULTS)
|
||||||
for (k,v) in Main.PLOTS_DEFAULTS
|
for (k,v) in Main.PLOTS_DEFAULTS
|
||||||
default(k, v)
|
default(k, v)
|
||||||
|
|||||||
@ -250,71 +250,72 @@ end
|
|||||||
|
|
||||||
const _ijulia_output = String["text/html"]
|
const _ijulia_output = String["text/html"]
|
||||||
|
|
||||||
function setup_ijulia()
|
using Requires
|
||||||
# override IJulia inline display
|
@require IJulia begin
|
||||||
if isijulia()
|
if IJulia.inited
|
||||||
@eval begin
|
export set_ijulia_output
|
||||||
import IJulia
|
|
||||||
export set_ijulia_output
|
|
||||||
function set_ijulia_output(mimestr::AbstractString)
|
|
||||||
# info("Setting IJulia output format to $mimestr")
|
|
||||||
global _ijulia_output
|
|
||||||
_ijulia_output[1] = mimestr
|
|
||||||
end
|
|
||||||
function IJulia.display_dict(plt::Plot)
|
|
||||||
global _ijulia_output
|
|
||||||
Dict{String, String}(_ijulia_output[1] => sprint(show, _ijulia_output[1], plt))
|
|
||||||
end
|
|
||||||
|
|
||||||
# default text/plain passes to html... handles Interact issues
|
function set_ijulia_output(mimestr::AbstractString)
|
||||||
function Base.show(io::IO, m::MIME"text/plain", plt::Plot)
|
# info("Setting IJulia output format to $mimestr")
|
||||||
show(io, MIME("text/html"), plt)
|
global _ijulia_output
|
||||||
end
|
_ijulia_output[1] = mimestr
|
||||||
end
|
end
|
||||||
@eval set_ijulia_output("text/html")
|
function IJulia.display_dict(plt::Plot)
|
||||||
|
global _ijulia_output
|
||||||
|
Dict{String, String}(_ijulia_output[1] => sprint(show, _ijulia_output[1], plt))
|
||||||
|
end
|
||||||
|
|
||||||
|
# default text/plain passes to html... handles Interact issues
|
||||||
|
function Base.show(io::IO, m::MIME"text/plain", plt::Plot)
|
||||||
|
show(io, MIME("text/html"), plt)
|
||||||
|
end
|
||||||
|
|
||||||
|
set_ijulia_output("text/html")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# Atom PlotPane
|
# Atom PlotPane
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
using Requires
|
|
||||||
@require Juno begin
|
@require Juno begin
|
||||||
import Hiccup, Media
|
import Hiccup, Media
|
||||||
Media.media(Plot, Media.Plot)
|
|
||||||
|
|
||||||
function Juno.render(e::Juno.Editor, plt::Plot)
|
if Juno.isactive()
|
||||||
Juno.render(e, nothing)
|
Media.media(Plot, Media.Plot)
|
||||||
end
|
|
||||||
|
|
||||||
if get(ENV, "PLOTS_USE_ATOM_PLOTPANE", true) in (true, 1, "1", "true", "yes")
|
function Juno.render(e::Juno.Editor, plt::Plot)
|
||||||
function Juno.render(pane::Juno.PlotPane, plt::Plot)
|
Juno.render(e, nothing)
|
||||||
# temporarily overwrite size to be Atom.plotsize
|
|
||||||
sz = plt[:size]
|
|
||||||
jsize = Juno.plotsize()
|
|
||||||
jsize[1] == 0 && (jsize[1] = 400)
|
|
||||||
jsize[2] == 0 && (jsize[2] = 500)
|
|
||||||
|
|
||||||
plt[:size] = Juno.plotsize()
|
|
||||||
Juno.render(pane, HTML(stringmime(MIME("text/html"), plt)))
|
|
||||||
plt[:size] = sz
|
|
||||||
end
|
end
|
||||||
# special handling for PlotlyJS
|
|
||||||
function Juno.render(pane::Juno.PlotPane, plt::Plot{PlotlyJSBackend})
|
if get(ENV, "PLOTS_USE_ATOM_PLOTPANE", true) in (true, 1, "1", "true", "yes")
|
||||||
display(Plots.PlotsDisplay(), plt)
|
function Juno.render(pane::Juno.PlotPane, plt::Plot)
|
||||||
|
# temporarily overwrite size to be Atom.plotsize
|
||||||
|
sz = plt[:size]
|
||||||
|
jsize = Juno.plotsize()
|
||||||
|
jsize[1] == 0 && (jsize[1] = 400)
|
||||||
|
jsize[2] == 0 && (jsize[2] = 500)
|
||||||
|
|
||||||
|
plt[:size] = Juno.plotsize()
|
||||||
|
Juno.render(pane, HTML(stringmime(MIME("text/html"), plt)))
|
||||||
|
plt[:size] = sz
|
||||||
|
end
|
||||||
|
# special handling for PlotlyJS
|
||||||
|
function Juno.render(pane::Juno.PlotPane, plt::Plot{PlotlyJSBackend})
|
||||||
|
display(Plots.PlotsDisplay(), plt)
|
||||||
|
end
|
||||||
|
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, HTML(s))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
function Juno.render(pane::Juno.PlotPane, plt::Plot)
|
# special handling for plotly... use PlotsDisplay
|
||||||
|
function Juno.render(pane::Juno.PlotPane, plt::Plot{PlotlyBackend})
|
||||||
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. 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, HTML(s))
|
Juno.render(pane, 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, HTML(s))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user