Skip to content

Commit

Permalink
Merge pull request #106 from alyst/plotly_version_config
Browse files Browse the repository at this point in the history
Allow configuring plotly.js
  • Loading branch information
sglyon authored Dec 12, 2024
2 parents f8bc850 + f38ab60 commit d3da080
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ const _MATHJAX_CONFIG = """
if (window.MathJax) {MathJax.Hub.Config({SVG: {font: "STIX-Web"}});}
</script>"""

const PLOTLYJS_VERSION = "2.3.0"
const PLOTLYJS_VERSION = Ref("2.33.0")

const CDN_URL = "https://cdn.plot.ly/plotly-$(PLOTLYJS_VERSION).min.js"
plotly_version() = PLOTLYJS_VERSION[]
set_plotly_version(v) = PLOTLYJS_VERSION[] = v

cdn_url(; plotly_version = plotly_version(), ext = ".js") = "https://cdn.plot.ly/plotly-$plotly_version.min$ext"

function _requirejs_config()
function _requirejs_config(; plotly_version = PlotlyBase.plotly_version())
"""
$(_WINDOW_PLOTLY_CONFIG)
$(_MATHJAX_CONFIG)
Expand All @@ -26,7 +28,7 @@ function _requirejs_config()
require.undef("plotly");
requirejs.config({
paths: {
'plotly': ['$(rsplit(CDN_URL, '.', limit=2)[1])']
'plotly': ['$(cdn_url(; plotly_version = plotly_version, ext=""))']
}
});
require(['plotly'], function(Plotly) {
Expand Down Expand Up @@ -159,7 +161,7 @@ function to_html(
if !ismissing(include_plotlyjs)
including = lowercase(include_plotlyjs)
if including == "require"
load_plotlyjs = _requirejs_config()
load_plotlyjs = _requirejs_config(; plotly_version = plotly_version)
require_start = "require([\"plotly\"], function(Plotly) {"
require_end = "});"
elseif including == "require-loaded"
Expand Down Expand Up @@ -192,7 +194,7 @@ function to_html(
else # assume cdn
load_plotlyjs = """
$(_WINDOW_PLOTLY_CONFIG)
<script src="$(CDN_URL)"></script>
<script src="$(cdn_url())"></script>
"""
end
end
Expand Down

0 comments on commit d3da080

Please sign in to comment.