MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / cluster

Function cluster

ui/src/lib/steps-model.ts:844–874  ·  view source on GitHub ↗
(root: string)

Source from the content-addressed store, hash-verified

842 * for anything that leads on further.
843 */
844 const cluster = (root: string): { pos: Map<string, { x: number; line: number }>; lines: number; width: number } => {
845 const pos = new Map<string, { x: number; line: number }>();
846 let line = 0;
847 let width = 0;
848 const spread = (list: string[], left: number): void => {
849 if (list.length === 0) return;
850 let lx = left;
851 for (const id of list) {
852 const bw = widthOf(id);
853 if (lx > left && lx + bw - left > lineMax) {
854 line += 1;
855 lx = left;
856 }
857 pos.set(id, { x: lx, line });
858 width = Math.max(width, lx + bw);
859 lx += bw + NODE_GAP;
860 }
861 line += 1;
862 };
863 const place = (id: string, depth: number): void => {
864 const x = Math.min(depth, CLUSTER_DEPTH_MAX) * CLUSTER_INDENT;
865 pos.set(id, { x, line });
866 width = Math.max(width, x + widthOf(id));
867 line += 1;
868 const kids = kidsOf(id);
869 spread(kids.filter((k) => kidsOf(k).length === 0), x + CLUSTER_INDENT);
870 for (const hub of kids.filter((k) => kidsOf(k).length > 0)) place(hub, depth + 1);
871 };
872 place(root, 0);
873 return { pos, lines: line, width };
874 };
875
876 /** The steps that fire nothing, side by side — a screen's handlers are siblings, not a hierarchy. */
877 const flat = (list: string[]): { pos: Map<string, { x: number; line: number }>; lines: number; width: number } => {

Callers 1

layAtFunction · 0.85

Calls 1

placeFunction · 0.70

Tested by

no test coverage detected