Loaded groups from Json are not loaded to the position they were saved

Hi,
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 :


See attached pic after loading from Json :

  1. I DO NOT use any auto layout
  2. I bind “location” in group and node templates.
  3. i DO NOT set the initialContentAlignment
  4. I bind the “isSubGraphExpanded” in the group template, makeTwoWay
  5. When i create the group, I DO NOT set the “loc” value, they are created elsewhere on the diagram and i drag them to a new location and save to Json.
  6. Before i load from Json, i run diagram.clear();
  7. I set scrollMode:go.Diagram.InfiniteScroll

I need the diagram nodes/groups to be loaded to the location they were saved.
Please advise.
Tany

What is the value of Diagram.position before and after the load?

Does not setting Diagram.scrollMode make any difference?

Console log:
Before saving to JSON : Point(-22.72783406334603,11.253808593749994)
After loading from JSON : Point(-22.72783406334603,-5)

Diagram.scrollMode does not make any difference

I get the same results even i eliminate the diagram.clear() after saving to JSON
and before loading from JSON.
and

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.

Yep,
This works fine.

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 ?

Actually, it’s being restored at “InitialLayoutCompleted” time, because it’s setting Diagram.initialPosition, not Diagram.position.

So, i can stick with draggable links sample, right ?

I have updated my post.

I’m sorry,
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.)

Clear,
Thanks