singhn9 commited on
Commit
c54dd7e
·
verified ·
1 Parent(s): ccb99c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -15
app.py CHANGED
@@ -380,22 +380,35 @@ function draw() {
380
  });
381
  }
382
 
383
- function setOpacityFor(nodeName){
 
 
 
384
  nodeCircleGroup.selectAll("circle")
385
- .style("opacity", d => d.name===nodeName ? 1 : 0.18);
386
-
387
- labelGroup.style("opacity", d => d.name===nodeName?1:0.28);
388
-
389
- function isConn(p){
390
- return p.getAttribute("data-src")===nodeName ||
391
- p.getAttribute("data-tgt")===nodeName;
 
 
 
 
 
 
 
 
392
  }
393
-
394
  buyGroup.selectAll("path").style("opacity", function(){ return isConn(this)?0.98:0.06; });
395
  sellGroup.selectAll("path").style("opacity", function(){ return isConn(this)?0.98:0.06; });
396
  transferGroup.selectAll("path").style("opacity", function(){ return isConn(this)?0.98:0.06; });
 
397
  }
398
 
 
399
  function resetOpacity(){
400
  nodeCircleGroup.selectAll("circle").style("opacity",1);
401
  labelGroup.style("opacity",1);
@@ -408,14 +421,33 @@ function draw() {
408
  "<b>Click a node</b> to view details here.";
409
  }
410
 
411
- function showInfo(name){
412
- const con = [...getConnections(name)].sort();
413
- document.getElementById("info-box").innerHTML =
414
- `<b>${name}</b><br><br>
415
- <b>Connected nodes:</b><br>
416
- ${con.length?con.join(", "):"None"}`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
  }
418
 
 
419
  function selectNode(d){
420
  const name = d.name;
421
  setOpacityFor(name);
 
380
  });
381
  }
382
 
383
+ function setOpacityFor(nodeName) {
384
+ const connected = getConnections(nodeName);
385
+
386
+ // highlight circles
387
  nodeCircleGroup.selectAll("circle")
388
+ .style("opacity", d =>
389
+ d.name === nodeName || connected.has(d.name) ? 1 : 0.18
390
+ );
391
+
392
+ // highlight labels
393
+ labelGroup.style("opacity", d =>
394
+ d.name === nodeName || connected.has(d.name) ? 1 : 0.28
395
+ );
396
+
397
+ // highlight arcs
398
+ function isConn(path){
399
+ const src = path.getAttribute("data-src");
400
+ const tgt = path.getAttribute("data-tgt");
401
+ return src === nodeName || tgt === nodeName ||
402
+ connected.has(src) || connected.has(tgt);
403
  }
404
+
405
  buyGroup.selectAll("path").style("opacity", function(){ return isConn(this)?0.98:0.06; });
406
  sellGroup.selectAll("path").style("opacity", function(){ return isConn(this)?0.98:0.06; });
407
  transferGroup.selectAll("path").style("opacity", function(){ return isConn(this)?0.98:0.06; });
408
+ loopGroup.selectAll("path").style("opacity",0.95); // loops unchanged
409
  }
410
 
411
+
412
  function resetOpacity(){
413
  nodeCircleGroup.selectAll("circle").style("opacity",1);
414
  labelGroup.style("opacity",1);
 
421
  "<b>Click a node</b> to view details here.";
422
  }
423
 
424
+ function showInfo(nodeName) {
425
+ const buys = BUYS.filter(x => x[0] === nodeName || x[1] === nodeName)
426
+ .map(x => x[0] === nodeName ? x[1] : x[0]);
427
+
428
+ const sells = SELLS.filter(x => x[0] === nodeName || x[1] === nodeName)
429
+ .map(x => x[0] === nodeName ? x[1] : x[0]);
430
+
431
+ const transfers = TRANSFERS.filter(x => x[0] === nodeName || x[1] === nodeName)
432
+ .map(x => x[0] === nodeName ? x[1] : x[0]);
433
+
434
+ const loops = LOOPS.filter(x => x[0] === nodeName || x[2] === nodeName)
435
+ .map(x => x[0] === nodeName ? x[2] : x[0]);
436
+
437
+ const box = document.getElementById("info-box");
438
+
439
+ box.innerHTML = `
440
+ <div style="font-size:14px;"><b>${nodeName}</b></div>
441
+ <div style="margin-top:8px; font-size:13px;">
442
+ <b>Buys:</b> ${buys.length ? buys.join(", ") : "<span style='color:#777'>None</span>"}<br>
443
+ <b>Sells:</b> ${sells.length ? sells.join(", ") : "<span style='color:#777'>None</span>"}<br>
444
+ <b>Transfers:</b> ${transfers.length ? transfers.join(", ") : "<span style='color:#777'>None</span>"}<br>
445
+ <b>Loops:</b> ${loops.length ? loops.join(", ") : "<span style='color:#777'>None</span>"}
446
+ </div>
447
+ `;
448
  }
449
 
450
+
451
  function selectNode(d){
452
  const name = d.name;
453
  setOpacityFor(name);