Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update filters to hide ancestral nodes before last common ancestor #1248

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hideNodesAboveVisibleCommonAncestor = (visArray, node) => {
if (!node.hasChildren) {
return; // Terminal node without children
}
const visibleChildren = node.children.filter((child) => visArray[child.arrayIdx]);
if (visibleChildren.length > 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Beyond the scope of this PR, but this may be a good place to set some property / state defining the CA of the filtered tips, which will be needed for #1132, although dates will also have to be taken into account for that feature.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can try to tackle #1132 next in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be awesome. #1132 I think would add a whole bunch to usability.

return; // This is the common ancestor of visible children
}
visArray[node.arrayIdx] = false;
visibleChildren.forEach((child) => hideNodesAboveVisibleCommonAncestor(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 */
hideNodesAboveVisibleCommonAncestor(filtered, tree.nodes[0]);
}
/* intersect the various arrays contributing to visibility */
const visibility = tree.nodes.map((node, idx) => {
Expand Down