hesamation commited on
Commit
fa01707
·
1 Parent(s): 5fc2d28

connections in right panel are color coded

Browse files
Files changed (2) hide show
  1. css/style.css +16 -0
  2. js/main.js +132 -13
css/style.css CHANGED
@@ -181,6 +181,22 @@ canvas#sigma_bg_1 {
181
  list-style: none;
182
  }
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  #attributepane .p {
185
  padding-top: 10px;
186
  font-weight: bold;
 
181
  list-style: none;
182
  }
183
 
184
+ #attributepane .link li.connection-type-header {
185
+ margin-top: 12px;
186
+ margin-bottom: 6px;
187
+ font-weight: bold;
188
+ border-bottom: 1px solid rgba(0, 0, 0, 0.1);
189
+ padding-bottom: 3px;
190
+ }
191
+
192
+ #attributepane .link li a {
193
+ text-decoration: none;
194
+ }
195
+
196
+ #attributepane .link li a:hover {
197
+ text-decoration: underline;
198
+ }
199
+
200
  #attributepane .p {
201
  padding-top: 10px;
202
  font-weight: bold;
js/main.js CHANGED
@@ -163,6 +163,16 @@ function initializeGraph(data) {
163
  console.log("Adding nodes to sigma instance...");
164
  for (let i = 0; i < graph.nodes.length; i++) {
165
  let node = graph.nodes[i];
 
 
 
 
 
 
 
 
 
 
166
  let nodeColor = node.color || (node.type && config.nodeTypes && config.nodeTypes[node.type] ?
167
  config.nodeTypes[node.type].color : nodeTypes[node.type]?.color || '#666');
168
 
@@ -421,6 +431,14 @@ function nodeActive(nodeId) {
421
  return;
422
  }
423
 
 
 
 
 
 
 
 
 
424
  // Mark as in detail view
425
  sigmaInstance.detail = true;
426
 
@@ -431,7 +449,13 @@ function nodeActive(nodeId) {
431
  var neighbors = {};
432
  sigmaInstance.iterEdges(function(e) {
433
  if (e.source == nodeId || e.target == nodeId) {
434
- neighbors[e.source == nodeId ? e.target : e.source] = true;
 
 
 
 
 
 
435
  }
436
  });
437
 
@@ -565,6 +589,113 @@ function nodeActive(nodeId) {
565
  'visibility': 'visible',
566
  'opacity': '1'
567
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
 
569
  // Set the node name/title
570
  $('.nodeattributes .name').text(selected.label || selected.id);
@@ -614,18 +745,6 @@ function nodeActive(nodeId) {
614
  $('.nodeattributes .data').html(dataHTML);
615
 
616
  // Build connection list
617
- var connectionList = [];
618
- for (var id in neighbors) {
619
- var neighborNode = null;
620
- sigmaInstance.iterNodes(function(n) {
621
- if (n.id == id) neighborNode = n;
622
- });
623
-
624
- if (neighborNode) {
625
- connectionList.push('<li><a href="#" data-node-id="' + id + '">' + (neighborNode.label || id) + '</a></li>');
626
- }
627
- }
628
-
629
  $('.nodeattributes .link ul')
630
  .html(connectionList.length ? connectionList.join('') : '<li>No connections</li>')
631
  .css('display', 'block');
 
163
  console.log("Adding nodes to sigma instance...");
164
  for (let i = 0; i < graph.nodes.length; i++) {
165
  let node = graph.nodes[i];
166
+
167
+ // Try to detect node type if not already set
168
+ if (!node.type && node.id && node.id.includes('_')) {
169
+ const idParts = node.id.split('_');
170
+ if (idParts.length >= 2 && ['paper', 'author', 'organization'].includes(idParts[0])) {
171
+ node.type = idParts[0];
172
+ console.log(`Detected type from ID: ${node.id} → ${node.type}`);
173
+ }
174
+ }
175
+
176
  let nodeColor = node.color || (node.type && config.nodeTypes && config.nodeTypes[node.type] ?
177
  config.nodeTypes[node.type].color : nodeTypes[node.type]?.color || '#666');
178
 
 
431
  return;
432
  }
433
 
434
+ // Debug: Log the structure of the selected node to understand available properties
435
+ console.log("Selected node structure:", selected);
436
+ if (selected.id && selected.id.includes('_')) {
437
+ console.log("ID parts:", selected.id.split('_'));
438
+ }
439
+ console.log("Node type from property:", selected.type);
440
+ console.log("Node color:", selected.color);
441
+
442
  // Mark as in detail view
443
  sigmaInstance.detail = true;
444
 
 
449
  var neighbors = {};
450
  sigmaInstance.iterEdges(function(e) {
451
  if (e.source == nodeId || e.target == nodeId) {
452
+ // Get ID of the neighbor node
453
+ const neighborId = e.source == nodeId ? e.target : e.source;
454
+ // Initialize the neighbor object if it doesn't exist
455
+ neighbors[neighborId] = neighbors[neighborId] || {};
456
+ // Store edge information if needed
457
+ neighbors[neighborId].edgeLabel = e.label || "";
458
+ neighbors[neighborId].edgeColor = e.color;
459
  }
460
  });
461
 
 
589
  'visibility': 'visible',
590
  'opacity': '1'
591
  });
592
+
593
+ // Collect neighbor node information for the information panel
594
+ sigmaInstance.iterNodes(function(n) {
595
+ if (neighbors[n.id]) {
596
+ neighbors[n.id].label = n.label || n.id;
597
+
598
+ // Determine node type using multiple methods
599
+ let nodeType = "unknown";
600
+
601
+ // Method 1: Direct type property
602
+ if (n.type) {
603
+ nodeType = n.type;
604
+ }
605
+ // Method 2: Parse from ID if it follows the format type_number
606
+ else if (n.id && n.id.includes('_')) {
607
+ const idParts = n.id.split('_');
608
+ if (idParts.length >= 2 && ['paper', 'author', 'organization'].includes(idParts[0])) {
609
+ nodeType = idParts[0];
610
+ }
611
+ }
612
+ // Method 3: Try to determine from color
613
+ else if (n.color) {
614
+ // Match the color to known node types
615
+ for (const type in config.nodeTypes) {
616
+ if (config.nodeTypes[type].color === n.color) {
617
+ nodeType = type;
618
+ break;
619
+ }
620
+ }
621
+ // Try with default node types if not found in config
622
+ if (nodeType === "unknown") {
623
+ for (const type in nodeTypes) {
624
+ if (nodeTypes[type].color === n.color) {
625
+ nodeType = type;
626
+ break;
627
+ }
628
+ }
629
+ }
630
+ }
631
+
632
+ neighbors[n.id].type = nodeType;
633
+ neighbors[n.id].color = n.color;
634
+ }
635
+ });
636
+
637
+ // Populate connection list
638
+ var connectionList = [];
639
+ // Group neighbors by type
640
+ var neighborsByType = {};
641
+
642
+ for (var id in neighbors) {
643
+ var neighbor = neighbors[id];
644
+ if (neighbor) {
645
+ // Initialize array for this type if it doesn't exist
646
+ neighborsByType[neighbor.type] = neighborsByType[neighbor.type] || [];
647
+ // Add this neighbor to its type group
648
+ neighborsByType[neighbor.type].push({
649
+ id: id,
650
+ label: neighbor.label || id,
651
+ color: neighbor.color
652
+ });
653
+ }
654
+ }
655
+
656
+ // For each type, add a header and then list the connections
657
+ // Sort types to have known types first, 'unknown' last
658
+ let sortedTypes = Object.keys(neighborsByType).sort((a, b) => {
659
+ if (a === 'unknown') return 1;
660
+ if (b === 'unknown') return -1;
661
+ return a.localeCompare(b);
662
+ });
663
+
664
+ sortedTypes.forEach(function(type) {
665
+ // Get the color for this type from config
666
+ var typeColor = config.nodeTypes && config.nodeTypes[type] ?
667
+ config.nodeTypes[type].color :
668
+ nodeTypes[type]?.color || '#666';
669
+
670
+ // Debug connection types
671
+ console.log(`Found ${neighborsByType[type].length} neighbors of type: ${type}`);
672
+
673
+ // Get a readable type name
674
+ let typeName = type;
675
+ if (type === 'unknown') {
676
+ typeName = 'Other Connections';
677
+ }
678
+
679
+ // Add a header for this type with appropriate styling
680
+ connectionList.push('<li class="connection-type-header" style="margin-top: 8px; margin-bottom: 5px; font-weight: bold; color: ' + typeColor + ';">' +
681
+ (type === 'unknown' ? typeName : typeName.charAt(0).toUpperCase() + typeName.slice(1) + 's') +
682
+ ' (' + neighborsByType[type].length + '):</li>');
683
+
684
+ // Add each connection of this type
685
+ neighborsByType[type].forEach(function(neighbor) {
686
+ // For unknown type connections, try to get a hint from the ID if available
687
+ let labelHint = '';
688
+ if (type === 'unknown' && neighbor.id && neighbor.id.includes('_')) {
689
+ const idParts = neighbor.id.split('_');
690
+ if (idParts.length >= 2) {
691
+ labelHint = ` (${idParts[0]})`;
692
+ }
693
+ }
694
+
695
+ connectionList.push('<li><a href="#" data-node-id="' + neighbor.id + '" style="color: ' + typeColor + ';">' +
696
+ neighbor.label + labelHint + '</a></li>');
697
+ });
698
+ });
699
 
700
  // Set the node name/title
701
  $('.nodeattributes .name').text(selected.label || selected.id);
 
745
  $('.nodeattributes .data').html(dataHTML);
746
 
747
  // Build connection list
 
 
 
 
 
 
 
 
 
 
 
 
748
  $('.nodeattributes .link ul')
749
  .html(connectionList.length ? connectionList.join('') : '<li>No connections</li>')
750
  .css('display', 'block');