@@ -25,65 +25,61 @@ document.addEventListener('DOMContentLoaded', function() {
2525
2626 // Initialize the visualization
2727 function init ( ) {
28- // Create SVG and container for the visualization
29- svg = d3 . select ( '#chart' )
30- . append ( 'svg' )
31- . attr ( 'width' , '100%' )
32- . attr ( 'height' , '100%' ) ;
28+ // Load data and set up the visualization
29+ loadGraph ( ) ;
30+ }
31+
32+ // Set up the visualization after data is loaded
33+ function setupVisualization ( ) {
34+ // Process data
35+ processData ( ) ;
3336
34- // Add a background rect to handle zoom events on empty space
35- svg . append ( 'rect' )
36- . attr ( 'width' , '100%' )
37- . attr ( 'height' , '100%' )
38- . attr ( 'fill' , 'transparent' ) ;
37+ // Calculate stats
38+ updateStats ( ) ;
3939
40- gContainer = svg . append ( 'g' )
41- . attr ( 'class' , 'everything' ) ;
40+ // Draw graph
41+ drawGraph ( ) ;
4242
43- // Setup zoom behavior
44- zoomBehavior = d3 . zoom ( )
45- . scaleExtent ( [ 0.1 , 10 ] )
46- . on ( 'zoom' , ( event ) => {
47- gContainer . attr ( 'transform' , event . transform ) ;
48- } ) ;
49-
50- svg . call ( zoomBehavior ) ;
51-
52- // Setup event listeners
43+ // Set up event listeners
5344 setupEventListeners ( ) ;
54-
55- // Load the data
56- loadData ( ) ;
5745 }
5846
59- // Load graph data from the JSON file
60- function loadData ( ) {
61- fetch ( 'graph.json' )
62- . then ( response => response . json ( ) )
63- . then ( data => {
64- graph = data ;
65- processData ( ) ;
66- drawGraph ( ) ;
67- hideLoading ( ) ;
68- updateStatistics ( ) ;
69- } )
70- . catch ( err => {
71- console . error ( "Error loading graph data:" , err ) ;
72- hideLoading ( ) ;
73- alert ( "Failed to load graph data. Please check the console for details." ) ;
47+ // Load graph data
48+ function loadGraph ( ) {
49+ d3 . json ( 'graph.json' ) . then ( data => {
50+ // Store the data
51+ graph = data ;
52+
53+ // Ensure all nodes have the required properties
54+ graph . nodes . forEach ( node => {
55+ // Make sure all properties exist
56+ node . group = node . group || '' ;
57+ node . label = node . label || '' ;
58+ node . id = node . id || '' ;
59+ node . used = node . used || false ;
60+
61+ // Convert isexternal from string to boolean if needed
62+ // This handles potential issues with JSON serialization
63+ if ( typeof node . isexternal === 'string' ) {
64+ node . isexternal = node . isexternal . toLowerCase ( ) === 'true' ;
65+ } else {
66+ node . isexternal = Boolean ( node . isexternal ) ;
67+ }
68+
69+ console . log ( `Node ${ node . id } : isexternal=${ node . isexternal } (type: ${ typeof node . isexternal } )` ) ;
7470 } ) ;
71+
72+ // Set up visualization
73+ setupVisualization ( ) ;
74+ } ) . catch ( error => {
75+ console . error ( 'Error loading graph data:' , error ) ;
76+ } ) ;
7577 }
7678
7779 // Process the data to analyze usage patterns
7880 function processData ( ) {
7981 // Initialize node usage counts
8082 graph . nodes . forEach ( node => {
81- node . group = node . group || '' ;
82- node . label = node . label || '' ;
83- node . id = node . id || '' ;
84- node . used = node . used || false ;
85- node . isexternal = node . isexternal || false ; // Lowercase to match JSON naming
86-
8783 nodeUsageCounts . set ( node . id , 0 ) ;
8884 nodeReferences . set ( node . id , { incoming : [ ] , outgoing : [ ] } ) ;
8985 } ) ;
@@ -146,7 +142,31 @@ document.addEventListener('DOMContentLoaded', function() {
146142 // Draw the graph using D3
147143 function drawGraph ( ) {
148144 // Clear previous visualization
149- gContainer . selectAll ( '*' ) . remove ( ) ;
145+ d3 . select ( '#chart' ) . html ( '' ) ;
146+
147+ // Create SVG and container for the visualization
148+ svg = d3 . select ( '#chart' )
149+ . append ( 'svg' )
150+ . attr ( 'width' , '100%' )
151+ . attr ( 'height' , '100%' ) ;
152+
153+ // Add a background rect to handle zoom events on empty space
154+ svg . append ( 'rect' )
155+ . attr ( 'width' , '100%' )
156+ . attr ( 'height' , '100%' )
157+ . attr ( 'fill' , 'transparent' ) ;
158+
159+ gContainer = svg . append ( 'g' )
160+ . attr ( 'class' , 'everything' ) ;
161+
162+ // Setup zoom behavior
163+ zoomBehavior = d3 . zoom ( )
164+ . scaleExtent ( [ 0.1 , 10 ] )
165+ . on ( 'zoom' , ( event ) => {
166+ gContainer . attr ( 'transform' , event . transform ) ;
167+ } ) ;
168+
169+ svg . call ( zoomBehavior ) ;
150170
151171 // Get element and window sizes
152172 const width = chartContainer . clientWidth ;
@@ -828,6 +848,9 @@ document.addEventListener('DOMContentLoaded', function() {
828848 selectedNode = null ;
829849 resetHighlights ( ) ;
830850 } ) ;
851+
852+ // Initial call to apply filters
853+ applyFilters ( ) ;
831854 }
832855
833856 // Apply all filters
@@ -846,20 +869,40 @@ document.addEventListener('DOMContentLoaded', function() {
846869 const showInternal = document . getElementById ( 'filter-internal' ) . checked ;
847870 const showExternal = document . getElementById ( 'filter-external' ) . checked ;
848871
872+ console . log ( "Filters:" , { selectedGroups, showUsed, showUnused, showInternal, showExternal } ) ;
873+
849874 // Apply all filters together
850875 gContainer . selectAll ( '.node' )
851876 . style ( 'display' , function ( d ) {
852877 // Type filter
853- if ( ! selectedGroups . includes ( d . group ) ) return 'none' ;
878+ if ( ! selectedGroups . includes ( d . group ) ) {
879+ console . log ( `Node ${ d . id } hidden: group ${ d . group } not in selected groups` ) ;
880+ return 'none' ;
881+ }
854882
855883 // Usage filter
856- if ( d . used && ! showUsed ) return 'none' ;
857- if ( ! d . used && ! showUnused ) return 'none' ;
884+ if ( d . used && ! showUsed ) {
885+ console . log ( `Node ${ d . id } hidden: used but showUsed is false` ) ;
886+ return 'none' ;
887+ }
888+ if ( ! d . used && ! showUnused ) {
889+ console . log ( `Node ${ d . id } hidden: unused but showUnused is false` ) ;
890+ return 'none' ;
891+ }
892+
893+ // Library filter - debugging to find the issue
894+ console . log ( `Checking external for ${ d . id } : isexternal=${ d . isexternal } , showExternal=${ showExternal } , showInternal=${ showInternal } ` ) ;
858895
859- // Library filter
860- if ( d . isexternal && ! showExternal ) return 'none' ;
861- if ( ! d . isexternal && ! showInternal ) return 'none' ;
896+ if ( d . isexternal && ! showExternal ) {
897+ console . log ( `Node ${ d . id } hidden: external library` ) ;
898+ return 'none' ;
899+ }
900+ if ( ! d . isexternal && ! showInternal ) {
901+ console . log ( `Node ${ d . id } hidden: internal code` ) ;
902+ return 'none' ;
903+ }
862904
905+ console . log ( `Node ${ d . id } visible` ) ;
863906 return 'block' ;
864907 } ) ;
865908
0 commit comments