Skip to content

Commit

Permalink
update artifacts, add way to inject code into html head
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday committed Jul 20, 2024
1 parent c34fc71 commit a2967cd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[plotly_artifacts]
git-tree-sha1 = "0482d05aeb45f0389a9f2ec9919f430d6dfd454d"
git-tree-sha1 = "cb3112c4d60b522ef0302c35516aee1a5b2eb711"

[[plotly_artifacts.download]]
sha256 = "a3b7b176230c3c49c8fb4866a845e133d0afe4f58b23b941f9b3059e907d913e"
url = "https://gist.github.com/joshday/c62001c14794e2f28c8f6ab6937b3e94/raw/0482d05aeb45f0389a9f2ec9919f430d6dfd454d.tar.gz"
sha256 = "44265cd24ac7acc3d2b21527d0326e2c131a1b4fe9266f5661b5ecb783aff4bb"
url = "https://gist.github.com/joshday/30654755d769aa794fb8f84bc36d882c/raw/cb3112c4d60b522ef0302c35516aee1a5b2eb711.tar.gz"
1 change: 1 addition & 0 deletions deps/artifacts.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Pkg
Pkg.activate(@__DIR__)
Pkg.instantiate()

using ArtifactUtils, JSON3

Expand Down
2 changes: 1 addition & 1 deletion docs/src/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ PlotlyLight.settings.layout::EasyConfig.Config # default `layout` for all plots
PlotlyLight.settings.config::EasyConfig.Config # default `config` for all plots
PlotlyLight.settings.reuse_preview::Bool # In the REPL, open plots in same page (true, the default) or different pages.
PlotlyLight.settings.style::Dict{String,String} # CSS styles for the plot <div>
PlotlyLight.settings.inject_head::Cobweb.Node # Code to inject at the bottom the <head>
```

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

9 changes: 7 additions & 2 deletions src/PlotlyLight.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ Base.@kwdef mutable struct Settings
config::Config = Config(responsive=true)
reuse_preview::Bool = true
style::Dict{String,String} = Dict("display" => "block", "border" => "none", "min-height" => "350px", "min-width" => "350px", "width" => "100%", "height" => "100%")
inject_head::Union{Nothing, Node} = nothing
end
settings::Settings = Settings()

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

mathjax_script = h.script(type="text/javascript", id="MathJax-script", async=true,
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.0.0/es5/latest?tex-mml-chtml.js")

#-----------------------------------------------------------------------------# Plot
mutable struct Plot
data::Vector{Config}
Expand Down Expand Up @@ -94,6 +98,7 @@ function html_page(o::Plot)
h.meta(name="description", content="PlotlyLight.jl"),
h.title("PlotlyLight.jl"),
h.style("html, body { padding: 0px; margin: 0px; } /* remove scrollbar in iframe */"),
isnothing(settings.inject_head) ? "" : settings.inject_head
),
h.body(html_div(o))
)
Expand All @@ -106,7 +111,7 @@ Base.show(io::IO, ::MIME"juliavscode/html", o::Plot) = show(io, MIME"text/html"(

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

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


#-----------------------------------------------------------------------------# preset
Expand Down

0 comments on commit a2967cd

Please sign in to comment.