@@ -3,16 +3,12 @@ using Scratch
33using REPL
44
55const plotly_local_file_path = Ref {Union{Nothing,String}} (nothing )
6- const BACKEND_PATH_GASTON = @path joinpath (@__DIR__ , " backends" , " gaston.jl" )
7- const BACKEND_PATH_HDF5 = @path joinpath (@__DIR__ , " backends" , " hdf5.jl" )
8- const BACKEND_PATH_INSPECTDR = @path joinpath (@__DIR__ , " backends" , " inspectdr.jl" )
9- const BACKEND_PATH_PLOTLYBASE = @path joinpath (@__DIR__ , " backends" , " plotlybase.jl" )
10- const BACKEND_PATH_PGFPLOTS =
11- @path joinpath (@__DIR__ , " backends" , " deprecated" , " pgfplots.jl" )
12- const BACKEND_PATH_PGFPLOTSX = @path joinpath (@__DIR__ , " backends" , " pgfplotsx.jl" )
13- const BACKEND_PATH_PLOTLYJS = @path joinpath (@__DIR__ , " backends" , " plotlyjs.jl" )
14- const BACKEND_PATH_PYPLOT = @path joinpath (@__DIR__ , " backends" , " pyplot.jl" )
15- const BACKEND_PATH_UNICODEPLOTS = @path joinpath (@__DIR__ , " backends" , " unicodeplots.jl" )
6+
7+ backend_path (sym) = @path joinpath (@__DIR__ , " backends" , " $sym .jl" )
8+
9+ # Use fixed version of Plotly instead of the latest one for stable dependency
10+ # Ref: https://github.com/JuliaPlots/Plots.jl/pull/2779
11+ const _plotly_min_js_filename = " plotly-2.6.3.min.js"
1612
1713_plots_defaults () =
1814 if isdefined (Main, :PLOTS_DEFAULTS )
@@ -64,44 +60,50 @@ function __init__()
6460 end ,
6561 )
6662
67- @require HDF5 = " f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" begin
68- include (BACKEND_PATH_HDF5)
63+ _plots_plotly_defaults ()
64+
65+ @require GR = " 28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" begin
66+ initialized (:gr ) || include (backend_path (:gr ))
6967 end
7068
71- @require InspectDR = " d0351b0e-4b05-5898-87b3-e2a8edfddd1d " begin
72- include (BACKEND_PATH_INSPECTDR )
69+ @require PyPlot = " d330b81b-6aea-500a-939a-2ce795aea3ee " begin
70+ initialized ( :pyplot ) || include (backend_path ( :pyplot ) )
7371 end
7472
7573 @require PGFPlots = " 3b7a836e-365b-5785-a47d-02c71176b4aa" begin
76- include (BACKEND_PATH_PGFPLOTS)
74+ initialized (:pgfplots ) || include (backend_path (:pgfplots ))
75+ end
76+
77+ @require PGFPlotsX = " 8314cec4-20b6-5062-9cdb-752b83310925" begin
78+ initialized (:pgfplotsx ) || include (backend_path (:pgfplotsx ))
7779 end
7880
7981 @require PlotlyBase = " a03496cd-edff-5a9b-9e67-9cda94a718b5" begin
8082 @require PlotlyKaleido = " f2990250-8cf9-495f-b13a-cce12b45703c" begin
81- include (BACKEND_PATH_PLOTLYBASE)
83+ initialized (:plotly ) || include (backend_path (:plotly ))
84+ initialized (:plotlybase ) || include (backend_path (:plotlybase ))
8285 end
8386 end
8487
85- @require PGFPlotsX = " 8314cec4-20b6-5062-9cdb-752b83310925" begin
86- include (BACKEND_PATH_PGFPLOTSX)
87- end
88-
8988 @require PlotlyJS = " f0f68f2c-4968-5e81-91da-67840de0976a" begin
90- include (BACKEND_PATH_PLOTLYJS)
89+ initialized (:plotly ) || include (backend_path (:plotly ))
90+ initialized (:plotlyjs ) || include (backend_path (:plotlyjs ))
9191 end
9292
93- _plots_plotly_defaults ()
93+ @require UnicodePlots = " b8865327-cd53-5732-bb35-84acbb429228" begin
94+ initialized (:unicodeplots ) || include (backend_path (:unicodeplots ))
95+ end
9496
95- @require PyPlot = " d330b81b-6aea-500a-939a-2ce795aea3ee " begin
96- include (BACKEND_PATH_PYPLOT )
97+ @require Gaston = " 4b11ee91-296f-5714-9832-002c20994614 " begin
98+ initialized ( :gaston ) || include (backend_path ( :gaston ) )
9799 end
98100
99- @require UnicodePlots = " b8865327-cd53-5732-bb35-84acbb429228 " begin
100- include (BACKEND_PATH_UNICODEPLOTS )
101+ @require InspectDR = " d0351b0e-4b05-5898-87b3-e2a8edfddd1d " begin
102+ initialized ( :inspectdr ) || include (backend_path ( :inspectdr ) )
101103 end
102104
103- @require Gaston = " 4b11ee91-296f-5714-9832-002c20994614 " begin
104- include (BACKEND_PATH_GASTON )
105+ @require HDF5 = " f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f " begin
106+ initialized ( :hdf5 ) || include (backend_path ( :hdf5 ) )
105107 end
106108
107109 @require IJulia = " 7073ff75-c697-5162-941a-fcdaad2a7d2a" begin
@@ -163,3 +165,46 @@ function __init__()
163165 @reexport using . UnitfulRecipes
164166 end
165167end
168+
169+ # #################################################################
170+ backend () # get from `Preferences` or env, and initialize backend
171+
172+ # needs to be split from `init` for precompilation, because `__init__` is ran after parsing
173+ @eval const $ (backend_package_name ()) = Main.$ (backend_package_name ())
174+
175+ include (backend_path (backend_name ()))
176+
177+ # COV_EXCL_START
178+ if get (ENV , " PLOTS_PRECOMPILE" , " true" ) == " true"
179+ @precompile_setup begin
180+ n = length (_examples)
181+ imports = sizehint! (Expr[], n)
182+ examples = sizehint! (Expr[], 10 n)
183+ for i in setdiff (1 : n, _backend_skips[backend_name ()], _animation_examples)
184+ _examples[i]. external && continue
185+ (imp = _examples[i]. imports) === nothing || push! (imports, imp)
186+ func = gensym (string (i))
187+ push! (examples, quote
188+ $ func () = begin # evaluate each example in a local scope
189+ $ (_examples[i]. exprs)
190+ if $ i == 1 # only for one example
191+ fn = tempname ()
192+ pl = current ()
193+ show (devnull , pl)
194+ Sys. iswindows () || savefig (pl, " $fn .png" )
195+ Sys. iswindows () || savefig (pl, " $fn .pdf" )
196+ end
197+ nothing
198+ end
199+ $ func ()
200+ end )
201+ end
202+ withenv (" GKSwstype" => " nul" ) do
203+ @precompile_all_calls begin
204+ eval .(imports)
205+ eval .(examples)
206+ end
207+ end
208+ end
209+ end
210+ # COV_EXCL_STOP
0 commit comments