Fold large graphs
foldGraph answers what to collapse, never what the collapsed nodes should look like. Your renderer owns the resulting node IDs, dimensions, labels, and data.
import { foldGraph } from 'ego-graph/fold';
const plan = foldGraph(graph, { threshold: 10, expandedRoots: new Set(['important-branch']), isSatellite: (node) => node.type === 'shared-attribute', isStructural: (edge) => edge.type !== 'same-ip',});
for (const fold of plan.folds) { console.log(fold.rootId, fold.memberIds, fold.internalEdgeCount);}The shallowest branch whose total weight is greater than threshold folds first. Hold one fold open with expandedRoots and the rule applies again to its children, so nested drill-down works naturally.
plan.mergedEdges tells you which original edges are represented by each edge between folded stand-ins. plan.heldOpen returns qualifying roots that were deliberately expanded, which is useful for a “regroup” action.