From 80633a1f7971c674860294c774a80c2ae1501d60 Mon Sep 17 00:00:00 2001 From: james hadfield Date: Wed, 26 Feb 2020 12:03:18 +1300 Subject: [PATCH] Improve which branches we display labels for Auspice was build during a time when only "clade" and "aa" labels existed. We always showed labels for the former, and only showed the latter for branches with a large number of descendants. Auspice now supports different labels, and this commit makes it so that any non "aa" label is always displayed. "aa" labels are shown if the branch has any other labels defined or if there are enough descendants. --- src/components/tree/phyloTree/labels.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/components/tree/phyloTree/labels.js b/src/components/tree/phyloTree/labels.js index a4ff68e69..8e67935bc 100644 --- a/src/components/tree/phyloTree/labels.js +++ b/src/components/tree/phyloTree/labels.js @@ -69,19 +69,26 @@ 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} + * @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. */ const createBranchLabelVisibility = (key, layout, totalTipsInView) => { - if (key === "clade") return "visible"; + if (key !== "aa") return "visible"; const magicTipFractionToShowBranchLabel = 0.05; return (d) => { + if (layout !== "rect") { + return "hidden"; + } + /* if any other labelling is defined on the branch, then show AA mutations */ + if (Object.keys(d.n.branch_attrs.labels).filter((k) => k!=="aa").length) { + return "visible"; + } /* 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 && - layout === "rect" - ) { + if (d.n.tipCount > magicTipFractionToShowBranchLabel * totalTipsInView) { return "visible"; } return "hidden";