@figtreejs/core 0.1.0-beta.3 → 0.1.0-beta.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@figtreejs/core",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "A react component library for phylogenetic visualization and app building",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,7 +21,7 @@ import { immerable, produce } from "immer";
21
21
  import type { Taxon, TaxonSetInterface } from "../taxa/taxon";
22
22
  import { TaxonSet } from "../taxa/taxon";
23
23
  import { format } from "d3-format";
24
- import { extent } from "d3-array";
24
+ import { extent, min } from "d3-array";
25
25
 
26
26
  import {
27
27
  MaybeType,
@@ -1200,6 +1200,24 @@ export function* preOrderIterator(
1200
1200
  yield* traverse(node);
1201
1201
  }
1202
1202
 
1203
+ // we want to traverse the tree in a consistent order
1204
+ // this requires ignoring the root when we hit it.
1205
+ function stableNodeNumber(tree: Tree, a: NodeRef, node: NodeRef) {
1206
+ let num;
1207
+ if (tree.isRoot(a)) {
1208
+ num = min(
1209
+ tree.getChildren(a).filter((child) => child.number != node.number),
1210
+ (n) => n.number,
1211
+ );
1212
+ } else {
1213
+ num = a.number;
1214
+ }
1215
+ return unNullify(
1216
+ num,
1217
+ "There was an error finding the path through the root. check the children",
1218
+ );
1219
+ }
1220
+
1203
1221
  type PseudoNode = NodeRef & {
1204
1222
  pseudoChildren: NodeRef[];
1205
1223
  pseudoLength: number | undefined;
@@ -1223,6 +1241,10 @@ export function* psuedoRootPostOrderIterator(
1223
1241
  const pseudoChildren = branches.filter((n) => n.number !== visited);
1224
1242
  const pseudoParent = branches.find((node) => node.number === visited);
1225
1243
  // branches.sort(sort);
1244
+ pseudoChildren.sort(
1245
+ (a, b) =>
1246
+ stableNodeNumber(tree, a, node) - stableNodeNumber(tree, b, node),
1247
+ );
1226
1248
  let pseudoLength = undefined;
1227
1249
  if (!tree.isRoot(node) && pseudoParent === tree.getParent(node)) {
1228
1250
  // the root will not have a parent
@@ -1264,9 +1286,13 @@ export function* psuedoRootPreOrderIterator(
1264
1286
  if (!tree.isRoot(node)) {
1265
1287
  branches.push(tree.getParent(node));
1266
1288
  }
1289
+
1267
1290
  const pseudoChildren = branches.filter((n) => n.number !== visited);
1268
1291
  const pseudoParent = branches.find((node) => node.number === visited);
1269
- // branches.sort(sort);
1292
+ pseudoChildren.sort(
1293
+ (a, b) =>
1294
+ stableNodeNumber(tree, a, node) - stableNodeNumber(tree, b, node),
1295
+ );
1270
1296
  let pseudoLength = undefined;
1271
1297
  if (!tree.isRoot(node) && pseudoParent === tree.getParent(node)) {
1272
1298
  // the root will not have a parent
@@ -1310,9 +1336,13 @@ export function* pseudoTipIterator(
1310
1336
  if (!tree.isRoot(node)) {
1311
1337
  branches.push(tree.getParent(node));
1312
1338
  }
1339
+ // branches.sort((a,b)=>a.number-b.number)
1313
1340
  const pseudoChildren = branches.filter((n) => n.number !== visited);
1314
1341
  const pseudoParent = branches.find((node) => node.number === visited);
1315
- // branches.sort(sort);
1342
+ pseudoChildren.sort(
1343
+ (a, b) =>
1344
+ stableNodeNumber(tree, a, node) - stableNodeNumber(tree, b, node),
1345
+ );
1316
1346
  let pseudoLength = undefined;
1317
1347
  if (!tree.isRoot(node) && pseudoParent === tree.getParent(node)) {
1318
1348
  // the root will not have a parent