Skip to content

Is there a way to pan and set focus to a node by their id? #3264

Answered by bcakmakoglu
sagunji asked this question in Q&A
Discussion options

You must be logged in to vote

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 type dimensions.
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.

onNodesChange={(changes) => {
	// call the actual change handler to apply the node changes to your nodes
  onNodesChange(changes);

	// loop through …

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
6 replies
@bcakmakoglu
Comment options

@bcakmakoglu
Comment options

@sagunji
Comment options

@bcakmakoglu
Comment options

Answer selected by sagunji
@sagunji
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants