Skip to content

Commit 6c489df

Browse files
committed
bring templates online
1 parent 4daea7b commit 6c489df

File tree

5 files changed

+79
-32
lines changed

5 files changed

+79
-32
lines changed

Artifacts.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
["plotly.min.js"]
2-
git-tree-sha1 = "8e9de38e6b7f40c85bf6924e89cf0181f1cb2bbb"
2+
git-tree-sha1 = "21a0e611f2cc26091222ee1056ba1f3ec8d4499e"
33

44
[["plotly.min.js".download]]
5-
sha256 = "9feeeddc191cbac16815c2c36c3fbd6e41989395f146c4a185bc8c2be7a7ca12"
6-
url = "https://github.com/joshday/PlotlyLight.jl/releases/download/artifacts_2022-02-14/PlotlyLightArtifacts.tar.gz"
5+
sha256 = "28785dd92d8707fe29c06d4c59e563a0832445b3563d034e133926771e95d120"
6+
url = "https://github.com/joshday/PlotlyLight.jl/releases/download/artifacts_2022-02-15/plotly.tar.gz"
7+
8+
[plotly_templates]
9+
git-tree-sha1 = "e88ffaa4a1b30cf2efa853b79b4d7bbb3f1beec7"
10+
11+
[[plotly_templates.download]]
12+
sha256 = "3d39fd24df0c9aa27b2bed0f8597fd9993860f9b23b95142f14e72c955587dab"
13+
url = "https://github.com/joshday/PlotlyLight.jl/releases/download/artifacts_2022-02-15/templates.tar.gz"

deps/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
22
ArtifactUtils = "8b73e784-e7d8-4ea5-973d-377fed4e3bce"
33
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
4+
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
45
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
56
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
67
PlotlyLight = "ca7969ec-10b3-423e-8d99-40f33abb42bf"

deps/artifact_bundle.jl

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,53 @@
11
using Pkg
22
Pkg.activate(@__DIR__)
33

4-
using Downloads, Tar, ArtifactUtils, Artifacts, Dates
4+
using Downloads, Tar, ArtifactUtils, Artifacts, Dates, Pkg
55

6-
v = "2.8.3"
6+
#-----------------------------------------------------------------------------# Start from scratch
7+
for file in readdir(@__DIR__)
8+
if endswith(file, ".tar") || endswith(file, ".gz")
9+
rm(joinpath(@__DIR__, file), force=true)
10+
end
11+
end
12+
13+
#-----------------------------------------------------------------------------# Templates
14+
# Need to install plotly.py in order to get themes because they are generated in python
15+
# ENV["CONDA_JL_HOME"] = "/opt/homebrew/Caskroom/miniconda/base/envs/conda_jl"
16+
# Pkg.build("Conda")
17+
# using Conda
18+
# Conda.add("plotly")
19+
templates = "/opt/homebrew/Caskroom/miniconda/base/envs/conda_jl/pkgs/plotly-5.1.0-pyhd3eb1b0_0/site-packages/plotly/package_data/templates"
20+
21+
run(`gzip $(Tar.create(templates, joinpath(@__DIR__, "templates.tar")))`)
722

8-
#-----------------------------------------------------------------------------# build artifacts
9-
file = "plotly-$v.min.js"
10-
url = "https://cdn.plot.ly/$file"
11-
dir = mkpath(joinpath(@__DIR__, "artifacts"))
12-
tar = joinpath(@__DIR__, "PlotlyLightArtifacts.tar")
13-
rm(tar, force=true)
14-
rm(tar * ".gz", force=true)
15-
artifacts_today = "artifacts_$(today())"
1623

24+
#-----------------------------------------------------------------------------# Plotly.js
25+
url = "https://cdn.plot.ly/plotly-2.8.3.min.js"
26+
dir = mkpath(joinpath(@__DIR__, "plotlyjs"))
1727
Downloads.download(url, joinpath(dir, "plotly.min.js"))
1828

19-
run(`gzip $(Tar.create(dir, tar))`)
29+
run(`gzip $(Tar.create(dir, joinpath(@__DIR__, "plotly.tar")))`)
2030

