@thoughtspot/ts-chart-sdk 2.5.7 → 2.6.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.
- package/dist/ts-chart-sdk.d.ts +71 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/main/custom-chart-context.d.ts +3 -1
- package/lib/main/custom-chart-context.d.ts.map +1 -1
- package/lib/main/custom-chart-context.js +46 -1
- package/lib/main/custom-chart-context.js.map +1 -1
- package/lib/main/custom-chart-context.spec.js +64 -1
- package/lib/main/custom-chart-context.spec.js.map +1 -1
- package/lib/react/mocks/custom-chart-context-mock.d.ts.map +1 -1
- package/lib/react/mocks/custom-chart-context-mock.js +3 -7
- package/lib/react/mocks/custom-chart-context-mock.js.map +1 -1
- package/lib/react/use-custom-chart-context.spec.js +67 -1
- package/lib/react/use-custom-chart-context.spec.js.map +1 -1
- package/lib/types/chart-to-ts-event.types.d.ts +27 -0
- package/lib/types/chart-to-ts-event.types.d.ts.map +1 -1
- package/lib/types/chart-to-ts-event.types.js +7 -0
- package/lib/types/chart-to-ts-event.types.js.map +1 -1
- package/lib/types/common.types.d.ts +31 -1
- package/lib/types/common.types.d.ts.map +1 -1
- package/lib/types/common.types.js +11 -0
- package/lib/types/common.types.js.map +1 -1
- package/lib/types/conditional-formatting.types.d.ts +1 -0
- package/lib/types/conditional-formatting.types.d.ts.map +1 -1
- package/lib/types/conditional-formatting.types.js.map +1 -1
- package/lib/types/ts-to-chart-event.types.d.ts +6 -1
- package/lib/types/ts-to-chart-event.types.d.ts.map +1 -1
- package/lib/types/ts-to-chart-event.types.js +1 -0
- package/lib/types/ts-to-chart-event.types.js.map +1 -1
- package/lib/utils/chart-config.d.ts +8 -0
- package/lib/utils/chart-config.d.ts.map +1 -0
- package/lib/utils/chart-config.js +56 -0
- package/lib/utils/chart-config.js.map +1 -0
- package/lib/utils/chart-config.spec.d.ts +2 -0
- package/lib/utils/chart-config.spec.d.ts.map +1 -0
- package/lib/utils/chart-config.spec.js +574 -0
- package/lib/utils/chart-config.spec.js.map +1 -0
- package/package.json +2 -1
- package/src/index.ts +1 -0
- package/src/main/custom-chart-context.spec.ts +106 -1
- package/src/main/custom-chart-context.ts +69 -1
- package/src/react/mocks/custom-chart-context-mock.ts +4 -13
- package/src/react/use-custom-chart-context.spec.tsx +81 -1
- package/src/types/chart-to-ts-event.types.ts +86 -2
- package/src/types/common.types.ts +116 -7
- package/src/types/conditional-formatting.types.ts +1 -0
- package/src/types/ts-to-chart-event.types.ts +16 -1
- package/src/utils/chart-config.spec.ts +680 -0
- package/src/utils/chart-config.ts +100 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { create } from '../main/logger';
|
|
2
|
+
import {
|
|
3
|
+
AxisConfig,
|
|
4
|
+
AxisType,
|
|
5
|
+
ChartConfig,
|
|
6
|
+
ChartConfigDimension,
|
|
7
|
+
ChartConfigMode,
|
|
8
|
+
} from '../types/common.types';
|
|
9
|
+
import { QueryColumn } from '../types/ts-to-chart-event.types';
|
|
10
|
+
|
|
11
|
+
const logger = create('chart-config-utils');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Fetch the query columns from the dimension config.
|
|
15
|
+
* @param config - The dimension config.
|
|
16
|
+
* @returns The query columns.
|
|
17
|
+
*/
|
|
18
|
+
export function fetchQueryColumnsFromDimensionConfig(
|
|
19
|
+
config: AxisConfig,
|
|
20
|
+
): QueryColumn[] {
|
|
21
|
+
const columns: QueryColumn[] = [];
|
|
22
|
+
if (config.type === AxisType.FLAT) {
|
|
23
|
+
columns.push(config.column);
|
|
24
|
+
} else if (config.type === AxisType.MERGED) {
|
|
25
|
+
columns.push(...config.columns);
|
|
26
|
+
} else if (config.type === AxisType.DUAL) {
|
|
27
|
+
columns.push(
|
|
28
|
+
...fetchQueryColumnsFromDimensionConfig(config.primary),
|
|
29
|
+
...fetchQueryColumnsFromDimensionConfig(config.secondary),
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return columns;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Fetch the query columns from the chart config dimension.
|
|
37
|
+
* @param dimension - The dimension.
|
|
38
|
+
* @returns The query columns.
|
|
39
|
+
*/
|
|
40
|
+
export function fetchQueryColumnsFromDimension(
|
|
41
|
+
dimension: ChartConfigDimension,
|
|
42
|
+
): QueryColumn[] {
|
|
43
|
+
if (dimension.mode === ChartConfigMode.AXIS_DRIVEN) {
|
|
44
|
+
// AxisDrivenDimension
|
|
45
|
+
return (
|
|
46
|
+
dimension.axes
|
|
47
|
+
?.map((axis) => fetchQueryColumnsFromDimensionConfig(axis))
|
|
48
|
+
.flat() ?? []
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
// ColumnDrivenDimension
|
|
52
|
+
return dimension.columns ?? [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Fetch the query columns from the chart config.
|
|
57
|
+
* @param chartConfig - The chart config.
|
|
58
|
+
* @returns The query columns.
|
|
59
|
+
*/
|
|
60
|
+
export function fetchQueryColumns(chartConfig: ChartConfig): QueryColumn[] {
|
|
61
|
+
return chartConfig.dimensions
|
|
62
|
+
.map((dimension) => fetchQueryColumnsFromDimension(dimension))
|
|
63
|
+
.flat();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function validateChartConfig(chartConfig: ChartConfig): void {
|
|
67
|
+
if (!chartConfig?.dimensions?.length) {
|
|
68
|
+
const errorMessage =
|
|
69
|
+
'The chart config is invalid. it does not have any dimensions';
|
|
70
|
+
logger.error(errorMessage);
|
|
71
|
+
throw new Error(errorMessage);
|
|
72
|
+
}
|
|
73
|
+
const currentConfigMode = chartConfig.dimensions[0].mode;
|
|
74
|
+
if (!currentConfigMode) {
|
|
75
|
+
logger.warn(
|
|
76
|
+
'The chart config is missing mode property, assuming COLUMN_DRIVEN',
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const allDimensionsHaveSameMode = chartConfig.dimensions.every(
|
|
80
|
+
(dimension) => dimension.mode === currentConfigMode,
|
|
81
|
+
);
|
|
82
|
+
if (!allDimensionsHaveSameMode) {
|
|
83
|
+
const errorMessage =
|
|
84
|
+
'The chart config is invalid. all dimensions must have the same mode';
|
|
85
|
+
logger.error(errorMessage);
|
|
86
|
+
throw new Error(errorMessage);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function validateAllChartConfigs(chartConfigList: ChartConfig[]): void {
|
|
91
|
+
if (!chartConfigList?.length) {
|
|
92
|
+
logger.warn(
|
|
93
|
+
'The chart config is invalid. it does not have any chart configs',
|
|
94
|
+
);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
chartConfigList.forEach((chartConfig) => {
|
|
98
|
+
validateChartConfig(chartConfig);
|
|
99
|
+
});
|
|
100
|
+
}
|