Skip to content

Commit

Permalink
Update filters to hide ancestral nodes before last common ancestor
Browse files Browse the repository at this point in the history
Before this commit, filters determined visibility by:
1. Finding all terminal nodes in view window that match the filters and
mark them as visible.
2. Recursively marking all parent nodes of these terminal nodes visible,
all the way up to the root of the tree.

This commit adds an additional step to hide ancestral nodes before
the last common ancestor of visible terminal nodes. Starting from
the root of the tree, recursively hide each node if it does not have
more than one child node that is visible.
  • Loading branch information
joverlee521 committed Dec 19, 2020
1 parent 95dc21b commit 2332920
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/util/treeVisibilityHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ const makeParentVisible = (visArray, node) => {
makeParentVisible(visArray, node.parent);
};

/* Recursively hide nodes that do not have more than one child node in
* the param visArray.
* Relies on visArray having been updated by `makeParentVisible` */
const hideNodeIfOnlyOneChildVisible = (visArray, node) => {
if (!node.hasChildren) {
return; // Terminal node without children
}
const visibleChildren = node.children.filter((child) => visArray[child.arrayIdx]);
if (visibleChildren.length > 1) {
return; // This is the common ancestor of visible children
}
visArray[node.arrayIdx] = false;
visibleChildren.forEach((child) => hideNodeIfOnlyOneChildVisible(visArray, child));
};

/* calcVisibility
USES:
inView: attribute of phyloTree.nodes, but accessible through redux.tree.nodes[idx].shell.inView
Expand Down Expand Up @@ -154,6 +169,9 @@ export const calcVisibility = (tree, controls, dates) => {
for (let i = 0; i < idxsOfFilteredTips.length; i++) {
makeParentVisible(filtered, tree.nodes[idxsOfFilteredTips[i]]);
}
/* Recursivley hide ancestor nodes that are not the last common
* ancestor of selected nodes, starting from the root of the tree */
hideNodeIfOnlyOneChildVisible(filtered, tree.nodes[0]);
}
/* intersect the various arrays contributing to visibility */
const visibility = tree.nodes.map((node, idx) => {
Expand Down

0 comments on commit 2332920

Please sign in to comment.