...edge,
type: "insert",
...(otherwise ? { sourceHandle: "otherwise" } : {}),
- data: { trace: runs.value.get(edge.target), otherwise, insertAfter, types: typesAt(insertAfter), editable: editable.value, onInsert: (after: StepPath, type: string) => emit("insert", after, type) },
+ data: { trace: runs.value.get(edge.target), insertAfter, types: typesAt(insertAfter), editable: editable.value, onInsert: (after: StepPath, type: string) => emit("insert", after, type) },
}
: {
...edge,
diff --git a/ui/src/workflows/workflow-graph.ts b/ui/src/workflows/workflow-graph.ts
index 9b37251dd..ced463f57 100644
--- a/ui/src/workflows/workflow-graph.ts
+++ b/ui/src/workflows/workflow-graph.ts
@@ -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]);