Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Sep 27, 2022
1 parent 0b0eeac commit 854ea65
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 83 deletions.
108 changes: 27 additions & 81 deletions src/Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,46 +29,42 @@ 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

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
Expand Down Expand Up @@ -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")
Expand All @@ -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
2 changes: 2 additions & 0 deletions src/animation.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using FFMPEG

"Represents an animation object"
struct Animation
dir::String
Expand Down
4 changes: 4 additions & 0 deletions src/init.jl
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
7 changes: 5 additions & 2 deletions src/plotmeasures.jl
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
37 changes: 37 additions & 0 deletions src/precompilation.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 854ea65

Please sign in to comment.