@euphrasiologist/lwphylo 1.2.19 → 1.2.21

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.
package/dist/index.cjs CHANGED
@@ -586,6 +586,9 @@ function getChildArcsFan(pd) {
586
586
  const TAU = Math.PI * 2;
587
587
  const norm = (t) => ((t % TAU) + TAU) % TAU;
588
588
 
589
+ const ccwDelta = (a0, a1) => (a1 - a0 + TAU) % TAU;
590
+ const cwDelta = (a0, a1) => (a0 - a1 + TAU) % TAU;
591
+
589
592
  // Circular midpoint that travels CCW from a -> b by half the CCW span
590
593
  function midCCW(a, b) {
591
594
  const d = (b - a + TAU) % TAU; // CCW delta in [0, 2π)
@@ -631,20 +634,25 @@ function getChildArcsFan(pd) {
631
634
 
632
635
  for (let i = 0; i < N; i++) {
633
636
  const prev = A[(i - 1 + N) % N];
634
- const cur = A[i];
637
+ const cur = A[i];
635
638
  const next = A[(i + 1) % N];
636
639
 
637
640
  // “fan” wedge around the child: midpoint(prev→cur) .. midpoint(cur→next), CCW
638
641
  const start = midCCW(prev.a, cur.a);
639
- const end = midCCW(cur.a, next.a);
642
+ const end = midCCW(cur.a, next.a);
643
+
644
+ // Choose the **shorter** sweep (0 = CCW, 1 = CW in our math-angle convention)
645
+ const ccw = ccwDelta(start, end);
646
+ const cw = cwDelta(start, end);
647
+ const sweep = ccw <= cw ? 0 : 1;
640
648
 
641
649
  child_arcs.push({
642
650
  parentId: pid,
643
- childId: cur.id,
651
+ childId: cur.id,
644
652
  radius,
645
653
  start,
646
654
  end,
647
- sweep: 0 // CCW (consistent with describeArcSweep and your y-flip)
655
+ sweep
648
656
  });
649
657
  }
650
658
  }
@@ -652,8 +660,6 @@ function getChildArcsFan(pd) {
652
660
  return child_arcs;
653
661
  }
654
662
 
655
- // src/radial/radialLayout.js
656
-
657
663
  /**
658
664
  * radialLayout(node, opts?)
659
665
  * opts:
@@ -699,7 +705,7 @@ function radialLayout(node, opts = {}) {
699
705
 
700
706
  // per-child arcs for half-arc highlighting if you already use them
701
707
  let child_arcs = [];
702
- if (opts.arcsStyle === "fan") {
708
+ if (arcsStyle === "fan") {
703
709
  child_arcs = getChildArcsFan(pd);
704
710
  } else {
705
711
  child_arcs = getChildArcs(pd);
@@ -1614,7 +1620,10 @@ function drawPhylogeny(
1614
1620
  lineLayer.selectAll("*").remove();
1615
1621
  arcLayer.selectAll("*").remove();
1616
1622
 
1617
- let cur = typeof target === "number" ? byId.get(target) : target;
1623
+ let cur = (typeof target === "number" || typeof target === "string")
1624
+ ? byId.get(target)
1625
+ : target;
1626
+
1618
1627
  if (!cur) return;
1619
1628
 
1620
1629
  let first = true;