@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.
@@ -40,6 +40,21 @@ function describeArc(cx, cy, radius, startAngle, endAngle) {
40
40
  return `M ${p0.x} ${p0.y} A ${radius} ${radius} 0 ${largeArcFlag} ${sweepFlag} ${p1.x} ${p1.y}`;
41
41
  }
42
42
 
43
+ // src/radial/describeArcSweep.js
44
+ const TAU$1 = Math.PI * 2;
45
+ const norm$1 = (t) => ((t % TAU$1) + TAU$1) % TAU$1;
46
+
47
+ function describeArcSweep(cx, cy, r, a0, a1, sweep /*0=CCW,1=CW*/) {
48
+ const delta = sweep === 0 ? norm$1(a1 - a0) : norm$1(a0 - a1);
49
+ if (!(r > 0) || delta < 1e-9) return "";
50
+ const largeArcFlag = delta > Math.PI ? 1 : 0;
51
+
52
+ const x0 = cx + r * Math.cos(a0), y0 = cy - r * Math.sin(a0);
53
+ const x1 = cx + r * Math.cos(a1), y1 = cy - r * Math.sin(a1);
54
+
55
+ return `M ${x0} ${y0} A ${r} ${r} 0 ${largeArcFlag} ${sweep} ${x1} ${y1}`;
56
+ }
57
+
43
58
  /**
44
59
  * Recursive function for pre-order traversal of tree (returns array)
45
60
  */
@@ -918,7 +933,7 @@ function drawPhylogeny(
918
933
  const byId = new Map(horizontal.map((d) => [d.thisId, d]));
919
934
  const tipById = new Map(tips.map((d) => [d.thisId, d]));
920
935
  const tipByLabel = new Map(tips.map((d) => [d.thisLabel, d]));
921
- const rootToTip = makeRootToTipGetter(byId, { prefer: "x1" });
936
+ const rootToTip = makeRootToTipGetter(byId, { prefer: "x1" });
922
937
 
923
938
  const maxY = d3.max(horizontal, (d) => d.y1);
924
939
  const minY = d3.min(horizontal, (d) => d.y1);
@@ -1080,7 +1095,10 @@ function drawPhylogeny(
1080
1095
  return svg.node();
1081
1096
  } else if (layout === "radial") {
1082
1097
  const parsedTree = readTree(treeText);
1083
- const rad = radialLayout(parsedTree);
1098
+ const rad = radialLayout(parsedTree, {
1099
+ angleStrategy: "fan",
1100
+ arcsStyle: "fan"
1101
+ });
1084
1102
 
1085
1103
  // ===== MODE =====
1086
1104
  const TIP_MODE = radialMode; // "phylo" (shorten to original tips) or "outer" (project to one circle)
@@ -1106,6 +1124,7 @@ function drawPhylogeny(
1106
1124
  .scaleLinear()
1107
1125
  .domain([-scaleRadial, scaleRadial])
1108
1126
  .range([h, 0]);
1127
+
1109
1128
  const radiusPx = (r) => r * (w / (2 * scaleRadial));
1110
1129
 
1111
1130
  // ===== INDEXES / HELPERS =====
@@ -1290,7 +1309,7 @@ function drawPhylogeny(
1290
1309
 
1291
1310
  // label hover
1292
1311
  labels
1293
- .on("mouseenter", function(event, d) {
1312
+ .on("mouseenter", function(_event, d) {
1294
1313
  drawRadialPath(d, hoverLines, hoverArcs, hoverStroke, hoverWidth);
1295
1314
  d3.select(this).select("text").attr("font-weight", 600);
1296
1315
  })
@@ -1347,15 +1366,23 @@ function drawPhylogeny(
1347
1366
  if (a) {
1348
1367
  arcLayer
1349
1368
  .append("path")
1350
- .attr(
1351
- "d",
1352
- describeArc(
1353
- centerX,
1354
- centerY,
1355
- Math.max(0, radiusPx(a.radius)),
1356
- a.start,
1357
- a.end
1358
- )
1369
+ .attr("d", (d) =>
1370
+ d.sweep == null
1371
+ ? describeArc(
1372
+ centerX,
1373
+ centerY,
1374
+ radiusPx(d.radius),
1375
+ d.start,
1376
+ d.end
1377
+ )
1378
+ : describeArcSweep(
1379
+ centerX,
1380
+ centerY,
1381
+ radiusPx(d.radius),
1382
+ d.start,
1383
+ d.end,
1384
+ d.sweep
1385
+ )
1359
1386
  )
1360
1387
  .attr("fill", "none")
1361
1388
  .attr("stroke", stroke)