diff --git a/src/init.jl b/src/init.jl index 59320a0d98..719b6dd952 100644 --- a/src/init.jl +++ b/src/init.jl @@ -21,13 +21,30 @@ _plots_defaults() = Dict{Symbol,Any}() end -function __init__() +function _plots_theme_defaults() user_defaults = _plots_defaults() if haskey(user_defaults, :theme) theme(pop!(user_defaults, :theme); user_defaults...) else default(; user_defaults...) end +end + +function _plots_plotly_defaults() + if get(ENV, "PLOTS_HOST_DEPENDENCY_LOCAL", "false") == "true" + global plotly_local_file_path[] = + joinpath(@get_scratch!("plotly"), _plotly_min_js_filename) + isfile(plotly_local_file_path[]) || Downloads.download( + "https://cdn.plot.ly/$(_plotly_min_js_filename)", + plotly_local_file_path[], + ) + use_local_plotlyjs[] = true + end + use_local_dependencies[] = use_local_plotlyjs[] +end + +function __init__() + _plots_theme_defaults() insert!( Base.Multimedia.displays, @@ -77,6 +94,8 @@ function __init__() include(BACKEND_PATH_PLOTLYJS) end + _plots_plotly_defaults() + @require PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee" begin include(BACKEND_PATH_PYPLOT) end @@ -96,19 +115,6 @@ function __init__() end end - if get(ENV, "PLOTS_HOST_DEPENDENCY_LOCAL", "false") == "true" - global plotly_local_file_path[] = - joinpath(@get_scratch!("plotly"), _plotly_min_js_filename) - isfile(plotly_local_file_path[]) || Downloads.download( - "https://cdn.plot.ly/$(_plotly_min_js_filename)", - plotly_local_file_path[], - ) - - use_local_plotlyjs[] = true - end - - use_local_dependencies[] = use_local_plotlyjs[] - @require ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254" begin if get(ENV, "PLOTS_IMAGE_IN_TERMINAL", "false") == "true" && ImageInTerminal.ENCODER_BACKEND[] == :Sixel diff --git a/test/runtests.jl b/test/runtests.jl index 9f0b3dab04..9f79927691 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,3 +1,4 @@ +import Unitful: m, s, cm, DimensionError import Plots: PLOTS_SEED, Plot, with import GeometryBasics import ImageMagick diff --git a/test/test_defaults.jl b/test/test_defaults.jl index bd7cbc8cba..d96f821526 100644 --- a/test/test_defaults.jl +++ b/test/test_defaults.jl @@ -1,8 +1,5 @@ -using Plots, Test -using Plots.Colors - const PLOTS_DEFAULTS = Dict(:theme => :wong2, :fontfamily => :palantino) -Plots.__init__() +Plots._plots_theme_defaults() @testset "Loading theme" begin pl = plot(1:5) @@ -11,7 +8,7 @@ Plots.__init__() end empty!(PLOTS_DEFAULTS) -Plots.__init__() +Plots._plots_theme_defaults() @testset "default" begin default(fillrange = 0) diff --git a/test/test_misc.jl b/test/test_misc.jl index 19ed05f91b..878d9801b7 100644 --- a/test/test_misc.jl +++ b/test/test_misc.jl @@ -11,7 +11,7 @@ end @test Plots.plotly_local_file_path[] === nothing temp = Plots.use_local_dependencies[] withenv("PLOTS_HOST_DEPENDENCY_LOCAL" => true) do - Plots.__init__() + Plots._plots_plotly_defaults() @test Plots.plotly_local_file_path[] isa String @test isfile(Plots.plotly_local_file_path[]) @test Plots.use_local_dependencies[] = true diff --git a/test/test_unitful.jl b/test/test_unitful.jl index a9e1fa2e9b..a57c26dea5 100644 --- a/test/test_unitful.jl +++ b/test/test_unitful.jl @@ -1,4 +1,3 @@ -using Unitful: m, s, cm, DimensionError # Some helper functions to access the subplot labels and the series inside each test plot xguide(pl, idx = length(pl.subplots)) = pl.subplots[idx].attr[:xaxis].plotattributes[:guide]