Files
Aura/crates/aura-cli/tests/chart_viewer_xmode.mjs
T
Brummel 08a272c73d fix(trace-charts): drop glitchy custom wheel/pan, restore uPlot default mouse control
The hand-rolled wheel-zoom + drag-pan (wheelZoomPlugin) was hakelig/glitchy —
uPlot is not built to be driven that way. Remove the plugin and the cursor.drag
override so uPlot's own defaults govern the mouse: drag = box-zoom on x,
double-click = reset to full range, with the legend value-readout and crosshair
unchanged.

Everything else from the Tier-1 pass stays: the ordinal (gap-collapsed) x-axis
default + continuous toggle, the ordinal-label honesty (ticks/legend report the
real xs[i]), and panel cursor-sync (cursor.sync key retained; only the drag
override and the plugin are dropped). The x-mode guard is flipped to pin the
revert — overlay carries no custom plugin and no cursor.drag override, panels
carry no plugin — and stays green alongside the other three chart guards.

refs #103
2026-06-19 23:15:39 +02:00

52 lines
3.0 KiB
JavaScript

// Headless guard for the trace-chart viewer's x-mode + interaction wiring.
// Properties: (1) the DEFAULT x spine is ORDINAL — data[0] is [0..n-1], not the raw
// timestamps, so non-trading gaps collapse; the x-axis carries an index->label values
// formatter. (2) "continuous" mode restores data[0] === xs verbatim. (3) panels carry a
// shared cursor.sync.key so the crosshair lines up. (4) no custom interaction plugin and
// no cursor.drag override — uPlot's default drag-box-zoom / dblclick-reset governs the
// mouse (the hand-rolled wheel/pan was glitchy). Drives the pure buildCharts; no DOM/uPlot.
import { createRequire } from "node:module";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
const require = createRequire(import.meta.url);
const here = dirname(fileURLToPath(import.meta.url));
const traces = JSON.parse(readFileSync(join(here, "fixtures", "sample-traces.json"), "utf8"));
const fail = (msg) => { console.error("FAIL: " + msg); process.exit(1); };
const sameArr = (a, b, msg) => {
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length || a.some((v, i) => v !== b[i])) fail(msg);
};
global.window = { AURA_TRACES: traces };
const { buildCharts } = require(join(here, "..", "assets", "chart-viewer.js"));
const n = traces.xs.length;
const idx = Array.from({ length: n }, (_, i) => i);
// (1) default is ordinal: data[0] is the index spine, with an x-axis values formatter.
const ov = buildCharts(traces, "overlay");
sameArr(ov[0].data[0], idx, "default overlay x is the ordinal index spine [0..n-1]");
if (typeof ov[0].opts.axes[0].values !== "function") fail("ordinal overlay x-axis lacks a values formatter");
// (4) interaction is uPlot's default: overlay carries no custom plugin and no
// cursor.drag override (so drag = box-zoom, dblclick = reset, both uPlot built-ins).
if (ov[0].opts.plugins && ov[0].opts.plugins.length) fail("overlay should carry no custom interaction plugin (uPlot defaults)");
if (ov[0].opts.cursor && ov[0].opts.cursor.drag) fail("overlay should not override cursor.drag (uPlot default box-zoom)");
// (2) continuous mode: data[0] is xs verbatim.
const ovc = buildCharts(traces, "overlay", "continuous");
sameArr(ovc[0].data[0], traces.xs, "continuous overlay x is xs verbatim");
// (3) panels: cursor.sync.key present and equal across panels; default still ordinal.
const panels = buildCharts(traces, "panels");
const keys = panels.map((p) => p.opts.cursor && p.opts.cursor.sync && p.opts.cursor.sync.key);
if (keys.some((k) => !k)) fail("a panel lacks cursor.sync.key");
if (new Set(keys).size !== 1) fail("panels do not share one cursor.sync key");
if (panels.some((p) => p.opts.plugins && p.opts.plugins.length)) fail("panels should carry no custom interaction plugin (uPlot defaults)");
sameArr(panels[0].data[0], idx, "default panel x is the ordinal index spine");
console.log("OK — ordinal default + continuous toggle + panel cursor-sync + uPlot-default controls.");
process.exit(0);