Skip to content

Commit

Permalink
🚧 add extra padding after last visible node
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin committed Oct 9, 2024
1 parent 9a2bdb4 commit a1ae090
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/components/tree/phyloTree/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,27 @@ function getDisplayOrderCallback(nodes, focus) {
*/
let displayOrder = 0;

/**
* Keep track of whether the previous node was selected
*/
let previousWasVisible;

if (focus) {
const nSelected = nodes.filter((d) => !d.hasChildren && d.visibility === NODE_VISIBLE).length;
const yPerSelected = (0.8 * nodes.length) / nSelected;
const yPerUnselected = (0.2 * nodes.length) / (nodes.length - nSelected);
const numVisible = nodes.filter((d) => !d.hasChildren && d.visibility === NODE_VISIBLE).length;
const yPerFocused = (0.8 * nodes.length) / numVisible;
const yPerUnfocused = (0.2 * nodes.length) / (nodes.length - numVisible);

return (node) => {
displayOrder += node.visibility === NODE_VISIBLE ? yPerSelected : yPerUnselected;
// Focus if the current node is visible or if the previous node was visible (for symmetric padding)
if (node.visibility === NODE_VISIBLE || previousWasVisible) {
displayOrder += yPerFocused;
} else {
displayOrder += yPerUnfocused;
}

// Update for the next node
previousWasVisible = node.visibility === NODE_VISIBLE;

return displayOrder;
};
} else {
Expand Down

0 comments on commit a1ae090

Please sign in to comment.