@thoughtspot/ts-chart-sdk 0.0.1-alpha.0 → 0.0.1-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +782 -0
  2. package/cjs/index.d.ts +9 -0
  3. package/cjs/index.d.ts.map +1 -0
  4. package/cjs/index.js +25 -0
  5. package/cjs/index.js.map +1 -0
  6. package/cjs/main/custom-chart-context.d.ts +47 -0
  7. package/cjs/main/custom-chart-context.d.ts.map +1 -0
  8. package/cjs/main/custom-chart-context.js +326 -0
  9. package/cjs/main/custom-chart-context.js.map +1 -0
  10. package/cjs/main/custom-chart-context.spec.d.ts +2 -0
  11. package/cjs/main/custom-chart-context.spec.d.ts.map +1 -0
  12. package/cjs/main/custom-chart-context.spec.js +699 -0
  13. package/cjs/main/custom-chart-context.spec.js.map +1 -0
  14. package/cjs/main/post-message-event-bridge.d.ts +6 -0
  15. package/cjs/main/post-message-event-bridge.d.ts.map +1 -0
  16. package/cjs/main/post-message-event-bridge.js +46 -0
  17. package/cjs/main/post-message-event-bridge.js.map +1 -0
  18. package/cjs/main/post-message-event-bridge.spec.d.ts +2 -0
  19. package/cjs/main/post-message-event-bridge.spec.d.ts.map +1 -0
  20. package/cjs/main/post-message-event-bridge.spec.js +124 -0
  21. package/cjs/main/post-message-event-bridge.spec.js.map +1 -0
  22. package/cjs/react/mocks/custom-chart-context-mock.d.ts +3 -0
  23. package/cjs/react/mocks/custom-chart-context-mock.d.ts.map +1 -0
  24. package/cjs/react/mocks/custom-chart-context-mock.js +100 -0
  25. package/cjs/react/mocks/custom-chart-context-mock.js.map +1 -0
  26. package/cjs/react/use-custom-chart-context.d.ts +4 -0
  27. package/cjs/react/use-custom-chart-context.d.ts.map +1 -0
  28. package/cjs/react/use-custom-chart-context.js +95 -0
  29. package/cjs/react/use-custom-chart-context.js.map +1 -0
  30. package/cjs/react/use-custom-chart-context.spec.d.ts +2 -0
  31. package/cjs/react/use-custom-chart-context.spec.d.ts.map +1 -0
  32. package/cjs/react/use-custom-chart-context.spec.js +391 -0
  33. package/cjs/react/use-custom-chart-context.spec.js.map +1 -0
  34. package/cjs/react/use-custom-chart-context.util.d.ts +6 -0
  35. package/cjs/react/use-custom-chart-context.util.d.ts.map +1 -0
  36. package/cjs/react/use-custom-chart-context.util.js +60 -0
  37. package/cjs/react/use-custom-chart-context.util.js.map +1 -0
  38. package/cjs/react/use-custom-chart-types.d.ts +23 -0
  39. package/cjs/react/use-custom-chart-types.d.ts.map +1 -0
  40. package/cjs/react/use-custom-chart-types.js +3 -0
  41. package/cjs/react/use-custom-chart-types.js.map +1 -0
  42. package/cjs/test/test-utils.d.ts +7 -0
  43. package/cjs/test/test-utils.d.ts.map +1 -0
  44. package/cjs/test/test-utils.js +14 -0
  45. package/cjs/test/test-utils.js.map +1 -0
  46. package/cjs/types/answer-column.types.d.ts +69 -0
  47. package/cjs/types/answer-column.types.d.ts.map +1 -0
  48. package/cjs/types/answer-column.types.js +59 -0
  49. package/cjs/types/answer-column.types.js.map +1 -0
  50. package/cjs/types/chart-to-ts-event.types.d.ts +98 -0
  51. package/cjs/types/chart-to-ts-event.types.d.ts.map +1 -0
  52. package/cjs/types/chart-to-ts-event.types.js +32 -0
  53. package/cjs/types/chart-to-ts-event.types.js.map +1 -0
  54. package/cjs/types/common.types.d.ts +52 -0
  55. package/cjs/types/common.types.d.ts.map +1 -0
  56. package/cjs/types/common.types.js +3 -0
  57. package/cjs/types/common.types.js.map +1 -0
  58. package/cjs/types/configurator.types.d.ts +15 -0
  59. package/cjs/types/configurator.types.d.ts.map +1 -0
  60. package/cjs/types/configurator.types.js +3 -0
  61. package/cjs/types/configurator.types.js.map +1 -0
  62. package/cjs/types/ts-to-chart-event.types.d.ts +91 -0
  63. package/cjs/types/ts-to-chart-event.types.d.ts.map +1 -0
  64. package/cjs/types/ts-to-chart-event.types.js +18 -0
  65. package/cjs/types/ts-to-chart-event.types.js.map +1 -0
  66. package/cjs/types/visual-prop.types.d.ts +73 -0
  67. package/cjs/types/visual-prop.types.d.ts.map +1 -0
  68. package/cjs/types/visual-prop.types.js +3 -0
  69. package/cjs/types/visual-prop.types.js.map +1 -0
  70. package/dist/ts-chart-sdk.d.ts +151 -23
  71. package/lib/index.d.ts +1 -0
  72. package/lib/index.d.ts.map +1 -1
  73. package/lib/index.js +1 -0
  74. package/lib/index.js.map +1 -1
  75. package/lib/main/custom-chart-context.d.ts +12 -3
  76. package/lib/main/custom-chart-context.d.ts.map +1 -1
  77. package/lib/main/custom-chart-context.js +128 -9
  78. package/lib/main/custom-chart-context.js.map +1 -1
  79. package/lib/main/custom-chart-context.spec.js +381 -25
  80. package/lib/main/custom-chart-context.spec.js.map +1 -1
  81. package/lib/main/post-message-event-bridge.js +1 -1
  82. package/lib/main/post-message-event-bridge.js.map +1 -1
  83. package/lib/main/post-message-event-bridge.spec.js +5 -3
  84. package/lib/main/post-message-event-bridge.spec.js.map +1 -1
  85. package/lib/react/mocks/custom-chart-context-mock.d.ts +3 -0
  86. package/lib/react/mocks/custom-chart-context-mock.d.ts.map +1 -0
  87. package/lib/react/mocks/custom-chart-context-mock.js +94 -0
  88. package/lib/react/mocks/custom-chart-context-mock.js.map +1 -0
  89. package/lib/react/use-custom-chart-context.d.ts +4 -0
  90. package/lib/react/use-custom-chart-context.d.ts.map +1 -0
  91. package/lib/react/use-custom-chart-context.js +68 -0
  92. package/lib/react/use-custom-chart-context.js.map +1 -0
  93. package/lib/react/use-custom-chart-context.spec.d.ts +2 -0
  94. package/lib/react/use-custom-chart-context.spec.d.ts.map +1 -0
  95. package/lib/react/use-custom-chart-context.spec.js +363 -0
  96. package/lib/react/use-custom-chart-context.spec.js.map +1 -0
  97. package/lib/react/use-custom-chart-context.util.d.ts +6 -0
  98. package/lib/react/use-custom-chart-context.util.d.ts.map +1 -0
  99. package/lib/react/use-custom-chart-context.util.js +51 -0
  100. package/lib/react/use-custom-chart-context.util.js.map +1 -0
  101. package/lib/react/use-custom-chart-types.d.ts +23 -0
  102. package/lib/react/use-custom-chart-types.d.ts.map +1 -0
  103. package/lib/react/use-custom-chart-types.js +2 -0
  104. package/lib/react/use-custom-chart-types.js.map +1 -0
  105. package/lib/types/chart-to-ts-event.types.d.ts +63 -13
  106. package/lib/types/chart-to-ts-event.types.d.ts.map +1 -1
  107. package/lib/types/chart-to-ts-event.types.js +13 -0
  108. package/lib/types/chart-to-ts-event.types.js.map +1 -1
  109. package/lib/types/common.types.d.ts +9 -8
  110. package/lib/types/common.types.d.ts.map +1 -1
  111. package/lib/types/ts-to-chart-event.types.d.ts +25 -1
  112. package/lib/types/ts-to-chart-event.types.d.ts.map +1 -1
  113. package/lib/types/ts-to-chart-event.types.js +3 -0
  114. package/lib/types/ts-to-chart-event.types.js.map +1 -1
  115. package/lib/types/visual-prop.types.d.ts +27 -1
  116. package/lib/types/visual-prop.types.d.ts.map +1 -1
  117. package/package.json +9 -3
  118. package/src/index.ts +1 -0
  119. package/src/main/custom-chart-context.spec.ts +513 -26
  120. package/src/main/custom-chart-context.ts +269 -18
  121. package/src/main/post-message-event-bridge.spec.ts +5 -3
  122. package/src/main/post-message-event-bridge.ts +3 -3
  123. package/src/react/mocks/custom-chart-context-mock.ts +114 -0
  124. package/src/react/use-custom-chart-context.spec.tsx +464 -0
  125. package/src/react/use-custom-chart-context.tsx +180 -0
  126. package/src/react/use-custom-chart-context.util.ts +101 -0
  127. package/src/react/use-custom-chart-types.ts +70 -0
  128. package/src/types/answer-column.types.ts +5 -5
  129. package/src/types/chart-to-ts-event.types.ts +233 -31
  130. package/src/types/common.types.ts +37 -26
  131. package/src/types/configurator.types.ts +8 -8
  132. package/src/types/ts-to-chart-event.types.ts +80 -4
  133. package/src/types/visual-prop.types.ts +148 -11
  134. package/lib/dist/ts-chart-sdk.d.ts +0 -312
