Each model (DiagramModel, NodeModel etc..) are all built ontop of an event system. You can listen for most of these events by registering an event on the model itself.
All models will fire these events:
Fires when the lock state of the entity changes. If an element is locked, it cannot be moved or deletes.
When the selected property of a model changes
When the entity is going to be deleted. The DiagramModel listenes for this event to when to remove the model from itself.
When nodes are added or removed
when links are added or removed
depreciated, use offsetUpdated and zoomUpdated instead
to know when the canvas was translated in any direction
to know when the zoom level of the canvas was updated
The diagram engine
When node factories have been added or removed from the engine
When link factories have been added or removed from the engine
let model = new SRD.DiagramModel();
let node1 = new SRD.DefaultNodeModel("default","rgb(0,192,255)");
node1.addListener({
entityRemoved: (node) => {
console.log('Removed', node.id)
},
selectionChanged: (node, isSelected) => {
console.log(isSelected?'Selected':'Unselected', node)
}
});
model.addListener({
linksUpdated:(entity, isAdded) => {
console.log(isAdded?'added':'removed', entity)
},
nodesUpdated: (entity, isAdded) => {
console.log(isAdded?'added':'removed', entity)
}
});