I tried calling go.Diagram.rebuildParts() but that didn’t work and looking to the API I saw that the correct to use is “myDiagram.rebuildParts()”, but without the effect wanted.
However, I think the problem is in another place. I looked further and I discovered that myDiagram.model.toJSON() is not creating correctly the JSON.
I changed my sendChanges() function into this:
function sendChanges(e)
{
console.log(e);
if(subscribed && has_current_state)
{
var str = myDiagram.model.toJSON();
channel.trigger(“client-modified”, {“diagram” : str});
console.log('Sent: ’ + str);
}
}
It was looking to this “Sent” log that I discovered toJSON() is not creating what is expected. I don’t know how to describe this clearly here, but I will try.
1) First, I create the nodes and I link 2 of them, resulting into this (LinkDrawn was the event raised):
Sent: { “class”: “go.GraphLinksModel”,
“linkFromPortIdProperty”: “fromPort”,
“linkToPortIdProperty”: “toPort”,
“nodeDataArray”: [
{“category”:“start”, “item”:“Start”, “key”:-1, “loc”:"-278.390625 -243"},
{“category”:“endError”, “item”:“End with error”, “key”:-2, “loc”:"-128.390625 -310"},
{“category”:“endOK”, “item”:“Expected end”, “key”:-3, “loc”:"-138.390625 -222"}
],
“linkDataArray”: [ {“from”:-1, “to”:-2, “fromPort”:“R”, “toPort”:“L”} ]}
2) Then, I move one of the nodes so “linkDataArray” will show the points, resulting into this (SelectionMoved was the event raised):
Sent: { “class”: “go.GraphLinksModel”,
“linkFromPortIdProperty”: “fromPort”,
“linkToPortIdProperty”: “toPort”,
“nodeDataArray”: [
{“category”:“start”, “item”:“Start”, “key”:-1, “loc”:"-278.390625 -243"},
{“category”:“endError”, “item”:“End with error”, “key”:-2, “loc”:"-91.390625 -307"},
{“category”:“endOK”, “item”:“Expected end”, “key”:-3, “loc”:"-138.390625 -222"}
],
“linkDataArray”: [ {“from”:-1, “to”:-2, “fromPort”:“R”, “toPort”:“L”, “points”:[-263.390625,-243,-253.390625,-243,-184.890625,-243,-184.890625,-307,-116.390625,-307,-106.390625,-307]} ]}
3) Finally, I move the link so it links other nodes (LinkRelinked was the event raised):
Sent: { “class”: “go.GraphLinksModel”,
“linkFromPortIdProperty”: “fromPort”,
“linkToPortIdProperty”: “toPort”,
“nodeDataArray”: [
{“category”:“start”, “item”:“Start”, “key”:-1, “loc”:"-278.390625 -243"},
{“category”:“endError”, “item”:“End with error”, “key”:-2, “loc”:"-91.390625 -307"},
{“category”:“endOK”, “item”:“Expected end”, “key”:-3, “loc”:"-138.390625 -222"}
],
“linkDataArray”: [ {“from”:-1, “to”:-3, “fromPort”:“R”, “toPort”:“T”, “points”:[-263.390625,-243,-253.390625,-243,-184.890625,-243,-184.890625,-307,-116.390625,-307,-106.390625,-307]} ]}
As you can see, “linkDataArray” is not generated correctly, because the “points” parameter is the same as before.
However, just to be sure, I moved the node with key -2 (because it has no link). As you can see below, “points” changed, although I didn’t made anything to the link:
SelectionMoved active_admin.js:43525
Sent: { “class”: “go.GraphLinksModel”,
“linkFromPortIdProperty”: “fromPort”,
“linkToPortIdProperty”: “toPort”,
“nodeDataArray”: [
{“category”:“start”, “item”:“Start”, “key”:-1, “loc”:"-278.390625 -243"},
{“category”:“endError”, “item”:“End with error”, “key”:-2, “loc”:"-42.390625 -307"},
{“category”:“endOK”, “item”:“Expected end”, “key”:-3, “loc”:"-138.390625 -222"}
],
“linkDataArray”: [ {“from”:-1, “to”:-3, “fromPort”:“R”, “toPort”:“T”, “points”:[-263.390625,-243,-253.390625,-243,-207.390625,-243,-207.390625,-247,-138.390625,-247,-138.390625,-237]} ]
I’m sorry I didn’t notice this before. So, rebuildParts(), actually, is working fine…