Skip to content

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

fix(renderers): close the adjacent gaps around label containment and repair hints

Rererr4e22f71f4f93
diff --git a/archify.zip b/archify.zip
index 1bc73555..340bfac3 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/renderers/architecture/render-architecture.mjs b/archify/renderers/architecture/render-architecture.mjs
index 361fe982..5046f919 100644
--- a/archify/renderers/architecture/render-architecture.mjs
+++ b/archify/renderers/architecture/render-architecture.mjs
@@ -150,26 +150,23 @@ const architectureLegendEntries = resolveLegend(
);
-// One source for connection label geometry: the auto canvas has to cover the
-// same rects the containment rule measures, and the layout report has to
-// publish them.
+// One source for connection label geometry: the rect the containment rule
+// measures is the rect the SVG mask draws, the auto canvas covers, the legend
+// avoids, and the layout report publishes.
+function connectionLabelBox(conn) {
+ if (!conn.label) return null;
+ const [lx, ly] = labelPoint(conn, pathFor(conn).points);
+ const width = Math.max(30, textUnits(conn.label) * 4.8 + 10);
+ return { x: lx - width / 2, y: ly - 10, width, height: 14, lx, ly };
+}
+
function connectionLabelRects() {
const rects = [];
for (const [relationIndex, conn] of asArray(arch.connections).entries()) {
- if (!conn.label || !components.has(conn.from) || !components.has(conn.to)) continue;
- const [lx, ly] = labelPoint(conn, pathFor(conn).points);
- const width = Math.max(30, textUnits(conn.label) * 4.8 + 10);
- rects.push({
- relation: conn,
- relationIndex,
- label: conn.label,
- x: lx - width / 2,
- y: ly - 10,
- width,
- height: 14,
- lx,
- ly,
- });
+ if (!components.has(conn.from) || !components.has(conn.to)) continue;
+ const box = connectionLabelBox(conn);
+ if (!box) continue;
+ rects.push({ relation: conn, relationIndex, label: conn.label, ...box });
}
return rects;
}
@@ -207,7 +204,7 @@ function resolvedViewBoxWidth(candidateBoundaries) {
if (Array.isArray(arch.meta?.viewBox) && Number.isFinite(arch.meta.viewBox[0])) {
return arch.meta.viewBox[0];
}
- return autoViewBoxFor(candidateBoundaries)[0];
+ return autoViewBoxFor(candidateBoundaries, connectionLabels)[0];
}
function expandBoundaryForReadableTitle(boundary, minimumFontSize) {
@@ -304,6 +301,26 @@ function layoutBoundaryTitles(rawBoundaries, minimumFontSize) {
});
}
+// ---- Routing state ----------------------------------------------------------
+// Initialized before the boundary-title work below: connection label rects are
+// part of the derived canvas, so the title convergence must measure the same
+// width the diagram actually renders into (a title sized for a narrower canvas
+// would fall below the desktop-readability floor once labels grow it). Routing
+// reads only components and connections, never boundaries or the viewBox.
+const OUTWARD_SIDE_VECTOR = {
+ left: [-1, 0],
+ right: [1, 0],
+ top: [0, -1],
+ bottom: [0, 1],
+};
+const AUTOMATIC_PORT_CORNER_GUTTER = 16;
+const AUTOMATIC_PORT_ALIGNMENT_DELTA = 16;
+const pathCache = new Map();
+const automaticPorts = automaticPortSpread(arch.connections, components);
+// The auto canvas has to cover these rects; an authored viewBox is never
+// resized to fit them — there the containment rule reports the clipping.
+const connectionLabels = connectionLabelRects();
+
const rawBoundaries = asArray(arch.boundaries).map(boundaryRect).filter(Boolean);
function resolveBoundaryTitles() {
if (!enforcesBoundaryTitleComposition || rawBoundaries.length === 0) {
@@ -358,7 +375,10 @@ function componentContext(component) {
}
// ---- Auto viewBox: fit all geometry + the measured resolved legend ----------
-let viewBox = arch.meta?.viewBox || autoViewBoxFor(boundaries);
+// Connection labels are diagram content, so an auto canvas that stopped at the
+// component/boundary bbox would clip them; the label rects join the fit here
+// and in the title convergence above, which sizes fonts for this same width.
+const viewBox = arch.meta?.viewBox || autoViewBoxFor(boundaries, connectionLabels);
const legendY = () => viewBox[1] - 16;
// ---- Validation: mechanical correctness, never layout taste -----------------
@@ -592,11 +612,11 @@ function validateArchitecture() {
}));
// Connection labels must not land on top of components.
- const labelRects = connectionLabelRects();
+ const labelRects = connectionLabels;
for (const rect of labelRects) {
for (const c of components.values()) {
if (rectsOverlap(rect, c, -2)) {
- problems.push(`Label "${rect.label}" overlaps component "${c.id}" — adjust labelDx/labelDy/labelSegment or set labelAt.\n${suggestLabelObstacleFix(rect, rect.lx, rect.ly, c, 'component', viewBox)}`);
+ problems.push(`Label "${rect.label}" overlaps component "${c.id}" — adjust labelDx/labelDy/labelSegment or set labelAt.\n${suggestLabelObstacleFix(rect, rect.lx, rect.ly, c, 'component', viewBox, components.values())}`);
}
}
if (enforcesBoundaryTitleComposition) {
@@ -636,7 +656,7 @@ function validateArchitecture() {
}
function buildLayoutReport() {
- const labels = connectionLabelRects().map((rect) => ({
+ const labels = connectionLabels.map((rect) => ({
text: rect.label,
x: Math.round(rect.x),
y: Math.round(rect.y),
@@ -686,13 +706,6 @@ function routeClearsEndpointComponents(points, from, to) {
return true;
}
-const OUTWARD_SIDE_VECTOR = {
- left: [-1, 0],
- right: [1, 0],
- top: [0, -1],
- bottom: [0, 1],
-};
-
function outwardStub(point, side, distance = 24) {
const [dx, dy] = OUTWARD_SIDE_VECTOR[side] || [0, 0];
return [point[0] + dx * distance, point[1] + dy * distance];
@@ -758,9 +771,6 @@ function sideAwareBridgeCandidates(start, end, fromSide, toSide) {
.map((points) => points.slice(1, -1));
}
-const AUTOMATIC_PORT_CORNER_GUTTER = 16;
-const AUTOMATIC_PORT_ALIGNMENT_DELTA = 16;
-
function portHasCornerClearance(rect, side, point) {
if (side === 'left' || side === 'right') {
const inset = Math.min(AUTOMATIC_PORT_CORNER_GUTTER, rect.height / 2);
@@ -931,8 +941,6 @@ function routeVia(conn, from, to, start, end, fromSide, toSide) {
}
}
-const pathCache = new Map();
-const automaticPorts = automaticPortSpread(arch.connections, components);
function connectionSides(conn) {
const from = components.get(conn.from);
const to = components.get(conn.to);
@@ -995,12 +1003,11 @@ function renderConnectionPath(conn, index) {
}
function renderConnectionLabel(conn, index) {
- if (!conn.label) return '';
- const [lx, ly] = labelPoint(conn, pathFor(conn).points);
- const w = Math.max(30, textUnits(conn.label) * 4.8 + 10);
+ const box = connectionLabelBox(conn);
+ if (!box) return '';
return ` <g data-detail="context" ${focusEdgeAttrs(conn.from, conn.to, conn.label, index, conn.id)}>
- <rect x="${lx - w / 2}" y="${ly - 10}" width="${w}" height="14" rx="3" class="c-mask"/>
- <text x="${lx}" y="${ly}" class="${variantAccent(conn.variant)}" font-size="8" text-anchor="middle">${esc(conn.label)}</text>
+ <rect x="${box.x}" y="${box.y}" width="${box.width}" height="${box.height}" rx="3" class="c-mask"/>
+ <text x="${box.lx}" y="${box.ly}" class="${variantAccent(conn.variant)}" font-size="8" text-anchor="middle">${esc(conn.label)}</text>
</g>`;
}
@@ -1032,12 +1039,7 @@ function renderLegend() {
const entries = architectureLegendEntries;
const relationshipObstacles = relationshipLegendObstacles(arch.connections, {
pointsFor: (connection) => pathFor(connection).points,
- labelRectFor: (connection) => {
- if (!connection.label) return null;
- const [x, y] = labelPoint(connection, pathFor(connection).points);
- const width = Math.max(30, textUnits(connection.label) * 4.8 + 10);
- return { x: x - width / 2, y: y - 10, width, height: 14 };
- },
+ labelRectFor: connectionLabelBox,
});
const contentBottom = Math.max(
0,
@@ -1088,13 +1090,6 @@ ${renderLegend()}
</svg>`;
}
-// Connection labels are diagram content, so an auto canvas that stops at the
-// component/boundary bbox clips them. Routing state only exists once the whole
-// module is initialized, so the auto canvas is grown here rather than inside
-// the boundary-title convergence above. An authored viewBox is never resized:
-// there the containment rule reports the clipping instead.
-if (!arch.meta?.viewBox) viewBox = autoViewBoxFor(boundaries, connectionLabelRects());
-
validateArchitecture();
if (layoutJsonMode) {
console.log(JSON.stringify(buildLayoutReport(), null, 2));
diff --git a/archify/renderers/dataflow/render-dataflow.mjs b/archify/renderers/dataflow/render-dataflow.mjs
index 76f0bfb1..bb82ab15 100644
--- a/archify/renderers/dataflow/render-dataflow.mjs
+++ b/archify/renderers/dataflow/render-dataflow.mjs
@@ -260,7 +260,7 @@ function validateDataflow() {
for (const rect of labelRects) {
for (const node of nodes.values()) {
if (rectsOverlap(rect, node, -2)) {
- problems.push(`Label "${rect.label}" overlaps node "${node.id}" — adjust labelDx/labelDy/labelSegment or set labelAt.\n${suggestLabelObstacleFix(rect, rect.lx, rect.ly, node, 'node', viewBox)}`);
+ problems.push(`Label "${rect.label}" overlaps node "${node.id}" — adjust labelDx/labelDy/labelSegment or set labelAt.\n${suggestLabelObstacleFix(rect, rect.lx, rect.ly, node, 'node', viewBox, nodes.values())}`);
}
}
}
diff --git a/archify/renderers/lifecycle/render-lifecycle.mjs b/archify/renderers/lifecycle/render-lifecycle.mjs
index 65f6190d..30dec28f 100644
--- a/archify/renderers/lifecycle/render-lifecycle.mjs
+++ b/archify/renderers/lifecycle/render-lifecycle.mjs
@@ -299,7 +299,7 @@ function validateLifecycle() {
for (const rect of labelRects) {
for (const state of states.values()) {
if (rectsOverlap(rect, state, -2)) {
- problems.push(`Label "${rect.label}" overlaps state "${state.id}" — adjust labelDx/labelDy/labelSegment or set labelAt.\n${suggestLabelObstacleFix(rect, rect.lx, rect.ly, state, 'state', viewBox)}`);
+ problems.push(`Label "${rect.label}" overlaps state "${state.id}" — adjust labelDx/labelDy/labelSegment or set labelAt.\n${suggestLabelObstacleFix(rect, rect.lx, rect.ly, state, 'state', viewBox, states.values())}`);
}
}
}
diff --git a/archify/renderers/shared/geometry.mjs b/archify/renderers/shared/geometry.mjs
index 8757a5c2..ce7361df 100644
--- a/archify/renderers/shared/geometry.mjs
+++ b/archify/renderers/shared/geometry.mjs
@@ -979,6 +979,10 @@ export function collectLabelCanvasOverflow({ labels, viewBox, tolerance = 0.5 })
for (const [fallbackIndex, label] of asArray(labels).entries()) {
const rect = label?.rect || label;
if (!rect || !isFinitePoint(rect.x, rect.y, rect.width, rect.height)) continue;
+ // `check` parses foreign markup, so a malformed negative-size rect is
+ // skipped like the other label collectors do — its flipped interval would
+ // otherwise read as contained.
+ if (rect.width < 0 || rect.height < 0) continue;
const horizontal = axisCanvasOverflow(rect.x, rect.width, canvasWidth, originX);
const vertical = axisCanvasOverflow(rect.y, rect.height, canvasHeight, originY);
const overflow = {
@@ -1523,9 +1527,17 @@ function clampAnchorToCanvas(anchorValue, offset, size, extent) {
* rect inside the canvas.
* The authored values therefore come from `labelRect.relation`, the authored
* relationship the renderer already attaches to every label record.
+ * `obstacles` is every box the callers' own overlap loop tests (defaults to
+ * the named obstacle alone): a placement that merely traded the named obstacle
+ * for its neighbor would fail the same rule again when applied.
*/
-export function suggestLabelObstacleFix(labelRect, lx, ly, obstacle, obstacleKind = 'component', viewBox) {
- const [canvasWidth, canvasHeight] = asArray(viewBox);
+export function suggestLabelObstacleFix(labelRect, lx, ly, obstacle, obstacleKind = 'component', viewBox, obstacles) {
+ // Renderer canvases are origin-zero [width, height] by schema, but read a
+ // 4-number [min-x, min-y, width, height] the same way the containment
+ // collector does — degraded no-ajv runs must not clamp against the origin
+ // pair as if it were the canvas size.
+ const box = asArray(viewBox);
+ const [canvasWidth, canvasHeight] = box.length === 4 ? box.slice(2) : box;
const xOffset = labelRect.x - lx;
const yOffset = labelRect.y - ly;
const anchorX = clampAnchorToCanvas(lx, xOffset, labelRect.width, canvasWidth);
@@ -1535,22 +1547,27 @@ export function suggestLabelObstacleFix(labelRect, lx, ly, obstacle, obstacleKin
// lifecycle note) back on the obstacle it must clear. The overlap filter
// uses the callers' own detection call, so a surviving hint cannot re-raise
// the problem it repairs.
+ const blockers = obstacles ? [...obstacles] : [obstacle];
const placements = [
{ name: 'below', y: Math.round(obstacle.y + obstacle.height + 4 - yOffset) },
{ name: 'above', y: Math.round(obstacle.y - 4 - labelRect.height - yOffset) },
].filter(({ y }) => anchorX !== null
&& anchorFitsCanvas(y, yOffset, labelRect.height, canvasHeight)
- && !rectsOverlap(
+ && blockers.every((blocker) => !rectsOverlap(
{ x: anchorX + xOffset, y: y + yOffset, width: labelRect.width, height: labelRect.height },
- obstacle,
+ blocker,
-2,
- ));
+ )));
const lines = [
` label rect: ${formatRect(labelRect)}`,
` ${obstacleKind} "${obstacle.id}" rect: ${formatRect(obstacle)}`,
];
if (!placements.length) {
- lines.push(` Suggested fix: no position clears "${obstacle.id}" inside the ${canvasWidth}x${canvasHeight} viewBox — shorten the label, move the ${obstacleKind}, or enlarge meta.viewBox`);
+ // Only the vertical slots beside the named obstacle were tried, so an
+ // unclaimed spot elsewhere may still exist — never assert that none does.
+ lines.push(anchorX === null
+ ? ` Suggested fix: the ${Math.round(labelRect.width)}px label rect cannot fit the ${canvasWidth}x${canvasHeight} viewBox at any anchor — shorten the label or enlarge meta.viewBox`
+ : ` Suggested fix: no placement directly above or below "${obstacle.id}" stays clear inside the ${canvasWidth}x${canvasHeight} viewBox — move the label to an open area with labelAt, shorten the label, move the ${obstacleKind}, or enlarge meta.viewBox`);
return lines.join('\n');
}
const authored = labelRect.relation || {};
diff --git a/archify/renderers/workflow/workflow-compiler.mjs b/archify/renderers/workflow/workflow-compiler.mjs
index f48de41c..e2eaaa08 100644
--- a/archify/renderers/workflow/workflow-compiler.mjs
+++ b/archify/renderers/workflow/workflow-compiler.mjs
@@ -2452,7 +2452,7 @@ function validateWorkflow() {
for (const rect of labelRects) {
for (const node of nodes.values()) {
if (rectsOverlap(rect, node, -2)) {
- problems.push(`Label "${rect.label}" overlaps node "${node.id}" — adjust labelDx/labelDy/labelSegment or set labelAt.\n${suggestLabelObstacleFix(rect, rect.lx, rect.ly, node, 'node', viewBox)}`);
+ problems.push(`Label "${rect.label}" overlaps node "${node.id}" — adjust labelDx/labelDy/labelSegment or set labelAt.\n${suggestLabelObstacleFix(rect, rect.lx, rect.ly, node, 'node', viewBox, nodes.values())}`);
}
}
}
diff --git a/archify/scripts/check-render-output.mjs b/archify/scripts/check-render-output.mjs
index f890d24f..15607cbc 100644
--- a/archify/scripts/check-render-output.mjs
+++ b/archify/scripts/check-render-output.mjs
@@ -2,7 +2,7 @@
import fs from 'node:fs';
import path from 'node:path';
-import { collectAmbiguousCorridors, collectBorderRuns, collectLabelCanvasOverflow, collectLabelRouteClearance, collectRouteRhythmIssues, describeLabelCanvasOverflow, routeBudgetMetrics } from '../renderers/shared/geometry.mjs';
+import { collectAmbiguousCorridors, collectBorderRuns, collectLabelCanvasOverflow, collectLabelRouteClearance, collectRouteRhythmIssues, describeLabelCanvasOverflow, formatRect, routeBudgetMetrics } from '../renderers/shared/geometry.mjs';
import {
DESKTOP_READABILITY_VIEWPORT,
DESKTOP_READER_DIAGRAM_WIDTH,
@@ -189,17 +189,20 @@ if (svgMatches.length === 1) {
from: hit.start.map((value) => Math.round(value * 10) / 10),
to: hit.end.map((value) => Math.round(value * 10) / 10),
})),
- ...labelCanvasOverflow.map((hit) => ({
- severity: labelContainmentIsError ? 'error' : 'warning',
- code: 'composition/label-canvas-containment',
- label: hit.label?.label || hit.relation?.label || '',
- relationship: relationshipRecord(hit.relation),
- labelRect: roundedRect(hit.rect),
- viewBox: hit.viewBox,
- viewBoxOrigin: hit.viewBoxOrigin,
- overflowPx: hit.overflowPx,
- detail: `[composition/label-canvas-containment] ${qualityProfile} label "${hit.label?.label || hit.relation?.label || ''}" on ${relationshipName(hit.relation)} extends past the ${describeLabelCanvasOverflow(hit)} (label rect ${formatRectDetail(hit.rect)}; viewBox ${hit.viewBox[0]}x${hit.viewBox[1]}${hit.viewBoxOrigin.some(Boolean) ? ` at ${hit.viewBoxOrigin[0]},${hit.viewBoxOrigin[1]}` : ''}) — adjust labelAt, labelDx, labelDy, or labelSegment; otherwise enlarge meta.viewBox.`,
- })),
+ ...labelCanvasOverflow.map((hit) => {
+ const label = hit.label?.label || hit.relation?.label || '';
+ return {
+ severity: labelContainmentIsError ? 'error' : 'warning',
+ code: 'composition/label-canvas-containment',
+ label,
+ relationship: relationshipRecord(hit.relation),
+ labelRect: roundedRect(hit.rect),
+ viewBox: hit.viewBox,
+ viewBoxOrigin: hit.viewBoxOrigin,
+ overflowPx: hit.overflowPx,
+ detail: `[composition/label-canvas-containment] ${qualityProfile} label "${label}" on ${relationshipName(hit.relation)} extends past the ${describeLabelCanvasOverflow(hit)} (label rect ${formatRect(hit.rect)}; viewBox ${hit.viewBox[0]}x${hit.viewBox[1]}${hit.viewBoxOrigin.some(Boolean) ? ` at ${hit.viewBoxOrigin[0]},${hit.viewBoxOrigin[1]}` : ''}) — use renderer-supported label controls (shorten the label or reorder participants for sequence; otherwise labelAt, labelDx, labelDy, or labelSegment), or enlarge meta.viewBox.`,
+ };
+ }),
...relationshipCrossings.map((hit) => ({
severity: crossingIsError ? 'error' : 'warning',
code: 'composition/proper-crossing',
@@ -652,10 +655,6 @@ function viewBoxSize(svgAttrs) {
return viewBoxRect(svgAttrs).slice(2);
}
-function formatRectDetail(rect) {
- return `[${Math.round(rect.x)}, ${Math.round(rect.y)}, ${Math.round(rect.width)}, ${Math.round(rect.height)}]`;
-}
-
function collectDesktopReadability(svgAttrs, fragment) {
const [viewBoxWidth] = viewBoxSize(svgAttrs);
if (!Number.isFinite(viewBoxWidth) || viewBoxWidth <= 0) return null;
diff --git a/archify/test/geometry.test.mjs b/archify/test/geometry.test.mjs
index 737bc8c6..3cd1d273 100644
--- a/archify/test/geometry.test.mjs
+++ b/archify/test/geometry.test.mjs
@@ -843,12 +843,16 @@ test('suggestLabelObstacleFix keeps both two-line forms clear of the obstacle it
}
});
-test('suggestLabelObstacleFix reports when no in-canvas position clears the obstacle', () => {
+// Only the two vertical slots are tried, so the fallback must not claim that
+// no position exists anywhere — an open area elsewhere may still take the
+// label via labelAt.
+test('suggestLabelObstacleFix reports when neither vertical slot clears the obstacle', () => {
const labelRect = { x: 40, y: 30, width: 120, height: 14, label: 'commit' };
const obstacle = { id: 'store', x: 0, y: 0, width: 720, height: 400 };
const hint = suggestLabelObstacleFix(labelRect, 100, 40, obstacle, 'component', [720, 400]);
- assert.doesNotMatch(hint, /labelAt/);
- assert.match(hint, /no position clears "store" inside the 720x400 viewBox/);
+ assert.doesNotMatch(hint, /set label/);
+ assert.match(hint, /no placement directly above or below "store" stays clear inside the 720x400 viewBox/);
+ assert.match(hint, /move the label to an open area with labelAt/);
});
test('suggestLabelObstacleFix offers no coordinate for a label wider than the canvas', () => {
@@ -856,7 +860,20 @@ test('suggestLabelObstacleFix offers no coordinate for a label wider than the ca
const obstacle = { id: 'api', x: 200, y: 180, width: 140, height: 54 };
const hint = suggestLabelObstacleFix(labelRect, 360, 200, obstacle, 'component', [720, 400]);
assert.doesNotMatch(hint, /labelAt|labelDx|labelDy/);
- assert.match(hint, /no position clears "api" inside the 720x400 viewBox — shorten the label/);
+ assert.match(hint, /800px label rect cannot fit the 720x400 viewBox at any anchor — shorten the label/);
+});
+
+// A placement that merely trades the named obstacle for its neighbor fails the
+// same rule on re-render, so the filter takes every box the caller checks.
+test('suggestLabelObstacleFix keeps placements clear of the other supplied obstacles', () => {
+ const labelRect = { x: 310, y: 100, width: 120, height: 14, label: 'check' };
+ const named = { id: 'a', x: 300, y: 80, width: 140, height: 50 };
+ const neighborBelow = { id: 'b', x: 300, y: 140, width: 140, height: 50 };
+ const hint = suggestLabelObstacleFix(
+ labelRect, 370, 110, named, 'component', [720, 400], [named, neighborBelow],
+ );
+ assert.doesNotMatch(hint, /\(below\)/, hint);
+ assert.match(hint, /set labelAt \[370, 72\][^;]*\(above\)/);
});
test('cleanLabelCanvasContainmentProblems names both edges a corner overhang crosses and stays off standard', () => {
diff --git a/archify/test/layout-rules.test.mjs b/archify/test/layout-rules.test.mjs
index 0e91ec29..e4d018ea 100644
--- a/archify/test/layout-rules.test.mjs
+++ b/archify/test/layout-rules.test.mjs
@@ -17,6 +17,7 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
+import { minimumReadableSourceTextPx } from '../renderers/shared/desktop-readability.mjs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const skillRoot = path.resolve(__dirname, '..');
@@ -1263,6 +1264,49 @@ test('architecture: an auto viewBox grows to contain a wide connection label', (
assert.match(pinned.stderr, /\[composition\/label-canvas-containment\]/);
});
+// Boundary-title fonts are resolved against the same width the canvas actually
+// renders into. When a connection label alone widens the auto canvas past the
+// desktop reader width, the title font must rise with it — otherwise validate
+// would pass an artifact the desktop-readability check rejects.
+test('architecture: label-driven canvas growth keeps boundary titles at the readability floor', () => {
+ const d = {
+ schema_version: 1,
+ diagram_type: 'architecture',
+ meta: { title: 'Label-grown canvas', quality_profile: 'showcase' },
+ boundaries: [{
+ kind: 'region',
+ label: 'Shared production tenant isolation and compliance perimeter for the primary region',
+ wraps: ['a', 'b', 'c'],
+ }],
+ components: [
+ { id: 'a', type: 'frontend', label: 'A', pos: [60, 160], size: [140, 54] },
+ { id: 'b', type: 'backend', label: 'B', pos: [480, 160], size: [140, 54] },
+ { id: 'c', type: 'backend', label: 'C', pos: [860, 160], size: [140, 54] },
+ { id: 'd', type: 'database', label: 'D', pos: [860, 320], size: [140, 54] },
+ ],
+ connections: [{
+ id: 'c-to-d',
+ from: 'c',
+ to: 'd',
+ label: 'streaming replication of the full transaction journal with retries',
+ labelAt: [1310, 300],
+ }],
+ };
+ const { code, stderr, outPath } = render('architecture', d);
+ assert.equal(code, 0, stderr);
+ const html = fs.readFileSync(outPath, 'utf8');
+ const [, width] = html.match(/viewBox="0 0 (\d+) (\d+)"/).map(Number);
+ assert.ok(width > 1395, `expected the label to grow the canvas past 1395px, got ${width}`);
+ const floor = minimumReadableSourceTextPx(width);
+ const fonts = [...html.matchAll(/data-boundary-label=""[^>]*font-size="([\d.]+)"/g)]
+ .map(([, size]) => Number(size));
+ assert.equal(fonts.length, 1, 'expected exactly one boundary title');
+ assert.ok(
+ fonts[0] + 1e-6 >= floor,
+ `boundary title font ${fonts[0]} is below the ${floor}px floor for the ${width}px canvas`,
+ );
+});
+
// The validator must not answer an off-canvas defect with another off-canvas
// coordinate: every suggested labelAt has to keep the whole label rect inside.
test('architecture: label obstacle fixes stay inside the viewBox', () => {
@@ -1289,7 +1333,7 @@ test('architecture: label obstacle fixes stay inside the viewBox', () => {
assert.ok(rect, `expected a label rect in stderr:\n${stderr}`);
const width = Number(rect[3]);
const height = Number(rect[4]);
- const suggestions = [...stderr.matchAll(/labelAt \[(-?\d+), (-?\d+)\]/g)].map(([, x, y]) => [Number(x), Number(y)]);
+ const suggestions = suggestedLabelAts(stderr);
assert.ok(suggestions.length > 0, `expected at least one labelAt suggestion:\n${stderr}`);
for (const [x, y] of suggestions) {
assert.ok(x - width / 2 >= 0 && x + width / 2 <= 720, `labelAt [${x}, ${y}] leaves the 720px canvas width (label width ${width})`);