EventAPI¶
Interface EventAPI
registerListener<T extends WebVisEvent = WebVisEvent>(
eventTypes: EventType[],
listener: IEventListener<T>,
nodeID?: number,
observeSubTree?: boolean,
): number;
unregisterListener(listenerID: number): void;
}
Hierarchy (View Summary)
- EventAPI
Index
Methods
register Listener
- registerListener<T extends WebVisEvent = WebVisEvent>(
eventTypes: EventType[],
listener: IEventListener<T>,
nodeID?: number,
observeSubTree?: boolean,
): numberRegisters a listener for a set of EventTypes. If the given event types array is empty, the listener will react to all event types. The listener must implement the IEventListener interface. It will be called with events that extend the WebVisEvent base class. An event's
typeproperty specifies its EventType and determines its structure.Scoping listeners in the node hierarchy
Several EventTypes are linked to a specific node in the hierarchy. These include all that have a
NODE_orTOPOLOGY_prefix, as well as several animation-related event types.When registering a listener for these event types, a listening scope must be specified in the node hierarchy. This is done by setting the optional parameters
nodeIDandobserveSubTree. TheobserveSubTreeflag determines whether the listener is scoped to only the specified node or the entire subtree under the node.By default, listeners are scoped to the global root node and
observeSubTreeisfalse, such that listeners do not receive any events linked to added nodes. To listen to events from all nodes, setnodeIDto0andobserveSubTreetotrue.There are a few things to note when scoping listeners:
- NODE_ADDED events are linked to the parent node of the added node.
- NODE_CHANGED events behave differently depending on the node property that has changed. When the node property is recursive, the event is passed to all listeners in the subtree. When the change to the node property affects the node's ancestors, events will also be triggered for the ancestors.
Type Parameters
- T extends WebVisEvent = WebVisEvent
The type of event that the listener listens to. This can also be a union of multiple event types.
Parameters
- eventTypes: EventType[]
The types of events that the listener listens to. If an empty array is passed, the listener will listen to all event types.
- listener: IEventListener<T>
The event listener.
OptionalnodeID: numberThe ID of the node to which the listener should be scoped. Default:
0OptionalobserveSubTree: booleanIf set to true, the listener will be scoped to the whole subtree under the specified node. Default:
false
Returns number
- The ID of the event listener.
EventAPI
Overview
The EventAPI provides the functions registerListener and unregisterListener for managing event listeners. Examples of event triggers are the addition and removal of nodes, changes to node properties, and user interactions with the visualization.
Quick Start
The example below demonstrates how to register a listener for NODE_ADDED events. Registering an event listener returns a listener ID, which can be used to unregister the listener later.
Scoping listeners in the node hierarchy
Several events are linked to a specific node in the hierarchy, e.g. NodeClickedEvents. When registering a listener for the corresponding event types, a listening scope must be specified in the node hierarchy. For more information, see the registerListener function.