-
-
Notifications
You must be signed in to change notification settings - Fork 358
/
Copy pathinit.jl
151 lines (135 loc) · 4.63 KB
/
init.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using Scratch
using REPL
import Base64
"""
Reference to hold path of local plotly temp file. Initialized to `nothing`.
"""
const _plotly_local_file_path = Ref{Union{Nothing,String}}(nothing)
"""
Reference to hold cached plotly data URL. Initialized to `nothing`.
"""
const _plotly_data_url_cached = Ref{Union{Nothing,String}}(nothing)
_plotly_data_url() =
if _plotly_data_url_cached[] === nothing
_plotly_data_url_cached[] = "data:text/javascript;base64,$(Base64.base64encode(read(_plotly_local_file_path)))"
else
_plotly_data_url_cached[]
end
"""
use fixed version of Plotly instead of the latest one for stable dependency
"""
const _plotly_min_js_filename = "plotly-2.6.3.min.js"
"""
Whether to use local embedded or local dependencies instead of CDN.
"""
const _use_local_dependencies = Ref(false)
"""
Whether to use local plotly.js files instead of CDN.
"""
const _use_local_plotlyjs = Ref(false)
_plots_defaults() =
if isdefined(Main, :PLOTS_DEFAULTS)
copy(Dict{Symbol,Any}(Main.PLOTS_DEFAULTS))
else
Dict{Symbol,Any}()
end
function _plots_theme_defaults()
user_defaults = _plots_defaults()
theme(pop!(user_defaults, :theme, :default); user_defaults...)
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[]
end
function __init__()
_plots_theme_defaults()
_plots_plotly_defaults()
insert!(
Base.Multimedia.displays,
findlast(
x -> x isa Base.TextDisplay || x isa REPL.REPLDisplay,
Base.Multimedia.displays,
) + 1,
PlotsDisplay(),
)
i ->
begin
while PlotsDisplay() in Base.Multimedia.displays
popdisplay(PlotsDisplay())
end
insert!(
Base.Multimedia.displays,
findlast(x -> x isa REPL.REPLDisplay, Base.Multimedia.displays) + 1,
PlotsDisplay(),
)
end |> atreplinit
@static if !isdefined(Base, :get_extension) # COV_EXCL_LINE
@require FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" include(
normpath(@__DIR__, "..", "ext", "FileIOExt.jl"),
)
@require GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" include(
normpath(@__DIR__, "..", "ext", "GeometryBasicsExt.jl"),
)
@require IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" include(
normpath(@__DIR__, "..", "ext", "IJuliaExt.jl"),
)
@require ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254" include(
normpath(@__DIR__, "..", "ext", "ImageInTerminalExt.jl"),
)
@require Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" include(
normpath(@__DIR__, "..", "ext", "UnitfulExt.jl"),
)
end
_runtime_init(backend())
nothing
end
##################################################################
backend()
include(_path(backend_name()))
# COV_EXCL_START
@setup_workload begin
@debug backend_package_name()
n = length(_examples)
imports = sizehint!(Expr[], n)
examples = sizehint!(Expr[], 10n)
scratch_dir = mktempdir()
for i in setdiff(1:n, _backend_skips[backend_name()], _animation_examples)
_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
$(_examples[i].exprs)
$i == 1 || return # only for one example
fn = tempname(scratch_dir)
pl = current()
show(devnull, pl)
showable(MIME"image/png"(), pl) && savefig(pl, "$fn.png")
showable(MIME"application/pdf"(), pl) && savefig(pl, "$fn.pdf")
if showable(MIME"image/svg+xml"(), pl)
show(IOBuffer(), MIME"image/svg+xml"(), pl)
end
nothing
end
$func()
end,
)
end
withenv("GKSwstype" => "nul") do
@compile_workload begin
load_default_backend()
eval.(imports)
eval.(examples)
end
end
CURRENT_PLOT.nullableplot = nothing
end
# COV_EXCL_STOP