(nodes: readonly { id: string }[], edges: readonly LoadEdge[])
| 5 | |
| 6 | /** Visual load counts distinct directed, typed lines, not aggregated calls or runtime traffic. */ |
| 7 | export function connectionLoad(nodes: readonly { id: string }[], edges: readonly LoadEdge[]): Map<string, ConnectionLoad> { |
| 8 | const links = new Map(nodes.map(node => [node.id, new Set<string>()])); |
| 9 | const neighbors = new Map(nodes.map(node => [node.id, new Set<string>()])); |
| 10 | for (const edge of edges) { |
| 11 | if (!links.has(edge.source) || !links.has(edge.target)) continue; |
| 12 | const types = new Set((edge.types?.length ? edge.types : [edge.type]).map(normalizeEdgeType)); |
| 13 | for (const type of types) { |
| 14 | const key = JSON.stringify([edge.source, edge.target, type]); |
| 15 | links.get(edge.source)!.add(key); links.get(edge.target)!.add(key); |
| 16 | } |
| 17 | if (edge.source !== edge.target) { |
| 18 | neighbors.get(edge.source)!.add(edge.target); neighbors.get(edge.target)!.add(edge.source); |
| 19 | } |
| 20 | } |
| 21 | const maximum = Math.max(0, ...[...links.values()].map(items => items.size)); |
| 22 | return new Map(nodes.map(node => { |
| 23 | const count = links.get(node.id)!.size; |
| 24 | return [node.id, { links: count, neighbors: neighbors.get(node.id)!.size, |
| 25 | strength: maximum ? Math.log1p(count) / Math.log1p(maximum) : 0 }]; |
| 26 | })); |
| 27 | } |
no test coverage detected