refactor: extract the scalar plot building

This commit is contained in:
Jeremy Wall 2024-03-10 21:11:32 -04:00
parent 75264dc095
commit 2f6b9b6c58

View File

@ -449,6 +449,9 @@ export class GraphPlot extends HTMLElement {
};
}
/**
* @param {any} triple
*/
buildSeriesPlot(triple) {
const labels = /** @type {Map<String, String>} */(triple[0]);
for (var label in labels) {
@ -483,6 +486,32 @@ export class GraphPlot extends HTMLElement {
return trace;
}
/**
* @param {any} triple
*/
buildScalarPlot(triple) {
const labels = /** @type {Map<String,String>} */(triple[0]);
for (var label in labels) {
var show = this.#filteredLabelSets[label];
if (show && !show.includes(labels[label])) {
return null;
}
}
const meta = /** @type {PlotMeta} */(triple[1]);
const series = triple[2];
const trace = /** @type GraphTrace */({
type: "bar",
x: [],
y: [],
yhoverformat: meta["d3_tick_format"],
});
var name = this.formatName(meta, labels);
if (name) { trace.name = name; }
trace.y.push(series.value);
trace.x.push(trace.name);
return trace;
}
/**
* Update the graph with new data.
*
@ -534,27 +563,11 @@ export class GraphPlot extends HTMLElement {
} else if (subplot.Scalar) {
// https://plotly.com/javascript/reference/bar/
loopScalar: for (const triple of subplot.Scalar) {
const labels = triple[0];
for (var label in labels) {
var show = this.#filteredLabelSets[label];
if (show && !show.includes(labels[label])) {
continue loopScalar;
}
}
const meta = triple[1];
const series = triple[2];
const trace = /** @type GraphTrace */({
type: "bar",
x: [],
y: [],
yhoverformat: meta["d3_tick_format"],
});
var name = this.formatName(meta, labels);
if (name) { trace.name = name; }
trace.y.push(series.value);
trace.x.push(trace.name);
const trace = this.buildScalarPlot(triple);
if (trace) {
traces.push(trace);
}
}
} else if (subplot.Stream) {
// TODO(jwall): It would be nice if scroll behavior would handle replots better.
// TODO(jwall): It's possible that this should actually be a separate custom