From 0cf2c537aef504c6e6818835be76daa6367befce Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Sat, 17 Feb 2024 10:22:09 -0500 Subject: [PATCH] feat: Allow you to name the axis for each subplot You can force them to share axis with this. --- src/query.rs | 1 + static/lib.js | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/query.rs b/src/query.rs index f41844f..ee9bba2 100644 --- a/src/query.rs +++ b/src/query.rs @@ -120,6 +120,7 @@ pub struct PlotMeta { name_prefix: Option, name_suffix: Option, name_label: Option, + named_axis: Option, d3_tick_format: Option, } diff --git a/static/lib.js b/static/lib.js index 692d597..7bb274f 100644 --- a/static/lib.js +++ b/static/lib.js @@ -137,12 +137,14 @@ class TimeseriesGraph extends HTMLElement { for (var subplot_idx in data) { const subplot = data[subplot_idx]; const subplotCount = Number(subplot_idx) + 1; - const yaxis = "y" + subplotCount + const default_yaxis = "y" + subplotCount if (subplot.Series) { // https://plotly.com/javascript/reference/scatter/ for (const triple of subplot.Series) { const labels = triple[0]; const meta = triple[1]; + const yaxis = meta["named_axis"] || default_yaxis; + // https://plotly.com/javascript/reference/layout/yaxis/ layout["yaxis" + subplotCount] = { anchor: yaxis, tickformat: meta["d3_tick_format"] || this.#d3TickFormat @@ -153,6 +155,8 @@ class TimeseriesGraph extends HTMLElement { mode: "lines+text", x: [], y: [], + // We always share the x axis for timeseries graphs. + xaxis: "x", yaxis: yaxis, yhoverformat: meta["d3_tick_format"], }; @@ -201,7 +205,6 @@ class TimeseriesGraph extends HTMLElement { } } } - console.debug("traces: ", traces); // https://plotly.com/javascript/plotlyjs-function-reference/#plotlyreact Plotly.react(this.getTargetNode(), traces, layout, config); }