Aha! I suspect I know the issue.
When an <input>
of the Inspector changes, Inspector Component incrementally updates the data of the node based on whatever it has in its nodeData
property (plus the prop / val change of the <input>
that changed). Inspector.nodeData
is received via AppComponent.selectedNodeData
. It is possible Inspector’s nodeData
property is out of sync with what AppComponent has, since, if you’re using the gojs-angular-basic sample, we do not store location data in the data, and as such, we do not modify AppComponent.selectedNodeData
when a node is moved.
How do we fix this?
First, make sure in your node / link template(s) you have bound the location
property with a TwoWay data binding, like this
// The Node.location comes from the "loc" property of the node data,
// converted by the Point.parse static method.
// If the Node.location is changed, it updates the "loc" property of the node data,
// converting back using the Point.stringify static method.
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify)
Then, we need to make sure that when a node is moved, since we care about its location, whatever Inspector.nodeData
is holding knows about the change and is updated (i.e., we must update AppComponent.selectedNodeData
.
There are a few ways to do this, but this most future-proof one is to modify the diagramModelChange
function of AppComponent to check if one of the modified node data’s is what the Inspector is currently tracking. If so, we’ll update AppComponent.selectedNodeData
to this new state (this has the advantage of updating Inspector.nodeData
now whenever any data property of what the Inspector’s inspected node changes.
So, add this within the produce
section of your diagramModelChange
function:
// If one of the modified nodes was the selected node used by the inspector, update the inspector selectedNodeData object
const modifiedNodeDatas = changes.modifiedNodeData;
if (modifiedNodeDatas && draft.selectedNodeData) {
for (let i = 0; i < modifiedNodeDatas.length; i++) {
const mn = modifiedNodeDatas[i];
const nodeKeyProperty = appComp.myDiagramComponent.diagram.model.nodeKeyProperty as string;
if (mn[nodeKeyProperty] === draft.selectedNodeData[nodeKeyProperty]) {
draft.selectedNodeData = mn;
}
}
}
This is actually probably the behavior we should publish in gojs-angular-basic to be more thorough, so thank you for bringing this to my attention!