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

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 (63) hide show
  1. package/dist/ts-chart-sdk.d.ts +312 -0
  2. package/lib/dist/ts-chart-sdk.d.ts +312 -0
  3. package/lib/index.d.ts +8 -0
  4. package/lib/index.d.ts.map +1 -0
  5. package/lib/index.js +8 -0
  6. package/lib/index.js.map +1 -0
  7. package/lib/main/custom-chart-context.d.ts +38 -0
  8. package/lib/main/custom-chart-context.d.ts.map +1 -0
  9. package/lib/main/custom-chart-context.js +176 -0
  10. package/lib/main/custom-chart-context.js.map +1 -0
  11. package/lib/main/custom-chart-context.spec.d.ts +2 -0
  12. package/lib/main/custom-chart-context.spec.d.ts.map +1 -0
  13. package/lib/main/custom-chart-context.spec.js +315 -0
  14. package/lib/main/custom-chart-context.spec.js.map +1 -0
  15. package/lib/main/post-message-event-bridge.d.ts +6 -0
  16. package/lib/main/post-message-event-bridge.d.ts.map +1 -0
  17. package/lib/main/post-message-event-bridge.js +41 -0
  18. package/lib/main/post-message-event-bridge.js.map +1 -0
  19. package/lib/main/post-message-event-bridge.spec.d.ts +2 -0
  20. package/lib/main/post-message-event-bridge.spec.d.ts.map +1 -0
  21. package/lib/main/post-message-event-bridge.spec.js +117 -0
  22. package/lib/main/post-message-event-bridge.spec.js.map +1 -0
  23. package/lib/test/test-utils.d.ts +7 -0
  24. package/lib/test/test-utils.d.ts.map +1 -0
  25. package/lib/test/test-utils.js +11 -0
  26. package/lib/test/test-utils.js.map +1 -0
  27. package/lib/types/answer-column.types.d.ts +69 -0
  28. package/lib/types/answer-column.types.d.ts.map +1 -0
  29. package/lib/types/answer-column.types.js +56 -0
  30. package/lib/types/answer-column.types.js.map +1 -0
  31. package/lib/types/chart-to-ts-event.types.d.ts +48 -0
  32. package/lib/types/chart-to-ts-event.types.d.ts.map +1 -0
  33. package/lib/types/chart-to-ts-event.types.js +16 -0
  34. package/lib/types/chart-to-ts-event.types.js.map +1 -0
  35. package/lib/types/common.types.d.ts +51 -0
  36. package/lib/types/common.types.d.ts.map +1 -0
  37. package/lib/types/common.types.js +2 -0
  38. package/lib/types/common.types.js.map +1 -0
  39. package/lib/types/configurator.types.d.ts +15 -0
  40. package/lib/types/configurator.types.d.ts.map +1 -0
  41. package/lib/types/configurator.types.js +2 -0
  42. package/lib/types/configurator.types.js.map +1 -0
  43. package/lib/types/ts-to-chart-event.types.d.ts +67 -0
  44. package/lib/types/ts-to-chart-event.types.d.ts.map +1 -0
  45. package/lib/types/ts-to-chart-event.types.js +12 -0
  46. package/lib/types/ts-to-chart-event.types.js.map +1 -0
  47. package/lib/types/visual-prop.types.d.ts +47 -0
  48. package/lib/types/visual-prop.types.d.ts.map +1 -0
  49. package/lib/types/visual-prop.types.js +2 -0
  50. package/lib/types/visual-prop.types.js.map +1 -0
  51. package/package.json +88 -0
  52. package/src/index.ts +7 -0
  53. package/src/main/custom-chart-context.spec.ts +432 -0
  54. package/src/main/custom-chart-context.ts +587 -0
  55. package/src/main/post-message-event-bridge.spec.ts +215 -0
  56. package/src/main/post-message-event-bridge.ts +88 -0
  57. package/src/test/test-utils.ts +13 -0
  58. package/src/types/answer-column.types.ts +174 -0
  59. package/src/types/chart-to-ts-event.types.ts +159 -0
  60. package/src/types/common.types.ts +187 -0
  61. package/src/types/configurator.types.ts +102 -0
  62. package/src/types/ts-to-chart-event.types.ts +257 -0
  63. package/src/types/visual-prop.types.ts +271 -0
