From 0254c77a84d28c16a77f88fb7b1b020c0d47a991 Mon Sep 17 00:00:00 2001 From: James Hadfield Date: Fri, 9 Jul 2021 13:02:39 +1200 Subject: [PATCH] Don't display branch labels for inactive branches Closes https://github.com/nextstrain/auspice/issues/1335 --- src/components/tree/phyloTree/change.js | 2 +- src/components/tree/phyloTree/labels.js | 32 ++++++++++++------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/components/tree/phyloTree/change.js b/src/components/tree/phyloTree/change.js index 8369bb5ec..4fb9c4ce6 100644 --- a/src/components/tree/phyloTree/change.js +++ b/src/components/tree/phyloTree/change.js @@ -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; } diff --git a/src/components/tree/phyloTree/labels.js b/src/components/tree/phyloTree/labels.js index 4a93fa5cd..557404c2a 100644 --- a/src/components/tree/phyloTree/labels.js +++ b/src/components/tree/phyloTree/labels.js @@ -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) {