refactor(stammbaum): extract computeViewBox() helper from buildLayout (#361)

@Felix + @Markus on PR #693: viewBox computation is self-contained
(reads only positions + the MIN/PAD constants). Lift it out so buildLayout
ends with a readable two-line orchestration.

Pure refactor under green tests — no behaviour change, no test diff.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-28 20:43:25 +02:00
parent 52e48a6b8c
commit 9bdd9fb3a5

View File

@@ -277,9 +277,19 @@ export function buildLayout(allNodes: PersonNodeDTO[], allEdges: RelationshipDTO
}
}
// Bounding box around the actual content, then expanded to MIN dimensions
// (so a single node doesn't get scaled up to fill the canvas). The viewBox
// is centered on the content.
const viewBox = computeViewBox(positions);
return { positions, generations, ...viewBox };
}
// Bounding box around the actual content, expanded to MIN dimensions (so a
// single node doesn't get scaled up to fill the canvas) and centered on the
// content's midpoint.
function computeViewBox(positions: Map<string, { x: number; y: number }>): {
viewX: number;
viewY: number;
viewW: number;
viewH: number;
} {
let minX = Infinity;
let minY = Infinity;
let maxX = -Infinity;
@@ -302,7 +312,7 @@ export function buildLayout(allNodes: PersonNodeDTO[], allEdges: RelationshipDTO
const viewH = Math.max(contentH + 2 * VIEWBOX_PAD, MIN_VIEWBOX_H);
const viewX = minX + contentW / 2 - viewW / 2;
const viewY = minY + contentH / 2 - viewH / 2;
return { positions, generations, viewX, viewY, viewW, viewH };
return { viewX, viewY, viewW, viewH };
}
// Two-stage rank assignment (#689):