Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.18.8"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
AssetRegistry = "bf4720bc-e11a-5d0c-854e-bdca1663c893"
Blink = "ad839575-38b3-5650-b840-f874b8c74a25"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
JSExpr = "97c1335a-c9c5-57fe-bc5d-ec35cebe8660"
Expand Down
3 changes: 2 additions & 1 deletion src/PlotlyJS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import PlotlyBase:
react, react!, add_trace!

using WebIO
using AssetRegistry
using JSExpr
using JSExpr: @var, @new
using Blink
Expand All @@ -28,7 +29,7 @@ const _pkg_root = dirname(dirname(@__FILE__))
const _js_path = joinpath(artifact"plotly-artifacts", "plotly.min.js")
const _js_cdn_path = "https://cdn.plot.ly/plotly-latest.min.js"
const _mathjax_cdn_path =
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_SVG"
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS-MML_SVG"

struct PlotlyJSDisplay <: AbstractDisplay end

Expand Down
48 changes: 48 additions & 0 deletions src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,57 @@ function display_blink(p::SyncPlot)
"height" => floor(Int, plotSize[2] * sizeBuffer)
)
p.window = Blink.Window(windowOptions)

# check if the inlcude_mathjax option is set and add the respective header
# the syntax is chosen identical to the python version: Layout(include_mathjax = <mathjax_path>)
mathjax = mathjax_path(p)
mathjax == "" || try
# if file is local then add the mathjax path to the asset registry
# Currently `WebIO` does not support registering of directories, PR is pending ...
# otherwise we could do: `mathjax = WebIO.dep2url(mathjax)`
# so we have to use `AssetRegistry` directly
if WebIO.islocal(mathjax)
mathjax = joinpath(AssetRegistry.register(dirname(mathjax)), basename(mathjax))
end
# add the mathjax file to the <head> section
Blink.loadjs!(p.window, mathjax)
catch
@warn """Could not verify mathjax path!

Consider installing IJulia.
Currently, however, TexFonts need to be installed manually... :-(
"""
end

Blink.body!(p.window, p.scope)
end

# convert "cdn" and "local" to the respective online or local mathjax-paths
function mathjax_path(mj::AbstractString)
if mj == "cdn"
return _mathjax_cdn_path
elseif mj == "local"
mj = abspath(first(DEPOT_PATH), "conda", "3", "Lib", "site-packages",
"notebook", "static", "components", "MathJax", "MathJax.js")
return isfile(mj) ? (mj * "?config=TeX-AMS-MML_HTMLorMML-full") : ""
end
return mj
end

# retrieve the mathjax option from the SyncPlot
function mathjax_path(p::SyncPlot)
local mathjax
try
# Layout(include_mathjax = ...) results in a layout field :include with a dictionary entry :mathjax
mathjax = p.plot.layout[:include][:mathjax]
catch
# if called from Plot's plotlyjs() backend, the extra_kwargs are passed literally, i.e `:include_mathjax`
mathjax = get(p.plot.layout.fields, :include_mathjax, "")
end
# convert "cdn" and "local" to the respective online or local mathjax paths
return mathjax_path(mathjax)
end

function Base.close(p::SyncPlot)
if p.window !== nothing && Blink.active(p.window)
close(p.window)
Expand Down