If i save nodes to Json and load the Json back to the diagram, the nodes are loaded exactly to the position/location they were located when saved to Json.
When i group the nodes into some groups and save the groups to Json, when loaded, the group location are shifted linearly up and left
See attach pic, before saving to Json :
Yes, calling Diagram.clear is not needed if you are replacing the Diagram.model.
Well, the Diagram.position is different in the two cases. If you remember the original value and then either set it in an “InitialLayoutCompleted” DiagramEvent listener or just set Diagram.initialPosition, does it do what you want? You cannot set it too soon because the normal document alignment will happen after you have loaded the model. I think the Draggable Link sample does this, and it also saves the Diagram.position in the Model.modelData.
By the way i took a look at the draggable link sample.
In this sample the diagram position is saved before saving to JSON and restored right after loaded from JSON.
So, should i use this sample AS-IS or implement the diagram position restoration in InitialLayoutCompleted listener ?
i’m not clear with your answer,
Currently, i used the draggable link sample code which saves Diagram.position in ModelData and restore it into Diagram.initialPosition.
It work fine until next time…
As I said 23 minutes ago, setting Diagram.initialPosition at any time before the first layout has finished is effectively the same as setting Diagram.position in an “InitialLayoutCompleted” DiagramEvent listener.
(Same is true for the other “initial…” properties of Diagram – they affect the default behavior just after the first layout has finished.)