@euphrasiologist/lwphylo 1.2.9 → 1.2.11

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.
@@ -61,6 +61,21 @@ function describeArc(cx, cy, radius, startAngle, endAngle) {
61
61
  return `M ${p0.x} ${p0.y} A ${radius} ${radius} 0 ${largeArcFlag} ${sweepFlag} ${p1.x} ${p1.y}`;
62
62
  }
63
63
 
64
+ // src/radial/describeArcSweep.js
65
+ const TAU$1 = Math.PI * 2;
66
+ const norm$1 = (t) => ((t % TAU$1) + TAU$1) % TAU$1;
67
+
68
+ function describeArcSweep(cx, cy, r, a0, a1, sweep /*0=CCW,1=CW*/) {
69
+ const delta = sweep === 0 ? norm$1(a1 - a0) : norm$1(a0 - a1);
70
+ if (!(r > 0) || delta < 1e-9) return "";
71
+ const largeArcFlag = delta > Math.PI ? 1 : 0;
72
+
73
+ const x0 = cx + r * Math.cos(a0), y0 = cy - r * Math.sin(a0);
74
+ const x1 = cx + r * Math.cos(a1), y1 = cy - r * Math.sin(a1);
75
+
76
+ return `M ${x0} ${y0} A ${r} ${r} 0 ${largeArcFlag} ${sweep} ${x1} ${y1}`;
77
+ }
78
+
64
79
  /**
65
80
  * Recursive function for pre-order traversal of tree (returns array)
66
81
  */
@@ -939,7 +954,7 @@ function drawPhylogeny(
939
954
  const byId = new Map(horizontal.map((d) => [d.thisId, d]));
940
955
  const tipById = new Map(tips.map((d) => [d.thisId, d]));
941
956
  const tipByLabel = new Map(tips.map((d) => [d.thisLabel, d]));
942
- const rootToTip = makeRootToTipGetter(byId, { prefer: "x1" });
957
+ const rootToTip = makeRootToTipGetter(byId, { prefer: "x1" });
943
958
 
944
959
  const maxY = d3__namespace.max(horizontal, (d) => d.y1);
945
960
  const minY = d3__namespace.min(horizontal, (d) => d.y1);
@@ -1101,7 +1116,10 @@ function drawPhylogeny(
1101
1116
  return svg.node();
1102
1117
  } else if (layout === "radial") {
1103
1118
  const parsedTree = readTree(treeText);
1104
- const rad = radialLayout(parsedTree);
1119
+ const rad = radialLayout(parsedTree, {
1120
+ angleStrategy: "fan",
1121
+ arcsStyle: "fan"
1122
+ });
1105
1123
 
1106
1124
  // ===== MODE =====
1107
1125
  const TIP_MODE = radialMode; // "phylo" (shorten to original tips) or "outer" (project to one circle)
@@ -1127,6 +1145,7 @@ function drawPhylogeny(
1127
1145
  .scaleLinear()
1128
1146
  .domain([-scaleRadial, scaleRadial])
1129
1147
  .range([h, 0]);
1148
+
1130
1149
  const radiusPx = (r) => r * (w / (2 * scaleRadial));
1131
1150
 
1132
1151
  // ===== INDEXES / HELPERS =====
@@ -1311,7 +1330,7 @@ function drawPhylogeny(
1311
1330
 
1312
1331
  // label hover
1313
1332
  labels
1314
- .on("mouseenter", function(event, d) {
1333
+ .on("mouseenter", function(_event, d) {
1315
1334
  drawRadialPath(d, hoverLines, hoverArcs, hoverStroke, hoverWidth);
1316
1335
  d3__namespace.select(this).select("text").attr("font-weight", 600);
1317
1336
  })
@@ -1368,15 +1387,23 @@ function drawPhylogeny(
1368
1387
  if (a) {
1369
1388
  arcLayer
1370
1389
  .append("path")
1371
- .attr(
1372
- "d",
1373
- describeArc(
1374
- centerX,
1375
- centerY,
1376
- Math.max(0, radiusPx(a.radius)),
1377
- a.start,
1378
- a.end
1379
- )
1390
+ .attr("d", (d) =>
1391
+ d.sweep == null
1392
+ ? describeArc(
1393
+ centerX,
1394
+ centerY,
1395
+ radiusPx(d.radius),
1396
+ d.start,
1397
+ d.end
1398
+ )
1399
+ : describeArcSweep(
1400
+ centerX,
1401
+ centerY,
1402
+ radiusPx(d.radius),
1403
+ d.start,
1404
+ d.end,
1405
+ d.sweep
1406
+ )
1380
1407
  )
1381
1408
  .attr("fill", "none")
1382
1409
  .attr("stroke", stroke)