MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / packHierarchy

Function packHierarchy

graph-ui/src/architecture/semantic-graph.ts:213–236  ·  view source on GitHub ↗

Deterministic shelf packing; its inputs are source identity and hierarchy only.

(box: HierarchyBox)

Source from the content-addressed store, hash-verified

211
212/** Deterministic shelf packing; its inputs are source identity and hierarchy only. */
213function packHierarchy(box: HierarchyBox): void {
214 if (box.node) return;
215 const gap = 10;
216 const padding = box.level ? 12 : 0;
217 const labelEdge = box.level ? 16 : 0;
218 for (const child of box.children) packHierarchy(child);
219 const target = Math.max(24, ...box.children.map(child => child.width),
220 Math.sqrt(box.children.reduce((sum, child) => sum + (child.width + gap) * (child.depth + gap), 0)) * 1.2);
221 let x = 0; let z = 0; let rowDepth = 0; let width = 0;
222 for (const child of box.children) {
223 if (x > 0 && x + child.width > target) { x = 0; z += rowDepth + gap; rowDepth = 0; }
224 child.x = x + child.width / 2;
225 child.z = z + child.depth / 2;
226 width = Math.max(width, x + child.width);
227 rowDepth = Math.max(rowDepth, child.depth);
228 x += child.width + gap;
229 }
230 box.width = width + padding * 2;
231 box.depth = z + rowDepth + padding + labelEdge;
232 for (const child of box.children) {
233 child.x += padding - box.width / 2;
234 child.z += labelEdge - box.depth / 2;
235 }
236}
237
238/**
239 * Arrange candidates by actual source folders, never relation count or hotspot

Callers 1

layoutFolderHierarchyFunction · 0.85

Calls 1

reduceMethod · 0.80

Tested by

no test coverage detected