@@ -0,0 +1,187 @@
1
+ /**
2
+ * @file: Common Types
3
+ * @fileoverview All commons types for the Custom Chart implementations
4
+ * @author Chetan Agrawal <chetan.agrawal@thoughtspot.com>
5
+ *
6
+ * Copyright: ThoughtSpot Inc. 2023
7
+ */
8
+
9
+ import { ChartColumn, DataType } from './answer-column.types';
10
+
11
+ /**
12
+ * List of Columns for a dimension in the Custom Chart Config.
13
+ * Associated with the key defined in the chart config editor definition
14
+ * Relates to ChartConfigSection
15
+ *
16
+ * @version SDK: 0.1 | ThoughtSpot:
17
+ * @group Chart Model
18
+ */
19
+ export interface ChartConfigDimension {
20
+ /**
21
+ * key fo the dimension in the chart config
22
+ *
23
+ * @version SDK: 0.1 | ThoughtSpot:
24
+ */
25
+ key: string;
26
+ /**
27
+ * list of columns added for the dimension
28
+ *
29
+ * @version SDK: 0.1 | ThoughtSpot:
30
+ */
31
+ columns: ChartColumn[];
32
+ }
33
+
34
+ /**
35
+ * Custom Chart Config values stored in the metadata
36
+ * Relates to ChartConfigEditorDefinition
37
+ *
38
+ * @version SDK: 0.1 | ThoughtSpot:
39
+ * @group Chart Model
40
+ */
41
+ export interface ChartConfig {
42
+ /**
43
+ * key of the custom chart config defined in the chart config editor definition
44
+ * this is used to differentiate between different custom chart configurations
45
+ * within the same chart
46
+ *
47
+ * @version SDK: 0.1 | ThoughtSpot:
48
+ */
49
+ key: string;
50
+ /**
51
+ * Details of columns for each dimension
52
+ *
53
+ * @version SDK: 0.1 | ThoughtSpot:
54
+ */
55
+ dimensions: ChartConfigDimension[];
56
+ }
57
+
58
+ /**
59
+ * Data Array inteface to define each column data
60
+ *
61
+ * @version SDK: 0.1 | ThoughtSpot:
62
+ * @group Chart Model
63
+ */
64
+ export type DataArray = {
65
+ /**
66
+ * column id associated with the data array
67
+ *
68
+ * @version SDK: 0.1 | ThoughtSpot:
69
+ */
70
+ columnId: string;
71
+ /**
72
+ * type of data
73
+ *
74
+ * @version SDK: 0.1 | ThoughtSpot:
75
+ */
76
+ columnDataType: DataType;
77
+ /**
78
+ * The array of data values associated with the column
79
+ *
80
+ * @version SDK: 0.1 | ThoughtSpot:
81
+ */
82
+ dataValue: any[];
83
+ };
84
+
85
+ /**
86
+ * For each query defined by the user, a query data object is sent
87
+ * in the following format
88
+ *
89
+ * @version SDK: 0.1 | ThoughtSpot:
90
+ * @group Chart Model
91
+ */
92
+ export type QueryData = {
93
+ /**
94
+ * Data Array for each column
95
+ *
96
+ * @version SDK: 0.1 | ThoughtSpot:
97
+ */
98
+ data: DataArray[];
99
+
100
+ /**
101
+ * @hidden
102
+ * @version SDK: 0.1 | ThoughtSpot:
103
+ */
104
+ completionRatio: number;
105
+ /**
106
+ * @hidden
107
+ * @version SDK: 0.1 | ThoughtSpot:
108
+ */
109
+ samplingRatio: number;
110
+
111
+ /**
112
+ * number of rows of data fetched for the query
113
+ *
114
+ * @version SDK: 0.1 | ThoughtSpot:
115
+ */
116
+ totalRowCount: number;
117
+ };
118
+
119
+ /**
120
+ *
121
+ * @group Chart Model
122
+ * @version SDK: 0.1 | ThoughtSpot:
123
+ */
124
+ export interface ChartModel {
125
+ /**
126
+ * List of columns in the search query
127
+ * They may or may not be part of the data query or chart config
128
+ *
129
+ * @version SDK: 0.1 | ThoughtSpot:
130
+ */
131
+ columns: ChartColumn[];
132
+ /**
133
+ * Array of Datasets for each query
134
+ *
135
+ * @version SDK: 0.1 | ThoughtSpot:
136
+ */
137
+ data?: QueryData[];
138
+ sortInfo?: any; // TODO(chetan):
139
+ visualProps?: VisualProps;
140
+ config: {
141
+ // chart config stored by chart developer
142
+ chartConfig?: ChartConfig[];
143
+ };
144
+ }
145
+
146
+ // Generic Validation Response
147
+ export type ValidationResponse = {
148
+ isValid: boolean;
149
+ validationErrorMessage?: string[];
150
+ };
151
+
152
+ /**
153
+ * Custom Visual props is the stored metadata for the visual props definition
154
+ * configured by the user in the visual prop editor
155
+ * The JSON is defined by the visual prop types. See VisualPropEditorDefinition
156
+ *
157
+ * @group Chart Model
158
+ * @version SDK: 0.1 | ThoughtSpot:
159
+ */
160
+ export type VisualProps = JSON;
161
+
162
+ // Todo: this should be imported from custom style config package.
163
+ type CustomStylingConfig = any;
164
+
165
+ export interface AppConfig {
166
+ styleConfig?: CustomStylingConfig;
167
+
168
+ appOptions?: {
169
+ isMobile?: boolean;
170
+ isPrintMode?: boolean; // export mode on/off
171
+
172
+ // runtime configurations
173
+ isDebugMode?: boolean; // enables debug mode for logging
174
+ };
175
+
176
+ // locale related settings
177
+ localeOptions?: {
178
+ locale: string;
179
+ quarterStartMonth: string;
180
+ sessionTimezone: string;
181
+ };
182
+
183
+ // Idea: we might be able to map this to data and ask user to read data in a
184
+ // certain way the transformations for point during context menu operations
185
+ // need to be explored
186
+ customCalendarConfig?: any; // this is to initialize custom calendar service
187
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @file Column Configuration Definition
3
+ * @fileoverview
4
+ * Developers will use this to define the axis configuration that any
5
+ * creator of the chart can use the define the expected chart configuration.
6
+ *
7
+ * This will also be validated with the overall expectation
8
+ * of the chart developer using validate flow.
9
+ *
10
+ * Developer is expected to use this to be able to define the data queries
11
+ * required for the chart.
12
+ * @author Chetan Agrawal <chetan.agrawal@thoughtspot.com>
13
+ *
14
+ * Copyright: ThoughtSpot Inc. 2023
15
+ */
16
+
17
+ /**
18
+ *
19
+ * @group Chart Configuration Editor
20
+ */
21
+ export interface ChartConfigSection {
22
+ /**
23
+ * key to persist the columns
24
+ *
25
+ * @version SDK: 0.1 | ThoughtSpot:
26
+ */
27
+ key: string;
28
+ /**
29
+ * i18n'ed string to show the section label on the config editor
30
+ *
31
+ * @version SDK: 0.1 | ThoughtSpot:
32
+ */
33
+ label: string;
34
+
35
+ /**
36
+ * In the UI, the following values will only prevent from dropping unnecessary
37
+ * columns on the section config or prevent from opening a drop down in case of
38
+ * multiple queries. Validation is still expected to be done by developer.
39
+ */
40
+
41
+ /**
42
+ * Number of columns allowed in the section
43
+ *
44
+ * @default Number.POSITIVE_INFINITY
45
+ * @version SDK: 0.1 | ThoughtSpot:
46
+ */
47
+ maxColumnCount?: number;
48
+ /**
49
+ * Allow Numeric Columns on the Section
50
+ *
51
+ * @default true
52
+ * @version SDK: 0.1 | ThoughtSpot:
53
+ */
54
+ allowMeasureColumns?: boolean;
55
+ /**
56
+ * Allow Attribute/Dimensional Columns on the Section
57
+ * Example: strings, dates, etc
58
+ *
59
+ * @default true
60
+ * @version SDK: 0.1 | ThoughtSpot:
61
+ */
62
+ allowAttributeColumns?: boolean;
63
+ /**
64
+ * Allow Date and Time based Columns on the Section
65
+ *
66
+ * @default true
67
+ * @hidden Not exposing this now to define more clearly
68
+ * @version SDK: 0.1 | ThoughtSpot:
69
+ */
70
+ allowTimeSeriesColumns?: boolean;
71
+ }
72
+
73
+ /**
74
+ *
75
+ * @group Chart Configuration Editor
76
+ */
77
+ export interface ChartConfigEditorDefinition {
78
+ /**
79
+ * key to store the chart config
80
+ *
81
+ * @version SDK: 0.1 | ThoughtSpot:
82
+ */
83
+ key: string;
84
+ /**
85
+ * i18n'ed string to show the editor header for the chart config
86
+ *
87
+ * @version SDK: 0.1 | ThoughtSpot:
88
+ */
89
+ label?: string;
90
+ /**
91
+ * i18n'ed string to show the editor description for the chart config
92
+ *
93
+ * @version SDK: 0.1 | ThoughtSpot:
94
+ */
95
+ descriptionText?: string;
96
+ /**
97
+ * Following will define all the column sections for the chart config
98
+ *
99
+ * @version SDK: 0.1 | ThoughtSpot:
100
+ */
101
+ columnSections: ChartConfigSection[];
102
+ }
@@ -0,0 +1,257 @@
1
+ import { ChartColumn } from './answer-column.types';
2
+ import {
3
+ AppConfig,
4
+ ChartConfig,
5
+ ChartModel,
6
+ QueryData,
7
+ ValidationResponse,
8
+ VisualProps,
9
+ } from './common.types';
10
+ import { ChartConfigEditorDefinition } from './configurator.types';
11
+ import { VisualPropEditorDefinition } from './visual-prop.types';
12
+
13
+ /**
14
+ * All the events sent from TS application to Custom Chart App
15
+ *
16
+ * @version SDK: 0.1 | ThoughtSpot:
17
+ * @group ThoughtSpot to Chart Events
18
+ */
19
+ export enum TSToChartEvent {
20
+ /**
21
+ * @version SDK: 0.1 | ThoughtSpot:
22
+ */
23
+ Initialize = 'Initialize',
24
+
25
+ /**
26
+ * @version SDK: 0.1 | ThoughtSpot:
27
+ */
28
+ GetDataQuery = 'GetDataQuery',
29
+
30
+ /**
31
+ * @version SDK: 0.1 | ThoughtSpot:
32
+ */
33
+ ChartConfigValidate = 'ChartConfigValidate',
34
+ /**
35
+ * @version SDK: 0.1 | ThoughtSpot:
36
+ */
37
+ ChartModelUpdate = 'ChartModelUpdate',
38
+ /**
39
+ * @version SDK: 0.1 | ThoughtSpot:
40
+ */
41
+ DataUpdate = 'DataUpdate',
42
+
43
+ /**
44
+ * @version SDK: 0.1 | ThoughtSpot:
45
+ */
46
+ TriggerRenderChart = 'TriggerRenderChart',
47
+
48
+ /**
49
+ * @version SDK: 0.1 | ThoughtSpot:
50
+ */
51
+ VisualPropsValidate = 'VisualPropsValidate',
52
+ /**
53
+ * @version SDK: 0.1 | ThoughtSpot:
54
+ */
55
+ VisualPropsUpdate = 'VisualPropsUpdate',
56
+ }
57
+
58
+ /**
59
+ * Map of callback function with the event types
60
+ *
61
+ * @version SDK: 0.1 | ThoughtSpot:
62
+ * @group ThoughtSpot to Chart Events
63
+ */
64
+ export interface TSToChartEventsPayloadMap {
65
+ [TSToChartEvent.ChartModelUpdate]: (
66
+ payload: ChartModelUpdateEventPayload,
67
+ ) => void;
68
+ [TSToChartEvent.DataUpdate]: (payload: DataUpdateEventPayload) => void;
69
+ [TSToChartEvent.VisualPropsUpdate]: (
70
+ payload: VisualPropsUpdateEventPayload,
71
+ ) => void;
72
+ }
73
+
74
+ /**
75
+ * Map of internal events that will not be exposed to the developers
76
+ * and is only for internal usage.
77
+ *
78
+ * @internal
79
+ * @hidden
80
+ * @version SDK: 0.1 | ThoughtSpot:
81
+ * @group ThoughtSpot to Chart Events
82
+ */
83
+ export interface TSToChartInternalEventsPayloadMap {
84
+ [TSToChartEvent.Initialize]: (
85
+ payload: InitializeEventPayload,
86
+ ) => InitializeEventResponsePayload;
87
+
88
+ [TSToChartEvent.GetDataQuery]: (
89
+ payload: GetDataQueryPayload,
90
+ ) => GetDataQueryResponsePayload;
91
+
92
+ [TSToChartEvent.ChartConfigValidate]: (
93
+ payload: ChartConfigValidateEventPayload,
94
+ ) => ValidationResponse;
95
+
96
+ [TSToChartEvent.VisualPropsValidate]: (
97
+ payload: VisualPropsValidateEventPayload,
98
+ ) => ValidationResponse;
99
+
100
+ [TSToChartEvent.TriggerRenderChart]: () => void;
101
+ }
102
+
103
+ /**
104
+ *
105
+ * @group ThoughtSpot to Chart Events
106
+ */
107
+ export interface InitializeEventPayload {
108
+ /**
109
+ * The entire chart object with data
110
+ *
111
+ * @version SDK: 0.1 | ThoughtSpot:
112
+ */
113
+ chartModel: ChartModel;
114
+
115
+ /**
116
+ * Additional App Configuration
117
+ *
118
+ * @version SDK: 0.1 | ThoughtSpot:
119
+ */
120
+ appConfig?: AppConfig;
121
+
122
+ /**
123
+ * This is a unique component id that the context should send in every
124
+ * post message payload. This helps in identifying between multiple app components.
125
+ *
126
+ * @version SDK: 0.1 | ThoughtSpot:
127
+ */
128
+ componentId: string;
129
+ /**
130
+ * The host url of the parent to send the post message requests to.
131
+ * We cannot use the window.parent object details to fetch this.
132
+ * Hence sending in init flow.
133
+ *
134
+ * @version SDK: 0.1 | ThoughtSpot:
135
+ */
136
+ hostUrl: string;
137
+ }
138
+
139
+ /**
140
+ *
141
+ * @group ThoughtSpot to Chart Events
142
+ */
143
+ export interface InitializeEventResponsePayload {
144
+ /**
145
+ * Boolean value to define if the current config is valid or not
146
+ * Would be true if the validateChartConfig function is not defined
147
+ *
148
+ * @version SDK: 0.1 | ThoughtSpot:
149
+ */
150
+ isConfigValid: boolean;
151
+ /**
152
+ * Default Chart Config generated if the chart config is not valid or not present.
153
+ *
154
+ * @version SDK: 0.1 | ThoughtSpot:
155
+ */
156
+ defaultChartConfig: ChartConfig[];
157
+ /**
158
+ * chart config editor definition
159
+ *
160
+ * @version SDK: 0.1 | ThoughtSpot:
161
+ */
162
+ chartConfigEditorDefinition?: ChartConfigEditorDefinition[];
163
+ /**
164
+ * visual properties editor definition
165
+ *
166
+ * @version SDK: 0.1 | ThoughtSpot:
167
+ */
168
+ visualPropEditorDefinition?: VisualPropEditorDefinition;
169
+ }
170
+
171
+ /**
172
+ *
173
+ * @group ThoughtSpot to Chart Events
174
+ */
175
+ export interface GetDataQueryPayload {
176
+ config: ChartConfig[];
177
+ }
178
+
179
+ /**
180
+ *
181
+ * @group ThoughtSpot to Chart Events
182
+ */
183
+ export interface Query {
184
+ queryColumns: ChartColumn[];
185
+ queryParams?: {
186
+ offset?: number;
187
+ size?: number;
188
+ };
189
+ }
190
+
191
+ /**
192
+ *
193
+ * @group ThoughtSpot to Chart Events
194
+ */
195
+ export interface GetDataQueryResponsePayload {
196
+ queries: Query[];
197
+ }
198
+
199
+ /**
200
+ *
201
+ * @group ThoughtSpot to Chart Events
202
+ */
203
+ export interface ChartModelUpdateEventPayload {
204
+ /**
205
+ * updated chart model
206
+ *
207
+ * @version SDK: 0.1 | ThoughtSpot:
208
+ */
209
+ chartModel: ChartModel;
210
+ }
211
+
212
+ /**
213
+ *
214
+ * @group ThoughtSpot to Chart Events
215
+ */
216
+ export interface DataUpdateEventPayload {
217
+ /**
218
+ * updated data in the chart model
219
+ *
220
+ * @version SDK: 0.1 | ThoughtSpot:
221
+ */
222
+ data: QueryData[];
223
+ }
224
+ export interface VisualPropsUpdateEventPayload {
225
+ /**
226
+ * updated visual properties
227
+ *
228
+ * @version SDK: 0.1 | ThoughtSpot:
229
+ */
230
+ visualProps: VisualProps;
231
+ }
232
+
233
+ /**
234
+ *
235
+ * @group ThoughtSpot to Chart Events
236
+ */
237
+ export interface VisualPropsValidateEventPayload {
238
+ /**
239
+ * updated visual properties
240
+ *
241
+ * @version SDK: 0.1 | ThoughtSpot:
242
+ */
243
+ visualProps: VisualProps;
244
+ }
245
+
246
+ /**
247
+ *
248
+ * @group ThoughtSpot to Chart Events
249
+ */
250
+ export interface ChartConfigValidateEventPayload {
251
+ /**
252
+ * updated chart config properties
253
+ *
254
+ * @version SDK: 0.1 | ThoughtSpot:
255
+ */
256
+ chartConfig: ChartConfig[];
257
+ }