Skip to content

Commit

Permalink
Merge pull request #1907 from nextstrain/james/tree-resize-fix
Browse files Browse the repository at this point in the history
[tree] Reinstate transitions for all d3 updates
  • Loading branch information
jameshadfield authored Nov 18, 2024
2 parents 6e047d3 + 5a66b77 commit 522c21d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
19 changes: 9 additions & 10 deletions src/components/tree/phyloTree/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ const svgSetters = {
};


type SelectionOrTransition =
Selection<SVGGElement, PhyloNode, SVGSVGElement | null, unknown> |
Transition<SVGGElement, PhyloNode, SVGSVGElement | null, unknown>

type UpdateCall = (selectionOrTransition: SelectionOrTransition) => void;
type UpdateCall = (selection: Transition<SVGGElement, PhyloNode, SVGSVGElement | null, unknown>) => void;


/** createUpdateCall
Expand Down Expand Up @@ -120,12 +116,15 @@ const genericSelectAndModify = (
transitionTime: number,
): void => {
// console.log("general svg update for", treeElem);
let selection: SelectionOrTransition = svg.selectAll<SVGGElement, PhyloNode>(treeElem)
.filter((d: PhyloNode) => d.update);
if (transitionTime) {
selection = selection.transition().duration(transitionTime);

svg.selectAll<SVGGElement, PhyloNode>(treeElem)
.filter((d) => d.update)
.transition().duration(transitionTime)
.call(updateCall);
if (!transitionTime) {
timerFlush();
}
selection.call(updateCall);

};

/* use D3 to select and modify elements, such that a given element is only ever modified _once_
Expand Down
10 changes: 5 additions & 5 deletions src/components/tree/phyloTree/labels.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { timerFlush } from "d3-timer";
import { NODE_VISIBLE } from "../../../util/globals";
import { numericToDateObject, prettifyDate } from "../../../util/dateHelpers";
import { getTraitFromNode } from "../../../util/treeMiscHelpers";
Expand Down Expand Up @@ -107,16 +108,15 @@ export const updateBranchLabels = function updateBranchLabels(dt) {
);
const labelSize = branchLabelSize(this.params.branchLabelKey);
const fontWeight = branchLabelFontWeight(this.params.branchLabelKey);
let selection = this.groups.branchLabels
this.groups.branchLabels
.selectAll(".branchLabel")
if (dt) {
selection = selection.transition().duration(dt);
}
selection.attr("x", (d) => d.xTip - 5)
.transition().duration(dt)
.attr("x", (d) => d.xTip - 5)
.attr("y", (d) => d.yTip - this.params.branchLabelPadY)
.style("visibility", visibility)
.style("font-weight", fontWeight)
.style("font-size", labelSize);
if (!dt) timerFlush();
};

export const removeBranchLabels = function removeBranchLabels() {
Expand Down

0 comments on commit 522c21d

Please sign in to comment.