fix: update search to highlight matching nodes in yellow and neighbors in gray

- Search now highlights matching nodes in yellow (#ffff00)
- All neighbor nodes (any degree) are shown in gray (#808080)
- Fixed reanimate button to use correct node object references
- Restores original colors when search is cleared
- All reachable nodes from search remain at full opacity

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
nvaldez
2026-09-28 16:26:54 +02:00
parent 6dcae18033
commit 781ac7ca8f
+36 -21
View File
@@ -710,16 +710,28 @@
// Search/filter functionality
let filteredNodeIds = null;
let showOrphans = true;
let originalColors = new Map();
let searchActive = false;
// Store original colors for all nodes
nodeData.forEach(n => {
originalColors.set(n.id, getNodeColor(n));
});
document.getElementById('search-input').addEventListener('input', function(e) {
const searchTerm = e.target.value.toLowerCase();
if (searchTerm === '') {
// Show all nodes
// Clear search - restore all
filteredNodeIds = null;
node.style('opacity', function(d) {
return visibleNodes.has(d.id) ? 1 : 0;
});
searchActive = false;
node
.style('opacity', function(d) {
return visibleNodes.has(d.id) ? 1 : 0;
})
.style('fill', function(d) {
return originalColors.get(d.id);
});
link.style('opacity', function(d) {
return visibleEdges.has(d.index) ? 1 : 0;
});
@@ -737,12 +749,14 @@
if (matchingNodeIds.size === 0) {
// No matches - hide all
filteredNodeIds = new Set();
searchActive = true;
node.style('opacity', 0);
link.style('opacity', 0);
return;
}
filteredNodeIds = matchingNodeIds;
searchActive = true;
// Build adjacency map for degree calculation
const adjacency = {};
@@ -783,15 +797,20 @@
}
// Update node and link visibility based on distance
node.style('opacity', function(d) {
if (!visibleNodes.has(d.id)) return 0;
const dist = distances[d.id];
if (dist === undefined) return 0; // Not reachable from matching nodes
if (dist <= 1) return 1; // Direct match or direct neighbor
if (dist === 2) return 0.5; // 2nd degree neighbor
if (dist === 3) return 0.3; // 3rd degree neighbor
return 0;
});
node
.style('opacity', function(d) {
if (!visibleNodes.has(d.id)) return 0;
const dist = distances[d.id];
if (dist === undefined) return 0; // Not reachable from matching nodes
return 1; // All reachable nodes are visible
})
.style('fill', function(d) {
if (!visibleNodes.has(d.id)) return originalColors.get(d.id);
const dist = distances[d.id];
if (dist === undefined) return '#ffffff'; // Not reachable - white (hidden)
if (dist === 0) return '#ffff00'; // Matching nodes - yellow highlight
return '#808080'; // All neighbors - gray
});
link.style('opacity', function(d) {
if (!visibleEdges.has(d.index)) return 0;
@@ -799,12 +818,7 @@
const sourceVisible = distances[d.source.id] !== undefined;
const targetVisible = distances[d.target.id] !== undefined;
if (sourceVisible && targetVisible) {
const sourceDist = distances[d.source.id];
const targetDist = distances[d.target.id];
// Edge opacity is minimum of its two nodes' opacities
const sourceOp = sourceDist <= 1 ? 1 : (sourceDist === 2 ? 0.5 : 0.3);
const targetOp = targetDist <= 1 ? 1 : (targetDist === 2 ? 0.5 : 0.3);
return Math.min(sourceOp, targetOp);
return 1; // Full opacity for edges between visible nodes
}
return 0;
});
@@ -970,8 +984,9 @@
setTimeout(() => {
links.forEach((linkItem, linkIndex) => {
const sourceNode = nodeData[linkItem.source.index];
const targetNode = nodeData[linkItem.target.index];
// linkItem.source and linkItem.target are node objects
const sourceNode = linkItem.source;
const targetNode = linkItem.target;
if (!visibleEdges.has(linkIndex) &&
visibleNodes.has(sourceNode.id) &&
visibleNodes.has(targetNode.id)) {