@euphrasiologist/lwphylo 1.2.13 → 1.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -469,6 +469,54 @@ function getChildArcs(pd) {
469
469
  return arcs;
470
470
  }
471
471
 
472
+ function getChildArcsFan(pd) {
473
+ const TAU = Math.PI * 2;
474
+ const norm = (t) => ((t % TAU) + TAU) % TAU;
475
+
476
+ // Circular midpoint that travels CCW from a -> b by half the CCW span
477
+ function midCCW(a, b) {
478
+ const d = (b - a + TAU) % TAU; // CCW delta a->b in [0, 2π)
479
+ return norm(a + d / 2);
480
+ }
481
+
482
+ const byId = new Map(pd.map(d => [d.thisId, d]));
483
+ const childrenByParent = new Map(pd.map(d => [d.thisId, d.children || []]));
484
+
485
+ const child_arcs = [];
486
+
487
+ for (const parent of pd) {
488
+ const kids = childrenByParent.get(parent.thisId) || [];
489
+ if (kids.length < 2) continue;
490
+
491
+ // Sort children by angle (normalized) around the circle
492
+ const A = kids
493
+ .map(id => ({ id, a: norm(byId.get(id).angle) }))
494
+ .sort((u, v) => u.a - v.a);
495
+
496
+ const N = A.length;
497
+ for (let i = 0; i < N; i++) {
498
+ const prev = A[(i - 1 + N) % N];
499
+ const cur = A[i];
500
+ const next = A[(i + 1) % N];
501
+
502
+ // “fan” wedge around the child: midpoint(prev→cur) .. midpoint(cur→next)
503
+ const start = midCCW(prev.a, cur.a);
504
+ const end = midCCW(cur.a, next.a);
505
+
506
+ child_arcs.push({
507
+ parentId: parent.thisId,
508
+ childId: cur.id,
509
+ radius: parent.r, // IMPORTANT: draw at the PARENT circle
510
+ start,
511
+ end,
512
+ sweep: 0 // CCW (matches describeArcSweep usage)
513
+ });
514
+ }
515
+ }
516
+
517
+ return child_arcs;
518
+ }
519
+
472
520
  // src/radial/radialLayout.js
473
521
 
474
522
  /**
@@ -515,7 +563,12 @@ function radialLayout(node, opts = {}) {
515
563
  : getArcs(pd);
516
564
 
517
565
  // per-child arcs for half-arc highlighting if you already use them
518
- const child_arcs = getChildArcs(pd);
566
+ let child_arcs = [];
567
+ if (opts.arcsStyle === "fan") {
568
+ child_arcs = getChildArcsFan(pd);
569
+ } else {
570
+ child_arcs = getChildArcs(pd);
571
+ }
519
572
 
520
573
  return { data: pd, radii, arcs, child_arcs };
521
574
  }
@@ -1224,7 +1277,6 @@ function drawPhylogeny(
1224
1277
  d.sweep
1225
1278
  )
1226
1279
  )
1227
-
1228
1280
  .attr("fill", "none")
1229
1281
  .attr("stroke", "#777")
1230
1282
  .attr("stroke-width", strokeWidth);