diff --git a/Artifacts.toml b/Artifacts.toml new file mode 100644 index 000000000..bd3da5966 --- /dev/null +++ b/Artifacts.toml @@ -0,0 +1,6 @@ +[plotly-dist] +git-tree-sha1 = "3039420613779f4cd3620456d5c7f0849e419e3d" + + [[plotly-dist.download]] + sha256 = "20c27644d7791d01058cc3a61c1cac351e313931994d464dc1f7796703d32312" + url = "https://github.com/plotly/plotly.js/archive/refs/tags/v2.6.3.tar.gz" diff --git a/Project.toml b/Project.toml index d682b7d18..51e118193 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ author = ["Tom Breloff (@tbreloff)"] version = "1.39.0-dev" [deps] +Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" Contour = "d38c429a-6771-53c6-b99e-75d170b6e991" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -30,7 +31,6 @@ RecipesPipeline = "01d81517-befc-4cb6-b9ec-a95719d0359c" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00" Requires = "ae029012-a4dd-5104-9daa-d747884805df" -Scratch = "6c6a2e73-6563-6170-7368-637461726353" Showoff = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" @@ -75,7 +75,7 @@ PGFPlotsX = "1" PlotThemes = "2, 3" PlotUtils = "1" PlotlyBase = "0.7 - 0.8" -PlotlyJS = "0.18" +PlotlyJS = "0.18.12" PlotlyKaleido = "1" PrecompileTools = "1" PyPlot = "2" @@ -85,7 +85,6 @@ RecipesPipeline = "0.6.10" Reexport = "0.2, 1" RelocatableFolders = "0.3, 1" Requires = "1" -Scratch = "1" Showoff = "0.3.1, 1" Statistics = "1" StatsBase = "0.33, 0.34" diff --git a/ext/IJuliaExt.jl b/ext/IJuliaExt.jl index 5322c155b..0317de7f5 100644 --- a/ext/IJuliaExt.jl +++ b/ext/IJuliaExt.jl @@ -8,9 +8,7 @@ const IJulia = function _init_ijulia_plotting() # IJulia is more stable with local file - Plots._use_local_plotlyjs[] = - Plots._plotly_local_file_path[] === nothing ? false : - isfile(Plots._plotly_local_file_path[]) + Plots._use_local_plotlyjs[] = true ENV["MPLBACKEND"] = "Agg" end 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/backends/web.jl b/src/backends/web.jl index cfa7e454c..7e912dc64 100644 --- a/src/backends/web.jl +++ b/src/backends/web.jl @@ -45,8 +45,7 @@ function standalone_html_window(plt::AbstractPlot) old = _use_local_dependencies[] # save state to restore afterwards # if we open a browser ourself, we can host local files, so # when we have a local plotly downloaded this is the way to go! - _use_local_dependencies[] = - _plotly_local_file_path[] === nothing ? false : isfile(_plotly_local_file_path[]) + _use_local_dependencies[] = true filename = write_temp_html(plt) open_browser_window(filename) # restore for other backends diff --git a/src/init.jl b/src/init.jl index b962a843f..80b5ad1b4 100644 --- a/src/init.jl +++ b/src/init.jl @@ -1,13 +1,26 @@ -using Scratch using REPL +import Base64 +using Artifacts -const _plotly_local_file_path = Ref{Union{Nothing,String}}(nothing) +# Local uses artifacts now. To update this, also update Artifacts.toml. +# using ArtifactUtils +# add_artifact!("Artifacts.toml", "plotly-dist", "https://github.com/plotly/plotly.js/archive/refs/tags/v2.6.3.tar.gz") +# # update with your desired version +const _plotly_version = "2.6.3" +const _plotly_local_file_path = joinpath(artifact("plotly-dist"), "plotly.js-2.6.3", "dist", "plotly.min.js") # 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" const _use_local_dependencies = Ref(false) const _use_local_plotlyjs = Ref(false) +const _plotly_data_url_cached = Ref{Union{Nothing,String}}(nothing) + +_plotly_data_url() = if isnothing(_plotly_data_url_cached[]) + _plotly_data_url_cached[] = "data:text/javascript;base64,$(Base64.base64encode(read(_plotly_local_file_path)))" +else + _plotly_data_url_cached[] +end _plots_defaults() = if isdefined(Main, :PLOTS_DEFAULTS) @@ -23,10 +36,6 @@ end function _plots_plotly_defaults() if bool_env("PLOTS_HOST_DEPENDENCY_LOCAL", "false") - _plotly_local_file_path[] = - fn = joinpath(@get_scratch!("plotly"), _plotly_min_js_filename) - isfile(fn) || - Downloads.download("https://cdn.plot.ly/$(_plotly_min_js_filename)", fn) _use_local_plotlyjs[] = true end _use_local_dependencies[] = _use_local_plotlyjs[] diff --git a/test/test_misc.jl b/test/test_misc.jl index 172aee38c..9a7a9edd7 100644 --- a/test/test_misc.jl +++ b/test/test_misc.jl @@ -7,15 +7,12 @@ end @testset "Plotly standalone" begin - @test Plots._plotly_local_file_path[] ≡ nothing temp = Plots._use_local_dependencies[] withenv("PLOTS_HOST_DEPENDENCY_LOCAL" => true) do Plots._plots_plotly_defaults() - @test Plots._plotly_local_file_path[] isa String - @test isfile(Plots._plotly_local_file_path[]) + @test isfile(Plots._plotly_local_file_path) @test Plots._use_local_dependencies[] = true end - Plots._plotly_local_file_path[] = nothing Plots._use_local_dependencies[] = temp end