fix(ui): align branch lane ends and route the unmatched switch path down its own lane

This commit is contained in:
sam committed 2026-10-18 23:45:25 +11:00
1 parent 0d6d5e7dd3
commit 168ddde0dd
4 files changed
+32 -28

No files matched your search

+27 -20
View File
@@ -327,9 +327,22 @@ export function workflowGraph(source: string): WorkflowGraph {
const passes = kind === "switch" && !branches.some(([name]) => name === "default");
const lanes = branches.length + (passes ? 1 : 0);
const ends: string[] = [];
let depth = 0;
const depth = Math.max(1, ...branches.map(([, branchSteps]) => branchSteps.length));
const laneAt = (column: number) => (column - (lanes - 1) / 2) * COLUMN;
const lane = (id: string, x: number, title: string) =>
nodes.push({
id,
type: "lane",
position: { x: x - 12, y: row * ROW - 40 },
style: { width: `${COLUMN - 16}px`, height: `${(depth + 1) * ROW - 24}px` },
zIndex: -1,
data: { kind: "step", key: title, title, type: "", detail: "", lane: kind },
});
// Every lane closes at the same row, so the + that ends a branch sits at
// the foot of its own box and the joins into the next step line up.
const foot = (row + depth) * ROW;
branches.forEach(([name, branchSteps], column) => {
const x = (column - (lanes - 1) / 2) * COLUMN;
const x = laneAt(column);
let tail = [parent];
const path = ["steps", i, ...base, name];
branchSteps.forEach((branchStep, j) => {
@@ -337,32 +350,26 @@ export function workflowGraph(source: string): WorkflowGraph {
link(tail, id, [...path, j - 1]);
tail = [id];
});
depth = Math.max(depth, branchSteps.length);
const end = `add-${i}-${name}`;
nodes.push({ id: end, type: "add", position: { x: x + 104, y: (row + branchSteps.length) * ROW }, data: { kind: "step", key: end, title: "", type: "", detail: "", branch: name, lane: kind, insertAfter: [...path, branchSteps.length - 1] } });
nodes.push({ id: end, type: "add", position: { x: x + 104, y: foot }, data: { kind: "step", key: end, title: "", type: "", detail: "", branch: name, lane: kind, insertAfter: [...path, branchSteps.length - 1] } });
link(tail, end);
ends.push(end);
});
const height = (Math.max(depth, 1) + 1) * ROW - 24;
branches.forEach(([name], column) => {
const x = (column - (lanes - 1) / 2) * COLUMN;
nodes.push({
id: `lane-${i}-${name}`,
type: "lane",
position: { x: x - 12, y: row * ROW - 40 },
style: { width: `${COLUMN - 16}px`, height: `${height}px` },
zIndex: -1,
data: { kind: "step", key: name, title: name, type: "", detail: "", lane: kind },
});
lane(`lane-${i}-${name}`, x, name);
});
if (passes) {
// The run's way past an unmatched switch: an edge from the switch to
// the step after it, drawn down the last column.
ends.push(parent);
// The run's way past an unmatched switch runs down a lane of its own,
// so it never cuts across the cases.
const x = laneAt(lanes - 1);
const end = `pass-${i}`;
nodes.push({ id: end, type: "add", position: { x: x + 104, y: foot }, data: { kind: "step", key: end, title: "", type: "", detail: "", lane: kind } });
otherwise.add(parent);
link([parent], end);
otherwise.delete(parent);
ends.push(end);
lane(`pass-lane-${i}`, x, "default");
}
previous = ends;
row += Math.max(depth, 1) + 1;
row += depth + 1;
continue;
}
const id = addStep(step, String(i + 1), 0, row * ROW, undefined, undefined, ["steps", i]);