@@ -0,0 +1,101 @@
1
+ import _ from 'lodash';
2
+ import { CustomChartContext } from '../main/custom-chart-context';
3
+ import {
4
+ ChartToTSEvent,
5
+ ChartToTSEventsPayloadMap,
6
+ } from '../types/chart-to-ts-event.types';
7
+ import {
8
+ TSToChartEvent,
9
+ TSToChartEventsPayloadMap,
10
+ } from '../types/ts-to-chart-event.types';
11
+ import {
12
+ ChartToTSEventEmitters,
13
+ TSToChartEventListener,
14
+ TSToChartEventOffListener,
15
+ } from './use-custom-chart-types';
16
+
17
+ /**
18
+ *
19
+ * @param ctx Custom Chart Context
20
+ * @returns List of event emitters
21
+ */
22
+ export const emitter = (ctx: CustomChartContext): ChartToTSEventEmitters => {
23
+ const validEvents = Object.keys(
24
+ ChartToTSEvent,
25
+ ) as (keyof ChartToTSEventsPayloadMap)[];
26
+ return validEvents.reduce((acc, eventKey) => {
27
+ const eventName = eventKey as keyof ChartToTSEventsPayloadMap;
28
+ const emitterKey = `emit${eventKey}` as keyof ChartToTSEventEmitters;
29
+
30
+ acc[emitterKey] = (
31
+ ...args: ChartToTSEventsPayloadMap[keyof ChartToTSEventsPayloadMap]
32
+ ): Promise<void> => {
33
+ if (!ctx || _.isEmpty(ctx)) {
34
+ console.log('Context is not initialized');
35
+ return Promise.reject(new Error('Context not initialized'));
36
+ }
37
+ return ctx.emitEvent(eventName, ...args);
38
+ };
39
+
40
+ return acc;
41
+ }, {} as ChartToTSEventEmitters);
42
+ };
43
+
44
+ /**
45
+ *
46
+ * @param ctx Custom Chart Context
47
+ * @returns List of event listeners
48
+ */
49
+ export const eventListener = (
50
+ ctx: CustomChartContext,
51
+ ): TSToChartEventListener => {
52
+ const validEvents = Object.keys(
53
+ TSToChartEvent,
54
+ ) as (keyof TSToChartEventsPayloadMap)[];
55
+ return validEvents.reduce((acc, eventKey) => {
56
+ const eventName = eventKey as keyof TSToChartEventsPayloadMap;
57
+ const emitterKey = `setOn${eventKey}` as keyof TSToChartEventListener;
58
+
59
+ acc[emitterKey] = (
60
+ callbackFn: TSToChartEventsPayloadMap[keyof TSToChartEventsPayloadMap],
61
+ ): Promise<void> => {
62
+ if (!ctx || _.isEmpty(ctx)) {
63
+ console.log('Context is not initialized');
64
+ return Promise.reject(new Error('Context not initialized'));
65
+ }
66
+ ctx.on(eventName, callbackFn);
67
+ return Promise.resolve();
68
+ };
69
+
70
+ return acc;
71
+ }, {} as TSToChartEventListener);
72
+ };
73
+
74
+ /**
75
+ *
76
+ * @param ctx Custom Chart Context
77
+ * @returns List of event listeners
78
+ */
79
+ export const eventOffListener = (
80
+ ctx: CustomChartContext,
81
+ ): TSToChartEventOffListener => {
82
+ const validEvents = Object.keys(
83
+ TSToChartEvent,
84
+ ) as (keyof TSToChartEventsPayloadMap)[];
85
+ return validEvents.reduce((acc, eventKey) => {
86
+ const eventName = eventKey as keyof TSToChartEventsPayloadMap;
87
+ const emitterKey =
88
+ `setOff${eventKey}` as keyof TSToChartEventOffListener;
89
+
90
+ acc[emitterKey] = (): Promise<void> => {
91
+ if (!ctx || _.isEmpty(ctx)) {
92
+ console.log('Context is not initialized');
93
+ return Promise.reject(new Error('Context not initialized'));
94
+ }
95
+ ctx.off(eventName);
96
+ return Promise.resolve();
97
+ };
98
+
99
+ return acc;
100
+ }, {} as TSToChartEventOffListener);
101
+ };
@@ -0,0 +1,70 @@
1
+ import React from 'react';
2
+ import { ChartToTSEventsPayloadMap } from '../types/chart-to-ts-event.types';
3
+ import { ChartModel } from '../types/common.types';
4
+ import { TSToChartEventsPayloadMap } from '../types/ts-to-chart-event.types';
5
+
6
+ /**
7
+ * For all events that we trigger from React Chart to TS Host,
8
+ * this enum provides the trigger functions for each event.
9
+ * All the trigger functions have a prefix of emit.
10
+ */
11
+ export type ChartToTSEventEmitters = {
12
+ [key in keyof ChartToTSEventsPayloadMap as `emit${Capitalize<key>}`]: (
13
+ ...args: ChartToTSEventsPayloadMap[key]
14
+ ) => Promise<void>;
15
+ };
16
+
17
+ /**
18
+ * For all events that we trigger from TS Host to React Chart,
19
+ * this enum provides the event listener on functions for each external event listener.
20
+ * All the event listener functions have a prefix of on.
21
+ */
22
+ export type TSToChartEventListener = {
23
+ [key in keyof TSToChartEventsPayloadMap as `setOn${Capitalize<key>}`]: (
24
+ args: TSToChartEventsPayloadMap[key],
25
+ ) => Promise<void>;
26
+ };
27
+
28
+ /**
29
+ * For all events that we trigger from TS Host to React Chart,
30
+ * this enum provides the event listener on functions for each external event listener.
31
+ * All the event listener functions have a prefix of on.
32
+ */
33
+ export type TSToChartEventOffListener = {
34
+ [key in keyof TSToChartEventsPayloadMap as `setOff${Capitalize<key>}`]: () => Promise<void>;
35
+ };
36
+
37
+ export interface TSChartContextProps {
38
+ /**
39
+ * Child App which renders chart
40
+ * wrapper is used to control rendering of child app
41
+ */
42
+ children: React.ReactNode;
43
+ }
44
+
45
+ export interface ChartContextProps
46
+ extends ChartToTSEventEmitters,
47
+ TSToChartEventListener,
48
+ TSToChartEventOffListener {
49
+ /**
50
+ * decides if the chart context is initialzed
51
+ */
52
+ hasInitialized: boolean;
53
+ /**
54
+ * chart model to be used by client having
55
+ * config, data and visual props
56
+ */
57
+ chartModel: ChartModel | undefined;
58
+ /**
59
+ * For destroying current chart context
60
+ * @returns void
61
+ */
62
+ destroy: () => void;
63
+ /**
64
+ * Parent component wrapped around chart app
65
+ * for controlling re-rendering of chart
66
+ * @param children
67
+ * @returns React.JSX.Element
68
+ */
69
+ TSChartContext: ({ children }: TSChartContextProps) => React.JSX.Element;
70
+ }
@@ -72,14 +72,14 @@ export enum CurrencyFormatType {
72
72
  }
