Skip to content

Commit

Permalink
🚧 update accessing of children
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin committed Sep 13, 2024
1 parent 8f3ff54 commit f962b47
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/components/tree/phyloTree/layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,19 @@ export const calcYValues = (nodes, spacing = "even") => {
}

const recurse = (node) => {
if (node.children) {
for (let i = node.children.length - 1; i >= 0; i--) {
recurse(node.children[i]);
const children = node.n.children; // (redux) tree node
if (children && children.length) {
for (let i = children.length - 1; i >= 0; i--) {
recurse(children[i].shell);
}
} else {
node.displayOrder = calcY(node);
node.displayOrderRange = [node.displayOrder, node.displayOrder];
return;
}
/* if here, then all children have yvalues, but we dont. */
node.displayOrder = node.children.reduce((acc, d) => acc + d.displayOrder, 0) / node.children.length;
node.displayOrderRange = [node.n.children[0].displayOrder, node.n.children[node.n.children.length - 1].displayOrder];
node.displayOrder = children.reduce((acc, d) => acc + d.displayOrder, 0) / children.length;
node.displayOrderRange = [children[0].displayOrder, children[children.length - 1].displayOrder];
};
recurse(nodes[0]);
};
Expand Down

0 comments on commit f962b47

Please sign in to comment.