VSeed, an elegant data composer, transforming complexity into simplicity.
!!!###!!!title=event——VisActor/VGrammar tutorial documents!!!###!!!!!!###!!!description=After creating a visualization chart with VGrammar, users interacting with the visualization chart will trigger a series of events. VGrammar supports custom event listeners, various handle through callback functions, and implements various custom behaviors. Below we will introduce how to listen for events in **Spec mode** and **API mode** and implement custom interaction behaviors.!!!###!!!
Events and Interactions
After creating a visualization chart with VGrammar, users interacting with the visualization chart will trigger a series of events. VGrammar supports custom event listeners, various handle through callback functions, and implements various custom behaviors. Below we will introduce how to listen for events in Spec mode and API mode and implement custom interaction behaviors.
Event listening in Spec mode
In Spec mode, we need to configure event listening through the events field. Example:
When we need to trigger element state updates through events, we can call the API of element in the callback when configuring events, add or remove states
In addition to configuring the type, events also support the following configurations
filter: Filter function, accepts the event object as a parameter. If the return value is true, execute the corresponding callback function or signal update logic; otherwise, do not execute.
throttle: Sets the duration of throttling, in ms; if set to 0, no throttling; if the value is set to a reasonable positive number, the throttle method will be wrapped around the event callback function to achieve a throttling effect.
debounce: Sets the debounce duration, in ms; if the value is set to 0, no debounce; if the value is set to a reasonable positive number, the debounce method will be wrapped around the event callback function to achieve a debounce effect.
consume: Stop the execution and propagation of events; if the value is true, stopPropagation() will be called after executing the callback function or updating the behavior of the event, preventing event propagation.
Event listening in API mode
In API mode, you can call the addEventListener() of View for custom listening events and implement the event callback function