@euphrasiologist/lwphylo 1.2.12 → 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.
- package/dist/drawPhylogeny.cjs +69 -21
- package/dist/drawPhylogeny.cjs.map +1 -1
- package/dist/drawPhylogeny.esm.js +69 -21
- package/dist/drawPhylogeny.esm.js.map +1 -1
- package/dist/drawPhylogeny.umd.js +1 -1
- package/dist/drawPhylogeny.umd.js.map +1 -1
- package/dist/index.cjs +69 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +69 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/drawPhylogeny.cjs
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -1115,6 +1168,10 @@ function drawPhylogeny(
|
|
|
1115
1168
|
|
|
1116
1169
|
return svg.node();
|
|
1117
1170
|
} else if (layout === "radial") {
|
|
1171
|
+
// RADIAL LAYOUT
|
|
1172
|
+
if (width !== height) {
|
|
1173
|
+
throw new Error("width and height must be the same for radial layout");
|
|
1174
|
+
}
|
|
1118
1175
|
const parsedTree = readTree(treeText);
|
|
1119
1176
|
const rad = radialLayout(parsedTree, {
|
|
1120
1177
|
angleStrategy: "fan",
|
|
@@ -1124,6 +1181,10 @@ function drawPhylogeny(
|
|
|
1124
1181
|
// ===== MODE =====
|
|
1125
1182
|
const TIP_MODE = radialMode; // "phylo" (shorten to original tips) or "outer" (project to one circle)
|
|
1126
1183
|
const isOuter = TIP_MODE === "outer";
|
|
1184
|
+
if (TIP_MODE !== "phylo" && TIP_MODE !== "outer") {
|
|
1185
|
+
throw new Error("radialMode must be either 'phylo' or 'outer'");
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1127
1188
|
|
|
1128
1189
|
// visuals (0 = let spokes reach the dots)
|
|
1129
1190
|
const DOT_R = 3;
|
|
@@ -1216,7 +1277,6 @@ function drawPhylogeny(
|
|
|
1216
1277
|
d.sweep
|
|
1217
1278
|
)
|
|
1218
1279
|
)
|
|
1219
|
-
|
|
1220
1280
|
.attr("fill", "none")
|
|
1221
1281
|
.attr("stroke", "#777")
|
|
1222
1282
|
.attr("stroke-width", strokeWidth);
|
|
@@ -1289,7 +1349,7 @@ function drawPhylogeny(
|
|
|
1289
1349
|
|
|
1290
1350
|
// maps for fast lookup on hover (childId → spoke / arc)
|
|
1291
1351
|
const spokeByChild = new Map(rad.radii.map((s) => [childIdOf(s), s]));
|
|
1292
|
-
const arcByChild = new Map(rad.child_arcs.map((a) => [a.childId, a]));
|
|
1352
|
+
const arcByChild = new Map((rad.child_arcs ?? []).map((a) => [a.childId, a]));
|
|
1293
1353
|
|
|
1294
1354
|
// ===== LABELS =====
|
|
1295
1355
|
// Labels — make them follow the tip position used by the current mode
|
|
@@ -1395,29 +1455,17 @@ function drawPhylogeny(
|
|
|
1395
1455
|
// ----- half-arc at parent radius (parent.angle → child.angle) -----
|
|
1396
1456
|
const a = arcByChild.get(cur.thisId);
|
|
1397
1457
|
if (a) {
|
|
1458
|
+
const pathD = (a.sweep == null)
|
|
1459
|
+
? describeArc(centerX, centerY, radiusPx(a.radius), a.start, a.end)
|
|
1460
|
+
: describeArcSweep(centerX, centerY, radiusPx(a.radius), a.start, a.end, a.sweep);
|
|
1461
|
+
|
|
1398
1462
|
arcLayer
|
|
1399
1463
|
.append("path")
|
|
1400
|
-
.attr("d",
|
|
1401
|
-
d.sweep == null
|
|
1402
|
-
? describeArc(
|
|
1403
|
-
centerX,
|
|
1404
|
-
centerY,
|
|
1405
|
-
radiusPx(d.radius),
|
|
1406
|
-
d.start,
|
|
1407
|
-
d.end
|
|
1408
|
-
)
|
|
1409
|
-
: describeArcSweep(
|
|
1410
|
-
centerX,
|
|
1411
|
-
centerY,
|
|
1412
|
-
radiusPx(d.radius),
|
|
1413
|
-
d.start,
|
|
1414
|
-
d.end,
|
|
1415
|
-
d.sweep
|
|
1416
|
-
)
|
|
1417
|
-
)
|
|
1464
|
+
.attr("d", pathD)
|
|
1418
1465
|
.attr("fill", "none")
|
|
1419
1466
|
.attr("stroke", stroke)
|
|
1420
1467
|
.attr("stroke-width", width);
|
|
1468
|
+
|
|
1421
1469
|
}
|
|
1422
1470
|
|
|
1423
1471
|
first = false;
|