Skip to content

Commit 361e080

Browse files
committed
fix js
1 parent 55873f6 commit 361e080

1 file changed

Lines changed: 38 additions & 23 deletions

File tree

docs/enhanced_visualizer.js

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,29 +88,8 @@ document.addEventListener('DOMContentLoaded', function() {
8888
nodeReferences.set(node.id, { incoming: [], outgoing: [] });
8989
});
9090

91-
// Count references to each node
92-
graph.links.forEach(link => {
93-
// Increment the target's usage count
94-
const targetCount = nodeUsageCounts.get(link.target) || 0;
95-
nodeUsageCounts.set(link.target, targetCount + 1);
96-
97-
// Record the reference
98-
const sourceRefs = nodeReferences.get(link.source);
99-
if (sourceRefs) {
100-
sourceRefs.outgoing.push({
101-
id: link.target,
102-
type: link.type
103-
});
104-
}
105-
106-
const targetRefs = nodeReferences.get(link.target);
107-
if (targetRefs) {
108-
targetRefs.incoming.push({
109-
id: link.source,
110-
type: link.type
111-
});
112-
}
113-
});
91+
// Count references for each node
92+
countNodeReferences();
11493

11594
// Identify unused elements (methods and properties with no incoming references)
11695
graph.nodes.forEach(node => {
@@ -128,6 +107,42 @@ document.addEventListener('DOMContentLoaded', function() {
128107
});
129108
}
130109

110+
// Count references for each node
111+
function countNodeReferences() {
112+
// Reset counts
113+
graph.nodes.forEach(node => {
114+
nodeUsageCounts.set(node.id, 0);
115+
nodeReferences.set(node.id, { incoming: [], outgoing: [] });
116+
});
117+
118+
// Count references
119+
graph.links.forEach(link => {
120+
const sourceId = link.source.id || link.source;
121+
const targetId = link.target.id || link.target;
122+
123+
// Increment target's incoming count
124+
nodeUsageCounts.set(targetId, (nodeUsageCounts.get(targetId) || 0) + 1);
125+
126+
// Add to reference tracking
127+
if (nodeReferences.has(sourceId)) {
128+
nodeReferences.get(sourceId).outgoing.push(targetId);
129+
}
130+
131+
if (nodeReferences.has(targetId)) {
132+
nodeReferences.get(targetId).incoming.push(sourceId);
133+
}
134+
});
135+
136+
// Synchronize usage count with used flag
137+
// Any node with references should be marked as used
138+
graph.nodes.forEach(node => {
139+
const usageCount = nodeUsageCounts.get(node.id) || 0;
140+
if (usageCount > 0) {
141+
node.used = true;
142+
}
143+
});
144+
}
145+
131146
// Draw the graph using D3
132147
function drawGraph() {
133148
// Clear previous visualization

0 commit comments

Comments
 (0)