Skip to content

Commit

Permalink
Merge pull request #676 from nextstrain/hidden
Browse files Browse the repository at this point in the history
Allow tree nodes to be hidden
  • Loading branch information
jameshadfield authored Nov 1, 2018
2 parents 9ac4244 + 52f2aa4 commit a0c4ee8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/tree/phyloTree/change.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { calcConfidenceWidth } from "./confidence";
import { applyToChildren } from "./helpers";
import { timerStart, timerEnd } from "../../../util/perf";
import { NODE_VISIBLE } from "../../../util/globals";
import { getBranchVisibility } from "./renderers";

/* loop through the nodes and update each provided prop with the new value
* additionally, set d.update -> whether or not the node props changed
Expand Down Expand Up @@ -58,7 +59,8 @@ const svgSetters = {
".branch": {
stroke: (d) => d.branchStroke,
"stroke-width": (d) => d["stroke-width"] + "px", // style - as per drawBranches()
cursor: (d) => d.visibility === NODE_VISIBLE ? "pointer" : "default"
cursor: (d) => d.visibility === NODE_VISIBLE ? "pointer" : "default",
visibility: getBranchVisibility
}
}
};
Expand Down Expand Up @@ -298,11 +300,11 @@ export const change = function change({
nodePropsToModify["stroke-width"] = branchThickness;
}
if (newDistance || newLayout || zoomIntoClade || svgHasChangedDimensions) {
elemsToUpdate.add(".tip").add(".branch.S").add(".branch.T");
elemsToUpdate.add(".tip").add(".branch.S").add(".branch.T").add(".branch");
elemsToUpdate.add(".vaccineCross").add(".vaccineDottedLine").add(".conf");
elemsToUpdate.add('.branchLabel').add('.tipLabel');
elemsToUpdate.add(".grid").add(".regression");
svgPropsToUpdate.add("cx").add("cy").add("d").add("opacity");
svgPropsToUpdate.add("cx").add("cy").add("d").add("opacity").add("visibility");
}
if (newLayout) {
useModifySVGInStages = true;
Expand Down
19 changes: 19 additions & 0 deletions src/components/tree/phyloTree/renderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ export const drawTips = function drawTips() {
timerEnd("drawTips");
};

/**
* given a tree node, decide whether the branch should be rendered
* This enforces the "hidden" property set in the dataset JSON
* @return {string}
*/
export const getBranchVisibility = (d) => {
const hiddenSetting = d.n.hidden;
if (hiddenSetting &&
(
hiddenSetting === "always" ||
(hiddenSetting === "timetree" && d.that.distance === "num_date") ||
(hiddenSetting === "divtree" && d.that.distance === "div")
)
) {
return "hidden";
}
return "visible";
};

/**
* adds all branches to the svg, these are paths with class branch, which comprise two groups
Expand Down Expand Up @@ -167,6 +185,7 @@ export const drawBranches = function drawBranches() {
.style("stroke-linecap", "round")
.style("stroke-width", (d) => d['stroke-width']+"px" || params.branchStrokeWidth)
.style("fill", "none")
.style("visibility", getBranchVisibility)
.style("cursor", (d) => d.visibility === NODE_VISIBLE ? "pointer" : "default")
.style("pointer-events", "auto")
.on("mouseover", this.callbacks.onBranchHover)
Expand Down

0 comments on commit a0c4ee8

Please sign in to comment.