I have a requirement to save the graph each time a new node or link is added so thje backend can return the new nodes with few calculated properties.
My issue is that i initialize everything related to graph inside the ngAfterViewInit hook of angular.
here is the code:
ngAfterViewInit() {
configureShapes();
this.initDiagram();
this.diagram.model = new go.GraphLinksModel(
this.diagramModelData.nodeDataArray,
this.diagramModelData.linkDataArray
);
this.data = this.diagram.model.toJson();
this.load();
this.initListeners();
}
When i try to update only the model from an input like this:
@Input() set diagramModel(model: GraphNodeDetailsData) {
this.diagramModelData = model;
if(this.diagram) {
this.diagram.startTransaction('modify nodeDataArray');
this.diagram.model.nodeDataArray = model.nodeDataArray;
this.diagram.commitTransaction('modify nodeDataArray');
}
}
the nodes are getting lost. the only way i can update the diagram is to destroy the div that is rendered from the parent by turning a flag of loading to true. whats wrong with passing the new nodeDataArray to my model? any suggestions for updating the nodes without destroying the hole graph?