fix IJulia

This commit is contained in:
SimonDanisch 2018-10-05 12:27:09 +02:00
parent ee4fc2803b
commit 7e0960e7a0
2 changed files with 19 additions and 17 deletions

View File

@ -21,7 +21,11 @@ using Requires
if isfile(joinpath(@__DIR__, "..", "deps", "deps.jl"))
include(joinpath(@__DIR__, "..", "deps", "deps.jl"))
else
error("Plots not build, please run Pkg.build(\"Plots\")")
# This is a bit dirty, but I don't really see why anyone should be forced
# to build Plots, while it will just include exactly the below line
# as long as now ENV["PLOTS_HOST_DEPENDENCY_LOCAL"] = "true" is given
# If the above env is set + plotly_local_file_path = "", it will warn in the __init__ functtion
const plotly_local_file_path = ""
end
export

View File

@ -862,26 +862,24 @@ plotly_series_json(plt::Plot) = JSON.json(plotly_series(plt))
const ijulia_initialized = Ref(false)
function html_head(plt::Plot{PlotlyBackend})
if isfile(plotly_local_file_path) && isijulia() && !ijulia_initialized[]
js_code = read(plotly_local_file_path, String)
# borrowed from https://github.com/plotly/plotly.py/blob/2594076e29584ede2d09f2aa40a8a195b3f3fc66/plotly/offline/offline.py#L64-L71 c/o @spencerlyon2
js_script = """
<script type='text/javascript'>
define('plotly', function(require, exports, module) {
$(js_code)
});
require(['plotly'], function(Plotly) {
window.Plotly = Plotly;
local_file = ("file://" * plotly_local_file_path)
plotly = use_local_dependencies[] ? local_file : plotly_remote_file_path
if isijulia() && !ijulia_initialized[]
# using requirejs seems to be key to load a js depency in IJulia!
# https://requirejs.org/docs/start.html
# https://github.com/JuliaLang/IJulia.jl/issues/345
display("text/html", """
<script type="text/javascript">
requirejs([$(repr(plotly))], function(p) {
window.Plotly = p
});
</script>
"""
# if we're in IJulia call setupnotebook to load js and css
display("text/html", js_script)
""")
ijulia_initialized[] = true
end
local_file = ("file://" * plotly_local_file_path)
jsfilename = use_local_dependencies[] ? local_file : plotly_remote_file_path
"<script src=\"$jsfilename\"></script>"
# IJulia just needs one initialization
isijulia() && return ""
return "<script src=$(repr(plotly))></script>"
end
function html_body(plt::Plot{PlotlyBackend}, style = nothing)