@thoughtspot/ts-chart-sdk 0.0.2-alpha.2 → 0.0.2-alpha.20

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 (87) hide show
  1. package/README.md +126 -50
  2. package/dist/ts-chart-sdk.d.ts +820 -0
  3. package/lib/index.d.ts +4 -0
  4. package/lib/index.d.ts.map +1 -1
  5. package/lib/index.js +4 -0
  6. package/lib/index.js.map +1 -1
  7. package/lib/main/custom-chart-context.d.ts +22 -7
  8. package/lib/main/custom-chart-context.d.ts.map +1 -1
  9. package/lib/main/custom-chart-context.js +59 -4
  10. package/lib/main/custom-chart-context.js.map +1 -1
  11. package/lib/main/custom-chart-context.spec.js +402 -5
  12. package/lib/main/custom-chart-context.spec.js.map +1 -1
  13. package/lib/main/post-message-event-bridge.js +2 -2
  14. package/lib/main/post-message-event-bridge.js.map +1 -1
  15. package/lib/main/util.spec.d.ts +2 -0
  16. package/lib/main/util.spec.d.ts.map +1 -0
  17. package/lib/main/util.spec.js +31 -0
  18. package/lib/main/util.spec.js.map +1 -0
  19. package/lib/react/use-custom-chart-context.spec.js +54 -3
  20. package/lib/react/use-custom-chart-context.spec.js.map +1 -1
  21. package/lib/test/test-conditional-formatting-utils.d.ts +5 -0
  22. package/lib/test/test-conditional-formatting-utils.d.ts.map +1 -0
  23. package/lib/test/test-conditional-formatting-utils.js +43 -0
  24. package/lib/test/test-conditional-formatting-utils.js.map +1 -0
  25. package/lib/types/answer-column.types.d.ts +57 -1
  26. package/lib/types/answer-column.types.d.ts.map +1 -1
  27. package/lib/types/answer-column.types.js +47 -0
  28. package/lib/types/answer-column.types.js.map +1 -1
  29. package/lib/types/chart-to-ts-event.types.d.ts +2 -0
  30. package/lib/types/chart-to-ts-event.types.d.ts.map +1 -1
  31. package/lib/types/chart-to-ts-event.types.js +1 -0
  32. package/lib/types/chart-to-ts-event.types.js.map +1 -1
  33. package/lib/types/common.types.d.ts +67 -4
  34. package/lib/types/common.types.d.ts.map +1 -1
  35. package/lib/types/common.types.js +15 -1
  36. package/lib/types/common.types.js.map +1 -1
  37. package/lib/types/conditional-formatting.types.d.ts +140 -0
  38. package/lib/types/conditional-formatting.types.d.ts.map +1 -0
  39. package/lib/types/conditional-formatting.types.js +60 -0
  40. package/lib/types/conditional-formatting.types.js.map +1 -0
  41. package/lib/types/configurator.types.d.ts +5 -0
  42. package/lib/types/configurator.types.d.ts.map +1 -1
  43. package/lib/types/number-formatting.types.d.ts +55 -0
  44. package/lib/types/number-formatting.types.d.ts.map +1 -0
  45. package/lib/types/number-formatting.types.js +23 -0
  46. package/lib/types/number-formatting.types.js.map +1 -0
  47. package/lib/types/ts-to-chart-event.types.d.ts +10 -5
  48. package/lib/types/ts-to-chart-event.types.d.ts.map +1 -1
  49. package/lib/types/ts-to-chart-event.types.js.map +1 -1
  50. package/lib/types/visual-prop.types.d.ts +21 -0
  51. package/lib/types/visual-prop.types.d.ts.map +1 -1
  52. package/lib/utils/conditional-formatting/conditional-formatting.d.ts +10 -0
  53. package/lib/utils/conditional-formatting/conditional-formatting.d.ts.map +1 -0
  54. package/lib/utils/conditional-formatting/conditional-formatting.js +103 -0
  55. package/lib/utils/conditional-formatting/conditional-formatting.js.map +1 -0
  56. package/lib/utils/conditional-formatting/conditional-formatting.spec.d.ts +2 -0
  57. package/lib/utils/conditional-formatting/conditional-formatting.spec.d.ts.map +1 -0
  58. package/lib/utils/conditional-formatting/conditional-formatting.spec.js +142 -0
  59. package/lib/utils/conditional-formatting/conditional-formatting.spec.js.map +1 -0
  60. package/lib/utils/date-formatting.d.ts +19 -0
  61. package/lib/utils/date-formatting.d.ts.map +1 -0
  62. package/lib/utils/date-formatting.js +56 -0
  63. package/lib/utils/date-formatting.js.map +1 -0
  64. package/lib/utils/date-formatting.spec.d.ts +2 -0
  65. package/lib/utils/date-formatting.spec.d.ts.map +1 -0
  66. package/lib/utils/date-formatting.spec.js +124 -0
  67. package/lib/utils/date-formatting.spec.js.map +1 -0
  68. package/package.json +6 -4
  69. package/src/index.ts +4 -0
  70. package/src/main/custom-chart-context.spec.ts +474 -9
  71. package/src/main/custom-chart-context.ts +246 -12
  72. package/src/main/post-message-event-bridge.ts +1 -1
  73. package/src/main/util.spec.ts +41 -0
  74. package/src/react/use-custom-chart-context.spec.tsx +65 -3
  75. package/src/test/test-conditional-formatting-utils.ts +95 -0
  76. package/src/types/answer-column.types.ts +102 -1
  77. package/src/types/chart-to-ts-event.types.ts +7 -0
  78. package/src/types/common.types.ts +103 -9
  79. package/src/types/conditional-formatting.types.ts +157 -0
  80. package/src/types/configurator.types.ts +21 -0
  81. package/src/types/number-formatting.types.ts +80 -0
  82. package/src/types/ts-to-chart-event.types.ts +38 -6
  83. package/src/types/visual-prop.types.ts +75 -1
  84. package/src/utils/conditional-formatting/conditional-formatting.spec.ts +469 -0
  85. package/src/utils/conditional-formatting/conditional-formatting.ts +229 -0
  86. package/src/utils/date-formatting.spec.ts +168 -0
  87. package/src/utils/date-formatting.ts +109 -0
