aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-08-31 00:26:17 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-08-31 00:26:17 +0200
commit1070b7b60308925b9c0f98075c354bb05b6f25ca (patch)
tree36449adc32da941e5213d93609be59e0560dbca6 /src
parent205fa3c6183d12a274d635810197044a6487ec3d (diff)
downloadnotes-1070b7b60308925b9c0f98075c354bb05b6f25ca.tar.gz
notes-1070b7b60308925b9c0f98075c354bb05b6f25ca.zip
web: add plotly example
Diffstat (limited to 'src')
-rw-r--r--src/SUMMARY.md1
-rw-r--r--src/web/README.md1
-rw-r--r--src/web/plotly.md16
-rw-r--r--src/web/src/plotly.html69
4 files changed, 87 insertions, 0 deletions
diff --git a/src/SUMMARY.md b/src/SUMMARY.md
index 2861038..ea680ea 100644
--- a/src/SUMMARY.md
+++ b/src/SUMMARY.md
@@ -98,6 +98,7 @@
- [html](./web/html.md)
- [css](./web/css.md)
- [chartjs](./web/chartjs.md)
+ - [plotly](./web/plotly.md)
- [Arch](./arch/README.md)
- [x86_64](./arch/x86_64.md)
diff --git a/src/web/README.md b/src/web/README.md
index acaa58d..0bbc856 100644
--- a/src/web/README.md
+++ b/src/web/README.md
@@ -3,3 +3,4 @@
- [html](./html.md)
- [css](./css.md)
- [chartjs](./chartjs.md)
+- [plotly](./plotly.md)
diff --git a/src/web/plotly.md b/src/web/plotly.md
new file mode 100644
index 0000000..31736b7
--- /dev/null
+++ b/src/web/plotly.md
@@ -0,0 +1,16 @@
+# Plotly js
+
+Visualization library for javascript based on `d3`.
+
+Official documentation is [here][plotly-js].
+
+## Line chart example
+The following is an example for a *line* chart which contains many options that
+I frequently use. It is bloated on purpose to document the options for myself.
+
+[Rendered html](src/plotly.html)
+```html
+{{#include src/plotly.html:3: }}
+```
+
+[plotly-js]: https://plotly.com/javascript/
diff --git a/src/web/src/plotly.html b/src/web/src/plotly.html
new file mode 100644
index 0000000..c665c63
--- /dev/null
+++ b/src/web/src/plotly.html
@@ -0,0 +1,69 @@
+<script src="https://cdn.plot.ly/plotly-2.35.0.min.js" charset="utf-8"></script>
+
+<div id="plot-1"></div>
+
+<script>
+ const commits = [ "b5a7c219", "72bb8889", "fa9e9079", "f5178ed1", "e830fa71" ]
+
+ const common_layout = {
+ xaxis: {
+ // Set range explicitly because of markers+lines mode used.
+ // https://stackoverflow.com/questions/46383368
+ range: [0, commits.length - 1],
+ gridcolor: "ligthgray",
+ rangeslider: {},
+ },
+ yaxis: {
+ title: "runtime in sec",
+ // Disable interactive y-axis zoom.
+ fixedrange: true,
+ gridcolor: "ligthgray",
+ },
+ legend: {
+ orientation: "h",
+ x: 0,
+ y: 1,
+ },
+ modebar: {
+ add: [ "hoverclosest", "hovercompare" ],
+ remove: [ "pan", "lasso", "select", "zoomin", "zoomout" ],
+ },
+ // Transparent plot + paper background.
+ plot_bgcolor: "rgba(0, 0, 0, 0)",
+ paper_bgcolor: "rgba(0, 0, 0, 0)",
+ }
+ const common_config = {
+ // Automatically resize plot when page resizes.
+ responsive: true,
+ // Dont display the plotly logo.
+ displaylogo: false,
+ }
+
+ const plot_1 = document.getElementById("plot-1")
+ const data_10 = {
+ x: commits,
+ y: [ 10.2, 11.4, 10.5, 11.0, 10.0 ],
+ name: "plot 10",
+ mode: "lines+markers",
+ }
+ const data_11 = {
+ x: commits,
+ y: [ 20.2, 21.4, 20.5, 21.0, 20.0 ],
+ name: "plot 11",
+ mode: "lines+markers",
+ }
+
+ Plotly.newPlot(plot_1, [data_10, data_11], {
+ ...common_layout,
+ title: "plot-1",
+ }, common_config)
+
+ plot_1.on("plotly_click", data => {
+ if (data.points.length == 1) {
+ // Change page to following url.
+ window.location = "https://github.com/johannst/notes/commit/" + data.points[0].x
+ } else {
+ console.log("ignore click event, multiple elements selected")
+ }
+ })
+</script>