How to update geometry string based on the user input using setDataproperty

creating the shape node data.

createShape(nodeData) {
        this.node = new go.Node(go.Panel.Auto);
        this.node.bind(new go.Binding("location", "location", go.Point.parse));
        // this.node.doubleClick = (e, node) => {
        //     console.log(e, node);
        // }
        this.shape = new go.Shape();
        this.shape.geometryString = nodeData.geometry;  // this is i am getting from the model I have already defined the json format
         //this.shape.bind(new go.Binding())
        this.node.add(this.shape);
        return this.node;
    }

this function I am taking as a parameter newGeometry and key and based on the key updating the geometry but its not updating the model. for other attribute like location it is working fine.

public modifyNodeDetails(newGeometry,key){
        let dataInfo=this.diagram.model.nodeDataArray;
       
        for(let i=0;i<dataInfo.length;i++){
         if(dataInfo[i].key==key){
             let node=this.diagram.findNodeForKey(key);
            //this.diagram.model.setDataProperty(node,"location",new go.Point(100,299));
            this.diagram.model.setDataProperty(node,"geometry",newGeometry);
         }
        }
        this.diagram.commitTransaction("changenodestate");
    }

findNodeForKey returns a node, not a node data object. Do you mean to update the actual node’s shape’s geometry, or the geometry string in the node data object?

Yes I want to update geometry string inside the object. Here I am able to update location of node based on user input but how to update geometry string?

This should do it:

function modifyNodeGeometry(newGeometry, key) {
  var data = this.diagram.model.findNodeDataForKey(key);
  if (data) {
    this.diagram.model.commit(function(m) {
      m.set(data, "geometry", newGeometry);
    });
  }
}

it is not working can you look below code it is working for location attribute If I am giving different location it’s working fine.

public modifyNodeDetails(newGeometry,key){
let dataInfo=this.diagram.model.nodeDataArray;
for(let i=0;i<dataInfo.length;i++){
if(dataInfo[i].key==key){
let node=this.diagram.findNodeForKey(key);
this.diagram.model.setDataProperty(node,“location”,new go.Point(100,299)); // its working fine if I am doing for location attribute but for the same manner if I am doing for geometry it is not working .
//this.diagram.model.setDataProperty(node,“geometry”,newGeometry);
}
}
this.diagram.commitTransaction(“changenodestate”);
}

below code how I am creating the node shape and assign the geometry string first time
but if you will set for location I am using new go.Binding but for the geometry directly I am assigning geometry string I have a doubt here because of that it is not working can you correct me if I am wrong.

createShape(nodeData) {
this.node = new go.Node(go.Panel.Auto);
this.node.bind(new go.Binding(“location”, “location”, go.Point.parse));
this.shape = new go.Shape();
this.shape.geometryString = nodeData.geometry;
this.node.add(this.shape);
return this.node;

}

As @jhardy pointed out, you must not pass an instance of Node to the Model.setDataProperty method, but you should pass the Node.data value instead.

And in my reply I pointed out that you could call Model.findNodeDataForKey so that you don’t have to do a linear search for a data object with a particular key value.

And as you can read in GoJS Using Models -- Northwoods Software you really want to add a Binding of the Shape.geometryString property to get its value from the data.geometry property.