web: clearer workflow graph labels, routes and kinds

- Gaps between stages are sized from the widest straight-route label, so a chip
  never reaches into either box; a source's forward routes fan across its side
  instead of sharing a 20px band.
- A label prefers the widest horizontal run that can hold it; when only a stub
  exists the chip moves onto the edge's longest run and sits beside a vertical
  one, keeping clear of both the box and the neighbouring label.
- Hovering a wire or its chip highlights the route and dims the rest.
- System-added routes (the parser's implicit error fallback) draw dotted with a
  legend entry, distinct from declared routes and executed state.
- Lanes are 34px apart, so a dense definition no longer doubles the canvas height.
- The graph opens expanded by default and remembers a collapse (graphPrefs.js).
This commit is contained in:
2026-10-19 22:23:58 +01:00
parent 1eaedf5c53
commit b00b434c5d
8 changed files with 313 additions and 58 deletions
+45
View File
@@ -20,6 +20,7 @@ import {
edgeLabel,
graphEdges,
graphNodeKind,
labelWidthFor,
graphDescription,
hitTest,
layoutGraph,
@@ -203,6 +204,50 @@ test("layoutGraph labels sit on the edge's own widest horizontal run", () => {
}
});
test("a gap is at least as wide as the widest straight-route label plus padding", () => {
const graph = {
stages: [
{ key: "a", edges: { success: "b", repair_attempt: "b", error: "#" }, fallback_error: true },
{ key: "b", edges: { success: "#success" } },
],
};
const layout = layoutGraph(graph);
const [a, b] = layout.nodes.filter((node) => !node.terminal);
const gap = b.x - (a.x + a.width);
const widest = Math.max(labelWidthFor("success"), labelWidthFor("repair_attempt"));
assert.ok(gap >= widest + 2 * 10, `gap ${gap} fits the ${widest}px chip`);
});
test("a source's straight routes fan across its side instead of one shared band", () => {
const graph = {
stages: [
{ key: "a", edges: { success: "b", repair_attempt: "b", error: "#" }, fallback_error: true },
{ key: "b", edges: { success: "#success" } },
],
};
const layout = layoutGraph(graph);
const ys = layout.edges
.filter((edge) => edge.forward && edge.source === "a")
.map((edge) => edge.from.y)
.sort((x, y) => x - y);
assert.equal(ys.length, 2);
assert.ok(ys[1] - ys[0] >= 18, "their chips (18px tall) cannot touch");
});
test("graphEdges marks only the parser's implicit error fallback", () => {
const graph = {
stages: [
{ key: "a", edges: { success: "b", error: "#" }, fallback_error: true },
{ key: "b", edges: { success: "#success", error: "#" }, fallback_error: false },
],
};
const edges = graphEdges(graph);
assert.equal(edges.filter((edge) => edge.fallback).length, 1);
assert.equal(edges.find((edge) => edge.fallback).source, "a");
const layout = layoutGraph(graph);
assert.equal(layout.edges.filter((edge) => edge.fallback).length, 1);
});
test("layoutGraph is empty and finite for a graph with no stages", () => {
const layout = layoutGraph({ stages: [] });
assert.deepEqual(layout.nodes, []);
+32
View File
@@ -0,0 +1,32 @@
// The graph expansion preference: expanded by default, a collapse remembered.
import { test } from "node:test";
import assert from "node:assert/strict";
import { GRAPH_EXPANDED_KEY, readGraphExpanded, writeGraphExpanded } from "../src/graphPrefs.js";
function fakeStorage(initial = {}) {
const values = new Map(Object.entries(initial));
return {
getItem: (key) => (values.has(key) ? values.get(key) : null),
setItem: (key, value) => values.set(key, String(value)),
values,
};
}
test("the graph is expanded when nothing was stored", () => {
assert.equal(readGraphExpanded(fakeStorage()), true);
});
test("a collapse survives and expands again on request", () => {
const storage = fakeStorage();
writeGraphExpanded(false, storage);
assert.equal(storage.values.get(GRAPH_EXPANDED_KEY), "0");
assert.equal(readGraphExpanded(storage), false);
writeGraphExpanded(true, storage);
assert.equal(readGraphExpanded(storage), true);
});
test("storage failures fall back to the expanded default", () => {
const broken = { getItem() { throw new Error("denied"); }, setItem() { throw new Error("denied"); } };
assert.equal(readGraphExpanded(broken), true);
assert.doesNotThrow(() => writeGraphExpanded(false, broken));
});