hemsby commited on
Commit
86cd64f
·
1 Parent(s): 2d344b9

feat: click locks focus state — clicked node stays highlighted, rest muted

Browse files
Files changed (1) hide show
  1. build_network.py +24 -12
build_network.py CHANGED
@@ -396,11 +396,12 @@ function draw(id) {{
396
  document.getElementById('nodeCount').textContent = data.nodes.length;
397
  document.getElementById('edgeCount').textContent = data.edges.length;
398
 
399
- // Store original node styling for restore on blur
400
  var origNodes = {{}};
401
  nodesDS.forEach(function(n) {{
402
  origNodes[n.id] = {{ color: n.color, font: n.font, borderWidth: n.borderWidth }};
403
  }});
 
404
 
405
  var FADED = {{
406
  color: {{ background: '#f5f5f5', border: '#e0e0e0',
@@ -410,19 +411,16 @@ function draw(id) {{
410
  borderWidth: 1
411
  }};
412
 
413
- network.on('hoverNode', function(params) {{
414
- var hId = params.node;
415
- var connected = network.getConnectedNodes(hId);
416
- var connEdges = network.getConnectedEdges(hId);
417
-
418
  var nUp = [];
419
  nodesDS.forEach(function(n) {{
420
- if (n.id !== hId && connected.indexOf(n.id) === -1) {{
421
  nUp.push({{ id: n.id, color: FADED.color, font: FADED.font, borderWidth: FADED.borderWidth }});
422
  }}
423
  }});
424
  nodesDS.update(nUp);
425
-
426
  var eUp = [];
427
  edgesDS.forEach(function(e) {{
428
  if (connEdges.indexOf(e.id) === -1) {{
@@ -430,27 +428,41 @@ function draw(id) {{
430
  }}
431
  }});
432
  edgesDS.update(eUp);
433
- }});
434
 
435
- network.on('blurNode', function() {{
436
  var nUp = [];
437
  nodesDS.forEach(function(n) {{
438
  var o = origNodes[n.id];
439
  if (o) nUp.push({{ id: n.id, color: o.color, font: o.font, borderWidth: o.borderWidth }});
440
  }});
441
  nodesDS.update(nUp);
442
-
443
  var eUp = [];
444
  edgesDS.forEach(function(e) {{
445
  eUp.push({{ id: e.id, hidden: false }});
446
  }});
447
  edgesDS.update(eUp);
 
 
 
 
 
 
 
 
 
 
448
  }});
449
 
450
  network.on('click', function(params) {{
451
  if (params.nodes.length > 0) {{
452
- showProfile(params.nodes[0]);
 
 
 
453
  }} else {{
 
 
454
  closeProfile();
455
  }}
456
  }});
 
396
  document.getElementById('nodeCount').textContent = data.nodes.length;
397
  document.getElementById('edgeCount').textContent = data.edges.length;
398
 
399
+ // Store original node styling for restore
400
  var origNodes = {{}};
401
  nodesDS.forEach(function(n) {{
402
  origNodes[n.id] = {{ color: n.color, font: n.font, borderWidth: n.borderWidth }};
403
  }});
404
+ var clickedNode = null;
405
 
406
  var FADED = {{
407
  color: {{ background: '#f5f5f5', border: '#e0e0e0',
 
411
  borderWidth: 1
412
  }};
413
 
414
+ function applyFocus(nodeId) {{
415
+ var connected = network.getConnectedNodes(nodeId);
416
+ var connEdges = network.getConnectedEdges(nodeId);
 
 
417
  var nUp = [];
418
  nodesDS.forEach(function(n) {{
419
+ if (n.id !== nodeId && connected.indexOf(n.id) === -1) {{
420
  nUp.push({{ id: n.id, color: FADED.color, font: FADED.font, borderWidth: FADED.borderWidth }});
421
  }}
422
  }});
423
  nodesDS.update(nUp);
 
424
  var eUp = [];
425
  edgesDS.forEach(function(e) {{
426
  if (connEdges.indexOf(e.id) === -1) {{
 
428
  }}
429
  }});
430
  edgesDS.update(eUp);
431
+ }}
432
 
433
+ function clearFocus() {{
434
  var nUp = [];
435
  nodesDS.forEach(function(n) {{
436
  var o = origNodes[n.id];
437
  if (o) nUp.push({{ id: n.id, color: o.color, font: o.font, borderWidth: o.borderWidth }});
438
  }});
439
  nodesDS.update(nUp);
 
440
  var eUp = [];
441
  edgesDS.forEach(function(e) {{
442
  eUp.push({{ id: e.id, hidden: false }});
443
  }});
444
  edgesDS.update(eUp);
445
+ }}
446
+
447
+ network.on('hoverNode', function(params) {{
448
+ if (clickedNode) return;
449
+ applyFocus(params.node);
450
+ }});
451
+
452
+ network.on('blurNode', function() {{
453
+ if (clickedNode) return;
454
+ clearFocus();
455
  }});
456
 
457
  network.on('click', function(params) {{
458
  if (params.nodes.length > 0) {{
459
+ clickedNode = params.nodes[0];
460
+ clearFocus();
461
+ applyFocus(clickedNode);
462
+ showProfile(clickedNode);
463
  }} else {{
464
+ clickedNode = null;
465
+ clearFocus();
466
  closeProfile();
467
  }}
468
  }});