33 * This file loads all the required modules in the correct order
44 */
55
6+ // Global graph data
7+ let graph = { nodes : [ ] , links : [ ] } ;
8+ let graphData = { } ;
9+ let nodeMap = new Map ( ) ;
10+ let nodeUsageCounts = new Map ( ) ;
11+ let nodeRelationships = new Map ( ) ;
12+ let namespaces = new Set ( ) ;
13+
14+ // Module references
15+ let chartContainer ;
16+ let detailPanel ;
17+ let loadingOverlay ;
18+ let tooltip ;
19+ let filterContainer ;
20+
21+ // Global variables for visualization
22+ let svg ;
23+ let gContainer ;
24+ let zoomBehavior ;
25+ let simulation ;
26+ let currentLayout = 'force' ;
27+
628// Load the visualization modules sequentially with dynamic imports
729document . addEventListener ( 'DOMContentLoaded' , async function ( ) {
830 // Add dynamic script loading function
@@ -17,15 +39,86 @@ document.addEventListener('DOMContentLoaded', async function() {
1739 }
1840
1941 try {
42+ console . log ( 'C# Code Graph Visualizer starting...' ) ;
43+
44+ // Initialize UI references
45+ chartContainer = document . getElementById ( 'chart' ) ;
46+ detailPanel = document . getElementById ( 'detail-panel' ) ;
47+ loadingOverlay = document . getElementById ( 'loading-overlay' ) ;
48+ tooltip = document . getElementById ( 'tooltip' ) ;
49+ filterContainer = document . getElementById ( 'filters-container' ) ;
50+
51+ // Show loading overlay
52+ if ( loadingOverlay ) {
53+ console . log ( 'Showing loading overlay' ) ;
54+ loadingOverlay . style . display = 'flex' ;
55+ } else {
56+ console . error ( 'Loading overlay element not found!' ) ;
57+ }
58+
2059 // Load modules in the required order
60+ console . log ( 'Loading visualization modules...' ) ;
2161 await loadScript ( 'visualizer-data.js' ) ;
2262 await loadScript ( 'visualizer-styles.js' ) ;
2363 await loadScript ( 'visualizer-filters.js' ) ;
2464 await loadScript ( 'visualizer-ui.js' ) ;
2565 await loadScript ( 'visualizer-core.js' ) ;
2666
2767 console . log ( 'All visualization modules loaded successfully' ) ;
68+
69+ // Initialize the visualization manually since modules are loaded dynamically
70+ setTimeout ( ( ) => initVisualization ( ) , 100 ) ;
2871 } catch ( error ) {
2972 console . error ( 'Error loading visualization modules:' , error ) ;
73+
74+ // Hide loading overlay on error
75+ if ( loadingOverlay ) {
76+ loadingOverlay . style . display = 'none' ;
77+ }
78+
79+ // Show error to user
80+ alert ( 'Failed to load visualization: ' + error . message ) ;
3081 }
3182} ) ;
83+
84+ /**
85+ * Initialize the visualization
86+ */
87+ async function initVisualization ( ) {
88+ try {
89+ console . log ( 'Initializing visualization...' ) ;
90+
91+ // Load data
92+ await loadGraph ( ) ;
93+
94+ // Setup visualization components
95+ setupVisualization ( ) ;
96+
97+ // Initialize filters
98+ initializeFilters ( ) ;
99+
100+ // Add custom styles
101+ addStyles ( ) ;
102+
103+ // Setup event listeners for layout controls
104+ document . getElementById ( 'force-layout' ) . addEventListener ( 'click' , switchToForceDirectedLayout ) ;
105+ document . getElementById ( 'hierarchical-layout' ) . addEventListener ( 'click' , switchToHierarchicalLayout ) ;
106+ document . getElementById ( 'reset-zoom' ) . addEventListener ( 'click' , resetZoom ) ;
107+ document . getElementById ( 'reset-filters' ) . addEventListener ( 'click' , resetAllFilters ) ;
108+
109+ // Hide loading overlay when complete
110+ if ( loadingOverlay ) {
111+ loadingOverlay . style . display = 'none' ;
112+ console . log ( 'Visualization initialized successfully!' ) ;
113+ }
114+ } catch ( error ) {
115+ console . error ( 'Error initializing visualization:' , error ) ;
116+
117+ // Hide loading overlay on error
118+ if ( loadingOverlay ) {
119+ loadingOverlay . style . display = 'none' ;
120+ }
121+
122+ alert ( 'Failed to initialize visualization: ' + error . message ) ;
123+ }
124+ }
0 commit comments