Location being lost after diagram.transaction


We are saving nodes location on server and binding them to nodes on time of load. This the the binding code:-

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

The location field is successfully bound to the nodes at load time but as soon as we make a transaction on diagram’s model, the node are arranged according to auto allign functionality – (myDiagram.layoutDiagram(true);)

and custom locations are lost. This can be seen on –

  • myDiagram.model.nodeDataArray
  • myDiagram.nodes.each(function(x){if(x.data.category == "CommandSectionGroup"){console.log(x.data.location)}})
that node-data's location is lost after any transaction on diagrams model. Below is a sample code where this data is lost/reset

for (var it = myDiagram.nodes.iterator; it.next() ;) {
if (it.value.category == “CommandSectionGroup”){
it.value.visible = !isHidden;
// To set the flag, so that current state of the chart can be saved in DB
myDiagram.startTransaction(“Set the isHidden flag to false”);
var data = it.value.data;
myDiagram.model.setDataProperty(data, “isHidden”, isHidden);
myDiagram.commitTransaction(“Set the isHidden flag to false”);

Images :-

Expected Behaviour

Actual behaviour :-


Do you have a value for Diagram.layout? If so, have you set its isInitial property to false? (And maybe its isOngoing property to false, too?)

If not, are you calling Diagram.layoutDiagram when you don’t want to?

1 Like