Skip to content

Commit

Permalink
Don't display branch labels for inactive branches
Browse files Browse the repository at this point in the history
Closes #1335
  • Loading branch information
jameshadfield committed Jul 9, 2021
1 parent 6fbd8eb commit 0254c77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/tree/phyloTree/change.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export const change = function change({
if (changeVisibility) {
/* check that visibility is not undefined */
/* in the future we also change the branch visibility (after skeleton merge) */
elemsToUpdate.add(".tip").add(".tipLabel");
elemsToUpdate.add(".tip").add(".tipLabel").add(".branchLabel");
svgPropsToUpdate.add("visibility").add("cursor");
nodePropsToModify.visibility = visibility;
}
Expand Down
32 changes: 15 additions & 17 deletions src/components/tree/phyloTree/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,24 @@ const branchLabelFontWeight = (key) => {
* @param {str} key e.g. "aa" or "clade"
* @param {str} layout
* @param {int} totalTipsInView visible tips also in view
* @return {func||str} Returns either a string ("visible") or a function.
* The function returned is handed nodes and returns either
* "visible" or "hidden". This function should only be
* provided nodes for which the label exists on that node.
* @return {func} Returns a function with 1 argument: the current node (branch).
* This fn will return "visible" or "hidden".
* NOTE: the fn should only be provided nodes which have a label.
*/
const createBranchLabelVisibility = (key, layout, totalTipsInView) => {
if (key !== "aa") return "visible";
const createBranchLabelVisibility = (key, layout, totalTipsInView) => (d) => {
if (d.visibility !== NODE_VISIBLE) return "hidden";
if (key!=="aa") return "visible";
const magicTipFractionToShowBranchLabel = 0.05;
return (d) => {
if (layout !== "rect") {
return "hidden";
}
/* if the number of _visible_ tips descending from this node are over the
magicTipFractionToShowBranchLabel (c/w the total numer of _visible_ and
_inView_ tips then display the label */
if (d.n.tipCount > magicTipFractionToShowBranchLabel * totalTipsInView) {
return "visible";
}
if (layout !== "rect") {
return "hidden";
};
}
/* if the number of _visible_ tips descending from this node are over the
magicTipFractionToShowBranchLabel (c/w the total number of _visible_ and
_inView_ tips then display the label */
if (d.n.tipCount > magicTipFractionToShowBranchLabel * totalTipsInView) {
return "visible";
}
return "hidden";
};

export const updateBranchLabels = function updateBranchLabels(dt) {
Expand Down

0 comments on commit 0254c77

Please sign in to comment.