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

Improve which branches we display labels for #908

Merged
merged 1 commit into from
Mar 4, 2020
Merged
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
19 changes: 13 additions & 6 deletions src/components/tree/phyloTree/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down