fix: Force-Graph zeigt nichts — Edges sind Index-basiert, nicht ID-basiert

Backend liefert edges als {a: 0, b: 1, sim: ...} mit Indizes in der
nodes-Liste. d3.forceLink mappt per id-Lookup und fand 'drucksache' als
Lookup-Key nicht. Folge: keine Links, Force-Sim degeneriert ohne Layout.

Fix: Index-Strings als id verwenden.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dotty Dotter 2026-05-06 22:11:16 +02:00
parent d72a6f30df
commit 60db39d5b3

View File

@ -285,15 +285,21 @@ function renderClusterGraph(cl) {
return map[f] || '#888'; return map[f] || '#888';
}; };
const nodes = rawNodes.map(n => ({ // Edges sind Index-basiert (a/b sind Positionen in rawNodes).
id: n.drucksache, // d3.forceLink mappt per id-Lookup → wir nutzen den Index als id-String.
const nodes = rawNodes.map((n, i) => ({
id: String(i),
drucksache: n.drucksache, drucksache: n.drucksache,
title: n.title || n.titel || n.drucksache, title: n.title || n.titel || n.drucksache,
bundesland: n.bundesland || '', bundesland: n.bundesland || '',
fraktion: (n.fraktionen && n.fraktionen[0]) || '', fraktion: (n.fraktionen && n.fraktionen[0]) || '',
score: n.gwoe_score != null ? parseFloat(n.gwoe_score) : 5, score: n.gwoe_score != null ? parseFloat(n.gwoe_score) : 5,
})); }));
const links = rawEdges.map(e => ({ source: e.a, target: e.b, sim: e.sim || 0.5 })); const links = rawEdges.map(e => ({
source: String(e.a),
target: String(e.b),
sim: e.sim || 0.5,
}));
const svg = d3.select(container).append('svg') const svg = d3.select(container).append('svg')
.attr('width', width).attr('height', height) .attr('width', width).attr('height', height)