Updating diagram on model change

Hi. In my diagram, some changes to the model happen in the backend (ie. from an external source), I can detect these changes, but I don’t know how to “refresh” the related nodes (is this even possible?)…

Well, if you know which Nodes (or Links) that were affected, you could do something like:

var nodekeys = [...];
myDiagram.startTransaction();
for (var i = 0; i < nodekeys.length; i++) {
  var node = myDiagram.findNodeForKey(nodekeys[i]);
  if (node === null) continue;
  // this call might not be necessary if no relationships had changed:
  node.updateRelationshipsFromData();
  // update any Bindings depending on data source property changes:
  node.updateTargetBindings();
  // would be more efficient if you knew exactly which properties had changed --
  // pass the property name as the argument to updateTargetBindings
}
myDiagram.commitTransaction("update");

The least efficient but most general would be do to:

myDiagram.startTransaction();
myDiagram.updateAllRelationshipsFromData();
myDiagram.updateAllTargetBindings();
myDiagram.commitTransaction("update");

CAUTION! all of these update... methods do not support undo! If the data has changed out from under the model (i.e. without calling Model methods), then there is no way to recover the original structure or property values of the model data, so one cannot successfully Undo.

Thanks for the reply. If I raise an event on the changed model and bubble it with a raiseDataChanged, would I be able to use the undo?

Yes, calling methods on Model or GraphLinksModel would support undo. Note though, that those “raise…” methods require providing enough information to be able to build a ChangedEvent that can implement undo and redo.

Thanks Walter. it is works for me