From 7a46e9b1aba47bf3d52b96476ac0951e9e10a512 Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Fri, 5 Jan 2024 11:35:11 +0100 Subject: [PATCH 1/3] Use data URL for local plotly asset --- src/backends/plotly.jl | 2 +- src/init.jl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 1c251c639..12f81ad60 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -1055,7 +1055,7 @@ html_body(plt::Plot{PlotlyBackend}) = plotly_html_body(plt) plotly_url() = if _use_local_dependencies[] - "file:///" * _plotly_local_file_path[] + _plotly_data_url() else "https://cdn.plot.ly/$_plotly_min_js_filename" end diff --git a/src/init.jl b/src/init.jl index aa58c2bb9..f2322c2ee 100644 --- a/src/init.jl +++ b/src/init.jl @@ -1,7 +1,14 @@ using 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) +_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 # 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.6.3.min.js" From f8ef3dc68e94c1c28c488134f02a6f1e4dc34dbc Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Mon, 15 Jan 2024 12:50:25 +0100 Subject: [PATCH 2/3] formatting --- src/init.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/init.jl b/src/init.jl index f2322c2ee..00ff5e43c 100644 --- a/src/init.jl +++ b/src/init.jl @@ -4,7 +4,8 @@ import Base64 const _plotly_local_file_path = Ref{Union{Nothing,String}}(nothing) const _plotly_data_url_cached = Ref{Union{Nothing,String}}(nothing) -_plotly_data_url() = if _plotly_data_url_cached[] === nothing +_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[] From 32468f98b32637704d34249190a94290fdb62efd Mon Sep 17 00:00:00 2001 From: Panagiotis Georgakopoulos Date: Fri, 2 Feb 2024 20:02:48 +0200 Subject: [PATCH 3/3] fix: reviewdog suggestion --- src/init.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.jl b/src/init.jl index 00ff5e43c..29ea9ae27 100644 --- a/src/init.jl +++ b/src/init.jl @@ -4,7 +4,7 @@ import Base64 const _plotly_local_file_path = Ref{Union{Nothing,String}}(nothing) const _plotly_data_url_cached = Ref{Union{Nothing,String}}(nothing) -_plotly_data_url() = +_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