merge parallel edges in graph visualization; update link representation to include combined types and max count

This commit is contained in:
ImBenji 2026-04-23 16:45:30 +01:00
parent e2e39f2836
commit 3c436b0992

View file

@ -1346,10 +1346,24 @@ function renderIntelGraph() {
// deep-copy so d3 doesnt mutate our stored arrays on re-render
const nodesCopy = nodes.map(n => ({ ...n }));
const linksCopy = links.map(l => ({
// merge parallel edges (same src+tgt pair) into one — concat labels, take max count
const edgeMap = new Map();
for (const l of links) {
const src = typeof l.source === 'object' ? l.source.key : l.source;
const tgt = typeof l.target === 'object' ? l.target.key : l.target;
const key = `${src}||${tgt}`;
if (edgeMap.has(key)) {
const existing = edgeMap.get(key);
if (!existing.types.includes(l.type)) existing.types.push(l.type);
existing.count = Math.max(existing.count, l.count || 1);
} else {
edgeMap.set(key, { source: src, target: tgt, types: [l.type], count: l.count || 1 });
}
}
const linksCopy = Array.from(edgeMap.values()).map(l => ({
...l,
source: typeof l.source === 'object' ? l.source.key : l.source,
target: typeof l.target === 'object' ? l.target.key : l.target,
type: l.types.join(' · '),
}));
const svgEl = document.getElementById('intel-graph-svg');