diff --git a/src/Plots.jl b/src/Plots.jl index 1d45c32fc..c17a62707 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -12,6 +12,7 @@ using Pkg const _plots_project = Pkg.Types.read_project(normpath(@__DIR__, "..", "Project.toml")) const _current_plots_version = _plots_project.version const _plots_compats = _plots_project.compat + function _check_compat(sim::Module) sim_str = string(sim) haskey(_plots_compats, sim_str) || return nothing @@ -28,16 +29,12 @@ function _check_compat(sim::Module) end end -using Dates, Printf, Statistics, Base64, LinearAlgebra, Random, Unzip -using RelocatableFolders -using SnoopPrecompile +using Dates, Printf, Statistics, Base64, LinearAlgebra, Random using SparseArrays using Base.Meta using Requires using Reexport -using Scratch -using FFMPEG -using REPL +using Unzip @reexport using RecipesBase @reexport using PlotThemes @reexport using PlotUtils @@ -45,29 +42,29 @@ using REPL import RecipesBase: plot, plot!, animate, is_explicit, grid import RecipesPipeline import RecipesPipeline: - SliceIt, - DefaultsDict, - Formatted, + inverse_scale_func, + datetimeformatter, AbstractSurface, - Surface, - Volume, - is3d, - is_surface, - needs_3d_axes, group_as_matrix, # for StatsPlots + dateformatter, + timeformatter, + needs_3d_axes, + DefaultsDict, + scale_func, + is_surface, + Formatted, reset_kw!, + SliceIt, + Surface, pop_kw!, - scale_func, - inverse_scale_func, - dateformatter, - datetimeformatter, - timeformatter + Volume, + is3d import UnicodeFun import StatsBase import Downloads import Showoff -import JSON import JLFzf +import JSON #! format: off export @@ -162,36 +159,19 @@ ignorenan_extrema(x::AbstractArray{<:AbstractFloat}) = NaNMath.extrema(x) ignorenan_extrema(x) = Base.extrema(x) # --------------------------------------------------------- - -# to cater for block matrices, Base.transpose is recursive. -# This makes it impossible to create row vectors of String and Symbol with the transpose operator. -# This solves this issue, internally in Plots at least. - -# commented out on the insistence of the METADATA maintainers - -#Base.transpose(x::Symbol) = x -#Base.transpose(x::String) = x - -# --------------------------------------------------------- - import Measures - include("plotmeasures.jl") - using .PlotMeasures import .PlotMeasures: Length, AbsoluteLength, Measure, width, height # --------------------------------------------------------- -# Use fixed version of Plotly instead of the latest one for stable dependency -# Ref: https://github.com/JuliaPlots/Plots.jl/pull/2779 -const _plotly_min_js_filename = "plotly-2.6.3.min.js" - include("types.jl") include("utils.jl") include("colorbars.jl") include("axes.jl") include("args.jl") include("components.jl") +include("legend.jl") include("consts.jl") include("themes.jl") include("plot.jl") @@ -206,54 +186,20 @@ include("backends.jl") include("output.jl") include("ijulia.jl") include("fileio.jl") + +# Use fixed version of Plotly instead of the latest one for stable dependency +# Ref: https://github.com/JuliaPlots/Plots.jl/pull/2779 +const _plotly_min_js_filename = "plotly-2.6.3.min.js" +const CURRENT_BACKEND = CurrentBackend(:none) +const PLOTS_SEED = 1234 + include("init.jl") -include("legend.jl") include("backends/plotly.jl") -include("backends/gr.jl") include("backends/web.jl") +include("backends/gr.jl") include("shorthands.jl") - -# --------------------------------------------------------- - -const CURRENT_BACKEND = CurrentBackend(:none) -const PLOTS_SEED = 1234 - -if get(ENV, "PLOTS_PRECOMPILE", "true") == "true" - @precompile_setup begin - n = length(_examples) - imports = sizehint!(Expr[], n) - examples = sizehint!(Expr[], 10n) - for i in setdiff(1:n, _backend_skips[:gr]) - _examples[i].external && continue - (imp = _examples[i].imports) === nothing || push!(imports, imp) - func = gensym(string(i)) - push!(examples, quote - $func() = begin # evaluate each example in a local scope - # @show $i # debug - $(_examples[i].exprs) - if $i == 1 # only for one example - fn = tempname() - pl = current() - gui(pl) - savefig(pl, "$fn.png") - savefig(pl, "$fn.pdf") - end - nothing - end - $func() - end) - end - withenv("GKSwstype" => "nul") do - @precompile_all_calls begin - eval.(imports) - gr() - eval.(examples) - # eventually eval for another backend ... - end - end - end -end +include("precompilation.jl") end diff --git a/src/animation.jl b/src/animation.jl index 324a4f3b0..44cc99804 100644 --- a/src/animation.jl +++ b/src/animation.jl @@ -1,3 +1,5 @@ +using FFMPEG + "Represents an animation object" struct Animation dir::String diff --git a/src/init.jl b/src/init.jl index a4aba6772..26baddf6e 100644 --- a/src/init.jl +++ b/src/init.jl @@ -1,3 +1,7 @@ +using RelocatableFolders +using Scratch +using REPL + const plotly_local_file_path = Ref{Union{Nothing,String}}(nothing) const BACKEND_PATH_GASTON = @path joinpath(@__DIR__, "backends", "gaston.jl") const BACKEND_PATH_HDF5 = @path joinpath(@__DIR__, "backends", "hdf5.jl") diff --git a/src/plotmeasures.jl b/src/plotmeasures.jl index af7bb16ec..7c9278493 100644 --- a/src/plotmeasures.jl +++ b/src/plotmeasures.jl @@ -1,7 +1,9 @@ module PlotMeasures -import Measures -import Measures: + +import ..Measures +import ..Measures: Length, AbsoluteLength, Measure, BoundingBox, mm, cm, inch, pt, width, height, w, h + const BBox = Measures.Absolute2DBox export BBox, BoundingBox, mm, cm, inch, px, pct, pt, w, h @@ -15,4 +17,5 @@ Base.:*(m1::AbsoluteLength, m2::Length{:pct}) = AbsoluteLength(m1.value * m2.val Base.:*(m1::Length{:pct}, m2::AbsoluteLength) = AbsoluteLength(m2.value * m1.value) Base.:/(m1::AbsoluteLength, m2::Length{:pct}) = AbsoluteLength(m1.value / m2.value) Base.:/(m1::Length{:pct}, m2::AbsoluteLength) = AbsoluteLength(m2.value / m1.value) + end diff --git a/src/precompilation.jl b/src/precompilation.jl new file mode 100644 index 000000000..1bba37c73 --- /dev/null +++ b/src/precompilation.jl @@ -0,0 +1,37 @@ +using SnoopPrecompile + +if get(ENV, "PLOTS_PRECOMPILE", "true") == "true" + @precompile_setup begin + n = length(_examples) + imports = sizehint!(Expr[], n) + examples = sizehint!(Expr[], 10n) + for i in setdiff(1:n, _backend_skips[:gr]) + _examples[i].external && continue + (imp = _examples[i].imports) === nothing || push!(imports, imp) + func = gensym(string(i)) + push!(examples, quote + $func() = begin # evaluate each example in a local scope + # @show $i # debug + $(_examples[i].exprs) + if $i == 1 # only for one example + fn = tempname() + pl = current() + gui(pl) + savefig(pl, "$fn.png") + savefig(pl, "$fn.pdf") + end + nothing + end + $func() + end) + end + withenv("GKSwstype" => "nul") do + @precompile_all_calls begin + eval.(imports) + gr() + eval.(examples) + # eventually eval for another backend ... + end + end + end +end