Skip to content

Commit 26e3c8e

Browse files
george-gcalzyang2000
authored andcommitted
Added support for plotly js (alshedivat#3097)
Only now I realized that the [previous support](https://alshedivat.github.io/al-folio/blog/2021/distill/#interactive-plots) for [plotly](https://plotly.com/) was enabled by exporting an HTML from python code. This adds support for [plotly.js](https://plotly.com/javascript/). --------- Signed-off-by: George Araújo <[email protected]>
1 parent ba65ffd commit 26e3c8e

File tree

7 files changed

+237
-0
lines changed

7 files changed

+237
-0
lines changed

_config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,12 @@ third_party_libraries:
548548
url:
549549
js: "https://cdn.jsdelivr.net/npm/photoswipe@{{version}}/dist/photoswipe-lightbox.esm.min.js"
550550
version: "5.4.4"
551+
plotly:
552+
integrity:
553+
js: "sha256-oy6Be7Eh6eiQFs5M7oXuPxxm9qbJXEtTpfSI93dW16Q="
554+
url:
555+
js: "https://cdn.jsdelivr.net/npm/plotly.js@{{version}}/dist/plotly.min.js"
556+
version: "3.0.1"
551557
polyfill:
552558
url:
553559
js: "https://cdnjs.cloudflare.com/polyfill/v{{version}}/polyfill.min.js?features=es6"

_includes/distill_scripts.liquid

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@
8181
<script defer src="{{ '/assets/js/echarts-setup.js' | relative_url | bust_file_cache }}" type="text/javascript"></script>
8282
{% endif %}
8383

84+
{% if page.chart and page.chart.plotly %}
85+
<!-- Plotly -->
86+
<script
87+
defer
88+
src="{{ site.third_party_libraries.plotly.url.js }}"
89+
integrity="{{ site.third_party_libraries.plotly.integrity.js }}"
90+
crossorigin="anonymous"
91+
></script>
92+
<script defer src="{{ '/assets/js/plotly-setup.js' | relative_url | bust_file_cache }}" type="text/javascript"></script>
93+
{% endif %}
94+
8495
{% if page.chart and page.chart.vega_lite %}
8596
<!-- Vega -->
8697
<script

_includes/scripts.liquid

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@
9898
<script defer src="{{ '/assets/js/echarts-setup.js' | relative_url | bust_file_cache }}" type="text/javascript"></script>
9999
{% endif %}
100100

101+
{% if page.chart and page.chart.plotly %}
102+
<!-- Plotly -->
103+
<script
104+
defer
105+
src="{{ site.third_party_libraries.plotly.url.js }}"
106+
integrity="{{ site.third_party_libraries.plotly.integrity.js }}"
107+
crossorigin="anonymous"
108+
></script>
109+
<script defer src="{{ '/assets/js/plotly-setup.js' | relative_url | bust_file_cache }}" type="text/javascript"></script>
110+
{% endif %}
111+
101112
{% if page.chart and page.chart.vega_lite %}
102113
<!-- Vega -->
103114
<script

_posts/2025-03-26-plotly.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
layout: post
3+
title: a post with plotly.js
4+
date: 2025-03-26 14:24:00
5+
description: this is what included plotly.js code could look like
6+
tags: formatting charts
7+
categories: sample-posts
8+
chart:
9+
plotly: true
10+
---
11+
12+
This is an example post with some [plotly](https://plotly.com/javascript/) code.
13+
14+
````markdown
15+
```plotly
16+
{
17+
"data": [
18+
{
19+
"x": [1, 2, 3, 4],
20+
"y": [10, 15, 13, 17],
21+
"type": "scatter"
22+
},
23+
{
24+
"x": [1, 2, 3, 4],
25+
"y": [16, 5, 11, 9],
26+
"type": "scatter"
27+
}
28+
]
29+
}
30+
```
31+
````
32+
33+
Which generates:
34+
35+
```plotly
36+
{
37+
"data": [
38+
{
39+
"x": [1, 2, 3, 4],
40+
"y": [10, 15, 13, 17],
41+
"type": "scatter"
42+
},
43+
{
44+
"x": [1, 2, 3, 4],
45+
"y": [16, 5, 11, 9],
46+
"type": "scatter"
47+
}
48+
]
49+
}
50+
```
51+
52+
Also another example chart.
53+
54+
````markdown
55+
```plotly
56+
{
57+
"data": [
58+
{
59+
"x": [1, 2, 3, 4],
60+
"y": [10, 15, 13, 17],
61+
"mode": "markers"
62+
},
63+
{
64+
"x": [2, 3, 4, 5],
65+
"y": [16, 5, 11, 9],
66+
"mode": "lines"
67+
},
68+
{
69+
"x": [1, 2, 3, 4],
70+
"y": [12, 9, 15, 12],
71+
"mode": "lines+markers"
72+
}
73+
],
74+
"layout": {
75+
"title": {
76+
"text": "Line and Scatter Plot"
77+
}
78+
}
79+
}
80+
```
81+
````
82+
83+
This is how it looks like:
84+
85+
```plotly
86+
{
87+
"data": [
88+
{
89+
"x": [1, 2, 3, 4],
90+
"y": [10, 15, 13, 17],
91+
"mode": "markers"
92+
},
93+
{
94+
"x": [2, 3, 4, 5],
95+
"y": [16, 5, 11, 9],
96+
"mode": "lines"
97+
},
98+
{
99+
"x": [1, 2, 3, 4],
100+
"y": [12, 9, 15, 12],
101+
"mode": "lines+markers"
102+
}
103+
],
104+
"layout": {
105+
"title": {
106+
"text": "Line and Scatter Plot"
107+
}
108+
}
109+
}
110+
```

assets/js/copy_code.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ codeBlocks.forEach(function (codeBlock) {
88
codeBlock.querySelector("code:not(.language-echarts)") &&
99
codeBlock.querySelector("code:not(.language-geojson)") &&
1010
codeBlock.querySelector("code:not(.language-mermaid)") &&
11+
codeBlock.querySelector("code:not(.language-plotly)") &&
1112
codeBlock.querySelector("code:not(.language-vega_lite)")
1213
) {
1314
// create copy button

assets/js/plotly-setup.js

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)