Undefined issue when deleting a node that is locked onto
Hi,
I spent some time investigating an issue where deleting a node from the network leads to an error.
After adding a node, I want to focus on it. This is how my code goes:
if (id && id != '') {
var options: FocusOptions = {
locked: true, // <------------ this one causes the bug, I think
scale: 1.0,
animation: {
duration: 1000,
easingFunction: 'easeOutQuart',
},
};
this.network.focus(id, options);
}
Then, later, when I delete the node, I get this error:
TypeError: Cannot read properties of undefined (reading 'x')
at t.value (vis-network.min.js:32:264102)
at e.emit (vis-network.min.js:26:13475)
at t.value (vis-network.min.js:32:246367)
at aI.<anonymous> (vis-network.min.js:32:244488)
at e.emit (vis-network.min.js:26:13475)
at t.value (vis-network.min.js:32:218389)
at aI.<anonymous> (vis-network.min.js:32:215892)
at e.emit (vis-network.min.js:26:13475)
at aI.<anonymous> (vis-network.min.js:32:382434)
at e.emit (vis-network.min.js:26:13475)
Top of this stack trace takes me to this code in vis-network.min.js:
... function(){var t=this.body.nodes[this.lockedOnNodeId].x
Therefore I thought, this must have something to do with the node locking feature.
The error is there when deleting using this.network.deleteSelected(), also when using the node dataset this.nodes.remove(...), deleting a node is simply impossible. What did work is using this.network.setData(...) which is obviously not something you want to do.
💡 In the code above, when I set "locked" to false, the issue does no longer appear. This is the only workaround I have found (fix in my case, don't really need the locking feature).