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

[tree] Reinstate transitions for all d3 updates #1907

Merged
merged 1 commit into from
Nov 18, 2024
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
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
Loading