From 4ec6c292911c0df9db92c0e2d7db6858552d7cdd Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Tue, 30 Sep 2025 14:02:06 +0200 Subject: [PATCH 1/7] add fons code --- PlotsBase/src/plotly.jl | 73 ++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 49 deletions(-) diff --git a/PlotsBase/src/plotly.jl b/PlotsBase/src/plotly.jl index 6b4a232f3..2c0fcf327 100644 --- a/PlotsBase/src/plotly.jl +++ b/PlotsBase/src/plotly.jl @@ -1224,36 +1224,26 @@ plotly_series_json(plt::Plot) = JSON.json(plotly_series(plt), 4) html_head(plt::Plot{PlotlyBackend}) = plotly_html_head(plt) html_body(plt::Plot{PlotlyBackend}) = plotly_html_body(plt) -plotly_url() = -if PlotsBase._use_local_dependencies[] +function plotly_url() + if PlotsBase._use_local_dependencies[] "file:///$(PlotsBase._plotly_local_file_path[])" else "https://cdn.plot.ly/$(PlotsBase._plotly_min_js_filename)" end +end -function plotly_html_head(plt::Plot) - plotly = plotly_url() - +function mathjax_url(plt::Plot) include_mathjax = get(plt[:extra_plot_kwargs], :include_mathjax, "") - - mathjax_file = if include_mathjax != "cdn" + mathjax_version = get(plt[:extra_plot_kwargs], :include_mathjax, "2.7.7") + if include_mathjax != "cdn" "file://" * include_mathjax else - "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML" - end - - mathjax_head = if isempty(include_mathjax) - "" - else - "\n\t\t" - end - - return if PlotsBase.isijulia() - mathjax_head - else - "$mathjax_head" + "https://cdnjs.cloudflare.com/ajax/libs/mathjax/$mathjax_version/MathJax.js?config=TeX-MML-AM_CHTML" end end +function plotly_html_head(plt::Plot) + "" +end function plotly_html_body(plt, style = nothing) if style ≡ nothing @@ -1261,39 +1251,24 @@ function plotly_html_body(plt, style = nothing) style = "width:$(w)px;height:$(h)px;" end - requirejs_prefix = requirejs_suffix = "" - if PlotsBase.isijulia() - # require.js adds .js automatically - plotly_no_ext = plotly_url() |> splitext |> first - - requirejs_prefix = """ - requirejs.config({ - paths: { - plotly: '$(plotly_no_ext)' - } - }); - require(['plotly'], function (Plotly) { - """ - requirejs_suffix = "});" - end - unique_tag = "id_$(replace(string(UUIDs.uuid4()), '-' => '_'))" return """
- """ end From 3dd33d587029a35e59f069208d136db6bb2c454f Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Tue, 30 Sep 2025 14:05:47 +0200 Subject: [PATCH 2/7] format --- PlotsBase/src/plotly.jl | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/PlotsBase/src/plotly.jl b/PlotsBase/src/plotly.jl index 2c0fcf327..040ab131d 100644 --- a/PlotsBase/src/plotly.jl +++ b/PlotsBase/src/plotly.jl @@ -1225,24 +1225,24 @@ html_head(plt::Plot{PlotlyBackend}) = plotly_html_head(plt) html_body(plt::Plot{PlotlyBackend}) = plotly_html_body(plt) function plotly_url() - if PlotsBase._use_local_dependencies[] - "file:///$(PlotsBase._plotly_local_file_path[])" -else - "https://cdn.plot.ly/$(PlotsBase._plotly_min_js_filename)" -end + return if PlotsBase._use_local_dependencies[] + "file:///$(PlotsBase._plotly_local_file_path[])" + else + "https://cdn.plot.ly/$(PlotsBase._plotly_min_js_filename)" + end end function mathjax_url(plt::Plot) include_mathjax = get(plt[:extra_plot_kwargs], :include_mathjax, "") mathjax_version = get(plt[:extra_plot_kwargs], :include_mathjax, "2.7.7") - if include_mathjax != "cdn" + return if include_mathjax != "cdn" "file://" * include_mathjax else "https://cdnjs.cloudflare.com/ajax/libs/mathjax/$mathjax_version/MathJax.js?config=TeX-MML-AM_CHTML" end end function plotly_html_head(plt::Plot) - "" + return "" end function plotly_html_body(plt, style = nothing) @@ -1254,23 +1254,23 @@ function plotly_html_body(plt, style = nothing) unique_tag = "id_$(replace(string(UUIDs.uuid4()), '-' => '_'))" return """ -
- - - - - - """ +
+ + + + + + """ end js_body( From a79080fbf36e63572cdf209bec2d14066bb9a8dd Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Tue, 30 Sep 2025 14:06:30 +0200 Subject: [PATCH 3/7] fix mathjax version --- PlotsBase/src/plotly.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PlotsBase/src/plotly.jl b/PlotsBase/src/plotly.jl index 040ab131d..04edd4326 100644 --- a/PlotsBase/src/plotly.jl +++ b/PlotsBase/src/plotly.jl @@ -1234,7 +1234,7 @@ end function mathjax_url(plt::Plot) include_mathjax = get(plt[:extra_plot_kwargs], :include_mathjax, "") - mathjax_version = get(plt[:extra_plot_kwargs], :include_mathjax, "2.7.7") + mathjax_version = get(plt[:extra_plot_kwargs], :mathjax_version, "2.7.7") return if include_mathjax != "cdn" "file://" * include_mathjax else From 2e6c21f3b09428e21d36da45966ad87a9d21a989 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Tue, 30 Sep 2025 14:24:11 +0200 Subject: [PATCH 4/7] adapt local source according to https://github.com/JuliaPlots/Plots.jl/pull/4863 --- PlotsBase/src/init.jl | 11 +++++++++-- PlotsBase/src/plotly.jl | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/PlotsBase/src/init.jl b/PlotsBase/src/init.jl index 04f12116b..123c8a006 100644 --- a/PlotsBase/src/init.jl +++ b/PlotsBase/src/init.jl @@ -1,13 +1,20 @@ using Scratch: @get_scratch! using REPL +import Base64 const _plotly_local_file_path = Ref{Union{Nothing, String}}(nothing) +const _plotly_data_url_cached = Ref{Union{Nothing,String}}(nothing) +function _plotly_data_url() + if _plotly_data_url_cached[] === nothing + _plotly_data_url_cached[] = "data:text/javascript;base64,$(Base64.base64encode(read(_plotly_local_file_path)))" + else + _plotly_data_url_cached[] + end +end # use fixed version of Plotly instead of the latest one for stable dependency # see github.com/JuliaPlots/Plots.jl/pull/2779 const _plotly_min_js_filename = "plotly-2.3.0.min.js" # must match https://github.com/JuliaPlots/PlotlyJS.jl/blob/master/deps/plotly_cdn_version.jl -const _requirejs_version = v"2.3.7" - const _use_local_dependencies = Ref(false) const _use_local_plotlyjs = Ref(false) diff --git a/PlotsBase/src/plotly.jl b/PlotsBase/src/plotly.jl index 04edd4326..828c23ebe 100644 --- a/PlotsBase/src/plotly.jl +++ b/PlotsBase/src/plotly.jl @@ -1226,7 +1226,7 @@ html_body(plt::Plot{PlotlyBackend}) = plotly_html_body(plt) function plotly_url() return if PlotsBase._use_local_dependencies[] - "file:///$(PlotsBase._plotly_local_file_path[])" + PlotsBase._plotly_data_url() else "https://cdn.plot.ly/$(PlotsBase._plotly_min_js_filename)" end From 9946d1466bd4fb59693ddc61ead8777cdf4f4e8f Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Tue, 30 Sep 2025 14:26:17 +0200 Subject: [PATCH 5/7] format --- PlotsBase/src/init.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PlotsBase/src/init.jl b/PlotsBase/src/init.jl index 123c8a006..d03d88365 100644 --- a/PlotsBase/src/init.jl +++ b/PlotsBase/src/init.jl @@ -3,9 +3,9 @@ using REPL import Base64 const _plotly_local_file_path = Ref{Union{Nothing, String}}(nothing) -const _plotly_data_url_cached = Ref{Union{Nothing,String}}(nothing) +const _plotly_data_url_cached = Ref{Union{Nothing, String}}(nothing) function _plotly_data_url() - if _plotly_data_url_cached[] === nothing + return if _plotly_data_url_cached[] === nothing _plotly_data_url_cached[] = "data:text/javascript;base64,$(Base64.base64encode(read(_plotly_local_file_path)))" else _plotly_data_url_cached[] From 0d590443b62bd1c787a064e0208018adbee1155d Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Sun, 5 Oct 2025 18:36:49 +0200 Subject: [PATCH 6/7] fix mathjax --- PlotsBase/src/plotly.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PlotsBase/src/plotly.jl b/PlotsBase/src/plotly.jl index 828c23ebe..7621d1222 100644 --- a/PlotsBase/src/plotly.jl +++ b/PlotsBase/src/plotly.jl @@ -1228,17 +1228,17 @@ function plotly_url() return if PlotsBase._use_local_dependencies[] PlotsBase._plotly_data_url() else - "https://cdn.plot.ly/$(PlotsBase._plotly_min_js_filename)" + "https://cdn.jsdelivr.net/npm/plotly.js-dist-min@3.1.0/plotly.min.js" end end function mathjax_url(plt::Plot) include_mathjax = get(plt[:extra_plot_kwargs], :include_mathjax, "") - mathjax_version = get(plt[:extra_plot_kwargs], :mathjax_version, "2.7.7") + mathjax_version = get(plt[:extra_plot_kwargs], :mathjax_version, "3.2.2") return if include_mathjax != "cdn" "file://" * include_mathjax else - "https://cdnjs.cloudflare.com/ajax/libs/mathjax/$mathjax_version/MathJax.js?config=TeX-MML-AM_CHTML" + "https://cdn.jsdelivr.net/npm/mathjax@$mathjax_version/es5/tex-svg-full.js" end end function plotly_html_head(plt::Plot) @@ -1256,8 +1256,8 @@ function plotly_html_body(plt, style = nothing) return """
- - + +