Getting and error when trying to use centerNode method by click on button:
centerTree() {
findNodeById = (treeData, targetId) => {
for (const node of treeData) {
if (node.id === targetId) {
return node;
}
if (node.children) {
const found = findNodeById(node.children, targetId);
if (found) return found;
}
}
return null;
}
if (!this.treeRef.current) return;
requestAnimationFrame(() => {
const matched = findNodeById(
this.treeRef.current.state.data,
17
);
if (matched) {
this.treeRef.current.centerNode(matched);
}
}
}
Founded node has __rd3t key with its data, and its not null
I can't share fully working code because it's private, but the goal is simply to get child node and center the tree on it.
The error is - Error: attribute transform: Expected number, "translate(NaN,NaN)scale(0.…"..
I found in docs that the centerNode method gets the node and wrapped it with x/y coords (HierarchyPointNode<TreeNodeDatum>), so the tree can translate by it.
Looks like it is an automatic process and we don't have to do anything else, just pass the node to the method.
I spent many time to find the solution, and still not found it.
Getting and error when trying to use
centerNodemethod by click on button:Founded node has
__rd3tkey with its data, and its notnullI can't share fully working code because it's private, but the goal is simply to get child node and center the tree on it.
The error is - Error: attribute transform: Expected number, "translate(NaN,NaN)scale(0.…"..
I found in docs that the
centerNodemethod gets the node and wrapped it with x/y coords (HierarchyPointNode<TreeNodeDatum>), so the tree can translate by it.Looks like it is an automatic process and we don't have to do anything else, just pass the node to the method.
I spent many time to find the solution, and still not found it.