Files
Aura/crates/aura-cli/tests/chart_viewer_keys.rs
T
Brummel 06fdafa925 feat(trace-charts): keyboard chart control — pan / zoom-toward-cursor / reset / toggle
Keyboard control for the served chart, deliberately the discrete counterpart to the
glitchy hand-rolled pointer drag that was just removed: each key is one clean
setScale("x", …), deterministic, with none of uPlot's pointer-pan jank.

- arrows pan (15% of the visible span), +/- zoom, 0/Home reset, x toggles the spine.
- zoom anchors on the CURSOR: the x-value under the mouse keeps its relative position,
  so the point under the pointer stays put while zooming (centre when the mouse is off
  the chart). The mouse position is tracked per chart via posToVal on mousemove.
- keys drive every chart instance together, so panels stay x-aligned.
- uPlot's default mouse (drag = box-zoom, double-click = reset) is retained — you have
  both.

The load-bearing math is the pure keyXRange(key, lo, hi, anchor, ext) helper (the rest
is browser-only DOM wiring in mount); it is node-guarded by chart_viewer_keys.mjs, which
pins the zoom-toward-cursor invariant (anchor keeps its relative position) with an
off-centre anchor so a centre-zoom regression fails loudly. All five chart guards green.

refs #103
2026-06-19 23:28:54 +02:00

33 lines
1.2 KiB
Rust

//! Integration guard for the `aura chart` viewer's keyboard-control math: the pure
//! `keyXRange` (arrow-pan, +/- zoom-toward-cursor, 0/Home reset) lives in
//! `chart-viewer.js` and cannot be checked from Rust; this shells out to `node`, running
//! `tests/chart_viewer_keys.mjs`, which drives the pure export. `node` is REQUIRED: if
//! absent this test FAILS.
use std::path::PathBuf;
use std::process::Command;
#[test]
fn chart_viewer_keyboard_pan_zoom_toward_cursor() {
let script = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("chart_viewer_keys.mjs");
assert!(script.exists(), "guard script missing at {}", script.display());
let out = match Command::new("node").arg(&script).output() {
Ok(out) => out,
Err(e) => panic!(
"node is required for the chart-viewer keyboard guard but could not be run \
({e}); install Node.js or ensure `node` is on PATH"
),
};
let stdout = String::from_utf8_lossy(&out.stdout);
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(
out.status.success(),
"chart-viewer keyboard guard failed (exit {:?}).\n--- node stdout ---\n{stdout}\n--- node stderr ---\n{stderr}",
out.status.code()
);
}