Skip to main content

UI Events

These events are fired by the Surface widget. Note that some of these events are also fired by the underlying Toolkit, but the surface payload provides the related UI element information.

Binding to Surface events

Event listeners can be bound to the surface widget in one of three ways:

  • via the bind method
  • in the events parameter to a render call on an instance of the Toolkit
  • in the individual Node, Group, Port and Edge definitions in the view parameter to a render call.

The full list of bindable events is listed below.

Using bind

const surface = toolkitInstance.render(someElement, {
...
});

surface.bind("canvasClick", (e) => {
console.log("click on the canvas");
});

surface.bind("node:added", (params) => {

});

Declarative binding

const surface = toolkitInstance.render(someElement, {
...
events:{
canvasClick:(e) => {
console.log("click on the canvas");
},
"node:added":(params) => {}
}
});

Each of the entries in the events block is equivalent to first instantiating the surface and then calling bind on it.

Suspending Events

You can suspend/enable events from the surface widget with this method:

surface.setSuspendEvents(true);

You can also wrap the underlying Toolkit's batch command (which runs a series of operations without making any rendering changes) with the surface widget's batch command:

surface.batch(() => {
toolkit.addNode({id:"foo"});
toolkit.addNode({id:"bar"});
toolkit.addNode({source:"foo", target:"bar"});
});

This is equivalent to:

surface.setSuspendEvents(true);
toolkit.batch(() => {
toolkit.addNode({id:"foo"});
toolkit.addNode({id:"bar"});
toolkit.addNode({source:"foo", target:"bar"});
});
surface.setSuspendEvents(false);

Event List

EventConstantDescriptionPayload
node:addedEVENT_NODE_ADDEDFired whenever a new node is added to the data model
group:addedEVENT_GROUP_ADDEDFired whenever a new node is added to the data model
group:removedEVENT_GROUP_REMOVEDFired when a group is removed
group:resizedEVENT_GROUP_RESIZEFired when a group has been resized
edge:addedEVENT_EDGE_ADDEDFired when a new edge has been added
panEVENT_PANFired when the surface has just been panned.
zoomEVENT_ZOOMFired when the surface's zoom has just changed
node:move:startEVENT_NODE_MOVE_STARTFired when a node/group has just begun to be dragged
node:moveEVENT_NODE_MOVEFired continuously while a node/group is being dragged
node:move:endEVENT_NODE_MOVE_ENDFired when a node has just been dragged
group:move:endEVENT_GROUP_MOVE_ENDFired when a group has just been dragged
modeChangedEVENT_SURFACE_MODE_CHANGEDFired when the mode for a surface was changed
destroyEVENT_DESTROYFired when a surface has been destroyed
group:collapseEVENT_GROUP_COLLAPSEFired when a group has been collapsed
group:expandEVENT_GROUP_EXPANDFired when a group has been expanded