Skip to content

Commit a2967cd

Browse files
committed
update artifacts, add way to inject code into html head
1 parent c34fc71 commit a2967cd

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

Artifacts.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[plotly_artifacts]
2-
git-tree-sha1 = "0482d05aeb45f0389a9f2ec9919f430d6dfd454d"
2+
git-tree-sha1 = "cb3112c4d60b522ef0302c35516aee1a5b2eb711"
33

44
[[plotly_artifacts.download]]
5-
sha256 = "a3b7b176230c3c49c8fb4866a845e133d0afe4f58b23b941f9b3059e907d913e"
6-
url = "https://gist.github.com/joshday/c62001c14794e2f28c8f6ab6937b3e94/raw/0482d05aeb45f0389a9f2ec9919f430d6dfd454d.tar.gz"
5+
sha256 = "44265cd24ac7acc3d2b21527d0326e2c131a1b4fe9266f5661b5ecb783aff4bb"
6+
url = "https://gist.github.com/joshday/30654755d769aa794fb8f84bc36d882c/raw/cb3112c4d60b522ef0302c35516aee1a5b2eb711.tar.gz"

deps/artifacts.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Pkg
22
Pkg.activate(@__DIR__)
3+
Pkg.instantiate()
34

45
using ArtifactUtils, JSON3
56

docs/src/settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PlotlyLight.settings.layout::EasyConfig.Config # default `layout` for all plots
99
PlotlyLight.settings.config::EasyConfig.Config # default `config` for all plots
1010
PlotlyLight.settings.reuse_preview::Bool # In the REPL, open plots in same page (true, the default) or different pages.
1111
PlotlyLight.settings.style::Dict{String,String} # CSS styles for the plot <div>
12+
PlotlyLight.settings.inject_head::Cobweb.Node # Code to inject at the bottom the <head>
1213
```
1314

1415
Check out e.g. `PlotlyLight.Settings().src` to examine default values.
15-

src/PlotlyLight.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ Base.@kwdef mutable struct Settings
3434
config::Config = Config(responsive=true)
3535
reuse_preview::Bool = true
3636
style::Dict{String,String} = Dict("display" => "block", "border" => "none", "min-height" => "350px", "min-width" => "350px", "width" => "100%", "height" => "100%")
37+
inject_head::Union{Nothing, Node} = nothing
3738
end
3839
settings::Settings = Settings()
3940

40-
#-----------------------------------------------------------------------------# utils
41+
#-----------------------------------------------------------------------------# utils/other
4142
fix_matrix(x::Config) = Config(k => fix_matrix(v) for (k,v) in pairs(x))
4243
fix_matrix(x) = x
4344
fix_matrix(x::AbstractMatrix) = eachrow(x)
@@ -46,6 +47,9 @@ attributes(t::Symbol) = plotly.schema.traces[t].attributes
4647
check_attribute(trace, attr::Symbol) = haskey(attributes(Symbol(trace)), attr) || @warn("`$trace` does not have attribute `$attr`.")
4748
check_attributes(trace; kw...) = foreach(k -> check_attribute(Symbol(trace), k), keys(kw))
4849

50+
mathjax_script = h.script(type="text/javascript", id="MathJax-script", async=true,
51+
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.0.0/es5/latest?tex-mml-chtml.js")
52+
4953
#-----------------------------------------------------------------------------# Plot
5054
mutable struct Plot
5155
data::Vector{Config}
@@ -94,6 +98,7 @@ function html_page(o::Plot)
9498
h.meta(name="description", content="PlotlyLight.jl"),
9599
h.title("PlotlyLight.jl"),
96100
h.style("html, body { padding: 0px; margin: 0px; } /* remove scrollbar in iframe */"),
101+
isnothing(settings.inject_head) ? "" : settings.inject_head
97102
),
98103
h.body(html_div(o))
99104
)
@@ -106,7 +111,7 @@ Base.show(io::IO, ::MIME"juliavscode/html", o::Plot) = show(io, MIME"text/html"(
106111

107112
Base.display(::REPL.REPLDisplay, o::Plot) = Cobweb.preview(h.html(h.body(o, style="margin: 0px;")), reuse=settings.reuse_preview)
108113

109-
mathjax = h.script(type="text/javascript", async=true, src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js")
114+
mathjax_script = h.script(type="text/javascript", async=true, src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js")
110115

111116

112117
#-----------------------------------------------------------------------------# preset

0 commit comments

Comments
 (0)