2131
#-----------------------------------------------------------------------------# upload
2232
try
23-
run(`gh release create $artifacts_today $tar.gz --title $artifacts_today --notes ""`)
24-
catch
25-
@warn "Error (probably the release already exists). Attempting to clobber artifact."
26-
run(`gh release upload $artifacts_today $tar.gz --clobber`)
33+
artifacts_today = "artifacts_$(today())"
34+
35+
run(`gh release create $artifacts_today templates.tar.gz plotly.tar.gz --title $artifacts_today --notes ""`)
36+
37+
@info "Sleeping so artifacts are ready on GitHub..."
38+
sleep(10)
39+
add_artifact!(
40+
"Artifacts.toml",
41+
"plotly.min.js",
42+
"https://github.com/joshday/PlotlyLight.jl/releases/download/$artifacts_today/plotly.tar.gz",
43+
force=true,
44+
)
45+
add_artifact!(
46+
"Artifacts.toml",
47+
"plotly_templates",
48+
"https://github.com/joshday/PlotlyLight.jl/releases/download/$artifacts_today/templates.tar.gz",
49+
force=true,
50+
)
51+
catch ex
52+
@error "Error (probably the release already exists): $ex"
2753
end
28-
29-
#-----------------------------------------------------------------------------# update Artifacts.toml
30-
@info "Sleeping so artifact is ready on GitHub..."
31-
sleep(10)
32-
33-
add_artifact!(
34-
"Artifacts.toml",
35-
"plotly.min.js",
36-
"https://github.com/joshday/PlotlyLight.jl/releases/download/$artifacts_today/PlotlyLightArtifacts.tar.gz",
37-
force=true,
38-
)

src/PlotlyLight.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ using Artifacts
88

99
export Plot, Config
1010

11-
plotlyjs = joinpath(artifact"plotly.min.js", "plotly.min.js")
11+
const plotlyjs = joinpath(artifact"plotly.min.js", "plotly.min.js")
12+
const templates_dir = artifact"plotly_templates"
13+
const templates = map(x -> replace(x, ".json" => ""), readdir(templates_dir))
14+
1215

1316
#-----------------------------------------------------------------------------# defaults
1417
module Defaults
1518
using EasyConfig: Config
19+
using JSON3
20+
using ..PlotlyLight: templates_dir
1621
export src, class, style, parent_class, parent_style, config, layout
1722

1823
src = Ref(:cdn)
@@ -34,7 +39,7 @@ function reset!()
3439
end
3540
end
3641

37-
#-----------------------------------------------------------------------------# src
42+
#-----------------------------------------------------------------------------# src!
3843
src_opts = [:cdn, :local, :standalone, :none]
3944
"""
4045
src!(x::Symbol) # `x` must be one of: $src_opts
@@ -46,6 +51,13 @@ src_opts = [:cdn, :local, :standalone, :none]
4651
"""
4752
src!(x::Symbol) = (x in src_opts || error("src must be one of: $src_opts"); Defaults.src[] = x)
4853

54+
#-----------------------------------------------------------------------------# template!
55+
function template!(t = :plotly_white)
56+
string(t) in templates || error("$t not found. Options are one of: $(join(templates, ", ")).")
57+
tmp = open(io -> JSON3.read(io, Config), joinpath(templates_dir, string(t) * ".json"))
58+
Defaults.layout[].template = tmp
59+
end
60+
4961
#-----------------------------------------------------------------------------# Plot
5062
"""
5163
Plot(data, layout, config; id, js)

test/runtests.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ using PlotlyLight
22
using JSON3
33
using Test
44

5-
@testset "sanity check" begin
5+
#-----------------------------------------------------------------------------# simple checks
6+
@testset "simple checks" begin
67
@test Plot(Config(x = 1:10)) isa Plot
78
@test Plot(Config(x = 1:10), Config(title="Title")) isa Plot
89
@test Plot(Config(x = 1:10), Config(title="Title"), Config(displaylogo=true)) isa Plot
910
end
11+
#-----------------------------------------------------------------------------# src
1012
@testset "src" begin
1113
p = Plot(Config(y=1:10))
1214

@@ -22,3 +24,13 @@ end
2224
PlotlyLight.src!(:local)
2325
@test occursin("artifacts", repr("text/html", p))
2426
end
27+
#-----------------------------------------------------------------------------# templates
28+
@testset "templates" begin
29+
PlotlyLight.template!(:plotly_dark)
30+
p = Plot(Config(y=1:10))
31+
s = repr("text/html", p)
32+
PlotlyLight.template!(:plotly_white)
33+
p2 = Plot(Config(y=1:10))
34+
s2 = repr("text/html", p)
35+
@test s != s2
36+
end

0 commit comments

Comments
 (0)