Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

fix(dataflow): turn across stages in a clear gap

tt-a1id484668d758d
diff --git a/archify/renderers/dataflow/render-dataflow.mjs b/archify/renderers/dataflow/render-dataflow.mjs
index 6f098ef3..cac08f32 100644
--- a/archify/renderers/dataflow/render-dataflow.mjs
+++ b/archify/renderers/dataflow/render-dataflow.mjs
@@ -423,7 +423,17 @@ function routeVia(flow, from, to, start, end) {
}
if (Math.abs(start[1] - end[1]) < 4) return [];
const midX = start[0] + (end[0] - start[0]) / 2;
- return [[midX, start[1]], [midX, end[1]]];
+ // Across several stages the midpoint can fall inside a middle stage's
+ // node; then turn in the clear inter-stage gap nearest to it.
+ const gapXs = asArray(dataflow.stages).slice(1).map((_, index) => (stageX(index) + stageX(index + 1)) / 2)
+ .filter((x) => x > Math.min(start[0], end[0]) && x < Math.max(start[0], end[0]))
+ .sort((left, right) => Math.abs(left - midX) - Math.abs(right - midX));
+ const turnX = [midX, ...gapXs].find((x) => {
+ const points = [start, [x, start[1]], [x, end[1]], end];
+ return ![...nodes.values()].some((node) => node.id !== from.id && node.id !== to.id
+ && points.slice(1).some((point, index) => segmentIntersectsRect({ start: points[index], end: point }, node, 2)));
+ }) ?? midX;
+ return [[turnX, start[1]], [turnX, end[1]]];
}
}
}
diff --git a/test/dataflow-automatic-layout.test.mjs b/test/dataflow-automatic-layout.test.mjs
index 5e4cb0d3..97306f00 100644
--- a/test/dataflow-automatic-layout.test.mjs
+++ b/test/dataflow-automatic-layout.test.mjs
@@ -365,3 +365,20 @@ test('automatic dataflow routes honor perpendicular pinned sides', t => {
assert.equal(points.length, 3, JSON.stringify(points));
assert.ok(points[1][1] > points[2][1], 'final segment rises into the bottom side');
});
+
+test('automatic dataflow routes across stages turn in a clear gap, not inside a middle node', t => {
+ const diagram = {
+ schema_version: 1, diagram_type: 'dataflow',
+ meta: { title: 'Across stages', output: 'diagram.html', quality_profile: 'showcase' },
+ stages: [{ label: 'A' }, { label: 'B' }, { label: 'C' }, { label: 'D' }],
+ nodes: [
+ { id: 'source', type: 'backend', label: 'Source', stage: 0, row: 0 },
+ { id: 'middle', type: 'backend', label: 'Middle', stage: 1, row: 0 },
+ { id: 'other', type: 'backend', label: 'Other', stage: 2, row: 0 },
+ { id: 'target', type: 'backend', label: 'Target', stage: 3, row: 1 },
+ ],
+ flows: [{ id: 'push', from: 'source', to: 'target', label: 'push' }],
+ };
+ const { result, receipt } = inspect(t, diagram);
+ assert.equal(result.status, 0, JSON.stringify(receipt.diagnostics));
+});