Better way to update diagram after model change?

I am dynamically changing node and link model data and don’t see the diagram updating. I looked at the API for nodes, links, and models and don’t see anything to notify that the model has changed. I did find diagram.rebuildParts() and it works but wondering if that is doing too much work for what I need? If I have a large diagram I don’t know if that will cause performance problems.

Is there a better way to let the diagram know that just a node or link model data has changed?

Yes, rebuilding all Parts is almost always overkill.

Use Model.setDataProperty and maybe other methods such as addArrayItem.
Surround all that code with calls to startTransaction and commitTransaction.

Here is what I have to modify existing node data. The first time it gets called I get the console message below but it doesn’t work. Debugging I do see that the node’s data property has been changed but the diagram doesn’t update to reflect it.

GraphLinksModel.setDataProperty is modifying a GraphObject, “Node#1422(Node Name1n)” go-debug.js:28
Is that really your intent? go-debug.js:28

Now if I continue and call the same code a 2nd time I don’t get the message above AND the diagram updates correctly. Any idea on what is going on? Here is my code.

diagram.startTransaction(‘updateNode’);
nodeCt.buildNodeData();
node = diagram.findNodeForKey(modelForm.model.getId());
Ext.iterate(nodeCt.nodeData, function(key, value) {
diagram.model.setDataProperty(node, key, value);
}, me);
diagram.commitTransaction(‘updateNode’);

Is there a way to update all the data at once without having to iterate and call setDataProperty for each item?

There is a hard line between model data and diagram parts.

The Model holds model data which are normally plain JavaScript objects. Models have no knowledge of Diagrams or Nodes or Links. Naturally all model methods operate only on model data – plain JavaScript objects. That is why you are getting that warning. I think it’s a one-time warning, which is why you don’t see it again.

A Diagram holds Parts such as Nodes and Links, all composed of and inheriting from GraphObjects. (But Diagram is not a GraphObject.) These GraphObjects are rendered to the screen and can be manipulated by the user. But they are not part of any model. Typically you can get to the model data by getting the Part.data.

So the problem is that you are trying to modify GraphObjects using Model methods. I think you can just change the first argument to Model.setDataProperty from “node” to “node.data”.

Changing from node to node.data suppressed the message but the diagram is no longer updating. Debugging I see that node.data is being changed as before but the commit no longer updates the diagram.

FYI - I just switched from 1.3.3 to 1.3.4 before trying your suggestion.

What does nodeCt.buildNodeData() do? Does it replace any JavaScript object in Model.nodeDataArray? What is nodeCt.nodeData?

walter - that was the problem. nodeCt was referencing the same object as the model and once I had it make a new one each time it worked! Thx for your help.