@thoughtspot/ts-chart-sdk 0.0.2-alpha.24 → 0.0.2-alpha.26
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 +63 -3
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/main/custom-chart-context.d.ts.map +1 -1
- package/lib/main/custom-chart-context.js +3 -1
- package/lib/main/custom-chart-context.js.map +1 -1
- package/lib/types/answer-column.types.d.ts +3 -3
- package/lib/types/answer-column.types.d.ts.map +1 -1
- package/lib/types/answer-column.types.js +3 -3
- package/lib/types/answer-column.types.js.map +1 -1
- package/lib/types/visual-prop.types.d.ts +40 -0
- package/lib/types/visual-prop.types.d.ts.map +1 -1
- package/lib/types/visual-prop.types.js +32 -1
- package/lib/types/visual-prop.types.js.map +1 -1
- package/lib/utils/globalize-Initializer/globalize-utils.d.ts +16 -0
- package/lib/utils/globalize-Initializer/globalize-utils.d.ts.map +1 -0
- package/lib/utils/globalize-Initializer/globalize-utils.js +101 -0
- package/lib/utils/globalize-Initializer/globalize-utils.js.map +1 -0
- package/lib/utils/globalize-Initializer/globalize-utils.spec.d.ts +2 -0
- package/lib/utils/globalize-Initializer/globalize-utils.spec.d.ts.map +1 -0
- package/lib/utils/globalize-Initializer/globalize-utils.spec.js +149 -0
- package/lib/utils/globalize-Initializer/globalize-utils.spec.js.map +1 -0
- package/lib/utils/number-formatting/number-formatting-utils.d.ts +20 -0
- package/lib/utils/number-formatting/number-formatting-utils.d.ts.map +1 -0
- package/lib/utils/number-formatting/number-formatting-utils.js +159 -0
- package/lib/utils/number-formatting/number-formatting-utils.js.map +1 -0
- package/lib/utils/number-formatting/number-formatting-utils.spec.d.ts +2 -0
- package/lib/utils/number-formatting/number-formatting-utils.spec.d.ts.map +1 -0
- package/lib/utils/number-formatting/number-formatting-utils.spec.js +221 -0
- package/lib/utils/number-formatting/number-formatting-utils.spec.js.map +1 -0
- package/lib/utils/number-formatting/number-formatting.d.ts +5 -0
- package/lib/utils/number-formatting/number-formatting.d.ts.map +1 -0
- package/lib/utils/number-formatting/number-formatting.js +128 -0
- package/lib/utils/number-formatting/number-formatting.js.map +1 -0
- package/lib/utils/number-formatting/number-formatting.spec.d.ts +2 -0
- package/lib/utils/number-formatting/number-formatting.spec.d.ts.map +1 -0
- package/lib/utils/number-formatting/number-formatting.spec.js +159 -0
- package/lib/utils/number-formatting/number-formatting.spec.js.map +1 -0
- package/package.json +4 -1
- package/src/index.ts +2 -0
- package/src/main/custom-chart-context.ts +4 -1
- package/src/types/answer-column.types.ts +3 -3
- package/src/types/visual-prop.types.ts +86 -0
- package/src/utils/globalize-Initializer/globalize-utils.spec.ts +192 -0
- package/src/utils/globalize-Initializer/globalize-utils.ts +216 -0
- package/src/utils/number-formatting/number-formatting-utils.spec.ts +296 -0
- package/src/utils/number-formatting/number-formatting-utils.ts +260 -0
- package/src/utils/number-formatting/number-formatting.spec.ts +243 -0
- package/src/utils/number-formatting/number-formatting.ts +264 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { create } from '../../main/logger';
|
|
3
|
+
import { CurrencyFormatType, } from '../../types/answer-column.types';
|
|
4
|
+
import { CategoryType, } from '../../types/number-formatting.types';
|
|
5
|
+
import { formatNumberSafely, getDefaultCurrencyCode, globalizeCurrencyFormatter, globalizeNumberFormatter, sanitizeFormat, validateNumberFormat, } from '../globalize-Initializer/globalize-utils';
|
|
6
|
+
import { defaultFormatConfig, formatNegativeValue, formatSpecialDataValue, getLocaleName, mapFormatterConfig, UNITS_TO_DIVIDING_FACTOR, UNITS_TO_SUFFIX, } from './number-formatting-utils';
|
|
7
|
+
const logger = create('number-formatting');
|
|
8
|
+
const CURRENCY_CODE_EXTRACTOR_REGEX = /[\d.,]+/g;
|
|
9
|
+
export const formatCurrencyWithCustomPattern = (value, currencyCode, formatPattern) => {
|
|
10
|
+
const sanitizedPattern = sanitizeFormat(formatPattern);
|
|
11
|
+
const customFormatter = globalizeNumberFormatter({
|
|
12
|
+
...{ raw: sanitizedPattern },
|
|
13
|
+
});
|
|
14
|
+
const formattedValue = customFormatter(value);
|
|
15
|
+
const currencyFormatter = globalizeCurrencyFormatter(currencyCode, {
|
|
16
|
+
style: 'symbol',
|
|
17
|
+
});
|
|
18
|
+
const currencySymbol = currencyFormatter(0).replace(CURRENCY_CODE_EXTRACTOR_REGEX, '');
|
|
19
|
+
return `${currencySymbol}${formattedValue}`;
|
|
20
|
+
};
|
|
21
|
+
export const getFormattedValue = (value, formatConfigProp, columnFormatConfig) => {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
let formatConfig = _.cloneDeep(formatConfigProp);
|
|
24
|
+
if (_.isNil(formatConfig) || _.isEmpty(formatConfig)) {
|
|
25
|
+
formatConfig = defaultFormatConfig(columnFormatConfig);
|
|
26
|
+
}
|
|
27
|
+
const specialVal = formatSpecialDataValue(value);
|
|
28
|
+
if (specialVal) {
|
|
29
|
+
return specialVal;
|
|
30
|
+
}
|
|
31
|
+
const floatValue = parseFloat(value.toString());
|
|
32
|
+
const absFloatValue = Math.abs(floatValue);
|
|
33
|
+
switch (formatConfig.category) {
|
|
34
|
+
case CategoryType.Number: {
|
|
35
|
+
const configDetails = formatConfig.numberFormatConfig || {};
|
|
36
|
+
const formatterConfigMap = mapFormatterConfig(absFloatValue, configDetails);
|
|
37
|
+
const compactValue = absFloatValue /
|
|
38
|
+
UNITS_TO_DIVIDING_FACTOR[formatterConfigMap.unitDetails];
|
|
39
|
+
const suffix = UNITS_TO_SUFFIX[formatterConfigMap.unitDetails];
|
|
40
|
+
const formattedValue = formatNumberSafely({
|
|
41
|
+
style: 'decimal',
|
|
42
|
+
maximumFractionDigits: formatterConfigMap.decimalDetails,
|
|
43
|
+
minimumFractionDigits: formatterConfigMap.shouldRemoveTrailingZeros
|
|
44
|
+
? 0
|
|
45
|
+
: formatterConfigMap.decimalDetails,
|
|
46
|
+
useGrouping: configDetails.toSeparateThousands || false,
|
|
47
|
+
}, compactValue);
|
|
48
|
+
const absFormattedValue = `${formattedValue}${suffix}`;
|
|
49
|
+
if (absFloatValue !== floatValue) {
|
|
50
|
+
return formatNegativeValue(absFormattedValue, configDetails.negativeValueFormat);
|
|
51
|
+
}
|
|
52
|
+
return absFormattedValue;
|
|
53
|
+
}
|
|
54
|
+
case CategoryType.Percentage: {
|
|
55
|
+
const configDetails = formatConfig.percentageFormatConfig;
|
|
56
|
+
const decimalDetails = (configDetails === null || configDetails === void 0 ? void 0 : configDetails.decimals) || 0;
|
|
57
|
+
return formatNumberSafely({
|
|
58
|
+
style: 'percent',
|
|
59
|
+
maximumFractionDigits: decimalDetails,
|
|
60
|
+
minimumFractionDigits: (configDetails === null || configDetails === void 0 ? void 0 : configDetails.removeTrailingZeroes)
|
|
61
|
+
? 0
|
|
62
|
+
: decimalDetails,
|
|
63
|
+
}, floatValue);
|
|
64
|
+
}
|
|
65
|
+
case CategoryType.Currency: {
|
|
66
|
+
const configDetails = formatConfig.currencyFormatConfig || {};
|
|
67
|
+
const formatterConfigMap = mapFormatterConfig(absFloatValue, configDetails);
|
|
68
|
+
const compactValue = floatValue /
|
|
69
|
+
UNITS_TO_DIVIDING_FACTOR[formatterConfigMap.unitDetails];
|
|
70
|
+
let locale = configDetails.locale || getDefaultCurrencyCode();
|
|
71
|
+
if (locale === CurrencyFormatType.USER_LOCALE) {
|
|
72
|
+
locale = getLocaleName({
|
|
73
|
+
type: locale,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const formatter = globalizeCurrencyFormatter(locale, {
|
|
78
|
+
style: 'symbol',
|
|
79
|
+
maximumFractionDigits: formatterConfigMap.decimalDetails,
|
|
80
|
+
minimumFractionDigits: formatterConfigMap.shouldRemoveTrailingZeros
|
|
81
|
+
? 0
|
|
82
|
+
: formatterConfigMap.decimalDetails,
|
|
83
|
+
useGrouping: configDetails.toSeparateThousands || false,
|
|
84
|
+
});
|
|
85
|
+
const formattedValue = formatter(compactValue);
|
|
86
|
+
const currencyCode = formattedValue.replace(CURRENCY_CODE_EXTRACTOR_REGEX, '');
|
|
87
|
+
const suffix = !_.isNil(floatValue)
|
|
88
|
+
? UNITS_TO_SUFFIX[formatterConfigMap.unitDetails]
|
|
89
|
+
: '';
|
|
90
|
+
if (/[0-9]$/.test(formattedValue.charAt(0))) {
|
|
91
|
+
return `${formattedValue.replace(currencyCode, '')}${suffix}${currencyCode}`;
|
|
92
|
+
}
|
|
93
|
+
return `${formattedValue}${suffix}`;
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
logger.error('Corrupted format config passed, formatting using default config', formatConfig, e);
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case CategoryType.Custom: {
|
|
101
|
+
const formatPattern = (_a = formatConfig.customFormatConfig) === null || _a === void 0 ? void 0 : _a.format;
|
|
102
|
+
const currencyCode = (_b = columnFormatConfig.currencyFormat) === null || _b === void 0 ? void 0 : _b.isoCode;
|
|
103
|
+
if (!_.isNil(formatPattern) &&
|
|
104
|
+
validateNumberFormat(sanitizeFormat(formatPattern))) {
|
|
105
|
+
const sanitizedPattern = sanitizeFormat(formatPattern);
|
|
106
|
+
if (!_.isNil(currencyCode)) {
|
|
107
|
+
const formattedValueWithLocaleAndPattern = formatCurrencyWithCustomPattern(floatValue, currencyCode, formatPattern);
|
|
108
|
+
return `${formattedValueWithLocaleAndPattern}`;
|
|
109
|
+
}
|
|
110
|
+
return formatNumberSafely({
|
|
111
|
+
style: 'decimal',
|
|
112
|
+
raw: sanitizedPattern,
|
|
113
|
+
}, floatValue);
|
|
114
|
+
}
|
|
115
|
+
logger.error('Invalid custom format config passed:', formatConfig);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
default: {
|
|
119
|
+
return formatNumberSafely({
|
|
120
|
+
style: 'decimal',
|
|
121
|
+
}, floatValue);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return formatNumberSafely({
|
|
125
|
+
style: 'decimal',
|
|
126
|
+
}, floatValue);
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=number-formatting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-formatting.js","sourceRoot":"","sources":["../../../src/utils/number-formatting/number-formatting.ts"],"names":[],"mappings":"AAOA,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAGH,kBAAkB,GACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACH,YAAY,GAGf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,cAAc,EACd,oBAAoB,GACvB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACH,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,GAClB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,MAAM,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAE3C,MAAM,6BAA6B,GAAG,UAAU,CAAC;AAUjD,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAC3C,KAAa,EACb,YAAoB,EACpB,aAAqB,EACf,EAAE;IAER,MAAM,gBAAgB,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IAGvD,MAAM,eAAe,GAAG,wBAAwB,CAAC;QAC7C,GAAI,EAAE,GAAG,EAAE,gBAAgB,EAAU;KACxC,CAAC,CAAC;IAEH,MAAM,cAAc,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAE9C,MAAM,iBAAiB,GAAG,0BAA0B,CAAC,YAAY,EAAE;QAC/D,KAAK,EAAE,QAAQ;KAClB,CAAC,CAAC;IAEH,MAAM,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vB,oBAAoB,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,EACrD;gBACE,MAAM,gBAAgB,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;gBACvD,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;oBAMxB,MAAM,kCAAkC,GACpC,+BAA+B,CAC3B,UAAU,EACV,YAAY,EACZ,aAAa,CAChB,CAAC;oBACN,OAAO,GAAG,kCAAkC,EAAE,CAAC;iBAClD;gBACD,OAAO,kBAAkB,CACrB;oBACI,KAAK,EAAE,SAAS;oBAChB,GAAG,EAAE,gBAAgB;iBACxB,EACD,UAAiB,CACpB,CAAC;aACL;YACD,MAAM,CAAC,KAAK,CAAC,sCAAsC,EAAE,YAAY,CAAC,CAAC;YACnE,MAAM;SACT;QACD,OAAO,CAAC,CAAC;YACL,OAAO,kBAAkB,CACrB;gBACI,KAAK,EAAE,SAAS;aACnB,EACD,UAAiB,CACpB,CAAC;SACL;KACJ;IAGD,OAAO,kBAAkB,CACrB;QACI,KAAK,EAAE,SAAS;KACnB,EACD,UAAiB,CACpB,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-formatting.spec.d.ts","sourceRoot":"","sources":["../../../src/utils/number-formatting/number-formatting.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { create, LogLevel, logMethods } from '../../main/logger';
|
|
2
|
+
import { CurrencyFormatType, FormatType, } from '../../types/answer-column.types';
|
|
3
|
+
import { CategoryType, NegativeValueFormat, Unit, } from '../../types/number-formatting.types';
|
|
4
|
+
import { initGlobalize } from '../globalize-Initializer/globalize-utils';
|
|
5
|
+
import * as globalizeUtils from '../globalize-Initializer/globalize-utils';
|
|
6
|
+
import { formatCurrencyWithCustomPattern, getFormattedValue, } from './number-formatting';
|
|
7
|
+
jest.mock('../../main/util', () => ({
|
|
8
|
+
getQueryParam: jest.fn().mockReturnValue('true'),
|
|
9
|
+
}));
|
|
10
|
+
describe('formatCurrencyWithCustomPattern', () => {
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
initGlobalize('en-US');
|
|
13
|
+
});
|
|
14
|
+
test('formats value with a custom pattern and currency symbol', () => {
|
|
15
|
+
const value = 12345.678;
|
|
16
|
+
const currencyCode = 'USD';
|
|
17
|
+
const formatPattern = '#,##0.00';
|
|
18
|
+
const result = formatCurrencyWithCustomPattern(value, currencyCode, formatPattern);
|
|
19
|
+
expect(result).toBe('$12,345.68');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe('getFormattedValue', () => {
|
|
23
|
+
beforeAll(() => {
|
|
24
|
+
initGlobalize('en-US');
|
|
25
|
+
});
|
|
26
|
+
const columnFormatConfig = {
|
|
27
|
+
type: FormatType.CURRENCY,
|
|
28
|
+
currencyFormat: {
|
|
29
|
+
type: CurrencyFormatType.ISO_CODE,
|
|
30
|
+
column: '',
|
|
31
|
+
isoCode: 'USD',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
jest.clearAllMocks();
|
|
36
|
+
});
|
|
37
|
+
test('uses Number Fromatting as default configuration when formatConfigProp & columnFormatConfig are null', () => {
|
|
38
|
+
const result = getFormattedValue(12345, {}, {});
|
|
39
|
+
expect(result).toBe('12.35K');
|
|
40
|
+
});
|
|
41
|
+
test('use Custom Formatting as default configuration when only formatConfigProp is null', () => {
|
|
42
|
+
const result = getFormattedValue(12345, {}, columnFormatConfig);
|
|
43
|
+
expect(result).toBe('$12.35K');
|
|
44
|
+
});
|
|
45
|
+
test('formats special values (NaN, Infinity)', () => {
|
|
46
|
+
expect(getFormattedValue(NaN, {}, {})).toBe('NaN');
|
|
47
|
+
expect(getFormattedValue(Infinity, {}, {})).toBe('Infinity');
|
|
48
|
+
expect(getFormattedValue(-Infinity, {}, {})).toBe('-Infinity');
|
|
49
|
+
});
|
|
50
|
+
test('formats number category values with units and trailing zeroes', () => {
|
|
51
|
+
const formatConfig = {
|
|
52
|
+
category: CategoryType.Number,
|
|
53
|
+
numberFormatConfig: {
|
|
54
|
+
unit: Unit.Thousands,
|
|
55
|
+
decimals: 2,
|
|
56
|
+
toSeparateThousands: true,
|
|
57
|
+
negativeValueFormat: NegativeValueFormat.PrefixDash,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
const result = getFormattedValue(-12345, formatConfig, {});
|
|
61
|
+
expect(result).toBe('-12.35K');
|
|
62
|
+
});
|
|
63
|
+
test('formats percentage values correctly', () => {
|
|
64
|
+
const formatConfig = {
|
|
65
|
+
category: CategoryType.Percentage,
|
|
66
|
+
percentageFormatConfig: { decimals: 2, removeTrailingZeroes: true },
|
|
67
|
+
};
|
|
68
|
+
const result = getFormattedValue(0.1234, formatConfig, {});
|
|
69
|
+
expect(result).toBe('12.34%');
|
|
70
|
+
});
|
|
71
|
+
test('formats currency values with compact units', () => {
|
|
72
|
+
const formatConfig = {
|
|
73
|
+
category: CategoryType.Currency,
|
|
74
|
+
currencyFormatConfig: {
|
|
75
|
+
locale: 'USD',
|
|
76
|
+
toSeparateThousands: true,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
const result = getFormattedValue(12345.678, formatConfig, {});
|
|
80
|
+
expect(result).toMatch(/^\$\d+,\d+(\.\d+)?$/);
|
|
81
|
+
});
|
|
82
|
+
test('formats currency values with user Locale', () => {
|
|
83
|
+
jest.spyOn(globalizeUtils, 'getDefaultCurrencyCode').mockImplementationOnce(() => 'INR');
|
|
84
|
+
const formatConfig = {
|
|
85
|
+
category: CategoryType.Currency,
|
|
86
|
+
currencyFormatConfig: {
|
|
87
|
+
unit: Unit.Thousands,
|
|
88
|
+
decimals: 2,
|
|
89
|
+
locale: CurrencyFormatType.USER_LOCALE,
|
|
90
|
+
toSeparateThousands: true,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
const result = getFormattedValue(12345.678, formatConfig, {});
|
|
94
|
+
expect(result).toMatch('₹12.35K');
|
|
95
|
+
});
|
|
96
|
+
test('should normalize category to CategoryType.Number when it is a number', () => {
|
|
97
|
+
const formatConfig = {
|
|
98
|
+
category: CategoryType.Number,
|
|
99
|
+
numberFormatConfig: {
|
|
100
|
+
unit: Unit.Thousands,
|
|
101
|
+
decimals: 2,
|
|
102
|
+
toSeparateThousands: true,
|
|
103
|
+
negativeValueFormat: NegativeValueFormat.PrefixDash,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
const result = getFormattedValue(1000, formatConfig, {});
|
|
107
|
+
expect(result).toBe('1.00K');
|
|
108
|
+
});
|
|
109
|
+
test('falls back to default formatting for unsupported categories', () => {
|
|
110
|
+
const formatConfig = { category: 'Unknown' };
|
|
111
|
+
const result = getFormattedValue(12345.678, formatConfig, {});
|
|
112
|
+
expect(result).toBe('12,345.678');
|
|
113
|
+
});
|
|
114
|
+
test('formats custom pattern correctly', () => {
|
|
115
|
+
const formatConfig = {
|
|
116
|
+
category: CategoryType.Custom,
|
|
117
|
+
customFormatConfig: { format: '#,##0.00' },
|
|
118
|
+
};
|
|
119
|
+
const result = getFormattedValue(12345.678, formatConfig, {});
|
|
120
|
+
expect(result).toBe('12,345.68');
|
|
121
|
+
});
|
|
122
|
+
test('formats custom pattern with valid customColumn format', () => {
|
|
123
|
+
const formatConfig = {
|
|
124
|
+
category: CategoryType.Custom,
|
|
125
|
+
customFormatConfig: { format: '#,##0.00' },
|
|
126
|
+
};
|
|
127
|
+
const result = getFormattedValue(12345.678, formatConfig, columnFormatConfig);
|
|
128
|
+
expect(result).toBe('$12,345.68');
|
|
129
|
+
});
|
|
130
|
+
test('logs error for invalid custom format patterns', () => {
|
|
131
|
+
const formatConfig = {
|
|
132
|
+
category: CategoryType.Custom,
|
|
133
|
+
customFormatConfig: { format: 'invalid-format' },
|
|
134
|
+
};
|
|
135
|
+
const error = jest.fn();
|
|
136
|
+
logMethods[LogLevel.ERROR] = error;
|
|
137
|
+
const logger = create('TestLogger');
|
|
138
|
+
logger.error = error;
|
|
139
|
+
getFormattedValue(12345.678, formatConfig, {});
|
|
140
|
+
expect(logger.error).toHaveBeenCalled();
|
|
141
|
+
jest.restoreAllMocks();
|
|
142
|
+
});
|
|
143
|
+
test('handles currency formatting failure', () => {
|
|
144
|
+
const formatConfig = {
|
|
145
|
+
category: CategoryType.Currency,
|
|
146
|
+
};
|
|
147
|
+
jest.spyOn(globalizeUtils, 'globalizeCurrencyFormatter').mockImplementationOnce(() => {
|
|
148
|
+
throw new Error('Currency format error');
|
|
149
|
+
});
|
|
150
|
+
const error = jest.fn();
|
|
151
|
+
logMethods[LogLevel.ERROR] = error;
|
|
152
|
+
const logger = create('TestLogger');
|
|
153
|
+
logger.error = error;
|
|
154
|
+
getFormattedValue(12345.678, formatConfig, {});
|
|
155
|
+
expect(logger.error).toHaveBeenCalled();
|
|
156
|
+
jest.restoreAllMocks();
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
//# sourceMappingURL=number-formatting.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-formatting.spec.js","sourceRoot":"","sources":["../../../src/utils/number-formatting/number-formatting.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAEH,kBAAkB,EAClB,UAAU,GACb,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACH,YAAY,EAEZ,mBAAmB,EACnB,IAAI,GACP,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AACzE,OAAO,KAAK,cAAc,MAAM,0CAA0C,CAAC;AAC3E,OAAO,EACH,+BAA+B,EAC/B,iBAAiB,GACpB,MAAM,qBAAqB,CAAC;AAE7B,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC;IAChC,aAAa,EAAE,IAAI,CAAC,EAAE,EAAE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C,KAAK,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAExC,IAAI,CAAC,eAAe,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thoughtspot/ts-chart-sdk",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.2-alpha.
|
|
4
|
+
"version": "0.0.2-alpha.26",
|
|
5
5
|
"module": "lib/index",
|
|
6
6
|
"main": "lib/index",
|
|
7
7
|
"types": "lib/index",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@testing-library/react": "12.1.5",
|
|
36
36
|
"@testing-library/react-hooks": "^7.0.2",
|
|
37
|
+
"@types/globalize": "^1.5.5",
|
|
37
38
|
"@types/jest": "^27.0.3",
|
|
38
39
|
"@types/lodash": "4.14.175",
|
|
39
40
|
"@types/luxon": "^3.4.2",
|
|
@@ -74,6 +75,8 @@
|
|
|
74
75
|
"vite": "4.2.1"
|
|
75
76
|
},
|
|
76
77
|
"dependencies": {
|
|
78
|
+
"cldr-data": "^36.0.2",
|
|
79
|
+
"globalize": "^1.7.0",
|
|
77
80
|
"lodash": "^4.17.21",
|
|
78
81
|
"luxon": "^3.4.4",
|
|
79
82
|
"promise-postmessage": "^3.5.0",
|
package/src/index.ts
CHANGED
|
@@ -10,3 +10,5 @@ export * from './types/conditional-formatting.types';
|
|
|
10
10
|
export * from './types/number-formatting.types';
|
|
11
11
|
export * from './utils/date-formatting';
|
|
12
12
|
export * from './utils/conditional-formatting/conditional-formatting';
|
|
13
|
+
export * from './utils/number-formatting/number-formatting';
|
|
14
|
+
export * from './utils/globalize-Initializer/globalize-utils';
|
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
VisualEditorDefinitionSetter,
|
|
53
53
|
VisualPropEditorDefinition,
|
|
54
54
|
} from '../types/visual-prop.types';
|
|
55
|
+
import { setLocaleBasedStringFormats } from '../utils/number-formatting/number-formatting-utils';
|
|
55
56
|
import { create } from './logger';
|
|
56
57
|
import {
|
|
57
58
|
globalThis,
|
|
@@ -1020,7 +1021,9 @@ export class CustomChartContext {
|
|
|
1020
1021
|
this.containerEl = payload.containerElSelector
|
|
1021
1022
|
? document.querySelector(payload.containerElSelector)
|
|
1022
1023
|
: null;
|
|
1023
|
-
|
|
1024
|
+
setLocaleBasedStringFormats(
|
|
1025
|
+
this.appConfig.dateFormatsConfig?.tsLocaleBasedStringsFormats,
|
|
1026
|
+
);
|
|
1024
1027
|
return this.publishChartContextPropsToHost();
|
|
1025
1028
|
};
|
|
1026
1029
|
|
|
@@ -16,6 +16,38 @@ export type TSTooltipConfig = {
|
|
|
16
16
|
columnIds: Array<string>;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
export enum VisualPropComponentTranslationKeys {
|
|
20
|
+
SHOW_ALL_LABELS = 'SHOW_ALL_LABELS',
|
|
21
|
+
TOO_MANY_LABELS = 'TOO_MANY_LABELS',
|
|
22
|
+
MAP_TILE_LABEL = 'MAP_TILE_LABEL',
|
|
23
|
+
ENABLE_MARKERS = 'ENABLE_MARKERS',
|
|
24
|
+
SHOW_REGRESSION_LINE = 'SHOW_REGRESSION_LINE',
|
|
25
|
+
X_AXIS_GRID_LINE = 'X_AXIS_GRID_LINE',
|
|
26
|
+
Y_AXIS_GRID_LINE = 'Y_AXIS_GRID_LINE',
|
|
27
|
+
MAX_DATA_POINTS = 'MAX_DATA_POINTS',
|
|
28
|
+
HIGH_CARDINALITY_BATCH_SIZE_DISABLED = 'highCardinalityBatchSizeDisabled',
|
|
29
|
+
HIGH_CARDINALITY_BATCH_SIZE_LIMIT = 'highCardinalityBatchSizeLimit',
|
|
30
|
+
CHART_CUSTOMIZE = 'CHART_CUSTOMIZE',
|
|
31
|
+
SELECT_AN_AREA = 'chartConfigurator.SELECT_AN_AREA',
|
|
32
|
+
RESET_ZOOM = 'chartConfigurator.RESET_ZOOM',
|
|
33
|
+
EDIT_TOOLTIP = 'EDIT_TOOLTIP',
|
|
34
|
+
DONT_SHOW = 'DONT_SHOW',
|
|
35
|
+
SHOW_GAP = 'SHOW_GAP',
|
|
36
|
+
SHOW_AS_ZERO = 'SHOW_AS_ZERO',
|
|
37
|
+
HANDLE_MISSING_VALUES = 'HANDLE_MISSING_VALUES',
|
|
38
|
+
SHOW_NULL_AS_ZERO = 'SHOW_NULL_AS_ZERO',
|
|
39
|
+
EXCLUDE_NULL_VALUES = 'EXCLUDE_NULL_VALUES',
|
|
40
|
+
COLUMN_CUSTOMIZE = 'COLUMN_CUSTOMIZE',
|
|
41
|
+
SHOW_TOTAL_LABELS = 'SHOW_TOTAL_LABELS',
|
|
42
|
+
SHOW_DETAILED_LABELS = 'SHOW_DETAILED_LABELS',
|
|
43
|
+
SHOW_DATA_LABELS = 'SHOW_DATA_LABELS',
|
|
44
|
+
SHOW_AXIS_AS_PERCENT = 'SHOW_AXIS_AS_PERCENT',
|
|
45
|
+
RIGHT_LEGEND = 'RIGHT_LEGEND',
|
|
46
|
+
LEFT_LEGEND = 'LEFT_LEGEND',
|
|
47
|
+
TOP_LEGEND = 'TOP_LEGEND',
|
|
48
|
+
BOTTOM_LEGEND = 'BOTTOM_LEGEND',
|
|
49
|
+
}
|
|
50
|
+
|
|
19
51
|
/**
|
|
20
52
|
* Configuration for input validation rules
|
|
21
53
|
*/
|
|
@@ -127,6 +159,12 @@ export interface TextInputFormDetail {
|
|
|
127
159
|
* @version SDK: 0.0.2-alpha.13 | ThoughtSpot:
|
|
128
160
|
*/
|
|
129
161
|
disabled?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Translation key for the label
|
|
164
|
+
*
|
|
165
|
+
* @version SDK: 0.2 | ThoughtSpot:
|
|
166
|
+
*/
|
|
167
|
+
labelTranslation?: VisualPropComponentTranslationKeys;
|
|
130
168
|
}
|
|
131
169
|
|
|
132
170
|
/**
|
|
@@ -166,6 +204,12 @@ export interface NumberInputFormDetail {
|
|
|
166
204
|
* @version SDK: 0.0.2-alpha.13 | ThoughtSpot:
|
|
167
205
|
*/
|
|
168
206
|
disabled?: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Translation key for the label
|
|
209
|
+
*
|
|
210
|
+
* @version SDK: 0.2 | ThoughtSpot:
|
|
211
|
+
*/
|
|
212
|
+
labelTranslation?: VisualPropComponentTranslationKeys;
|
|
169
213
|
}
|
|
170
214
|
|
|
171
215
|
/**
|
|
@@ -200,6 +244,12 @@ export interface ColorPickerFormDetail {
|
|
|
200
244
|
* @version SDK: 0.0.1-alpha.7 | ThoughtSpot:
|
|
201
245
|
*/
|
|
202
246
|
defaultValue?: string;
|
|
247
|
+
/**
|
|
248
|
+
* Translation key for the label
|
|
249
|
+
*
|
|
250
|
+
* @version SDK: 0.2 | ThoughtSpot:
|
|
251
|
+
*/
|
|
252
|
+
labelTranslation?: VisualPropComponentTranslationKeys;
|
|
203
253
|
}
|
|
204
254
|
|
|
205
255
|
/**
|
|
@@ -233,6 +283,12 @@ export interface ToggleFormDetail {
|
|
|
233
283
|
* @version SDK: 0.0.2-alpha.13 | ThoughtSpot:
|
|
234
284
|
*/
|
|
235
285
|
disabled?: boolean;
|
|
286
|
+
/**
|
|
287
|
+
* Translation key for the label
|
|
288
|
+
*
|
|
289
|
+
* @version SDK: 0.2 | ThoughtSpot:
|
|
290
|
+
*/
|
|
291
|
+
labelTranslation?: VisualPropComponentTranslationKeys;
|
|
236
292
|
}
|
|
237
293
|
|
|
238
294
|
/**
|
|
@@ -266,6 +322,12 @@ export interface CheckboxFormDetail {
|
|
|
266
322
|
* @version SDK: 0.0.2-alpha.13 | ThoughtSpot:
|
|
267
323
|
*/
|
|
268
324
|
disabled?: boolean;
|
|
325
|
+
/**
|
|
326
|
+
* Translation key for the label
|
|
327
|
+
*
|
|
328
|
+
* @version SDK: 0.2 | ThoughtSpot:
|
|
329
|
+
*/
|
|
330
|
+
labelTranslation?: VisualPropComponentTranslationKeys;
|
|
269
331
|
}
|
|
270
332
|
|
|
271
333
|
/**
|
|
@@ -305,6 +367,12 @@ export interface RadioButtonFormDetail {
|
|
|
305
367
|
* @version SDK: 0.0.2-3 | ThoughtSpot:
|
|
306
368
|
*/
|
|
307
369
|
disabled?: boolean;
|
|
370
|
+
/**
|
|
371
|
+
* Translation key for the label
|
|
372
|
+
*
|
|
373
|
+
* @version SDK: 0.2 | ThoughtSpot:
|
|
374
|
+
*/
|
|
375
|
+
labelTranslation?: VisualPropComponentTranslationKeys;
|
|
308
376
|
}
|
|
309
377
|
|
|
310
378
|
/**
|
|
@@ -344,6 +412,12 @@ export interface DropDownFormDetail {
|
|
|
344
412
|
* @version SDK: 0.0.2-alpha.13 | ThoughtSpot:
|
|
345
413
|
*/
|
|
346
414
|
disabled?: boolean;
|
|
415
|
+
/**
|
|
416
|
+
* Translation key for the label
|
|
417
|
+
*
|
|
418
|
+
* @version SDK: 0.2 | ThoughtSpot:
|
|
419
|
+
*/
|
|
420
|
+
labelTranslation?: VisualPropComponentTranslationKeys;
|
|
347
421
|
}
|
|
348
422
|
|
|
349
423
|
/**
|
|
@@ -397,6 +471,12 @@ export interface Section {
|
|
|
397
471
|
* @version SDK: 0.0.2-alpha.19 | ThoughtSpot:
|
|
398
472
|
*/
|
|
399
473
|
isAccordianExpanded?: boolean;
|
|
474
|
+
/**
|
|
475
|
+
* Translation key for the label
|
|
476
|
+
*
|
|
477
|
+
* @version SDK: 0.2 | ThoughtSpot:
|
|
478
|
+
*/
|
|
479
|
+
labelTranslation?: VisualPropComponentTranslationKeys;
|
|
400
480
|
}
|
|
401
481
|
|
|
402
482
|
/**
|
|
@@ -431,6 +511,12 @@ export interface NativeEditToolTip {
|
|
|
431
511
|
* @version SDK: 0.0.2-alpha.13 | ThoughtSpot:
|
|
432
512
|
*/
|
|
433
513
|
disabled?: boolean;
|
|
514
|
+
/**
|
|
515
|
+
* Translation key for the label
|
|
516
|
+
*
|
|
517
|
+
* @version SDK: 0.2 | ThoughtSpot:
|
|
518
|
+
*/
|
|
519
|
+
labelTranslation?: VisualPropComponentTranslationKeys;
|
|
434
520
|
}
|
|
435
521
|
|
|
436
522
|
/**
|