Skip to content

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

fix(workflow): keep same-side automatic ports at least 16px apart

tt-a1i9ba05ef43c26
diff --git a/archify/renderers/workflow/workflow-compiler.mjs b/archify/renderers/workflow/workflow-compiler.mjs
index 90c9785f..d116f982 100644
--- a/archify/renderers/workflow/workflow-compiler.mjs
+++ b/archify/renderers/workflow/workflow-compiler.mjs
@@ -4245,7 +4245,7 @@ function automaticPortCandidates(edge, node, side, preferred, counterpart) {
const ownWidth = edge.width || (edge.variant === 'emphasis' ? 1.8 : 1.4);
const otherWidth = other.width || (other.variant === 'emphasis' ? 1.8 : 1.4);
if (Math.abs(point[1 - axis] - center[1 - axis]) < 0.0001) {
- occupied.push({ coordinate: point[axis], clearance: Math.max(12, 3.5 * (ownWidth + otherWidth)) });
+ occupied.push({ coordinate: point[axis], clearance: Math.max(16, 3.5 * (ownWidth + otherWidth)) });
}
}
}
diff --git a/test/fixtures/workflow-first-draft/customer-refund.workflow.json b/test/fixtures/workflow-first-draft/customer-refund.workflow.json
new file mode 100644
index 00000000..6233942b
--- /dev/null
+++ b/test/fixtures/workflow-first-draft/customer-refund.workflow.json
@@ -0,0 +1,121 @@
+{
+ "schema_version": 2,
+ "diagram_type": "workflow",
+ "meta": {
+ "title": "Customer refund",
+ "locale": "en",
+ "quality_profile": "showcase",
+ "output": "customer-refund.html"
+ },
+ "lanes": [
+ {
+ "id": "cust",
+ "label": "Customer"
+ },
+ {
+ "id": "cs",
+ "label": "Support"
+ },
+ {
+ "id": "fin",
+ "label": "Finance"
+ },
+ {
+ "id": "psp",
+ "label": "Processor"
+ }
+ ],
+ "nodes": [
+ {
+ "id": "ask",
+ "lane": "cust",
+ "col": 0,
+ "type": "frontend",
+ "label": "Request refund",
+ "sublabel": "in app"
+ },
+ {
+ "id": "triage",
+ "lane": "cs",
+ "col": 1,
+ "type": "backend",
+ "label": "Triage",
+ "sublabel": "policy check"
+ },
+ {
+ "id": "approve",
+ "lane": "fin",
+ "col": 2,
+ "type": "security",
+ "label": "Approve",
+ "sublabel": "amount limits"
+ },
+ {
+ "id": "charge",
+ "lane": "psp",
+ "col": 3,
+ "type": "cloud",
+ "label": "Refund charge",
+ "sublabel": "Stripe"
+ },
+ {
+ "id": "notify",
+ "lane": "cust",
+ "col": 4,
+ "type": "frontend",
+ "label": "Notify",
+ "sublabel": "email + push"
+ },
+ {
+ "id": "deny",
+ "lane": "cust",
+ "col": 2,
+ "type": "frontend",
+ "label": "Denied",
+ "sublabel": "with reason"
+ }
+ ],
+ "edges": [
+ {
+ "from": "ask",
+ "to": "triage",
+ "label": "submit"
+ },
+ {
+ "from": "triage",
+ "to": "approve",
+ "label": "within policy"
+ },
+ {
+ "from": "approve",
+ "to": "charge",
+ "label": "approved"
+ },
+ {
+ "from": "charge",
+ "to": "notify",
+ "label": "settled"
+ },
+ {
+ "from": "triage",
+ "to": "deny",
+ "label": "out of policy",
+ "role": "error",
+ "variant": "security"
+ },
+ {
+ "from": "approve",
+ "to": "deny",
+ "label": "over limit",
+ "role": "error",
+ "variant": "security"
+ }
+ ],
+ "mainPath": [
+ "ask",
+ "triage",
+ "approve",
+ "charge",
+ "notify"
+ ]
+}
\ No newline at end of file
diff --git a/test/workflow-compiler.test.mjs b/test/workflow-compiler.test.mjs
index 67c67687..92a8ab17 100644
--- a/test/workflow-compiler.test.mjs
+++ b/test/workflow-compiler.test.mjs
@@ -357,7 +357,7 @@ test('readable-v2 separates approval branches in the checked-in workflow example
// columns now keep a 32px route corridor, which widens the canvas by 12px,
// and tags keep their 7px preferred size.
sha256(result.svg.replace(/ data-(?:composition-routing|edge-role|layout-contract)="[^"]*"/g, '')),
- '9254f1c5304ea0a2ba0db9399952988a6af8c768930fd47b7d8ba5935499a073',
+ '09ece2904db9a525bd5990f896ab6f335b48cd7617beb6a47868874a17e94774',
);
});
diff --git a/test/workflow-route-order.test.mjs b/test/workflow-route-order.test.mjs
index 6a782fde..6167f908 100644
--- a/test/workflow-route-order.test.mjs
+++ b/test/workflow-route-order.test.mjs
@@ -52,3 +52,21 @@ test('a label that does not fit its preferred stretch moves to a run that clears
const edge = result.receipt.edges.find((entry) => entry.from === 'triage' && entry.to === 'status');
assert.deepEqual(edge.points, [[388.6, 269], [388.6, 491], [455.6, 491]]);
});
+
+// Two error edges into Denied used to share a 12px port gap (arrowheads
+// overlapping). Raising the same-side clearance floor to 16px separates them.
+const refund = path.join(__dirname, 'fixtures', 'workflow-first-draft', 'customer-refund.workflow.json');
+
+test('two automatic arrivals on one side of a node keep at least 16px between their ports', () => {
+ const result = compileWorkflow({ workflow: JSON.parse(fs.readFileSync(refund, 'utf8')) });
+ assert.equal(result.ok, true, result.error);
+ const ends = result.receipt.edges
+ .filter((edge) => edge.to === 'deny')
+ .map((edge) => edge.points.at(-1));
+ assert.ok(ends.length >= 2);
+ const axis = Math.abs(ends[0][0] - ends[1][0]) >= Math.abs(ends[0][1] - ends[1][1]) ? 0 : 1;
+ const values = ends.map((point) => point[axis]).sort((a, b) => a - b);
+ for (let index = 1; index < values.length; index += 1) {
+ assert.ok(values[index] - values[index - 1] >= 16, `ports ${values[index - 1]} and ${values[index]} are only ${values[index] - values[index - 1]}px apart`);
+ }
+});