73
73
 
74
74
  /**
75
- * Currency Format for the columm defined in the worksheet
75
+ * Currency format for the column defined in the worksheet
76
76
  *
77
77
  * @version SDK: 0.1 | ThoughtSpot:
78
78
  */
79
79
  export interface CurrencyFormat {
80
80
  type: CurrencyFormatType;
81
81
  /**
82
- * column id of the column in case of currency formatted by a column
82
+ * column ID of the column in case of currency formatted by a column
83
83
  *
84
84
  * @version SDK: 0.1 | ThoughtSpot:
85
85
  */
@@ -118,13 +118,13 @@ export interface ColumnFormat {
118
118
 
119
119
  export interface ChartColumn {
120
120
  /**
121
- * Column Id
121
+ * Column ID
122
122
  *
123
123
  * @version SDK: 0.1 | ThoughtSpot:
124
124
  */
125
125
  id: string;
126
126
  /**
127
- * Column Name
127
+ * Column name
128
128
  *
129
129
  * @version SDK: 0.1 | ThoughtSpot:
130
130
  */
@@ -137,7 +137,7 @@ export interface ChartColumn {
137
137
  type: ColumnType;
138
138
 
139
139
  /**
140
- * Type of the time based aggregation
140
+ * Type of the time-based aggregation
141
141
  * when the column data is of type Date, Datetime, Time
142
142
  *
143
143
  * @version SDK: 0.1 | ThoughtSpot:
@@ -1,4 +1,9 @@
1
1
  import { VisualProps } from './common.types';
2
+ import {
3
+ CustomAxisMenuAction,
4
+ CustomContextMenuAction,
5
+ Query,
6
+ } from './ts-to-chart-event.types';
2
7
 
3
8
  /**
4
9
  *
@@ -25,13 +30,30 @@ export enum ChartToTSEvent {
25
30
  RenderComplete = 'RenderComplete',
26
31
 
27
32
  /**
28
- * Visual Props Update
33
+ * Visual props update
29
34
  */
30
35
  UpdateVisualProps = 'UpdateVisualProps',
36
+
37
+ /**
38
+ * TML events
39
+ */
40
+ GetTMLString = 'GetTMLString',
41
+ SetTMLString = 'SetTMLString',
42
+
43
+ /**
44
+ * Fetch data for custom query
45
+ */
46
+ GetDataForQuery = 'GetDataForQuery',
47
+
48
+ /**
49
+ * Tooltip events
50
+ */
51
+ ShowToolTip = 'ShowToolTip',
52
+ HideToolTip = 'HideToolTip',
31
53
  }
32
54
 
33
55
  /**
34
- * This map defines the event type and its corresponding payload needed by event
56
+ * This map defines the event type and its corresponding payload needed by the event
35
57
  *
36
58
  * @version SDK: 0.1 | ThoughtSpot:
37
59
  * @group Chart to ThoughtSpot Events
@@ -42,55 +64,108 @@ export interface ChartToTSEventsPayloadMap {
42
64
  *
43
65
  * @version SDK: 0.1 | ThoughtSpot:
44
66
  */
45
- [ChartToTSEvent.OpenContextMenu]: OpenContextMenuEventPayload;
67
+ [ChartToTSEvent.OpenContextMenu]: [OpenContextMenuEventPayload];
46
68
  /**
47
69
  * Trigger to close Context Menu
48
70
  *
49
71
  * @version SDK: 0.1 | ThoughtSpot:
50
72
  */
51
- [ChartToTSEvent.CloseContextMenu]: null;
73
+ [ChartToTSEvent.CloseContextMenu]: [];
52
74
 
53
75
  /**
54
76
  * Trigger to notify the render start
55
77
  *
56
78
  * @version SDK: 0.1 | ThoughtSpot:
57
79
  */
58
- [ChartToTSEvent.RenderStart]: null;
80
+ [ChartToTSEvent.RenderStart]: [];
59
81
  /**
60
82
  * Trigger to notify the render completion
61
83
  *
62
84
  * @version SDK: 0.1 | ThoughtSpot:
63
85
  */
64
- [ChartToTSEvent.RenderComplete]: null;
86
+ [ChartToTSEvent.RenderComplete]: [];
65
87
  /**
66
88
  * Trigger to notify the render error
67
89
  *
68
90
  * @version SDK: 0.1 | ThoughtSpot:
69
91
  */
70
- [ChartToTSEvent.RenderError]: RenderErrorEventPayload;
92
+ [ChartToTSEvent.RenderError]: [RenderErrorEventPayload];
71
93
  /**
72
94
  * Trigger to update the visual props
73
95
  *
74
96
  * @version SDK: 0.1 | ThoughtSpot:
75
97
  */
76
- [ChartToTSEvent.UpdateVisualProps]: UpdateVisualPropsEventPayload;
98
+ [ChartToTSEvent.UpdateVisualProps]: [UpdateVisualPropsEventPayload];
99
+
100
+ /**
101
+ * Trigger to get the TML string
102
+ *
103
+ * @version SDK: 0.1 | ThoughtSpot:
104
+ */
105
+ [ChartToTSEvent.GetTMLString]: [];
106
+ /**
107
+ * Trigger to set the TML string
108
+ *
109
+ * @version SDK: 0.1 | ThoughtSpot:
110
+ */
111
+ [ChartToTSEvent.SetTMLString]: [SetTMLStringEventPayload];
112
+ /**
113
+ * Trigger to get the data for custom query
114
+ * @version SDK: 0.1 | ThoughtSpot:
115
+ */
116
+ [ChartToTSEvent.GetDataForQuery]: [GetDataForQueryEventPayload];
117
+ /**
118
+ * Trigger to update the visual props
119
+ *
120
+ * @version SDK: 0.0.1-alpha.4 | ThoughtSpot:
121
+ */
122
+ [ChartToTSEvent.ShowToolTip]: [ShowToolTipEventPayload];
123
+ /**
124
+ * Trigger to update the visual props
125
+ *
126
+ * @version SDK: 0.0.1-alpha.4 | ThoughtSpot:
127
+ */
128
+ [ChartToTSEvent.HideToolTip]: [];
129
+ /**
130
+ * Trigger to open Axis Menu
131
+ *
132
+ * @version SDK: 0.0.1-alpha.7 | ThoughtSpot:
133
+ */
134
+ [ChartToTSEvent.OpenAxisMenu]: [OpenAxisMenuEventPayload];
135
+ /**
136
+ * Trigger to close Axis Menu
137
+ *
138
+ * @version SDK: 0.0.1-alpha.7 | ThoughtSpot:
139
+ */
140
+ [ChartToTSEvent.CloseAxisMenu]: [];
141
+ }
142
+
143
+ /**
144
+ *
145
+ * @group Chart to ThoughtSpot Events
146
+ */
147
+ export interface UpdateVisualPropsEventPayload {
148
+ visualProps: VisualProps;
77
149
  }
78
150
 
79
151
  /**
80
152
  *
81
153
  * @group Chart to ThoughtSpot Events
82
154
  */
83
- type UpdateVisualPropsEventPayload = VisualProps;
155
+ export interface SetTMLStringEventPayload {
156
+ // TML string to be set
157
+ tmlString: string;
158
+ }
84
159
 
85
160
  /**
86
161
  * @group Chart to ThoughtSpot Events / Context Menu
87
162
  */
88
163
  // start - open context menu payload
89
164
  export interface PointVal {
90
- // column id of the column associated with the value
165
+ // Column ID of the column associated with the value
91
166
  columnId: string;
92
- // value of the point clicked on, mostly makes sense for attributes.
93
- // this can be an array of values as well.
167
+ // Value of the point clicked on, mostly makes sense for attributes.
168
+ // This can be an array of values as well.
94
169
  value: any;
95
170
  }
96
171
  /**
@@ -106,16 +181,16 @@ export interface Point {
106
181
  * @group Chart to ThoughtSpot Events / Context Menu
107
182
  */
108
183
  export interface CustomAction {
109
- id: string; // id of the action user defined
110
- label: string; // developer should i18n this
111
- icon: string; // icon string to show on the context/axis menu
184
+ id: string; // ID of the user-defined action
185
+ label: string; // Developer should i18n this
186
+ icon?: string; // Icon string to show on the context/axis menu
112
187
 
113
188
  /**
114
- * This function will need to have a defined set of args.
115
- * For e.g., pointClick Event, point details and chart model in case on context menu
116
- * For axis menu, it would be different.
189
+ * This function will need to have a defined set of arguments.
190
+ * For example, pointClick Event, point details and chart model in case of context menu
191
+ * For Axis menu, it would be different.
117
192
  *
118
- * Callback will be triggered via postMessage api contract.
193
+ * Callback will be triggered via postMessage API contract.
119
194
  */
120
195
  onClick: (...args: any[]) => void;
121
196
  }
@@ -125,31 +200,51 @@ export interface CustomAction {
125
200
  * @group Chart to ThoughtSpot Events
126
201
  */
127
202
  export interface OpenContextMenuEventPayload {
128
- event: Pick<
129
- PointerEvent,
130
- | 'x'
131
- | 'y'
132
- | 'clientX'
133
- | 'clientY'
134
- | 'pageX'
135
- | 'pageY'
136
- | 'screenX'
137
- | 'screenY'
138
- >;
203
+ event: Pick<PointerEvent, 'clientX' | 'clientY'>;
139
204
  clickedPoint: Point;
140
205
  selectedPoints?: Point[];
141
206
  customActions?: CustomAction[];
142
207
  }
143
208
  // end - open context menu payload
144
209
 
210
+ /**
211
+ * Payload for the event triggered to show a tooltip
212
+ */
213
+ export interface ShowToolTipEventPayload {
214
+ /**
215
+ * The pointer event that triggered the tooltip display
216
+ * It includes the client's X and Y coordinates.
217
+ */
218
+ event: Pick<PointerEvent, 'clientX' | 'clientY'>;
219
+ /**
220
+ * Optional custom content to display in the tooltip.
221
+ */
222
+ customTooltipContent?: string[];
223
+ /**
224
+ * Information about the data point associated
225
+ * with the tooltip
226
+ * User can also include both point and customTooltipContent
227
+ * depending upon the requirement
228
+ */
229
+ point?: Point;
230
+ }
231
+ // end - tooltip payload
232
+
145
233
  /**
146
234
  * @group Chart to ThoughtSpot Events
147
235
  */
148
- interface RenderErrorEventPayload {
236
+ export interface RenderErrorEventPayload {
149
237
  hasError: boolean;
150
238
  error: any;
151
239
  }
152
240
 
241
+ /**
242
+ * @group Chart to ThoughtSpot Events
243
+ */
244
+ export interface GetDataForQueryEventPayload {
245
+ queries: Query[];
246
+ }
247
+
153
248
  /**
154
249
  *
155
250
  * @group Chart to ThoughtSpot Events
@@ -157,3 +252,110 @@ interface RenderErrorEventPayload {
157
252
  export enum ErrorType {
158
253
  MultipleContextsNotSupported = 'MultipleContextsNotSupported',
159
254
  }
255
+
256
+ /**
257
+ * List of supported actions for the menu items in the axis menu
258
+ * @group Chart to ThoughtSpot Events
259
+ */
260
+ export enum AxisMenuActions {
261
+ /**
262
+ * Change the aggregation of the column from the possible options.
263
+ * Only supported for numeric columns.
264
+ */
265
+ AGGREGATE = 'AGGREGATE',
266
+ /**
267
+ * Change the bucketing of the date or date time column from the possible options.
268
+ * Only supported for date or date time columns.
269
+ * */
270
+ TIME_BUCKET = 'TIME_BUCKET',
271
+ /**
272
+ * Add or update the filter for the column.
273
+ * */
274
+ FILTER = 'FILTER',
275
+ /**
276
+ * Sort the column in ascending or descending order.
277
+ * */
278
+ SORT = 'SORT',
279
+
280
+ /**
281
+ * These 2 methods are disabled currently as they are not supported by the backend.
282
+ * Following are the reasons for the same:
283
+ * 1. Remove is ambiguous as it can mean remove from the answer scope or remove from the chart.
284
+ * 2. Rename columns is not supported by the menu for now. If need be, this can be implemented.
285
+ */
286
+ // /**
287
+ // * Rename the column.
288
+ // * */
289
+ // RENAME = 'RENAME',
290
+ // /**
291
+ // * Remove the column from the answer scope.
292
+ // * */
293
+ // REMOVE = 'REMOVE',
294
+ /**
295
+ * Defines a separator element between the actions.
296
+ * Can be added multiple times.
297
+ * */
298
+ SEPARATOR = 'SEPARATOR',
299
+ }
300
+
301
+ export interface AxisMenuCustomAction {
302
+ /**
303
+ * ID of the custom action.
304
+ * */
305
+ id: string;
306
+ /**
307
+ * Label of the custom action.
308
+ * */
309
+ label: string;
310
+ /**
311
+ * Icon of the custom action.
312
+ * */
313
+ icon?: string;
314
+ /**
315
+ * Callback function that will be triggered when the custom action is clicked.
316
+ * */
317
+ onClick: (...args: any[]) => void;
318
+ }
319
+
320
+ export interface OpenAxisMenuEventPayload {
321
+ /**
322
+ * The pointer event that triggered the event to position the axis menu.
323
+ */
324
+ event: Pick<PointerEvent, 'clientX' | 'clientY'>;
325
+ /**
326
+ * The column IDs of the columns that can be modified via the axis menu.
327
+ * This maps to the columns in chart model.
328
+ * The order of the column IDs is the same as the order of the columns in the axis menu.
329
+ * Atleast one column id is required.
330
+ * */
331
+ columnIds: string[];
332
+ /**
333
+ * The list of actions that are supported for the axis menu for each column.
334
+ * The order of the actions is the same as the order of the columns in the axis menu.
335
+ * If empty, all the supported actions in default order will be available.
336
+ * */
337
+ selectedActions?: AxisMenuActions[];
338
+ /**
339
+ * Custom action defined by the developer of the chart.
340
+ * This action will trigger the callback defined in the custom action payload.
341
+ * can be added multiple times.
342
+ * @hidden
343
+ * */
344
+ customActions?: AxisMenuCustomAction[];
345
+ }
346
+
347
+ /**
348
+ *
349
+ * @group Custom action callback mapping with action id/ Context Menu
350
+ */
351
+ export interface ContextMenuActionHandler {
352
+ [key: string]: (args: CustomContextMenuAction) => void;
353
+ }
354
+
355
+ /**
356
+ *
357
+ * @group Custom action callback mapping with action id/ Axis Menu
358
+ */
359
+ export interface AxisMenuActionHandler {
360
+ [key: string]: (args: CustomAxisMenuAction) => void;
361
+ }