mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-06 22:14:55 +00:00
BREAKING CHANGE Module paths moved to `github.com/HugoBlox/kit` with new names: - core `blox-tailwind` → `blox` - analytics → `analytics` - netlify → `integrations/netlify` - slides (reveal) → `slides` Update go.mod, module.yaml/params, scripts, tests, and v0.11 migration guide accordingly.
36 lines
1.0 KiB
HTML
36 lines
1.0 KiB
HTML
{{/*
|
|
Docs: https://docs.hugoblox.com/content/writing-markdown-latex/#charts
|
|
|
|
Parameters
|
|
----------
|
|
data :
|
|
Plotly JSON file name (without ".json" extension, since it is appended automatically to the name).
|
|
Expects the JSON file to be placed in the page folder.(.Get "data")
|
|
*/}}
|
|
|
|
{{ $json := printf "./%s.json" (.Get "data") }}
|
|
{{ $id := delimit (shuffle (seq 1 9)) "" }}
|
|
<div id="chart-{{$id}}" class="chart"></div>
|
|
<script>
|
|
(function() {
|
|
async function fetchChartJSON() {
|
|
console.debug('Hugo Blox fetching chart JSON...')
|
|
const response = await fetch('{{$json}}');
|
|
return await response.json();
|
|
}
|
|
|
|
let a = setInterval( function() {
|
|
if ( typeof window.Plotly === 'undefined' ) {
|
|
console.debug('Plotly not loaded yet...')
|
|
return;
|
|
}
|
|
clearInterval( a );
|
|
|
|
fetchChartJSON().then(chart => {
|
|
console.debug('Plotting chart...')
|
|
window.Plotly.newPlot('chart-{{$id}}', chart.data, chart.layout, {responsive: true});
|
|
});
|
|
}, 500 );
|
|
})();
|
|
</script>
|