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