Skip to content

Commit

Permalink
🚧 update yvalue/yRange variables
Browse files Browse the repository at this point in the history
follow-up to 00add58
  • Loading branch information
victorlin committed Sep 13, 2024
1 parent f483c40 commit 8f3ff54
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/components/tree/phyloTree/layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@ export const setDistance = function setDistance(distanceAttribute) {
};

/**
* given nodes add y values (node.yvalue) to every node
* given nodes add y values (node.displayOrder) to every node
* Nodes are the phyloTree nodes (i.e. node.n is the redux node)
* Nodes must have parent child links established (via createChildrenAndParents)
* PhyloTree can subsequently use this information. Accessed by prototypes
* rectangularLayout, radialLayout, createChildrenAndParents
* side effects: node.n.yvalue (i.e. in the redux node) and node.yRange (i.e. in the phyloTree node)
* side effects: node.displayOrder and node.displayOrderRange (i.e. in the phyloTree node)
*/
export const calcYValues = (nodes, spacing = "even") => {
// console.log("calcYValues started with ", spacing);
Expand All @@ -321,13 +321,13 @@ export const calcYValues = (nodes, spacing = "even") => {
recurse(node.children[i]);
}
} else {
node.n.yvalue = calcY(node);
node.yRange = [node.n.yvalue, node.n.yvalue];
node.displayOrder = calcY(node);
node.displayOrderRange = [node.displayOrder, node.displayOrder];
return;
}
/* if here, then all children have yvalues, but we dont. */
node.n.yvalue = node.children.reduce((acc, d) => acc + d.n.yvalue, 0) / node.children.length;
node.yRange = [node.n.children[0].yvalue, node.n.children[node.n.children.length - 1].yvalue];
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];
};
recurse(nodes[0]);
};
Expand Down

0 comments on commit 8f3ff54

Please sign in to comment.