@@ -1147,6 +1147,13 @@ document.addEventListener('DOMContentLoaded', function() {
11471147 function initializeFilters ( ) {
11481148 console . log ( "Initializing filters..." ) ;
11491149
1150+ // Make sure graph data is loaded
1151+ if ( ! graph || ! graph . nodes || graph . nodes . length === 0 ) {
1152+ console . error ( "Cannot initialize filters - graph data not loaded yet" ) ;
1153+ setTimeout ( initializeFilters , 500 ) ; // Retry after delay
1154+ return ;
1155+ }
1156+
11501157 // Extract all namespaces from the graph
11511158 const namespaces = new Set ( ) ;
11521159
@@ -1169,6 +1176,9 @@ document.addEventListener('DOMContentLoaded', function() {
11691176
11701177 if ( namespaceNode ) {
11711178 namespaces . add ( namespaceNode . id ) ;
1179+ } else if ( potentialNamespace ) {
1180+ // Add the potential namespace even if it's not explicitly defined as a node
1181+ namespaces . add ( potentialNamespace ) ;
11721182 }
11731183 }
11741184 }
@@ -1185,6 +1195,11 @@ document.addEventListener('DOMContentLoaded', function() {
11851195 // Clear loading placeholder
11861196 namespaceFiltersContainer . innerHTML = '' ;
11871197
1198+ if ( sortedNamespaces . length === 0 ) {
1199+ namespaceFiltersContainer . innerHTML = '<div class="no-data">No namespaces found</div>' ;
1200+ return ;
1201+ }
1202+
11881203 // Add "Select All" checkbox
11891204 const selectAllDiv = document . createElement ( 'div' ) ;
11901205 selectAllDiv . className = 'filter-item select-all' ;
@@ -1231,6 +1246,8 @@ document.addEventListener('DOMContentLoaded', function() {
12311246 namespaceFiltersContainer . appendChild ( div ) ;
12321247 } ) ;
12331248
1249+ console . log ( "Namespace filters initialized with" , sortedNamespaces . length , "namespaces" ) ;
1250+
12341251 // Set up event listeners for namespace filters
12351252 document . querySelectorAll ( '.namespace-filter' ) . forEach ( filter => {
12361253 filter . addEventListener ( 'change' , ( ) => {
@@ -1250,193 +1267,29 @@ document.addEventListener('DOMContentLoaded', function() {
12501267 } ) ;
12511268 applyFilters ( ) ;
12521269 } ) ;
1270+ } else {
1271+ console . error ( "Namespace filters container not found in DOM" ) ;
12531272 }
12541273 }
1255-
1256- // Update the "Select All" checkbox based on individual checkbox states
1274+
1275+ // Helper function to update the state of the "Select All" checkbox
12571276 function updateSelectAllCheckbox ( ) {
1258- const selectAllCheckbox = document . querySelector ( '.namespace-select-all' ) ;
12591277 const namespaceCheckboxes = document . querySelectorAll ( '.namespace-filter' ) ;
1278+ const selectAllCheckbox = document . querySelector ( '.namespace-select-all' ) ;
12601279
12611280 if ( selectAllCheckbox && namespaceCheckboxes . length > 0 ) {
1262- const allChecked = Array . from ( namespaceCheckboxes ) . every ( checkbox => checkbox . checked ) ;
1263- const someChecked = Array . from ( namespaceCheckboxes ) . some ( checkbox => checkbox . checked ) ;
1264-
1265- selectAllCheckbox . checked = allChecked ;
1266- selectAllCheckbox . indeterminate = ! allChecked && someChecked ;
1267- }
1268- }
1269-
1270- // Add CSS styles for proper visualization
1271- function addStyles ( ) {
1272- const styleElement = document . createElement ( 'style' ) ;
1273-
1274- styleElement . textContent = `
1275- /* Node styling */
1276- .node circle {
1277- stroke: #fff;
1278- stroke-width: 1.5px;
1279- }
1280-
1281- .node.selected circle {
1282- stroke: #ff0;
1283- stroke-width: 3px;
1284- }
1285-
1286- .node.hover circle {
1287- stroke: #f80;
1288- stroke-width: 2px;
1289- }
1290-
1291- .node text {
1292- font-family: sans-serif;
1293- font-size: 10px;
1294- pointer-events: none;
1295- text-shadow: 0 1px 0 #000, 1px 0 0 #000, 0 -1px 0 #000, -1px 0 0 #000;
1296- fill: white;
1297- }
1298-
1299- /* Link styling */
1300- .link {
1301- stroke-opacity: 0.6;
1302- }
1303-
1304- /* Highlighting */
1305- .node.highlighted circle {
1306- stroke: #ff0;
1307- stroke-width: 3px;
1308- }
1309-
1310- .node.connected circle {
1311- stroke: #f80;
1312- stroke-width: 2px;
1313- }
1314-
1315- .node.faded {
1316- opacity: 0.3;
1317- }
1318-
1319- .link.faded {
1320- opacity: 0.1;
1321- }
1322-
1323- .link.highlighted {
1324- stroke-width: 3px;
1325- stroke-opacity: 1;
1326- }
1327-
1328- /* Detail panel additional styling */
1329- .node-info {
1330- margin-bottom: 20px;
1331- border: 1px solid #ddd;
1332- padding: 10px;
1333- border-radius: 4px;
1334- background: #f8f8f8;
1335- }
1336-
1337- .info-item {
1338- margin: 5px 0;
1339- display: flex;
1340- align-items: center;
1341- }
1342-
1343- .info-label {
1344- font-weight: bold;
1345- width: 80px;
1346- color: #555;
1347- }
1348-
1349- .info-value {
1350- flex: 1;
1351- }
1352-
1353- .connected-list {
1354- list-style: none;
1355- padding: 0;
1356- }
1357-
1358- .connected-item {
1359- padding: 8px;
1360- margin: 5px 0;
1361- border-radius: 4px;
1362- background: #f5f5f5;
1363- cursor: pointer;
1364- transition: background 0.2s;
1365- }
1366-
1367- .connected-item:hover {
1368- background: #e0e0e0;
1369- }
1370-
1371- .relation-type {
1372- font-weight: bold;
1373- margin-right: 5px;
1374- color: #666;
1375- }
1376-
1377- .node-name {
1378- color: #333;
1379- }
1380-
1381- .used {
1382- color: var(--used-color);
1383- }
1384-
1385- .unused {
1386- color: var(--unused-color);
1387- }
1388-
1389- /* Namespace filter styles */
1390- #namespace-filters {
1391- max-height: 200px;
1392- overflow-y: auto;
1393- margin-bottom: 15px;
1394- border: 1px solid #eee;
1395- border-radius: 4px;
1396- padding: 5px;
1397- }
1398-
1399- .loading-placeholder {
1400- font-style: italic;
1401- color: #999;
1402- text-align: center;
1403- padding: 10px;
1404- }
1405-
1406- .filter-item {
1407- margin: 5px 0;
1408- }
1409-
1410- .filter-item label {
1411- display: flex;
1412- align-items: center;
1413- }
1414-
1415- .select-all {
1416- font-weight: bold;
1417- border-bottom: 1px solid #eee;
1418- padding-bottom: 5px;
1419- margin-bottom: 8px;
1420- }
1421-
1422- /* Reset button styling */
1423- #reset-filters {
1424- margin-left: 10px;
1425- font-size: 0.7em;
1426- padding: 3px 8px;
1427- background: #f5f5f5;
1428- border: 1px solid #ddd;
1429- border-radius: 3px;
1430- cursor: pointer;
1431- transition: all 0.2s;
1432- }
1433-
1434- #reset-filters:hover {
1435- background: #e0e0e0;
1281+ const checkedCount = document . querySelectorAll ( '.namespace-filter:checked' ) . length ;
1282+
1283+ if ( checkedCount === 0 ) {
1284+ selectAllCheckbox . checked = false ;
1285+ selectAllCheckbox . indeterminate = false ;
1286+ } else if ( checkedCount === namespaceCheckboxes . length ) {
1287+ selectAllCheckbox . checked = true ;
1288+ selectAllCheckbox . indeterminate = false ;
1289+ } else {
1290+ selectAllCheckbox . indeterminate = true ;
14361291 }
1437- ` ;
1438-
1439- document . head . appendChild ( styleElement ) ;
1292+ }
14401293 }
14411294
14421295 // Initialize the visualization
0 commit comments