@@ -0,0 +1,229 @@
1
+ /**
2
+ * @file: Conditional Formatting Utils
3
+ * @fileoverview All CF utils for the Custom Chart implementations
4
+ * @author Yashvardhan Nehra <yashvardhan.nehra@thoughtspot.com>
5
+ *
6
+ * Copyright: ThoughtSpot Inc. 2023
7
+ */
8
+
9
+ import _ from 'lodash';
10
+ import { ChartColumn } from '../../types/answer-column.types';
11
+ import { DataPointsArray } from '../../types/common.types';
12
+ import {
13
+ ConditionalFormatting,
14
+ ConditionalFormattingComparisonTypes,
15
+ ConditionalMetric,
16
+ Operators,
17
+ Parameter,
18
+ } from '../../types/conditional-formatting.types';
19
+
20
+ export const getMinRangeValue = (
21
+ metric: ConditionalMetric,
22
+ ): number | undefined | null => metric?.rangeValues?.min;
23
+
24
+ export const getMaxRangeValue = (
25
+ metric: ConditionalMetric,
26
+ ): number | undefined | null => metric?.rangeValues?.max;
27
+
28
+ /**
29
+ * Performs a value-based comparison between two values based on the specified operator in the
30
+ * metric.
31
+ *
32
+ * @param metric - The conditional formatting metric info
33
+ * @param lhsValue - The left-hand side value to compare.
34
+ * @param rhsValue - The right-hand side value to compare.
35
+ * @returns Boolean indicating the result of the comparison.
36
+ */
37
+ const doValueBasedComparison = (
38
+ metric: ConditionalMetric,
39
+ lhsValue?: string | number | null,
40
+ rhsValue?: string | number | null,
41
+ ): boolean => {
42
+ switch (metric.operator) {
43
+ case Operators.Is:
44
+ case Operators.EqualTo:
45
+ return (
46
+ !_.isNil(lhsValue) &&
47
+ !_.isNil(rhsValue) &&
48
+ (_.isEqual(lhsValue, rhsValue) ||
49
+ _.isEqual(_.toString(lhsValue), _.toString(rhsValue)))
50
+ );
51
+ case Operators.IsNot:
52
+ case Operators.NotEqualTo: {
53
+ if (_.isNil(lhsValue) || _.isNil(rhsValue))
54
+ return lhsValue !== rhsValue;
55
+ return !_.isEqual(_.toString(lhsValue), _.toString(rhsValue));
56
+ }
57
+ case Operators.IsNull:
58
+ case Operators.IsEmpty:
59
+ return _.isNil(lhsValue);
60
+ case Operators.IsNotNull:
61
+ case Operators.IsNotEmpty:
62
+ return !_.isNil(lhsValue);
63
+ case Operators.LessThan:
64
+ return _.toNumber(lhsValue) < _.toNumber(rhsValue);
65
+ case Operators.LessThanEqualTo:
66
+ return _.toNumber(lhsValue) <= _.toNumber(rhsValue);
67
+ case Operators.GreaterThan:
68
+ return _.toNumber(lhsValue) > _.toNumber(rhsValue);
69
+ case Operators.GreaterThanEqualTo:
70
+ return _.toNumber(lhsValue) >= _.toNumber(rhsValue);
71
+ case Operators.IsBetween:
72
+ return (
73
+ lhsValue != null &&
74
+ +lhsValue >= (getMinRangeValue(metric) ?? -Infinity) &&
75
+ +lhsValue <= (getMaxRangeValue(metric) ?? Infinity)
76
+ );
77
+ case Operators.Contains:
78
+ return (
79
+ lhsValue != null &&
80
+ rhsValue != null &&
81
+ _.includes(_.toString(lhsValue), rhsValue.toString())
82
+ );
83
+ case Operators.DoesNotContain:
84
+ return (
85
+ lhsValue != null &&
86
+ rhsValue != null &&
87
+ !_.includes(_.toString(lhsValue), rhsValue.toString())
88
+ );
89
+ case Operators.StartsWith:
90
+ return (
91
+ lhsValue != null &&
92
+ rhsValue != null &&
93
+ _.startsWith(_.toString(lhsValue), rhsValue.toString())
94
+ );
95
+ case Operators.EndsWith:
96
+ return (
97
+ lhsValue != null &&
98
+ rhsValue != null &&
99
+ _.endsWith(_.toString(lhsValue), rhsValue.toString())
100
+ );
101
+ default:
102
+ return false;
103
+ }
104
+ };
105
+
106
+ /**
107
+ * Evaluates whether the condition defined by the metric is satisfied.
108
+ *
109
+ * @param metric - The conditional formatting metric info
110
+ * @param parameters - An array of parameters that may include the parameter needed for ParameterBased comparison.
111
+ * @param lhsColValue - The value of the left-hand side column, used in ColumnBased and some ValueBased comparisons.
112
+ * @param rhsColValue - The value of the right-hand side column, used in ColumnBased comparisons.
113
+ * @returns Boolean indicating whether the condition is satisfied.
114
+ */
115
+ export const isConditionSatisfied = (
116
+ metric: ConditionalMetric,
117
+ parameters?: Parameter[],
118
+ lhsColValue?: string | number | null,
119
+ rhsColValue?: string | number | null,
120
+ ): boolean => {
121
+ let parameter = null;
122
+ let parameterValue = null;
123
+ switch (metric.comparisonType) {
124
+ case ConditionalFormattingComparisonTypes.ValueBased:
125
+ return doValueBasedComparison(metric, lhsColValue, metric.value);
126
+ case ConditionalFormattingComparisonTypes.ParameterBased:
127
+ parameter = parameters?.find(
128
+ (parameter: Parameter) =>
129
+ parameter.id === metric.comparisonParameterId,
130
+ );
131
+ parameterValue =
132
+ parameter?.overrideValue || parameter?.defaultValue;
133
+ return doValueBasedComparison(metric, lhsColValue, parameterValue);
134
+ case ConditionalFormattingComparisonTypes.ColumnBased:
135
+ return doValueBasedComparison(metric, lhsColValue, rhsColValue);
136
+ default:
137
+ return doValueBasedComparison(metric, lhsColValue, metric.value);
138
+ }
139
+ };
140
+
141
+ /**
142
+ * Validates if the conditional rule is applicable or not.
143
+ *
144
+ * @param conditionalMetric - The conditional rule to be validated.
145
+ * @param index - The index of the data point to evaluate.
146
+ * @param columnId - The ID of the column for which to validate the rule.
147
+ * @param dataAttr - The data points array containing the data for the chart.
148
+ * @param inScopeParameters - The list of parameters available for the chart.
149
+ * @returns Boolean indicating if the conditional rule is applicable or not.
150
+ */
151
+ export function validateCfCondition(
152
+ conditionalMetric: ConditionalMetric,
153
+ index: number,
154
+ columnId: string,
155
+ dataAttr?: DataPointsArray,
156
+ inScopeParameters?: Parameter[],
157
+ ): boolean {
158
+ let lhsColumnValue;
159
+ let rhsColumnValue;
160
+ if (dataAttr?.columns) {
161
+ const columnIdx = _.findIndex(
162
+ dataAttr.columns,
163
+ (colId) => colId === columnId,
164
+ );
165
+ lhsColumnValue = dataAttr?.dataValue[index][columnIdx];
166
+ }
167
+ const lhsId = conditionalMetric.lhsColumnId;
168
+ const rhsId = conditionalMetric.rhsColumnId;
169
+ if (lhsId && dataAttr?.columns) {
170
+ const lhsIdx = _.findIndex(
171
+ dataAttr.columns,
172
+ (colId) => colId === lhsId,
173
+ );
174
+ lhsColumnValue = dataAttr?.dataValue[index][lhsIdx];
175
+ }
176
+ if (rhsId && dataAttr?.columns) {
177
+ const rhsIdx = _.findIndex(
178
+ dataAttr.columns,
179
+ (colId) => colId === rhsId,
180
+ );
181
+ rhsColumnValue = dataAttr?.dataValue[index][rhsIdx];
182
+ }
183
+ return isConditionSatisfied(
184
+ conditionalMetric,
185
+ inScopeParameters,
186
+ lhsColumnValue,
187
+ rhsColumnValue,
188
+ );
189
+ }
190
+
191
+ /**
192
+ * Evaluates all conditional formatting rules against a specific data point and returns the first
193
+ * applicable rule.
194
+ *
195
+ * @param idx - The index of the data point to evaluate.
196
+ * @param columnId - The ID of the column for which to validate the rule.
197
+ * @param dataArr - The array of data points against which the conditional formatting rules will be evaluated.
198
+ * @param conditionalFormatting - The conditional formattings applied on a column.
199
+ * @returns The first ConditionalMetric that is applicable to the specified data point, or null if no rules are applicable.
200
+ */
201
+ export const applicableConditionalFormatting = (
202
+ idx: number,
203
+ columnId: string,
204
+ dataArr: DataPointsArray,
205
+ conditionalFormatting?: ConditionalFormatting,
206
+ ): ConditionalMetric | null => {
207
+ return (
208
+ _.find(conditionalFormatting?.rows, (conditionalMetric) => {
209
+ return validateCfCondition(
210
+ conditionalMetric as ConditionalMetric,
211
+ idx,
212
+ columnId,
213
+ dataArr,
214
+ );
215
+ }) || null
216
+ );
217
+ };
218
+
219
+ /**
220
+ * Retrieves all conditional formatting rules applied to a column.
221
+ *
222
+ * @param column - The column for which to retrieve conditional formatting rules.
223
+ * @returns An array of ConditionalFormatting configurations applied to the specified column, or undefined if no configurations are applicable.
224
+ */
225
+ export function getCfForColumn(
226
+ column: ChartColumn,
227
+ ): ConditionalFormatting | undefined {
228
+ return column?.columnProperties?.conditionalFormatting || undefined;
229
+ }
@@ -0,0 +1,168 @@
1
+ /**
2
+ * @file: Date Formatting Spec
3
+ *
4
+ * @author Yashvardhan Nehra <yashvardhan.nehra@thoughtspot.com>
5
+ *
6
+ * Copyright: ThoughtSpot Inc. 2023
7
+ */
8
+
9
+ import {
10
+ ChartColumn,
11
+ ChartSpecificColumnType,
12
+ ColumnTimeBucket,
13
+ ColumnType,
14
+ DataType,
15
+ } from '../types/answer-column.types';
16
+ import {
17
+ CustomCalendarDate,
18
+ dateFormatter,
19
+ getCustomCalendarGuidFromColumn,
20
+ getDisplayString,
21
+ getStartEpoch,
22
+ hasCustomCalendar,
23
+ isAttribute,
24
+ isDateColumn,
25
+ isDateFamilyColumn,
26
+ isDateNumColumn,
27
+ isTimeColumn,
28
+ } from './date-formatting';
29
+
30
+ describe('date-formatting', () => {
31
+ let col: ChartColumn;
32
+ beforeEach(() => {
33
+ col = {
34
+ id: 'testId',
35
+ name: 'test',
36
+ type: ColumnType.MEASURE,
37
+ chartSpecificColumnType: ChartSpecificColumnType.UNKNOWN,
38
+ timeBucket: ColumnTimeBucket.AUTO,
39
+ dataType: DataType.UNKNOWN,
40
+ calenderGuid: '12345',
41
+ };
42
+ });
43
+ test('isDateColumn should return true for DATE data type', () => {
44
+ col.dataType = DataType.DATE;
45
+ expect(isDateColumn(col)).toBe(true);
46
+ });
47
+
48
+ test('isDateColumn should return true for DATE_TIME data type', () => {
49
+ col.dataType = DataType.DATE_TIME;
50
+ expect(isDateColumn(col)).toBe(true);
51
+ });
52
+
53
+ test('isAttribute should return true for ATTRIBUTE column type', () => {
54
+ col.type = ColumnType.ATTRIBUTE;
55
+ expect(isAttribute(col)).toBe(true);
56
+ });
57
+
58
+ test('isAttribute should return false for non-ATTRIBUTE column type', () => {
59
+ col.type = ColumnType.MEASURE;
60
+ expect(isAttribute(col)).toBe(false);
61
+ });
62
+
63
+ test('getCustomCalendarGuidFromColumn should return the calendarGuid', () => {
64
+ col.calenderGuid = '12345';
65
+ expect(getCustomCalendarGuidFromColumn(col)).toBe('12345');
66
+ });
67
+
68
+ test('isDateNumColumn should return true for ATTRIBUTE type with specific time buckets', () => {
69
+ col.type = ColumnType.ATTRIBUTE;
70
+ col.timeBucket = ColumnTimeBucket.HOUR_OF_DAY;
71
+ expect(isDateNumColumn(col)).toBe(true);
72
+ });
73
+
74
+ test('isDateNumColumn should return false for non-ATTRIBUTE type', () => {
75
+ col.type = ColumnType.MEASURE;
76
+ col.timeBucket = ColumnTimeBucket.DAY_OF_WEEK;
77
+ expect(isDateNumColumn(col)).toBe(false);
78
+ });
79
+
80
+ test('isDateFamilyColumn should return true for DATE data type', () => {
81
+ col.dataType = DataType.DATE;
82
+ expect(isDateFamilyColumn(col)).toBe(true);
83
+ });
84
+
85
+ test('isDateFamilyColumn should return true for DATE_NUM column', () => {
86
+ col.type = ColumnType.ATTRIBUTE;
87
+ col.timeBucket = ColumnTimeBucket.DAY_OF_WEEK;
88
+ expect(isDateFamilyColumn(col)).toBe(true);
89
+ });
90
+
91
+ test('isTimeColumn should return true for TIME data type', () => {
92
+ col.dataType = DataType.TIME;
93
+ expect(isTimeColumn(col)).toBe(true);
94
+ });
95
+
96
+ test('hasCustomCalendar should return true for date family columns with custom calendar', () => {
97
+ col.dataType = DataType.DATE;
98
+ col.calenderGuid = '12345';
99
+ expect(hasCustomCalendar(col)).toBe(true);
100
+ });
101
+
102
+ test('getStartEpoch should return the start epoch from CustomCalendarDate', () => {
103
+ const date = {
104
+ v: { s: 12345, e: 12346 },
105
+ d: 'Custom_Date',
106
+ } as CustomCalendarDate;
107
+ expect(getStartEpoch(date)).toBe(date.v.s);
108
+ });
109
+
110
+ test('getStartEpoch should return null if start epoch is not present', () => {
111
+ const date = { v: {}, d: '01-07-2021' } as CustomCalendarDate;
112
+ expect(getStartEpoch(date)).toBe(null);
113
+ });
114
+
115
+ test('getDisplayString should return display string if present', () => {
116
+ const date = { v: { s: 1625097600, e: 1625184000 }, d: '01-07-2021' };
117
+ expect(getDisplayString(date)).toBe('01-07-2021');
118
+ });
119
+
120
+ test('getDisplayString should return null if display string is not present', () => {
121
+ const date = {
122
+ v: { s: 1625097600, e: 1625184000 },
123
+ } as CustomCalendarDate;
124
+ expect(getDisplayString(date)).toBe(null);
125
+ });
126
+
127
+ test('dateFormatter should return custom calendar display string if present', () => {
128
+ const dataValue = {
129
+ v: { s: 1625097600, e: 1625184000 },
130
+ d: '01-07-2021',
131
+ } as CustomCalendarDate;
132
+ col.dataType = DataType.DATE;
133
+ col.calenderGuid = '12345';
134
+ expect(dateFormatter(dataValue, col)).toBe('01-07-2021');
135
+ });
136
+
137
+ test('dateFormatter should return formatted date from start epoch if custom calendar display string is not present', () => {
138
+ const dataValue = {
139
+ v: { s: 1625097600, e: 1625184000 },
140
+ } as CustomCalendarDate;
141
+ col.dataType = DataType.DATE;
142
+ col.calenderGuid = '12345';
143
+ expect(dateFormatter(dataValue, col)).toBe('01-07-2021');
144
+ });
145
+
146
+ test('dateFormatter should return null if start epoch is not present', () => {
147
+ const dataValue = { v: { e: 1625184000 } } as CustomCalendarDate;
148
+ col.dataType = DataType.DATE;
149
+ col.calenderGuid = '12345';
150
+ expect(dateFormatter(dataValue, col)).toBe(null);
151
+ });
152
+
153
+ test('dateFormatter should return formatted date for non-custom calendar column', () => {
154
+ const dataValue = 1625097600;
155
+ col.dataType = DataType.DATE;
156
+ col.calenderGuid = undefined;
157
+ expect(dateFormatter(dataValue, col)).toBe('01-07-2021');
158
+ });
159
+ test('dateFormatter should format the date based on custom calendar', () => {
160
+ col.dataType = DataType.DATE;
161
+ col.calenderGuid = '12345';
162
+ const date = {
163
+ v: { s: 12345, e: 12346 },
164
+ d: 'Custom_Date',
165
+ } as CustomCalendarDate;
166
+ expect(dateFormatter(date, col)).toBe(date.d);
167
+ });
168
+ });
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @file: Date Formatting Utils
3
+ *
4
+ * @author Yashvardhan Nehra <yashvardhan.nehra@thoughtspot.com>
5
+ *
6
+ * Copyright: ThoughtSpot Inc. 2023
7
+ */
8
+
9
+ import _ from 'lodash';
10
+ import { DateTime } from 'luxon';
11
+ import {
12
+ ChartColumn,
13
+ ColumnTimeBucket,
14
+ ColumnType,
15
+ DataType,
16
+ } from '../types/answer-column.types';
17
+
18
+ export interface CustomCalendarDate {
19
+ v: {
20
+ s: number;
21
+ e: number;
22
+ };
23
+ d: string;
24
+ }
25
+
26
+ export const isDateColumn = (col: ChartColumn) =>
27
+ DataType[col.dataType] === 'DATE' || DataType[col.dataType] === 'DATE_TIME';
28
+
29
+ export const isAttribute = (col: ChartColumn) =>
30
+ col.type === ColumnType.ATTRIBUTE;
31
+
32
+ export const getCustomCalendarGuidFromColumn = (col: ChartColumn) =>
33
+ col.calenderGuid;
34
+
35
+ const isDateNumTimeBucket = (col: ChartColumn): boolean => {
36
+ return [
37
+ ColumnTimeBucket.HOUR_OF_DAY,
38
+ ColumnTimeBucket.DAY_OF_WEEK,
39
+ ColumnTimeBucket.DAY_OF_MONTH,
40
+ ColumnTimeBucket.DAY_OF_QUARTER,
41
+ ColumnTimeBucket.DAY_OF_YEAR,
42
+ ColumnTimeBucket.WEEK_OF_MONTH,
43
+ ColumnTimeBucket.WEEK_OF_QUARTER,
44
+ ColumnTimeBucket.WEEK_OF_YEAR,
45
+ ColumnTimeBucket.MONTH_OF_QUARTER,
46
+ ColumnTimeBucket.MONTH_OF_YEAR,
47
+ ColumnTimeBucket.QUARTER_OF_YEAR,
48
+ ].includes(col.timeBucket);
49
+ };
50
+ export const isDateNumColumn = (col: ChartColumn): boolean => {
51
+ return isAttribute(col) && isDateNumTimeBucket(col);
52
+ };
53
+
54
+ export const isDateFamilyColumn = (col: ChartColumn): boolean => {
55
+ return isDateColumn(col) || isDateNumColumn(col);
56
+ };
57
+
58
+ export const isTimeColumn = (col: ChartColumn) => {
59
+ return DataType[col.dataType] === 'TIME';
60
+ };
61
+
62
+ /**
63
+ * Determines if the given column has a custom calendar.
64
+ *
65
+ * @param col - The chart column to check.
66
+ * @returns True if the column is a date family column and has a custom calendar GUID, false otherwise.
67
+ */
68
+ export const hasCustomCalendar = (col: ChartColumn): boolean =>
69
+ isDateFamilyColumn(col) && !!getCustomCalendarGuidFromColumn(col);
70
+
71
+ /**
72
+ * Retrieves the start epoch from a custom calendar date.
73
+ *
74
+ * @param date - The custom calendar date object.
75
+ * @returns The start epoch time if present, null otherwise.
76
+ */
77
+ export function getStartEpoch(date: CustomCalendarDate): number | null {
78
+ if (_.has(date, 'v') && _.has(date.v, 's')) {
79
+ return date.v.s;
80
+ }
81
+ return null;
82
+ }
83
+
84
+ export function getDisplayString(date: CustomCalendarDate): string | null {
85
+ if (_.has(date, 'd')) {
86
+ return date.d;
87
+ }
88
+ return null;
89
+ }
90
+
91
+ /**
92
+ * Formats the date value based on the column's properties and custom calendar settings.
93
+ *
94
+ * @param dataValue - The date value to format.
95
+ * @param col - The chart column.
96
+ * @returns The formatted date string.
97
+ */
98
+ export function dateFormatter(dataValue: any, col: ChartColumn) {
99
+ if (hasCustomCalendar(col)) {
100
+ if (getDisplayString(dataValue)) {
101
+ return getDisplayString(dataValue);
102
+ }
103
+ const startEpoch = getStartEpoch(dataValue);
104
+ return startEpoch !== null
105
+ ? DateTime.fromMillis(startEpoch * 1000).toFormat('dd-MM-yyyy')
106
+ : null;
107
+ }
108
+ return DateTime.fromMillis(dataValue * 1000).toFormat('dd-MM-yyyy');
109
+ }