Can't focus node on InitialLayoutCompleted because of overview "resetting" after model data changed

Hello dear community - I’m having trouble focusing a node within the InitialLayoutCompleted event with

diagram.centerRect(node.actualBounds) 
diagram.select(node)

The diagram always moves to top left.If I search for the node I’m trying to focus I can see, that it is actually focused. I want to note that I’m changing the model data (links and nodes).

myDiagram.model.startTransaction("adding nodes");
myDiagram.model.addNodeDataCollection(nodesToAdd);
myDiagram.model.commitTransaction("adding nodes");

When I remove the model-changes, the focus works perfectly.
I’m assuming, that when changing the model’s data a different event gets fired and the overview gets updated and thus scrolling to the default position.

Is there a way to intercept this kind of behaviour? Or is it possible to make sure, that the specific node I want to focus gets focused after all initial data changes occured?

Thanks in advance. I’m happy to give more details if needed.

Are you adding those nodes within your “InitialLayoutCompleted” DiagramEvent listener? That is an odd thing to do. And of course, once the initialization has finished (including the initial layout being completed), further transactions are not considered “initial”, unless you call Diagram.delayInitialization.

It’s best to build the complete model and then set the Diagram.model, if you can, in order to avoid repeated layouts.

Once everything has settled down, calling Diagram.centerRect, or better, CommandHandler.scrollToPart, should work.

Hello Walter - thank you for your reply.
No I was making the changes directly after reading the models JSON and assign it to the diagram’s model.
I made sure to work with the JSON first and then setting the model.
That worked perfectly fine - so thank you!

Wish you a nice one.