singhn9 commited on
Commit
e16db89
Β·
verified Β·
1 Parent(s): 6a15124

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -212,6 +212,8 @@ const LOOPS = __LOOPS__;
212
 
213
  function draw() {
214
  const container = document.getElementById("arc-container");
 
 
215
  container.innerHTML = "";
216
 
217
  const w = Math.min(1200, container.clientWidth || 920);
@@ -253,10 +255,10 @@ function draw() {
253
  .enter()
254
  .append("g")
255
  .attr("transform", d => `translate(${d.x},${d.y})`)
256
- .style("pointer-events", "none"); // β˜… FIX ADDED
257
 
258
  //--------------------------------------------------------------------
259
- // CIRCLES β€” FIX #2: reenable pointer events on <circle>
260
  //--------------------------------------------------------------------
261
  nodeCircleGroup.append("circle")
262
  .attr("r", 16)
@@ -264,7 +266,7 @@ function draw() {
264
  .attr("stroke", "#222")
265
  .attr("stroke-width", 1)
266
  .style("cursor", "pointer")
267
- .style("pointer-events", "all"); // β˜… FIX ADDED
268
 
269
  //--------------------------------------------------------------------
270
  // ARC drawing (unchanged)
@@ -384,7 +386,7 @@ function draw() {
384
  }
385
 
386
  //--------------------------------------------------------------------
387
- // LABELS β€” FIX #3: enable pointer events
388
  //--------------------------------------------------------------------
389
  const labelGroup = svg.append("g")
390
  .attr("class", "node-labels")
@@ -402,11 +404,11 @@ function draw() {
402
  const deg = (d.angle * 180 / Math.PI);
403
  return (deg>-90 && deg<90) ? "start" : "end";
404
  })
405
- .style("pointer-events", "all") // β˜… FIX ADDED
406
  .text(d => d.abbrev);
407
 
408
  //--------------------------------------------------------------------
409
- // CLICK / HIGHLIGHT logic
410
  //--------------------------------------------------------------------
411
  function getConnections(nodeName){
412
  let buys = BUYS.filter(x=>x[0]===nodeName || x[1]===nodeName).map(x=>x[0]===nodeName?x[1]:x[0]);
@@ -462,12 +464,12 @@ function draw() {
462
  function showInfo(nodeName){
463
  const buys = BUYS.filter(x => x[0] === nodeName || x[1] === nodeName)
464
  .map(x => x[0] === nodeName ? x[1] : x[0]);
465
- const sells = SELLS.filter(x => x[0] === nodeName || x[1] === nodeName)
466
  .map(x => x[0] === nodeName ? x[1] : x[0]);
467
- const transfers = TRANSFERS.filter(x => x[0] === nodeName || x[1] === nodeName)
468
- .map(x => x[0] === nodeName ? x[1] : x[0]);
469
- const loops = LOOPS.filter(x => x[0] === nodeName || x[2] === nodeName)
470
- .map(x => x[0] === nodeName ? x[2] : x[0]);
471
 
472
  const box = document.getElementById("info-box");
473
  box.innerHTML = `
@@ -491,7 +493,7 @@ function draw() {
491
  }
492
 
493
  //--------------------------------------------------------------------
494
- // CLICK HANDLERS β€” working now
495
  //--------------------------------------------------------------------
496
  nodeCircleGroup.on("click", function(event, d){
497
  selectNode(d);
@@ -519,12 +521,13 @@ setTimeout(() => {
519
  clearTimeout(rz);
520
  rz = setTimeout(draw, 120);
521
  });
522
- }, 400); // β˜… delay enabling resize for 0.4 sec
523
 
524
  </script>
525
  """
526
 
527
 
 
528
  def make_arc_html(nodes, node_type, buys, sells, transfers, loops):
529
  nodes_json = json.dumps(nodes)
530
  node_type_json = json.dumps(node_type)
@@ -553,7 +556,7 @@ svg { font-family: sans-serif; }
553
 
554
  with gr.Blocks(css=responsive_css, title="MF Churn β€” Semi-layer Arc Diagram (L1 labels)") as demo:
555
  gr.Markdown("## Mutual Fund Churn β€” Weighted Arcs (BUY top / SELL bottom) β€” labels outside (L1)")
556
- gr.HTML(initial_html)
557
 
558
  gr.Markdown("### Inspect Company / AMC")
559
 
 
212
 
213
  function draw() {
214
  const container = document.getElementById("arc-container");
215
+
216
+ // β˜… FINAL FIX: always clear old SVG before drawing
217
  container.innerHTML = "";
218
 
219
  const w = Math.min(1200, container.clientWidth || 920);
 
255
  .enter()
256
  .append("g")
257
  .attr("transform", d => `translate(${d.x},${d.y})`)
258
+ .style("pointer-events", "none");
259
 
260
  //--------------------------------------------------------------------
261
+ // CIRCLES β€” FIX #2: re-enable pointer events
262
  //--------------------------------------------------------------------
263
  nodeCircleGroup.append("circle")
264
  .attr("r", 16)
 
266
  .attr("stroke", "#222")
267
  .attr("stroke-width", 1)
268
  .style("cursor", "pointer")
269
+ .style("pointer-events", "all");
270
 
271
  //--------------------------------------------------------------------
272
  // ARC drawing (unchanged)
 
386
  }
387
 
388
  //--------------------------------------------------------------------
389
+ // LABELS β€” FIX #3
390
  //--------------------------------------------------------------------
391
  const labelGroup = svg.append("g")
392
  .attr("class", "node-labels")
 
404
  const deg = (d.angle * 180 / Math.PI);
405
  return (deg>-90 && deg<90) ? "start" : "end";
406
  })
407
+ .style("pointer-events", "all")
408
  .text(d => d.abbrev);
409
 
410
  //--------------------------------------------------------------------
411
+ // CLICK / HIGHLIGHT logic (unchanged)
412
  //--------------------------------------------------------------------
413
  function getConnections(nodeName){
414
  let buys = BUYS.filter(x=>x[0]===nodeName || x[1]===nodeName).map(x=>x[0]===nodeName?x[1]:x[0]);
 
464
  function showInfo(nodeName){
465
  const buys = BUYS.filter(x => x[0] === nodeName || x[1] === nodeName)
466
  .map(x => x[0] === nodeName ? x[1] : x[0]);
467
+ const sells = SELLS.filter(x => x[0] === nodeName || x[1]===nodeName)
468
  .map(x => x[0] === nodeName ? x[1] : x[0]);
469
+ const transfers = TRANSFERS.filter(x => x[0]===nodeName || x[1]===nodeName)
470
+ .map(x => x[0]===nodeName ? x[1] : x[0]);
471
+ const loops = LOOPS.filter(x => x[0]===nodeName || x[2]===nodeName)
472
+ .map(x => x[0]===nodeName ? x[2] : x[0]);
473
 
474
  const box = document.getElementById("info-box");
475
  box.innerHTML = `
 
493
  }
494
 
495
  //--------------------------------------------------------------------
496
+ // CLICK HANDLERS
497
  //--------------------------------------------------------------------
498
  nodeCircleGroup.on("click", function(event, d){
499
  selectNode(d);
 
521
  clearTimeout(rz);
522
  rz = setTimeout(draw, 120);
523
  });
524
+ }, 400);
525
 
526
  </script>
527
  """
528
 
529
 
530
+
531
  def make_arc_html(nodes, node_type, buys, sells, transfers, loops):
532
  nodes_json = json.dumps(nodes)
533
  node_type_json = json.dumps(node_type)
 
556
 
557
  with gr.Blocks(css=responsive_css, title="MF Churn β€” Semi-layer Arc Diagram (L1 labels)") as demo:
558
  gr.Markdown("## Mutual Fund Churn β€” Weighted Arcs (BUY top / SELL bottom) β€” labels outside (L1)")
559
+ gr.HTML(initial_html,container=False)
560
 
561
  gr.Markdown("### Inspect Company / AMC")
562