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

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.5",
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,
@@ -655,6 +655,7 @@ export class ImmutableTree implements Tree, TaxonSetInterface {
655
655
  };
656
656
  newNodes.push(newNode);
657
657
  draft._data.nodes.allNodes.push(newNode);
658
+ draft._data.nodeToTaxon.length = number + i + 1; // add an empty elements for the new nodes
658
659
  }
659
660
  }),
660
661
  nodes: newNodes,
@@ -1200,6 +1201,24 @@ export function* preOrderIterator(
1200
1201
  yield* traverse(node);
1201
1202
  }
1202
1203
 
1204
+ // we want to traverse the tree in a consistent order
1205
+ // this requires ignoring the root when we hit it.
1206
+ function stableNodeNumber(tree: Tree, a: NodeRef, node: NodeRef) {
1207
+ let num;
1208
+ if (tree.isRoot(a)) {
1209
+ num = min(
1210
+ tree.getChildren(a).filter((child) => child.number != node.number),
1211
+ (n) => n.number,
1212
+ );
1213
+ } else {
1214
+ num = a.number;
1215
+ }
1216
+ return unNullify(
1217
+ num,
1218
+ "There was an error finding the path through the root. check the children",
1219
+ );
1220
+ }
1221
+
1203
1222
  type PseudoNode = NodeRef & {
1204
1223
  pseudoChildren: NodeRef[];
1205
1224
  pseudoLength: number | undefined;
@@ -1223,6 +1242,10 @@ export function* psuedoRootPostOrderIterator(
1223
1242
  const pseudoChildren = branches.filter((n) => n.number !== visited);
1224
1243
  const pseudoParent = branches.find((node) => node.number === visited);
1225
1244
  // branches.sort(sort);
1245
+ pseudoChildren.sort(
1246
+ (a, b) =>
1247
+ stableNodeNumber(tree, a, node) - stableNodeNumber(tree, b, node),
1248
+ );
1226
1249
  let pseudoLength = undefined;
1227
1250
  if (!tree.isRoot(node) && pseudoParent === tree.getParent(node)) {
1228
1251
  // the root will not have a parent
@@ -1264,9 +1287,13 @@ export function* psuedoRootPreOrderIterator(
1264
1287
  if (!tree.isRoot(node)) {
1265
1288
  branches.push(tree.getParent(node));
1266
1289
  }
1290
+
1267
1291
  const pseudoChildren = branches.filter((n) => n.number !== visited);
1268
1292
  const pseudoParent = branches.find((node) => node.number === visited);
1269
- // branches.sort(sort);
1293
+ pseudoChildren.sort(
1294
+ (a, b) =>
1295
+ stableNodeNumber(tree, a, node) - stableNodeNumber(tree, b, node),
1296
+ );
1270
1297
  let pseudoLength = undefined;
1271
1298
  if (!tree.isRoot(node) && pseudoParent === tree.getParent(node)) {
1272
1299
  // the root will not have a parent
@@ -1310,9 +1337,13 @@ export function* pseudoTipIterator(
1310
1337
  if (!tree.isRoot(node)) {
1311
1338
  branches.push(tree.getParent(node));
1312
1339
  }
1340
+ // branches.sort((a,b)=>a.number-b.number)
1313
1341
  const pseudoChildren = branches.filter((n) => n.number !== visited);
1314
1342
  const pseudoParent = branches.find((node) => node.number === visited);
1315
- // branches.sort(sort);
1343
+ pseudoChildren.sort(
1344
+ (a, b) =>
1345
+ stableNodeNumber(tree, a, node) - stableNodeNumber(tree, b, node),
1346
+ );
1316
1347
  let pseudoLength = undefined;
1317
1348
  if (!tree.isRoot(node) && pseudoParent === tree.getParent(node)) {
1318
1349
  // the root will not have a parent