Skip to content

Commit eb9a836

Browse files
committed
upup
1 parent 8503dec commit eb9a836

1 file changed

Lines changed: 84 additions & 22 deletions

File tree

docs/enhanced_visualizer.js

Lines changed: 84 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ document.addEventListener('DOMContentLoaded', function() {
256256
.on('start', dragstarted)
257257
.on('drag', dragged)
258258
.on('end', dragended))
259-
.on('click', nodeClicked);
259+
.on('click', handleNodeClick);
260260

261261
// Add circles to nodes
262262
node.append('circle')
@@ -460,6 +460,55 @@ document.addEventListener('DOMContentLoaded', function() {
460460
return null;
461461
}
462462

463+
// Highlight connections for a selected node
464+
function highlightConnections(node) {
465+
// Reset previous highlights
466+
resetHighlights();
467+
468+
// Find all connected nodes (both incoming and outgoing)
469+
const connectedNodeIds = new Set();
470+
471+
// Add the links that go to or from the selected node
472+
graph.links.forEach(link => {
473+
const sourceId = typeof link.source === 'object' ? link.source.id : link.source;
474+
const targetId = typeof link.target === 'object' ? link.target.id : link.target;
475+
476+
if (sourceId === node.id) {
477+
connectedNodeIds.add(targetId);
478+
} else if (targetId === node.id) {
479+
connectedNodeIds.add(sourceId);
480+
}
481+
});
482+
483+
// Fade all nodes and links
484+
gContainer.selectAll('.node').classed('faded', true);
485+
gContainer.selectAll('.link').classed('faded', true);
486+
487+
// Highlight the selected node and its connections
488+
gContainer.select(`.node[data-id="${node.id}"]`).classed('faded', false).classed('highlighted', true);
489+
490+
// Highlight connected nodes
491+
connectedNodeIds.forEach(id => {
492+
gContainer.select(`.node[data-id="${id}"]`).classed('faded', false).classed('connected', true);
493+
});
494+
495+
// Highlight links between the selected node and its connections
496+
gContainer.selectAll('.link').each(function(d) {
497+
const sourceId = typeof d.source === 'object' ? d.source.id : d.source;
498+
const targetId = typeof d.target === 'object' ? d.target.id : d.target;
499+
500+
if (sourceId === node.id || targetId === node.id) {
501+
d3.select(this).classed('faded', false).classed('highlighted', true);
502+
}
503+
});
504+
}
505+
506+
// Reset all highlights
507+
function resetHighlights() {
508+
gContainer.selectAll('.node').classed('faded', false).classed('highlighted', false).classed('connected', false);
509+
gContainer.selectAll('.link').classed('faded', false).classed('highlighted', false);
510+
}
511+
463512
// Handle node mouse over event
464513
function handleNodeMouseOver(event, d) {
465514
const node = d3.select(this);
@@ -493,18 +542,20 @@ document.addEventListener('DOMContentLoaded', function() {
493542
}
494543

495544
// Handle node click event
496-
function handleNodeClick(event, d) {
497-
// Toggle selection
498-
if (selectedNode === d.id) {
499-
selectedNode = null;
500-
detailPanel.classList.remove('active');
501-
resetHighlights();
502-
} else {
503-
selectedNode = d.id;
504-
showNodeDetails(d);
505-
highlightConnections(d.id);
506-
detailPanel.classList.add('active');
507-
}
545+
function handleNodeClick(d) {
546+
// Clear previous selection
547+
gContainer.selectAll('.node.selected').classed('selected', false);
548+
549+
// Mark this node as selected
550+
d3.select(this).classed('selected', true);
551+
selectedNode = d;
552+
553+
// Highlight connected nodes
554+
highlightConnections(d);
555+
556+
// Show node details panel
557+
showNodeDetails(d);
558+
detailPanel.classList.add('active');
508559
}
509560

510561
// Show detailed information about a node
@@ -681,14 +732,6 @@ document.addEventListener('DOMContentLoaded', function() {
681732
// Reset previous highlights
682733
resetHighlights();
683734

684-
// Fade all nodes and links
685-
gContainer.selectAll('.node').classed('faded', true);
686-
gContainer.selectAll('.link').classed('faded', true);
687-
688-
// Highlight the selected node
689-
const selectedNodeEl = gContainer.select(`.node[data-id="${nodeId}"]`);
690-
selectedNodeEl.classed('faded', false).classed('highlight', true);
691-
692735
// Find connected nodes
693736
const connectedNodeIds = new Set();
694737
connectedNodeIds.add(nodeId);
@@ -700,6 +743,14 @@ document.addEventListener('DOMContentLoaded', function() {
700743
refs.outgoing.forEach(ref => connectedNodeIds.add(ref.id));
701744
}
702745

746+
// Fade all nodes and links
747+
gContainer.selectAll('.node').classed('faded', true);
748+
gContainer.selectAll('.link').classed('faded', true);
749+
750+
// Highlight the selected node
751+
const selectedNodeEl = gContainer.select(`.node[data-id="${nodeId}"]`);
752+
selectedNodeEl.classed('faded', false).classed('highlight', true);
753+
703754
// Highlight connected nodes
704755
connectedNodeIds.forEach(id => {
705756
gContainer.select(`.node[data-id="${id}"]`).classed('faded', false);
@@ -1004,7 +1055,18 @@ document.addEventListener('DOMContentLoaded', function() {
10041055
loadingOverlay.style.display = 'flex';
10051056

10061057
setTimeout(() => {
1007-
const stats = calculateStats();
1058+
const stats = {
1059+
namespaces: graph.nodes.filter(n => n.group === 'namespace').length,
1060+
classes: graph.nodes.filter(n => n.group === 'class').length,
1061+
methods: graph.nodes.filter(n => n.group === 'method').length,
1062+
properties: graph.nodes.filter(n => n.group === 'property').length,
1063+
variables: graph.nodes.filter(n => n.group === 'variable').length,
1064+
unused: graph.nodes.filter(n => !n.used).length,
1065+
external: graph.nodes.filter(n => n.isexternal).length,
1066+
internal: graph.nodes.filter(n => !n.isexternal).length,
1067+
total: graph.nodes.length
1068+
};
1069+
10081070
document.getElementById('namespace-count').textContent = stats.namespaces;
10091071
document.getElementById('class-count').textContent = stats.classes;
10101072
document.getElementById('method-count').textContent = stats.methods;

0 commit comments

Comments
 (0)