Skip to content

Commit

Permalink
Use data URL for local plotly asset (#4863)
Browse files Browse the repository at this point in the history
* Use data URL for local plotly asset

* formatting

* fix: reviewdog suggestion

---------

Co-authored-by: Panagiotis Georgakopoulos <panagiotis.georgakopoulos@juliacomputing.com>
  • Loading branch information
fonsp and pankgeorg authored Feb 5, 2024
1 parent fcf2e74 commit 40281d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/backends/plotly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/init.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
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"
Expand Down

0 comments on commit 40281d0

Please sign in to comment.