Skip to content

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

fix(tree): snap near-aligned stems to remove micro-jogs

tt-a1i84139133bf89
diff --git a/archify.zip b/archify.zip
index cc24d14a..625485e7 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/examples/tree-archify-repository-rendered.html b/archify/examples/tree-archify-repository-rendered.html
index 9ff2da47..b3c3564d 100644
--- a/archify/examples/tree-archify-repository-rendered.html
+++ b/archify/examples/tree-archify-repository-rendered.html
@@ -5027,7 +5027,7 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
<path data-edge-from="repo" data-edge-to="site" data-edge-key="2" data-tree-ancestors="repo" data-composition-points="1157,123;1157,151;1481,151;1481,179" d="M 1157 123 L 1157 143 Q 1157 151 1165 151 L 1473 151 Q 1481 151 1481 159 L 1481 179" class="a-default tree-edge" stroke-width="1.5"/>
<path data-edge-from="repo" data-edge-to="scripts" data-edge-key="3" data-tree-ancestors="repo" data-composition-points="1157,123;1157,151;1680.5,151;1680.5,179" d="M 1157 123 L 1157 143 Q 1157 151 1165 151 L 1672.5 151 Q 1680.5 151 1680.5 159 L 1680.5 179" class="a-default tree-edge" stroke-width="1.5"/>
<path data-edge-from="skill" data-edge-to="renderers" data-edge-key="4" data-tree-ancestors="skill repo" data-composition-points="632.5,238;632.5,266;186,266;186,294" d="M 632.5 238 L 632.5 258 Q 632.5 266 624.5 266 L 194 266 Q 186 266 186 274 L 186 294" class="a-default tree-edge" stroke-width="1.5"/>
- <path data-edge-from="skill" data-edge-to="schemas" data-edge-key="5" data-tree-ancestors="skill repo" data-composition-points="632.5,238;632.5,266;632,266;632,294" d="M 632.5 238 L 632.5 266 L 632 266 L 632 294" class="a-default tree-edge" stroke-width="1.5"/>
+ <path data-edge-from="skill" data-edge-to="schemas" data-edge-key="5" data-tree-ancestors="skill repo" data-composition-points="632,238;632,294" d="M 632 238 L 632 294" class="a-default tree-edge" stroke-width="1.5"/>
<path data-edge-from="skill" data-edge-to="bin" data-edge-key="6" data-tree-ancestors="skill repo" data-composition-points="632.5,238;632.5,266;810,266;810,294" d="M 632.5 238 L 632.5 258 Q 632.5 266 640.5 266 L 802 266 Q 810 266 810 274 L 810 294" class="a-default tree-edge" stroke-width="1.5"/>
<path data-edge-from="skill" data-edge-to="references" data-edge-key="7" data-tree-ancestors="skill repo" data-composition-points="632.5,238;632.5,266;1066,266;1066,294" d="M 632.5 238 L 632.5 258 Q 632.5 266 640.5 266 L 1058 266 Q 1066 266 1066 274 L 1066 294" class="a-default tree-edge" stroke-width="1.5"/>
<path data-edge-from="renderers" data-edge-to="r_arch" data-edge-key="8" data-tree-ancestors="renderers skill repo" data-composition-points="186,353;186,381;44,381;44,438.5;60,438.5" d="M 186 353 L 186 373 Q 186 381 178 381 L 52 381 Q 44 381 44 389 L 44 430.5 Q 44 438.5 52 438.5 L 60 438.5" class="a-default tree-edge" stroke-width="1.5"/>
diff --git a/archify/renderers/tree/README.md b/archify/renderers/tree/README.md
index 050b5bc8..87b1b9ad 100644
--- a/archify/renderers/tree/README.md
+++ b/archify/renderers/tree/README.md
@@ -47,7 +47,7 @@ Each generation shares one band: a row for `layout.direction: "down"` (the
default) and a column for `"right"`. Along the other axis every subtree owns a
contiguous span, so unequal branch widths and depths never overlap. A parent is
centred over its first and last child (exactly over a middle child that sits
-within a few pixels of that midpoint, so the stem never jogs); going right,
+within a few pixels of that midpoint, so the stem never jogs; edge drawing also snaps stems aligned within 2px after rounding); going right,
nodes are left-aligned in their column.
Going down, a run of three or more consecutive leaf siblings is stacked as an
diff --git a/archify/renderers/tree/render-tree.mjs b/archify/renderers/tree/render-tree.mjs
index 45627f94..a9e87613 100644
--- a/archify/renderers/tree/render-tree.mjs
+++ b/archify/renderers/tree/render-tree.mjs
@@ -342,11 +342,21 @@ function edgePoints(parent, child) {
if (down) {
const end = [child.x + child.width / 2, child.y];
const midY = bandStart[child.depth] - depthGap / 2;
- return Math.abs(start[0] - end[0]) < 0.5 ? [start, end] : [start, [start[0], midY], [end[0], midY], end];
+ // Rounded parent/child centres can differ by ~1px and draw a useless
+ // elbow. Snap near-aligned stems to a shared x so they stay straight.
+ if (Math.abs(start[0] - end[0]) < 2) {
+ const x = Math.round((start[0] + end[0]) / 2);
+ return [[x, start[1]], [x, end[1]]];
+ }
+ return [start, [start[0], midY], [end[0], midY], end];
}
const end = [child.x, child.y + child.height / 2];
const midX = bandStart[child.depth] - depthGap / 2;
- return Math.abs(start[1] - end[1]) < 0.5 ? [start, end] : [start, [midX, start[1]], [midX, end[1]], end];
+ if (Math.abs(start[1] - end[1]) < 2) {
+ const y = Math.round((start[1] + end[1]) / 2);
+ return [[start[0], y], [end[0], y]];
+ }
+ return [start, [midX, start[1]], [midX, end[1]], end];
}
const edges = all.filter((node) => node.parent !== undefined).map((node, index) => ({
diff --git a/examples/tree-archify-repository-rendered.html b/examples/tree-archify-repository-rendered.html
index 9ff2da47..b3c3564d 100644
--- a/examples/tree-archify-repository-rendered.html
+++ b/examples/tree-archify-repository-rendered.html
@@ -5027,7 +5027,7 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
<path data-edge-from="repo" data-edge-to="site" data-edge-key="2" data-tree-ancestors="repo" data-composition-points="1157,123;1157,151;1481,151;1481,179" d="M 1157 123 L 1157 143 Q 1157 151 1165 151 L 1473 151 Q 1481 151 1481 159 L 1481 179" class="a-default tree-edge" stroke-width="1.5"/>
<path data-edge-from="repo" data-edge-to="scripts" data-edge-key="3" data-tree-ancestors="repo" data-composition-points="1157,123;1157,151;1680.5,151;1680.5,179" d="M 1157 123 L 1157 143 Q 1157 151 1165 151 L 1672.5 151 Q 1680.5 151 1680.5 159 L 1680.5 179" class="a-default tree-edge" stroke-width="1.5"/>
<path data-edge-from="skill" data-edge-to="renderers" data-edge-key="4" data-tree-ancestors="skill repo" data-composition-points="632.5,238;632.5,266;186,266;186,294" d="M 632.5 238 L 632.5 258 Q 632.5 266 624.5 266 L 194 266 Q 186 266 186 274 L 186 294" class="a-default tree-edge" stroke-width="1.5"/>
- <path data-edge-from="skill" data-edge-to="schemas" data-edge-key="5" data-tree-ancestors="skill repo" data-composition-points="632.5,238;632.5,266;632,266;632,294" d="M 632.5 238 L 632.5 266 L 632 266 L 632 294" class="a-default tree-edge" stroke-width="1.5"/>
+ <path data-edge-from="skill" data-edge-to="schemas" data-edge-key="5" data-tree-ancestors="skill repo" data-composition-points="632,238;632,294" d="M 632 238 L 632 294" class="a-default tree-edge" stroke-width="1.5"/>
<path data-edge-from="skill" data-edge-to="bin" data-edge-key="6" data-tree-ancestors="skill repo" data-composition-points="632.5,238;632.5,266;810,266;810,294" d="M 632.5 238 L 632.5 258 Q 632.5 266 640.5 266 L 802 266 Q 810 266 810 274 L 810 294" class="a-default tree-edge" stroke-width="1.5"/>
<path data-edge-from="skill" data-edge-to="references" data-edge-key="7" data-tree-ancestors="skill repo" data-composition-points="632.5,238;632.5,266;1066,266;1066,294" d="M 632.5 238 L 632.5 258 Q 632.5 266 640.5 266 L 1058 266 Q 1066 266 1066 274 L 1066 294" class="a-default tree-edge" stroke-width="1.5"/>
<path data-edge-from="renderers" data-edge-to="r_arch" data-edge-key="8" data-tree-ancestors="renderers skill repo" data-composition-points="186,353;186,381;44,381;44,438.5;60,438.5" d="M 186 353 L 186 373 Q 186 381 178 381 L 52 381 Q 44 381 44 389 L 44 430.5 Q 44 438.5 52 438.5 L 60 438.5" class="a-default tree-edge" stroke-width="1.5"/>