Skip to content

Commit

Permalink
Rename hovered node state
Browse files Browse the repository at this point in the history
With the previous commit creating "selectedNode" as part of redux state,
the tree state variable "selectedNode" is only used for hover events, so
rename it to convey this.
  • Loading branch information
jameshadfield committed Feb 6, 2024
1 parent f7e944d commit 86b8527
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
7 changes: 3 additions & 4 deletions src/components/tree/infoPanels/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,12 @@ const HoverInfoPanel = ({
observedMutations,
t
}) => {
if (selectedNode.event !== "hover") return null;
const node = selectedNode.node.n;
if (!selectedNode) return null
const node = selectedNode.n;
const idxOfInViewRootNode = getIdxOfInViewRootNode(node);

return (
<Container node={node} panelDims={panelDims}>
{selectedNode.type === "tip" ? (
{node.hasChildren===false ? (
<>
<StrainName name={node.name}/>
<VaccineInfo node={node} t={t}/>
Expand Down
24 changes: 5 additions & 19 deletions src/components/tree/reactD3Interface/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ export const onTipHover = function onTipHover(d) {
this.state.treeToo;
phylotree.svg.select("#"+getDomId("tip", d.n.name))
.attr("r", (e) => e["r"] + 4);
this.setState({
selectedNode: {
node: d,
type: "tip",
event: "hover"
}
});
this.setState({hoveredNode: d});
};

export const onTipClick = function onTipClick(d) {
Expand Down Expand Up @@ -49,13 +43,7 @@ export const onBranchHover = function onBranchHover(d) {
}

/* Set the hovered state so that an info box can be displayed */
this.setState({
selectedNode: {
node: d,
type: "branch",
event: "hover"
}
});
this.setState({hoveredNode: d});
};

export const onBranchClick = function onBranchClick(d) {
Expand Down Expand Up @@ -104,7 +92,6 @@ export const onBranchClick = function onBranchClick(d) {

/* onBranchLeave called when mouse-off, i.e. anti-hover */
export const onBranchLeave = function onBranchLeave(d) {
if (this.state.selectedNode.event!=="hover") return;

/* Reset the stroke back to what it was before */
branchStrokeForLeave(d);
Expand All @@ -115,19 +102,18 @@ export const onBranchLeave = function onBranchLeave(d) {
tree.removeConfidence();
}
/* Set selectedNode state to an empty object, which will remove the info box */
this.setState({selectedNode: {}});
this.setState({hoveredNode: null});
};

export const onTipLeave = function onTipLeave(d) {
if (this.state.selectedNode.event!=="hover") return;
const phylotree = d.that.params.orientation[0] === 1 ?
this.state.tree :
this.state.treeToo;
if (this.state.selectedNode) {
if (this.state.hoveredNode) {
phylotree.svg.select("#"+getDomId("tip", d.n.name))
.attr("r", (dd) => dd["r"]);
}
this.setState({selectedNode: {}});
this.setState({hoveredNode: null});
};

/* clearSelectedNode when clicking to remove the node-selected modal */
Expand Down
4 changes: 2 additions & 2 deletions src/components/tree/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Tree extends React.Component {
};
this.tangleRef = undefined;
this.state = {
selectedNode: {},
hoveredNode: null,
tree: null,
treeToo: null
};
Expand Down Expand Up @@ -199,7 +199,7 @@ class Tree extends React.Component {
<Legend width={this.props.width}/>
</ErrorBoundary>
<HoverInfoPanel
selectedNode={this.state.selectedNode}
selectedNode={this.state.hoveredNode}
colorBy={this.props.colorBy}
colorByConfidence={this.props.colorByConfidence}
colorScale={this.props.colorScale}
Expand Down

0 comments on commit 86b8527

Please sign in to comment.