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): drop degenerate points so vertical edges keep a real final segment (#169) (#203)

Yunare Maia499b75ddc518
diff --git a/archify.zip b/archify.zip
index 4a6a670e..10771aec 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/renderers/dataflow/render-dataflow.mjs b/archify/renderers/dataflow/render-dataflow.mjs
index f49b4471..3eda9d4a 100644
--- a/archify/renderers/dataflow/render-dataflow.mjs
+++ b/archify/renderers/dataflow/render-dataflow.mjs
@@ -342,7 +342,21 @@ function pathFor(flow) {
const { fromSide, toSide } = flowSides(flow);
const start = ports?.from || anchor(from, fromSide);
const end = ports?.to || anchor(to, toSide);
- const points = [start, ...routeVia(flow, from, to, start, end), end];
+ // Drop consecutive duplicate points so a purely vertical (or horizontal)
+ // auto-route never emits a zero-length final segment — SVG derives
+ // marker-end orientation from the last segment, and a degenerate segment
+ // leaves the arrowhead angle undefined (see #169).
+ const rawPoints = [start, ...routeVia(flow, from, to, start, end), end];
+ const points = [];
+ for (const p of rawPoints) {
+ const prev = points.at(-1);
+ if (!prev || Math.abs(p[0] - prev[0]) > 0.0001 || Math.abs(p[1] - prev[1]) > 0.0001) {
+ points.push(p);
+ }
+ }
+ // Guard against an all-degenerate route (e.g. start === end): keep both
+ // endpoints so the path is still well-formed even if the marker is hidden.
+ if (points.length < 2) points.push(end);
const routed = { d: polylinePath(points), points };
pathCache.set(flow, routed);
return routed;
diff --git a/archify/test/vertical-edge.test.mjs b/archify/test/vertical-edge.test.mjs
new file mode 100644
index 00000000..ba13e3b2
--- /dev/null
+++ b/archify/test/vertical-edge.test.mjs
@@ -0,0 +1,68 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { execFileSync } from 'node:child_process';
+import fs from 'node:fs';
+import os from 'node:os';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+const skillRoot = path.resolve(__dirname, '..');
+const bin = path.join(skillRoot, 'bin', 'archify.mjs');
+const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-vertical-edge-'));
+
+const REPRO = {
+ schema_version: 1,
+ diagram_type: 'dataflow',
+ meta: { title: 'Vertical edge arrowhead repro', quality_profile: 'showcase' },
+ stages: [{ label: 'Parse' }, { label: 'Store' }],
+ nodes: [
+ { id: 'extract', type: 'backend', label: 'Extract', stage: 0, row: 0 },
+ { id: 'parse', type: 'backend', label: 'Parse', stage: 0, row: 3 },
+ { id: 'store', type: 'database', label: 'Store', stage: 1, row: 1 },
+ ],
+ flows: [
+ { id: 'vertical-edge', from: 'extract', to: 'parse', label: 'chunks', variant: 'emphasis', labelDy: 40 },
+ { id: 'horizontal-edge', from: 'parse', to: 'store', label: 'rows', variant: 'emphasis' },
+ ],
+};
+
+function render(d) {
+ const inPath = path.join(tmp, 'in.dataflow.json');
+ const outPath = path.join(tmp, 'out.html');
+ fs.writeFileSync(inPath, JSON.stringify(d));
+ execFileSync('node', [bin, 'render', 'dataflow', inPath, outPath, '--quality', 'showcase'], { encoding: 'utf8' });
+ return fs.readFileSync(outPath, 'utf8');
+}
+
+function edgePath(html, edgeId) {
+ const re = new RegExp(`data-edge-id="${edgeId}"[^>]*\\sd="([^"]*)"`);
+ const m = html.match(re);
+ return m ? m[1] : null;
+}
+
+function segments(d) {
+ const pts = [...d.matchAll(/[ML] ([-\d.]+ [-\d.]+)/g)].map((m) => m[1]);
+ const segs = [];
+ for (let i = 1; i < pts.length; i += 1) segs.push(pts[i - 1] !== pts[i]);
+ return segs;
+}
+
+test('vertical auto-routed dataflow edge has no zero-length final segment (#169)', () => {
+ const html = render(REPRO);
+ const d = edgePath(html, 'vertical-edge');
+ assert.ok(d, 'vertical-edge path should exist');
+ const segs = segments(d);
+ // The final segment must have real length so marker-end orients correctly.
+ assert.ok(segs.at(-1) === true, `last segment must be non-zero length, got d="${d}"`);
+ // No segment may be zero-length (degenerate path confuses marker orientation).
+ assert.ok(segs.every(Boolean), `no segment may be zero-length, got d="${d}"`);
+});
+
+test('horizontal edge still renders with a real final segment (#169)', () => {
+ const html = render(REPRO);
+ const d = edgePath(html, 'horizontal-edge');
+ assert.ok(d, 'horizontal-edge path should exist');
+ const segs = segments(d);
+ assert.ok(segs.at(-1) === true, `last segment must be non-zero length, got d="${d}"`);
+});