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

Dynamically add tip labels #728

Merged
merged 3 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions src/components/tree/phyloTree/change.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const modifySVGInStages = function modifySVGInStages(elemsToUpdate, svgPr
if (this.params.showGrid) this.addGrid();
this.svg.selectAll(".tip").remove();
this.drawTips();
this.updateTipLabels();
if (this.vaccines) this.drawVaccines();
this.addTemporalSlice();
if (this.layout === "clock" && this.distance === "num_date") this.drawRegression();
Expand Down Expand Up @@ -263,7 +264,7 @@ export const change = function change({
const elemsToUpdate = new Set(); /* what needs updating? E.g. ".branch", ".tip" etc */
const nodePropsToModify = {}; /* which properties (keys) on the nodes should be updated (before the SVG) */
const svgPropsToUpdate = new Set(); /* which SVG properties shall be changed. E.g. "fill", "stroke" */
let useModifySVGInStages = false; /* use modifySVGInStages rather than modifySVG. Not used often. */
const useModifySVGInStages = newLayout; /* use modifySVGInStages rather than modifySVG. Not used often. */

/* calculate dt */
const idealTransitionTime = 500;
Expand All @@ -285,7 +286,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");
elemsToUpdate.add(".tip").add(".tipLabel");
svgPropsToUpdate.add("visibility").add("cursor");
nodePropsToModify.visibility = visibility;
}
Expand All @@ -306,9 +307,6 @@ export const change = function change({
elemsToUpdate.add(".grid").add(".regression");
svgPropsToUpdate.add("cx").add("cy").add("d").add("opacity").add("visibility");
}
if (newLayout) {
useModifySVGInStages = true;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 This type of refactor is small but I think really helpful to iteratively making complex logic more understandable/approachable.

/* change the requested properties on the nodes */
updateNodesWithNewData(this.nodes, nodePropsToModify);
Expand Down
3 changes: 2 additions & 1 deletion src/components/tree/phyloTree/labels.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { timerFlush } from "d3-timer";
import { NODE_VISIBLE } from "../../../util/globals";

export const updateTipLabels = function updateTipLabels(dt) {
if ("tipLabels" in this.groups) {
Expand Down Expand Up @@ -35,7 +36,7 @@ export const updateTipLabels = function updateTipLabels(dt) {
.text((d) => tLFunc(d))
.attr("class", "tipLabel")
.style("font-size", fontSize.toString()+"px")
.style('visibility', 'visible');
.style('visibility', (d) => d.visibility === NODE_VISIBLE ? "visible" : "hidden");
}, dt);
}
};
Expand Down