(nodes: readonly GraphNode[], edges: readonly GraphEdge[], roots: ReadonlySet<number>, discoveredLevels?: ReadonlyMap<number, number>)
| 92 | /** Deterministic concentric hop rings. Names within a folder stay adjacent; |
| 93 | * distances encode relationship depth, never runtime or architectural certainty. */ |
| 94 | export function arrangeScopedGraph(nodes: readonly GraphNode[], edges: readonly GraphEdge[], roots: ReadonlySet<number>, discoveredLevels?: ReadonlyMap<number, number>): GraphData { |
| 95 | const levels = new Map<number, number>(discoveredLevels); |
| 96 | roots.forEach(value => levels.set(value, 0)); |
| 97 | const adjacency = new Map<number, number[]>(); |
| 98 | for (const edge of edges) { |
| 99 | const from = adjacency.get(edge.source) ?? [], to = adjacency.get(edge.target) ?? []; |
| 100 | from.push(edge.target); to.push(edge.source); adjacency.set(edge.source, from); adjacency.set(edge.target, to); |
| 101 | } |
| 102 | const queue = [...roots]; |
| 103 | for (let at = 0; !discoveredLevels && at < queue.length; at++) for (const next of adjacency.get(queue[at]!) ?? []) { |
| 104 | if (levels.has(next)) continue; |
| 105 | levels.set(next, levels.get(queue[at]!)! + 1); queue.push(next); |
| 106 | } |
| 107 | const rings = new Map<number, GraphNode[]>(); |
| 108 | for (const node of nodes) { |
| 109 | const level = levels.get(node.id) ?? 0; |
| 110 | const ring = rings.get(level) ?? []; ring.push(node); rings.set(level, ring); |
| 111 | } |
| 112 | const arranged: GraphNode[] = []; |
| 113 | let radius = 0; |
| 114 | for (const [level, ring] of [...rings].sort(([a], [b]) => a - b)) { |
| 115 | ring.sort((a, b) => (a.file_path ?? '').localeCompare(b.file_path ?? '') || a.name.localeCompare(b.name) || a.id - b.id); |
| 116 | radius = level === 0 && ring.length === 1 ? 0 : Math.max(radius + 70, ring.length * 8 / Math.PI); |
| 117 | ring.forEach((node, index) => { |
| 118 | const angle = index / ring.length * Math.PI * 2; |
| 119 | arranged.push({ ...node, x: Math.cos(angle) * radius, y: Math.sin(angle) * radius, z: level * -18, |
| 120 | size: Math.min(5, Math.max(2, node.size)) }); |
| 121 | }); |
| 122 | } |
| 123 | return { nodes: arranged, edges: [...edges], total_nodes: arranged.length }; |
| 124 | } |
| 125 | |
| 126 | export async function loadGraphScope(project: string, scope: GraphScope, depth: number, direction: TraceDirection, |
| 127 | layout: GraphData | undefined, options: { fetch?: typeof globalThis.fetch; signal?: AbortSignal; client?: GraphQueryClient; previous?: ScopedGraph; edgeTypes?: readonly string[]; cache?: GraphNeighborhoodTransaction; |
no test coverage detected