Skip to content

Commit

Permalink
Add plotly shortcode support
Browse files Browse the repository at this point in the history
  • Loading branch information
hankhjliao committed Mar 12, 2024
1 parent b1e63a2 commit 3beceea
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions layouts/shortcodes/plotly.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ $json := .Get "json" }}
{{ $height := .Get "height" | default "200px" }}

{{ if not ($.Page.Scratch.Get "plotlyloaded") }}
{{ $.Page.Scratch.Set "plotlyloaded" 1 }}
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
{{ end }}

<div id="{{$json}}" class="plotly" style="height:{{$height}}"></div>

<script>
Plotly.d3.json({{$json}}, function(err, fig) {
Plotly.plot('{{$json}}', fig.data, fig.layout, {responsive: true});
});
</script>

0 comments on commit 3beceea

Please sign in to comment.