Is there a way to pan and set focus to a node by their id? #3264
-
I have a dynamic canvas which is updated with new nodes by user actions. I have positioned my nodes with auto-layout with dagre.
b7012c09-a412-4106-b0ed-966fc7547230.1.webmBut it doesn't seem to work. Any suggestion or help? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
What happens if you wrap the useEffect(() => {
if (focusNodeId) {
window.requestAnimationFrame(() => {
fitView({ nodes: [{ id: focusNodeId }]});
})
}
}, [fitView, focusNodeId]) |
Beta Was this translation helpful? Give feedback.
-
I've achieved this by creating a tag under |
Beta Was this translation helpful? Give feedback.
I see.
There is a way of doing this, it might seem a bit un-intuitive and there's probably different ways of going about this (for example by checking if a specific node is initialized yet and then triggering fitView) but imo this is the "easiest" way of doing this.
In your
onNodesChange
handler you can check for changes of typedimensions
.When a node is initialized this change will be fired with the actual dimensions of the node, which should be anything but 0,0.
So you can basically listen for that event and call fit view when it happens.