Enhance MindMapVisualization functionality: Implement connection count updates for nodes upon data processing and fallback scenarios. Refactor connected node retrieval methods to improve safety and reliability by ensuring valid node IDs. Introduce a new method for checking links between nodes, enhancing overall robustness of the mind map visualization logic.
This commit is contained in:
@@ -477,6 +477,9 @@ class MindMapVisualization {
|
|||||||
this.nodes = processed.nodes;
|
this.nodes = processed.nodes;
|
||||||
this.links = processed.links;
|
this.links = processed.links;
|
||||||
|
|
||||||
|
// Verbindungszählungen aktualisieren
|
||||||
|
this.updateConnectionCounts();
|
||||||
|
|
||||||
// Visualisierung aktualisieren
|
// Visualisierung aktualisieren
|
||||||
this.updateVisualization();
|
this.updateVisualization();
|
||||||
|
|
||||||
@@ -492,6 +495,9 @@ class MindMapVisualization {
|
|||||||
this.nodes = this.defaultNodes;
|
this.nodes = this.defaultNodes;
|
||||||
this.links = this.defaultLinks;
|
this.links = this.defaultLinks;
|
||||||
|
|
||||||
|
// Verbindungszählungen auch für Fallback-Daten aktualisieren
|
||||||
|
this.updateConnectionCounts();
|
||||||
|
|
||||||
// Fehler anzeigen
|
// Fehler anzeigen
|
||||||
this.showError('Mindmap-Daten konnten nicht geladen werden. Verwende Standarddaten.');
|
this.showError('Mindmap-Daten konnten nicht geladen werden. Verwende Standarddaten.');
|
||||||
this.showFlash('Fehler beim Laden der Mindmap-Daten. Standarddaten werden angezeigt.', 'error');
|
this.showFlash('Fehler beim Laden der Mindmap-Daten. Standarddaten werden angezeigt.', 'error');
|
||||||
@@ -936,7 +942,7 @@ class MindMapVisualization {
|
|||||||
// Highlights für verbundene Nodes und Links hinzufügen
|
// Highlights für verbundene Nodes und Links hinzufügen
|
||||||
if (this.g) {
|
if (this.g) {
|
||||||
// Verbundene Nodes identifizieren
|
// Verbundene Nodes identifizieren
|
||||||
const connectedNodes = this.getConnectedNodes(d);
|
const connectedNodes = this.getConnectedNodesById(d.id);
|
||||||
const connectedNodeIds = connectedNodes.map(node => node.id);
|
const connectedNodeIds = connectedNodes.map(node => node.id);
|
||||||
|
|
||||||
// Alle Nodes etwas transparenter machen
|
// Alle Nodes etwas transparenter machen
|
||||||
@@ -1035,7 +1041,7 @@ class MindMapVisualization {
|
|||||||
}
|
}
|
||||||
// Falls ein Node ausgewählt ist, den Highlight-Status für diesen beibehalten
|
// Falls ein Node ausgewählt ist, den Highlight-Status für diesen beibehalten
|
||||||
else if (this.selectedNode && this.g) {
|
else if (this.selectedNode && this.g) {
|
||||||
const connectedNodes = this.getConnectedNodes(this.selectedNode);
|
const connectedNodes = this.getConnectedNodesById(this.selectedNode.id);
|
||||||
const connectedNodeIds = connectedNodes.map(node => node.id);
|
const connectedNodeIds = connectedNodes.map(node => node.id);
|
||||||
|
|
||||||
// Alle Nodes auf den richtigen Highlight-Status setzen
|
// Alle Nodes auf den richtigen Highlight-Status setzen
|
||||||
@@ -1101,24 +1107,88 @@ class MindMapVisualization {
|
|||||||
|
|
||||||
// Findet alle verbundenen Knoten zu einem gegebenen Knoten
|
// Findet alle verbundenen Knoten zu einem gegebenen Knoten
|
||||||
getConnectedNodes(node) {
|
getConnectedNodes(node) {
|
||||||
if (!this.links || !this.nodes) return [];
|
if (!this.links || !this.nodes || !node) return [];
|
||||||
|
|
||||||
|
// Sicherstellen, dass der Knoten eine ID hat
|
||||||
|
const nodeId = node.id || node;
|
||||||
|
|
||||||
return this.nodes.filter(n =>
|
return this.nodes.filter(n =>
|
||||||
this.links.some(link =>
|
this.links.some(link => {
|
||||||
(link.source.id === node.id && link.target.id === n.id) ||
|
const sourceId = link.source?.id || link.source;
|
||||||
(link.target.id === node.id && link.source.id === n.id)
|
const targetId = link.target?.id || link.target;
|
||||||
)
|
return (sourceId === nodeId && targetId === n.id) ||
|
||||||
|
(targetId === nodeId && sourceId === n.id);
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prüft, ob zwei Knoten verbunden sind
|
// Prüft, ob zwei Knoten verbunden sind
|
||||||
isConnected(a, b) {
|
isConnected(a, b) {
|
||||||
return this.links.some(link =>
|
if (!this.links || !a || !b) return false;
|
||||||
(link.source.id === a.id && link.target.id === b.id) ||
|
|
||||||
(link.target.id === a.id && link.source.id === b.id)
|
// Sicherstellen, dass die Knoten IDs haben
|
||||||
|
const aId = a.id || a;
|
||||||
|
const bId = b.id || b;
|
||||||
|
|
||||||
|
return this.links.some(link => {
|
||||||
|
const sourceId = link.source?.id || link.source;
|
||||||
|
const targetId = link.target?.id || link.target;
|
||||||
|
return (sourceId === aId && targetId === bId) ||
|
||||||
|
(targetId === aId && sourceId === bId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Überprüft, ob ein Link zwischen zwei Knoten existiert
|
||||||
|
hasLink(source, target) {
|
||||||
|
if (!this.links || !source || !target) return false;
|
||||||
|
|
||||||
|
// Sicherstellen, dass die Knoten IDs haben
|
||||||
|
const sourceId = source.id || source;
|
||||||
|
const targetId = target.id || target;
|
||||||
|
|
||||||
|
return this.links.some(link => {
|
||||||
|
const linkSourceId = link.source?.id || link.source;
|
||||||
|
const linkTargetId = link.target?.id || link.target;
|
||||||
|
return (linkSourceId === sourceId && linkTargetId === targetId) ||
|
||||||
|
(linkTargetId === sourceId && linkSourceId === targetId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sicherere Methode zum Abrufen verbundener Knoten, die Prüfungen enthält
|
||||||
|
getConnectedNodesById(nodeId) {
|
||||||
|
if (!this.links || !this.nodes || !nodeId) return [];
|
||||||
|
|
||||||
|
return this.nodes.filter(n =>
|
||||||
|
this.links.some(link => {
|
||||||
|
const sourceId = link.source.id || link.source;
|
||||||
|
const targetId = link.target.id || link.target;
|
||||||
|
return (sourceId === nodeId && targetId === n.id) ||
|
||||||
|
(targetId === nodeId && sourceId === n.id);
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Aktualisiert die Verbindungszählungen für alle Knoten
|
||||||
|
updateConnectionCounts() {
|
||||||
|
if (!this.nodes || !this.links) return;
|
||||||
|
|
||||||
|
// Für jeden Knoten die Anzahl der Verbindungen berechnen
|
||||||
|
this.nodes.forEach(node => {
|
||||||
|
// Sichere Methode, um verbundene Knoten zu zählen
|
||||||
|
const connectedNodes = this.nodes.filter(n =>
|
||||||
|
n.id !== node.id && this.links.some(link => {
|
||||||
|
const sourceId = link.source.id || link.source;
|
||||||
|
const targetId = link.target.id || link.target;
|
||||||
|
return (sourceId === node.id && targetId === n.id) ||
|
||||||
|
(targetId === node.id && sourceId === n.id);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
// Speichere die Anzahl als Eigenschaft des Knotens
|
||||||
|
node.connectionCount = connectedNodes.length;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Klick-Handler für Knoten
|
// Klick-Handler für Knoten
|
||||||
nodeClicked(event, d) {
|
nodeClicked(event, d) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user