events
The Events API provides methods to emit and handle custom events in your Muze visualization. This allows you to integrate visualization lifecycle events with the ThoughtSpot platform and implement custom download handlers.
Methods
emitRenderCompletedEvent()
Emits a render completed event to notify the parent application that the chart has finished rendering.
const { events } = viz;
events.emitRenderCompletedEvent()
Parameters: None
Returns: void
Note: This method is typically called automatically when autoEmitRenderCompletedEvent is enabled in global options. Use manual emission when you need precise control over when the event is fired.
handleXLSXDownloadEvent()
Registers a custom handler for XLSX download requests from ThoughtSpot.
const { events } = viz;
events.handleXLSXDownloadEvent(handler?)
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| handler | DownloadXLSXHandlerType | false | Custom handler function for XLSX downloads |
Handler Function Type:
type DownloadXLSXHandlerType = (payload: {
answerTitle: string;
}) => { isDownloadHandled: boolean } | undefined | null;
Handler Parameters:
| Property | Type | Description |
|---|---|---|
| payload.answerTitle | string | The title of the answer/chart being downloaded |
Handler Return Value:
| Property | Type | Description |
|---|---|---|
| isDownloadHandled | boolean | |
| If the return value is true, then the xlsx download was handled . If the return value is false, then the default XLSX downloader of the Thoughtspot environment will be triggered to download the chart as a flat table in xlsx format. |
Returns: void
Basic Usage
events.handleXLSXDownloadEvent((payload) => {
console.log("Custom XLSX download payload", payload);
// Here, write your own logic to export the chart built using
// third party library to XLSX file.
return {
isDownloadHandled: true
};
});