@euphrasiologist/lwphylo 1.2.13 → 1.2.16

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
  }
@@ -1183,6 +1236,29 @@ function drawPhylogeny(
1183
1236
  return { X0, Y0, X1s: X0 + dx * t, Y1s: Y0 + dy * t, len };
1184
1237
  }
1185
1238
 
1239
+ // put this next to your other radial helpers (top of file or in your lib)
1240
+ function arcPathCCW(cx, cy, R, a0, a1) {
1241
+ const TAU = Math.PI * 2;
1242
+ const norm = (t) => ((t % TAU) + TAU) % TAU;
1243
+
1244
+ a0 = norm(a0);
1245
+ a1 = norm(a1);
1246
+
1247
+ const delta = (a1 - a0 + TAU) % TAU; // CCW span a0 -> a1 in [0, 2π)
1248
+ if (delta < 1e-9) return ""; // degenerate; draw nothing
1249
+
1250
+ // With your polarToCartesian using y = cy - r*sin(t),
1251
+ // sweepFlag=0 gives a visually CCW arc segment.
1252
+ const largeArcFlag = delta > Math.PI ? 1 : 0;
1253
+ const sweepFlag = 0;
1254
+
1255
+ const p0 = polarToCartesian(cx, cy, R, a0);
1256
+ const p1 = polarToCartesian(cx, cy, R, a1);
1257
+
1258
+ return `M ${p0.x} ${p0.y} A ${R} ${R} 0 ${largeArcFlag} ${sweepFlag} ${p1.x} ${p1.y}`;
1259
+ }
1260
+
1261
+
1186
1262
  // ===== SVG ROOT =====
1187
1263
  const svg = d3__namespace
1188
1264
  .create("svg")
@@ -1224,7 +1300,6 @@ function drawPhylogeny(
1224
1300
  d.sweep
1225
1301
  )
1226
1302
  )
1227
-
1228
1303
  .attr("fill", "none")
1229
1304
  .attr("stroke", "#777")
1230
1305
  .attr("stroke-width", strokeWidth);
@@ -1403,9 +1478,7 @@ function drawPhylogeny(
1403
1478
  // ----- half-arc at parent radius (parent.angle → child.angle) -----
1404
1479
  const a = arcByChild.get(cur.thisId);
1405
1480
  if (a) {
1406
- const pathD = (a.sweep == null)
1407
- ? describeArc(centerX, centerY, radiusPx(a.radius), a.start, a.end)
1408
- : describeArcSweep(centerX, centerY, radiusPx(a.radius), a.start, a.end, a.sweep);
1481
+ const pathD = arcPathCCW(centerX, centerY, radiusPx(a.radius), a.start, a.end);
1409
1482
 
1410
1483
  arcLayer
1411
1484
  .append("path")