Preserve node positions when changing layers

Hello,

I am changing layers in a diagram and using the layers to store the information of the nodes in the diagrams. I am also changing diagram model types so i need to preserve the information on where the nodes are located before switching layers/models.

So my question is: where is the information stored at for the position of the node so that I can preserve the positions of any nodes that were moved by the user.

Thanks!

Models do not automatically store any information other than the data properties named by “…Property” properties.

That includes not storing any Node.position or Node.location point.

Instead you should establish a TwoWay Binding on either of those two Node properties (but not both). There are lots of examples of this throughout the Introduction and the samples.

The following is an example of what Walter was talking about when he said I needed to make a two way binding on the location of the nodes in order to maintain their positions while switch layers/models:

var graphObjectMake = go.GraphObject.make;

Diagram.nodeTemplate = graphObjectMake(go.Node, “Table”,
new go.Binding(“location”, “loc”, go.Point.parse).makeTwoWay(go.Point.stringify),
<span =“Apple-tab-span” style=“white-space:pre”> …
<span =“Apple-tab-span” style=“white-space:pre”> …<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> …

That was really all I had to do in order to maintain position…lol thanks walter!

It does pull up another question though in the following line:

new go.Binding(“location”, “loc”, go.Point.parse).makeTwoWay(go.Point.stringify),


How is the location being set in that statement? go.Point.parse handles the string produced by go.Point.stringify but go.Point just looks like a call to the go library and doesnt look like its specific to the node. A general idea on whats going on would be appreciated as I don’t think I would have figured this out without your help walter.

This should explain everything: Introduction to Data Binding.