Skip to content

Commit

Permalink
Add missing standards file
Browse files Browse the repository at this point in the history
  • Loading branch information
halleysfifthinc committed May 1, 2024
1 parent 6dba73d commit 4b76198
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docs/src/plots/standards.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using PlotlyBase
using PlotlyBase: _TRACE_TYPES

struct PlotForceHTML
p::Plot
end

const INCLUDE_PLOTLYJS = Ref("require-loaded")

# "require-loaded" here because the first peak-animation plot already loaded plotly
function Base.show(io, ::MIME"text/html", p::PlotForceHTML)
PlotlyBase.to_html(io, filter_template!(p.p; no_colorscales=true);
autoplay=false, full_html=false,
include_plotlyjs=INCLUDE_PLOTLYJS[], include_mathjax=missing)
end

# Default template in PlotlyBase includes templates for many different trace types,
# filtering unnecessary elements can save 4.8 KiB per plot
function filter_template!(p::Plot; no_colorscales=false)
template = deepcopy(p.layout.template)
tracetypes = unique!(map(x -> x.type, p.data))
rmtraces = setdiff(_TRACE_TYPES, tracetypes)
foreach(rmtraces) do trace
delete!(template.data, trace)
end

if no_colorscales
delete!(template.layout.fields, :colorscale)
end

p.layout.template = template
return p
end

0 comments on commit 4b76198

Please sign in to comment.