@visactor/vseed 0.0.12 → 0.0.13
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/builder/builder/builder.d.ts +3 -0
- package/dist/i18n/i18n.d.ts +17 -0
- package/dist/i18n/index.d.ts +1 -0
- package/dist/index.cjs +200 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +146 -17
- package/dist/index.js.map +1 -1
- package/dist/pipeline/advanced/pipes/i18n/index.d.ts +1 -0
- package/dist/pipeline/advanced/pipes/i18n/locale.d.ts +2 -0
- package/dist/pipeline/advanced/pipes/index.d.ts +1 -0
- package/dist/pipeline/constant.d.ts +1 -1
- package/dist/pipeline/utils/format/createFormatter.d.ts +2 -1
- package/dist/pipeline/utils/format/createNumFormatter.d.ts +2 -1
- package/dist/pipeline/utils/format/index.d.ts +2 -2
- package/dist/types/advancedVSeed.d.ts +8 -4
- package/dist/types/chartType/area/area.d.ts +7 -0
- package/dist/types/chartType/areaPercent/areaPercent.d.ts +7 -0
- package/dist/types/chartType/bar/bar.d.ts +7 -0
- package/dist/types/chartType/barParallel/barParallel.d.ts +7 -0
- package/dist/types/chartType/barPercent/barPercent.d.ts +7 -0
- package/dist/types/chartType/column/column.d.ts +7 -0
- package/dist/types/chartType/columnParallel/columnParallel.d.ts +7 -0
- package/dist/types/chartType/columnPercent/columnPercent.d.ts +7 -0
- package/dist/types/chartType/donut/donut.d.ts +7 -0
- package/dist/types/chartType/dualAxis/dualAxis.d.ts +7 -0
- package/dist/types/chartType/line/line.d.ts +7 -0
- package/dist/types/chartType/pie/pie.d.ts +7 -0
- package/dist/types/chartType/pivotTable/pivotTable.d.ts +7 -0
- package/dist/types/chartType/rose/rose.d.ts +7 -0
- package/dist/types/chartType/table/table.d.ts +7 -0
- package/dist/types/i18n/i18n.d.ts +9 -0
- package/dist/types/i18n/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/properties/measures/measures.d.ts +8 -8
- package/dist/types/vseed.d.ts +13 -9
- package/package.json +1 -1
@@ -1396,6 +1396,7 @@ export declare class Builder implements VSeedBuilder {
|
|
1396
1396
|
outerPadding?: number | undefined;
|
1397
1397
|
}[] | undefined;
|
1398
1398
|
};
|
1399
|
+
locale: "zh-CN" | "en-US";
|
1399
1400
|
dimensions?: {
|
1400
1401
|
id: string;
|
1401
1402
|
location: "dimension" | "rowDimension" | "columnDimension";
|
@@ -6931,6 +6932,7 @@ export declare class Builder implements VSeedBuilder {
|
|
6931
6932
|
outerPadding?: number | undefined;
|
6932
6933
|
}[] | undefined;
|
6933
6934
|
};
|
6935
|
+
locale: "zh-CN" | "en-US";
|
6934
6936
|
dimensions?: {
|
6935
6937
|
id: string;
|
6936
6938
|
location: "dimension" | "rowDimension" | "columnDimension";
|
@@ -9730,6 +9732,7 @@ export declare class Builder implements VSeedBuilder {
|
|
9730
9732
|
outerPadding?: number | undefined;
|
9731
9733
|
}[] | undefined;
|
9732
9734
|
};
|
9735
|
+
locale: "zh-CN" | "en-US";
|
9733
9736
|
dimensions?: {
|
9734
9737
|
id: string;
|
9735
9738
|
location: "dimension" | "rowDimension" | "columnDimension";
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { Locale } from '../types';
|
2
|
+
declare class Intl {
|
3
|
+
private static instance;
|
4
|
+
private translateMap;
|
5
|
+
private locale;
|
6
|
+
canTranslate: (value: string) => boolean;
|
7
|
+
/**
|
8
|
+
* @example i18n`指标名称`
|
9
|
+
*/
|
10
|
+
i18n: (segments: TemplateStringsArray, ...values: Array<number | string>) => string;
|
11
|
+
setLocale: (locale: Locale) => void;
|
12
|
+
getLocale: () => Locale;
|
13
|
+
static getInstance(): Intl;
|
14
|
+
}
|
15
|
+
declare const intl: Intl;
|
16
|
+
declare const i18n: (segments: TemplateStringsArray, ...values: Array<number | string>) => string;
|
17
|
+
export { intl, i18n };
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './i18n.ts';
|
package/dist/index.cjs
CHANGED
@@ -26,6 +26,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
27
27
|
registerBar: ()=>registerBar,
|
28
28
|
isVChart: ()=>isVChart,
|
29
|
+
autoFormatter: ()=>autoFormatter,
|
29
30
|
zBaseConfig: ()=>zBaseConfig,
|
30
31
|
zTooltip: ()=>zTooltip,
|
31
32
|
pieAdvancedPipeline: ()=>pieAdvancedPipeline,
|
@@ -39,6 +40,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
39
40
|
zMeasures: ()=>zMeasures,
|
40
41
|
zCrosshairRect: ()=>zCrosshairRect,
|
41
42
|
FoldMeasureName: ()=>FoldMeasureName,
|
43
|
+
intl: ()=>intl,
|
42
44
|
darkTheme: ()=>darkTheme,
|
43
45
|
createNumFormatter: ()=>createNumFormatter,
|
44
46
|
columnPercentAdvancedPipeline: ()=>columnPercentAdvancedPipeline,
|
@@ -60,6 +62,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
60
62
|
columnAdvancedPipeline: ()=>columnAdvancedPipeline,
|
61
63
|
columnParallelSpecPipeline: ()=>columnParallelSpecPipeline,
|
62
64
|
zLabel: ()=>zLabel,
|
65
|
+
i18n: ()=>i18n,
|
63
66
|
registerColumn: ()=>registerColumn,
|
64
67
|
zAnnotationPoint: ()=>zAnnotationPoint,
|
65
68
|
lightTheme: ()=>lightTheme,
|
@@ -86,6 +89,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
86
89
|
zTheme: ()=>zTheme,
|
87
90
|
zEncoding: ()=>zEncoding,
|
88
91
|
registerAreaPercent: ()=>registerAreaPercent,
|
92
|
+
autoNumFormatter: ()=>autoNumFormatter,
|
89
93
|
zXLinearAxis: ()=>zXLinearAxis,
|
90
94
|
zConfig: ()=>zConfig,
|
91
95
|
zDatum: ()=>zDatum,
|
@@ -112,11 +116,11 @@ __webpack_require__.d(__webpack_exports__, {
|
|
112
116
|
zChartType: ()=>zChartType,
|
113
117
|
createFormatter: ()=>createFormatter,
|
114
118
|
unfoldDimensions: ()=>unfoldDimensions,
|
119
|
+
columnPercentSpecPipeline: ()=>columnPercentSpecPipeline,
|
115
120
|
areaAdvancedPipeline: ()=>areaAdvancedPipeline,
|
116
|
-
areaPercentSpecPipeline: ()=>areaPercentSpecPipeline,
|
117
121
|
Builder: ()=>Builder,
|
118
122
|
barParallelSpecPipeline: ()=>barParallelSpecPipeline,
|
119
|
-
|
123
|
+
areaPercentSpecPipeline: ()=>areaPercentSpecPipeline,
|
120
124
|
registerAll: ()=>all_registerAll
|
121
125
|
});
|
122
126
|
const initAdvancedVSeed = (advancedVSeed, context)=>{
|
@@ -127,6 +131,10 @@ const initAdvancedVSeed = (advancedVSeed, context)=>{
|
|
127
131
|
chartType
|
128
132
|
};
|
129
133
|
};
|
134
|
+
const execPipeline = (pipeline, context, initialValue = {})=>{
|
135
|
+
const result = pipeline.reduce((prev, cur)=>cur(prev, context), initialValue);
|
136
|
+
return result;
|
137
|
+
};
|
130
138
|
const isVTable = (chartType)=>[
|
131
139
|
'table',
|
132
140
|
'pivotTable'
|
@@ -138,6 +146,146 @@ const isPivotChart = (vseed)=>{
|
|
138
146
|
const hasMeasureGroup = measures && measures.find((measure)=>measure && measure.children);
|
139
147
|
return hasRowOrColumnDimension || hasMeasureGroup;
|
140
148
|
};
|
149
|
+
const external_remeda_namespaceObject = require("remeda");
|
150
|
+
var i18n_namespaceObject = JSON.parse('{"指标名称":{"en-US":"MeasureName","zh-CN":"指标名称"},"指标Id":{"en-US":"MeasureId","zh-CN":"指标Id"},"指标值":{"en-US":"MeasureValue","zh-CN":"指标值"}}');
|
151
|
+
class Intl {
|
152
|
+
static instance;
|
153
|
+
translateMap = i18n_namespaceObject;
|
154
|
+
locale = 'zh-CN';
|
155
|
+
canTranslate = (value)=>!!this.translateMap[value];
|
156
|
+
i18n = (segments, ...values)=>{
|
157
|
+
const text = segments.map((segment, index)=>segment + (values[index] || '')).join('');
|
158
|
+
const translatedText = this.translateMap?.[text]?.[this.locale];
|
159
|
+
if ((0, external_remeda_namespaceObject.isNullish)(translatedText)) {
|
160
|
+
console.warn(`i18n ${this.locale} no translate: ${text}`);
|
161
|
+
return text;
|
162
|
+
}
|
163
|
+
return translatedText;
|
164
|
+
};
|
165
|
+
setLocale = (locale)=>{
|
166
|
+
this.locale = locale;
|
167
|
+
};
|
168
|
+
getLocale = ()=>this.locale;
|
169
|
+
static getInstance() {
|
170
|
+
if (!Intl.instance) Intl.instance = new Intl();
|
171
|
+
return Intl.instance;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
const intl = Intl.getInstance();
|
175
|
+
const i18n = intl.i18n;
|
176
|
+
const createNumFormatter = (format)=>{
|
177
|
+
const { type = 'number', ratio = 1, symbol = '', thousandSeparator = true, decimalPlaces = 2, round = 'round', prefix = '', suffix = '' } = format || {};
|
178
|
+
return (value)=>{
|
179
|
+
let num = Number(value);
|
180
|
+
let typeSymbol = '';
|
181
|
+
if (Number.isNaN(num)) return num.toString();
|
182
|
+
if ('percent' === type) {
|
183
|
+
num *= 100;
|
184
|
+
typeSymbol = '%';
|
185
|
+
} else if ('permille' === type) {
|
186
|
+
num *= 1000;
|
187
|
+
typeSymbol = "\u2030";
|
188
|
+
} else if ('number' === type) num /= ratio || 1;
|
189
|
+
const multiplier = 10 ** decimalPlaces;
|
190
|
+
num = Math[round](num * multiplier) / multiplier;
|
191
|
+
let numStr = num.toFixed(decimalPlaces);
|
192
|
+
if (thousandSeparator) {
|
193
|
+
const parts = numStr.split('.');
|
194
|
+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
195
|
+
numStr = parts.join('.');
|
196
|
+
}
|
197
|
+
return `${prefix}${numStr}${typeSymbol}${symbol}${suffix}`;
|
198
|
+
};
|
199
|
+
};
|
200
|
+
const autoNumFormatter = (value, locale = intl.getLocale())=>{
|
201
|
+
if (null == value) return String(value);
|
202
|
+
const num = Number(value);
|
203
|
+
if (Number.isNaN(num)) return String(value);
|
204
|
+
const countDecimalPlaces = (num)=>{
|
205
|
+
if (Number.isInteger(num)) return 0;
|
206
|
+
const str = num.toString();
|
207
|
+
if (str.indexOf('e-') > -1) return parseInt(str.split('e-')[1]);
|
208
|
+
const decimalPart = str.split('.')[1];
|
209
|
+
if (!decimalPart) return 0;
|
210
|
+
const decimalPlaces = decimalPart.replace(/0+$/, '').length;
|
211
|
+
return Math.max(2, decimalPlaces);
|
212
|
+
};
|
213
|
+
const numFormat = {
|
214
|
+
type: 'number',
|
215
|
+
decimalPlaces: countDecimalPlaces(num),
|
216
|
+
round: 'round',
|
217
|
+
thousandSeparator: true
|
218
|
+
};
|
219
|
+
const rules = NUMBER_FORMAT_RULES[locale] || NUMBER_FORMAT_RULES['default'];
|
220
|
+
for (const rule of rules)if (num >= rule.threshold) {
|
221
|
+
numFormat.ratio = rule.ratio;
|
222
|
+
numFormat.symbol = rule.symbol;
|
223
|
+
break;
|
224
|
+
}
|
225
|
+
return createNumFormatter(numFormat)(value);
|
226
|
+
};
|
227
|
+
const NUMBER_FORMAT_RULES = {
|
228
|
+
'zh-CN': [
|
229
|
+
{
|
230
|
+
threshold: 100000000,
|
231
|
+
ratio: 100000000,
|
232
|
+
symbol: "\u4EBF"
|
233
|
+
},
|
234
|
+
{
|
235
|
+
threshold: 10000,
|
236
|
+
ratio: 10000,
|
237
|
+
symbol: "\u4E07"
|
238
|
+
}
|
239
|
+
],
|
240
|
+
'en-US': [
|
241
|
+
{
|
242
|
+
threshold: 1000000000,
|
243
|
+
ratio: 1000000000,
|
244
|
+
symbol: 'B'
|
245
|
+
},
|
246
|
+
{
|
247
|
+
threshold: 1000000,
|
248
|
+
ratio: 1000000,
|
249
|
+
symbol: 'M'
|
250
|
+
},
|
251
|
+
{
|
252
|
+
threshold: 1000,
|
253
|
+
ratio: 1000,
|
254
|
+
symbol: 'K'
|
255
|
+
}
|
256
|
+
],
|
257
|
+
default: [
|
258
|
+
{
|
259
|
+
threshold: 1000000000,
|
260
|
+
ratio: 1000000000,
|
261
|
+
symbol: 'B'
|
262
|
+
},
|
263
|
+
{
|
264
|
+
threshold: 1000000,
|
265
|
+
ratio: 1000000,
|
266
|
+
symbol: 'M'
|
267
|
+
},
|
268
|
+
{
|
269
|
+
threshold: 1000,
|
270
|
+
ratio: 1000,
|
271
|
+
symbol: 'K'
|
272
|
+
}
|
273
|
+
]
|
274
|
+
};
|
275
|
+
const createFormatter = (format)=>createNumFormatter(format);
|
276
|
+
const autoFormatter = (value, locale)=>autoNumFormatter(value, locale);
|
277
|
+
function findMeasureById(measures, id) {
|
278
|
+
if (!measures) return;
|
279
|
+
const stack = [
|
280
|
+
...measures
|
281
|
+
];
|
282
|
+
while(stack.length > 0){
|
283
|
+
const current = stack.pop();
|
284
|
+
if (!current) continue;
|
285
|
+
if (current.id === id && !('children' in current)) return current;
|
286
|
+
if ('children' in current && current.children) stack.push(...current.children);
|
287
|
+
}
|
288
|
+
}
|
141
289
|
const autoMeasures = (advancedVSeed, context)=>{
|
142
290
|
const result = {
|
143
291
|
...advancedVSeed
|
@@ -244,7 +392,6 @@ const FoldMeasureId = '__MeaId__';
|
|
244
392
|
const UnfoldDimensionGroup = '__DimGroup__';
|
245
393
|
const Separator = '-';
|
246
394
|
const ORIGINAL_DATA = '__OriginalData__';
|
247
|
-
const external_remeda_namespaceObject = require("remeda");
|
248
395
|
const unfoldDimensions = (dataset, dimensions, measures, unfoldStartIndex = 0, foldGroupName = UnfoldDimensionGroup, dimensionsSeparator = Separator)=>{
|
249
396
|
if (unfoldStartIndex < 0 || unfoldStartIndex >= dimensions.length) throw new Error('unfoldStartIndex is out of range');
|
250
397
|
const dimensionsToBeUnfolded = dimensions.slice(unfoldStartIndex);
|
@@ -323,18 +470,18 @@ const dataReshapeFor2D1M = (dataset, dimensions, measures, options)=>{
|
|
323
470
|
const { dataset: finalDataset, unfoldInfo } = unfoldDimensions(foldedDataset, [
|
324
471
|
{
|
325
472
|
id: foldMeasureId,
|
326
|
-
alias:
|
473
|
+
alias: i18n`指标Id`,
|
327
474
|
location: 'dimension'
|
328
475
|
},
|
329
476
|
{
|
330
477
|
id: foldMeasureName,
|
331
|
-
alias:
|
478
|
+
alias: i18n`指标名称`,
|
332
479
|
location: 'dimension'
|
333
480
|
}
|
334
481
|
], [
|
335
482
|
{
|
336
483
|
id: foldMeasureValue,
|
337
|
-
alias:
|
484
|
+
alias: i18n`指标值`
|
338
485
|
}
|
339
486
|
], 1, unfoldDimensionGroup);
|
340
487
|
return {
|
@@ -348,13 +495,13 @@ const dataReshapeFor2D1M = (dataset, dimensions, measures, options)=>{
|
|
348
495
|
...dimensions,
|
349
496
|
{
|
350
497
|
id: foldMeasureName,
|
351
|
-
alias:
|
498
|
+
alias: i18n`指标名称`,
|
352
499
|
location: 'dimension'
|
353
500
|
}
|
354
501
|
], [
|
355
502
|
{
|
356
503
|
id: foldMeasureValue,
|
357
|
-
alias:
|
504
|
+
alias: i18n`指标值`
|
358
505
|
}
|
359
506
|
], 1, unfoldDimensionGroup);
|
360
507
|
return {
|
@@ -385,13 +532,13 @@ const dataReshapeFor1D1M = (dataset, dimensions, measures, options)=>{
|
|
385
532
|
const { dataset: finalDataset, unfoldInfo } = unfoldDimensions(foldedDataset, [
|
386
533
|
{
|
387
534
|
id: foldMeasureName,
|
388
|
-
alias:
|
535
|
+
alias: i18n`指标名称`,
|
389
536
|
location: 'dimension'
|
390
537
|
}
|
391
538
|
], [
|
392
539
|
{
|
393
540
|
id: foldMeasureValue,
|
394
|
-
alias:
|
541
|
+
alias: i18n`指标值`
|
395
542
|
}
|
396
543
|
], 0, unfoldDimensionGroup);
|
397
544
|
return {
|
@@ -405,13 +552,13 @@ const dataReshapeFor1D1M = (dataset, dimensions, measures, options)=>{
|
|
405
552
|
...dimensions,
|
406
553
|
{
|
407
554
|
id: foldMeasureName,
|
408
|
-
alias:
|
555
|
+
alias: i18n`指标名称`,
|
409
556
|
location: 'dimension'
|
410
557
|
}
|
411
558
|
], [
|
412
559
|
{
|
413
560
|
id: foldMeasureValue,
|
414
|
-
alias:
|
561
|
+
alias: i18n`指标值`
|
415
562
|
}
|
416
563
|
], 0, unfoldDimensionGroup);
|
417
564
|
return {
|
@@ -759,10 +906,6 @@ const vchartTheme = (advancedVSeed, context)=>{
|
|
759
906
|
}
|
760
907
|
return result;
|
761
908
|
};
|
762
|
-
const execPipeline = (pipeline, context, initialValue = {})=>{
|
763
|
-
const result = pipeline.reduce((prev, cur)=>cur(prev, context), initialValue);
|
764
|
-
return result;
|
765
|
-
};
|
766
909
|
const pivotAdapter = (pipeline, pivotPipeline)=>(advancedVSeed, context)=>{
|
767
910
|
const { vseed } = context;
|
768
911
|
const usePivotChart = isPivotChart(vseed);
|
@@ -795,8 +938,17 @@ const annotation_annotation = (advancedVSeed, context)=>{
|
|
795
938
|
annotation
|
796
939
|
};
|
797
940
|
};
|
941
|
+
const locale_locale = (advancedVSeed, context)=>{
|
942
|
+
const { vseed } = context;
|
943
|
+
const { locale } = vseed;
|
944
|
+
return {
|
945
|
+
...advancedVSeed,
|
946
|
+
locale: locale || 'zh-CN'
|
947
|
+
};
|
948
|
+
};
|
798
949
|
const lineAdvancedPipeline = [
|
799
950
|
initAdvancedVSeed,
|
951
|
+
locale_locale,
|
800
952
|
autoMeasures,
|
801
953
|
autoDimensions,
|
802
954
|
pivotAdapter([
|
@@ -813,6 +965,7 @@ const lineAdvancedPipeline = [
|
|
813
965
|
];
|
814
966
|
const barAdvancedPipeline = [
|
815
967
|
initAdvancedVSeed,
|
968
|
+
locale_locale,
|
816
969
|
autoMeasures,
|
817
970
|
autoDimensions,
|
818
971
|
pivotAdapter([
|
@@ -829,6 +982,7 @@ const barAdvancedPipeline = [
|
|
829
982
|
];
|
830
983
|
const barParallelAdvancedPipeline = [
|
831
984
|
initAdvancedVSeed,
|
985
|
+
locale_locale,
|
832
986
|
autoMeasures,
|
833
987
|
autoDimensions,
|
834
988
|
pivotAdapter([
|
@@ -845,6 +999,7 @@ const barParallelAdvancedPipeline = [
|
|
845
999
|
];
|
846
1000
|
const barPercentAdvancedPipeline = [
|
847
1001
|
initAdvancedVSeed,
|
1002
|
+
locale_locale,
|
848
1003
|
autoMeasures,
|
849
1004
|
autoDimensions,
|
850
1005
|
pivotAdapter([
|
@@ -861,6 +1016,7 @@ const barPercentAdvancedPipeline = [
|
|
861
1016
|
];
|
862
1017
|
const columnAdvancedPipeline = [
|
863
1018
|
initAdvancedVSeed,
|
1019
|
+
locale_locale,
|
864
1020
|
autoMeasures,
|
865
1021
|
autoDimensions,
|
866
1022
|
pivotAdapter([
|
@@ -877,6 +1033,7 @@ const columnAdvancedPipeline = [
|
|
877
1033
|
];
|
878
1034
|
const columnParallelAdvancedPipeline = [
|
879
1035
|
initAdvancedVSeed,
|
1036
|
+
locale_locale,
|
880
1037
|
autoMeasures,
|
881
1038
|
autoDimensions,
|
882
1039
|
pivotAdapter([
|
@@ -893,6 +1050,7 @@ const columnParallelAdvancedPipeline = [
|
|
893
1050
|
];
|
894
1051
|
const columnPercentAdvancedPipeline = [
|
895
1052
|
initAdvancedVSeed,
|
1053
|
+
locale_locale,
|
896
1054
|
autoMeasures,
|
897
1055
|
autoDimensions,
|
898
1056
|
pivotAdapter([
|
@@ -909,6 +1067,7 @@ const columnPercentAdvancedPipeline = [
|
|
909
1067
|
];
|
910
1068
|
const areaAdvancedPipeline = [
|
911
1069
|
initAdvancedVSeed,
|
1070
|
+
locale_locale,
|
912
1071
|
autoMeasures,
|
913
1072
|
autoDimensions,
|
914
1073
|
pivotAdapter([
|
@@ -925,6 +1084,7 @@ const areaAdvancedPipeline = [
|
|
925
1084
|
];
|
926
1085
|
const areaPercentAdvancedPipeline = [
|
927
1086
|
initAdvancedVSeed,
|
1087
|
+
locale_locale,
|
928
1088
|
autoMeasures,
|
929
1089
|
autoDimensions,
|
930
1090
|
pivotAdapter([
|
@@ -941,6 +1101,7 @@ const areaPercentAdvancedPipeline = [
|
|
941
1101
|
];
|
942
1102
|
const pieAdvancedPipeline = [
|
943
1103
|
initAdvancedVSeed,
|
1104
|
+
locale_locale,
|
944
1105
|
autoMeasures,
|
945
1106
|
autoDimensions,
|
946
1107
|
pivotAdapter([
|
@@ -1244,13 +1405,14 @@ const xBand = (spec, context)=>{
|
|
1244
1405
|
return result;
|
1245
1406
|
};
|
1246
1407
|
const ANNOTATION_Z_INDEX = 1000;
|
1247
|
-
const LINEAR_AXIS_INNER_OFFSET_TOP =
|
1408
|
+
const LINEAR_AXIS_INNER_OFFSET_TOP = 7;
|
1248
1409
|
const xLinear = (spec, context)=>{
|
1249
1410
|
const result = {
|
1250
1411
|
...spec
|
1251
1412
|
};
|
1252
1413
|
const { advancedVSeed, vseed } = context;
|
1253
1414
|
const { chartType } = vseed;
|
1415
|
+
const { locale } = advancedVSeed;
|
1254
1416
|
const config = advancedVSeed.config?.[chartType]?.xAxis;
|
1255
1417
|
if (!result.axes) result.axes = [];
|
1256
1418
|
if (!config) {
|
@@ -1276,6 +1438,7 @@ const xLinear = (spec, context)=>{
|
|
1276
1438
|
min,
|
1277
1439
|
label: {
|
1278
1440
|
visible: label?.visible,
|
1441
|
+
formatMethod: (value)=>autoFormatter(value, locale),
|
1279
1442
|
style: {
|
1280
1443
|
fill: label?.labelColor,
|
1281
1444
|
angle: label?.labelAngle,
|
@@ -1425,6 +1588,7 @@ const yLinear = (spec, context)=>{
|
|
1425
1588
|
};
|
1426
1589
|
const { advancedVSeed, vseed } = context;
|
1427
1590
|
const { chartType } = vseed;
|
1591
|
+
const { locale } = advancedVSeed;
|
1428
1592
|
const config = advancedVSeed.config?.[chartType]?.yAxis;
|
1429
1593
|
if (!result.axes) result.axes = [];
|
1430
1594
|
if (!config) {
|
@@ -1450,6 +1614,7 @@ const yLinear = (spec, context)=>{
|
|
1450
1614
|
min,
|
1451
1615
|
label: {
|
1452
1616
|
visible: label?.visible,
|
1617
|
+
formatMethod: (value)=>autoFormatter(value, locale),
|
1453
1618
|
style: {
|
1454
1619
|
fill: label?.labelColor,
|
1455
1620
|
angle: label?.labelAngle,
|
@@ -1534,43 +1699,6 @@ const background_backgroundColor = (spec, context)=>{
|
|
1534
1699
|
background: backgroundColor
|
1535
1700
|
};
|
1536
1701
|
};
|
1537
|
-
function findMeasureById(measures, id) {
|
1538
|
-
if (!measures) return;
|
1539
|
-
const stack = [
|
1540
|
-
...measures
|
1541
|
-
];
|
1542
|
-
while(stack.length > 0){
|
1543
|
-
const current = stack.pop();
|
1544
|
-
if (!current) continue;
|
1545
|
-
if (current.id === id && !('children' in current)) return current;
|
1546
|
-
if ('children' in current && current.children) stack.push(...current.children);
|
1547
|
-
}
|
1548
|
-
}
|
1549
|
-
const createNumFormatter = (format)=>{
|
1550
|
-
const { type = 'number', ratio = 1, symbol = '', thousandSeparator = true, decimalPlaces = 2, round = 'round', prefix = '', suffix = '' } = format || {};
|
1551
|
-
return (value)=>{
|
1552
|
-
let num = Number(value);
|
1553
|
-
let typeSymbol = '';
|
1554
|
-
if (Number.isNaN(num)) return num.toString();
|
1555
|
-
if ('percent' === type) {
|
1556
|
-
num *= 100;
|
1557
|
-
typeSymbol = '%';
|
1558
|
-
} else if ('permille' === type) {
|
1559
|
-
num *= 1000;
|
1560
|
-
typeSymbol = "\u2030";
|
1561
|
-
} else if ('number' === type) num /= ratio || 1;
|
1562
|
-
const multiplier = 10 ** decimalPlaces;
|
1563
|
-
num = Math[round](num * multiplier) / multiplier;
|
1564
|
-
let numStr = num.toFixed(decimalPlaces);
|
1565
|
-
if (thousandSeparator) {
|
1566
|
-
const parts = numStr.split('.');
|
1567
|
-
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
1568
|
-
numStr = parts.join('.');
|
1569
|
-
}
|
1570
|
-
return `${prefix}${numStr}${typeSymbol}${symbol}${suffix}`;
|
1571
|
-
};
|
1572
|
-
};
|
1573
|
-
const createFormatter = (format)=>createNumFormatter(format);
|
1574
1702
|
const defaultTooltip = {
|
1575
1703
|
enable: true
|
1576
1704
|
};
|
@@ -1598,10 +1726,11 @@ const tooltip_tooltip = (spec, context)=>{
|
|
1598
1726
|
const measure = findMeasureById(measures, id);
|
1599
1727
|
if (!measure) return String(value);
|
1600
1728
|
const { format = {}, autoFormat = true } = measure;
|
1601
|
-
if (
|
1729
|
+
if (!(0, external_remeda_namespaceObject.isEmpty)(format)) {
|
1602
1730
|
const formatter = createFormatter(format);
|
1603
1731
|
return formatter(value);
|
1604
1732
|
}
|
1733
|
+
if (autoFormat) return autoFormatter(value);
|
1605
1734
|
return String(value);
|
1606
1735
|
}
|
1607
1736
|
}
|
@@ -1619,10 +1748,11 @@ const tooltip_tooltip = (spec, context)=>{
|
|
1619
1748
|
const measure = findMeasureById(measures, id);
|
1620
1749
|
if (!measure) return String(value);
|
1621
1750
|
const { format = {}, autoFormat = true } = measure;
|
1622
|
-
if (
|
1751
|
+
if (!(0, external_remeda_namespaceObject.isEmpty)(format)) {
|
1623
1752
|
const formatter = createFormatter(format);
|
1624
1753
|
return formatter(value);
|
1625
1754
|
}
|
1755
|
+
if (autoFormat) return autoFormatter(value);
|
1626
1756
|
return String(value);
|
1627
1757
|
}
|
1628
1758
|
}
|
@@ -1636,7 +1766,7 @@ const label_label = (spec, context)=>{
|
|
1636
1766
|
...spec
|
1637
1767
|
};
|
1638
1768
|
const { advancedVSeed } = context;
|
1639
|
-
const { measures, datasetReshapeInfo } = advancedVSeed;
|
1769
|
+
const { measures, datasetReshapeInfo, locale } = advancedVSeed;
|
1640
1770
|
const baseConfig = advancedVSeed.baseConfig.vchart;
|
1641
1771
|
if (!baseConfig || !baseConfig.label) return result;
|
1642
1772
|
const { measureId } = datasetReshapeInfo[0].foldInfo;
|
@@ -1649,10 +1779,12 @@ const label_label = (spec, context)=>{
|
|
1649
1779
|
const measure = findMeasureById(measures, id);
|
1650
1780
|
if (!measure) return value;
|
1651
1781
|
const { format = {}, autoFormat = true } = measure;
|
1652
|
-
if (
|
1782
|
+
if (!(0, external_remeda_namespaceObject.isEmpty)(format)) {
|
1653
1783
|
const formatter = createFormatter(format);
|
1654
1784
|
return formatter(value);
|
1655
1785
|
}
|
1786
|
+
if (autoFormat) return autoFormatter(value, locale);
|
1787
|
+
return String(value);
|
1656
1788
|
}
|
1657
1789
|
};
|
1658
1790
|
return result;
|
@@ -3552,6 +3684,7 @@ class Builder {
|
|
3552
3684
|
_spec = null;
|
3553
3685
|
constructor(vseed){
|
3554
3686
|
this._vseed = vseed;
|
3687
|
+
this._vseed.locale = vseed.locale || intl.getLocale();
|
3555
3688
|
}
|
3556
3689
|
build = ()=>build(this);
|
3557
3690
|
buildSpec = (advanced)=>buildSpec(this, advanced);
|
@@ -4161,7 +4294,7 @@ const zMeasure = external_zod_namespaceObject.z.object({
|
|
4161
4294
|
alias: external_zod_namespaceObject.z.string().optional(),
|
4162
4295
|
visible: external_zod_namespaceObject.z.boolean().default(true).optional(),
|
4163
4296
|
autoFormat: external_zod_namespaceObject.z.boolean().default(true).optional(),
|
4164
|
-
format: zNumFormat.optional()
|
4297
|
+
format: zNumFormat["default"]({}).optional()
|
4165
4298
|
});
|
4166
4299
|
const zMeasureGroup = external_zod_namespaceObject.z.object({
|
4167
4300
|
id: external_zod_namespaceObject.z.string(),
|
@@ -4807,6 +4940,8 @@ exports.areaAdvancedPipeline = __webpack_exports__.areaAdvancedPipeline;
|
|
4807
4940
|
exports.areaPercentAdvancedPipeline = __webpack_exports__.areaPercentAdvancedPipeline;
|
4808
4941
|
exports.areaPercentSpecPipeline = __webpack_exports__.areaPercentSpecPipeline;
|
4809
4942
|
exports.areaSpecPipeline = __webpack_exports__.areaSpecPipeline;
|
4943
|
+
exports.autoFormatter = __webpack_exports__.autoFormatter;
|
4944
|
+
exports.autoNumFormatter = __webpack_exports__.autoNumFormatter;
|
4810
4945
|
exports.barAdvancedPipeline = __webpack_exports__.barAdvancedPipeline;
|
4811
4946
|
exports.barParallelAdvancedPipeline = __webpack_exports__.barParallelAdvancedPipeline;
|
4812
4947
|
exports.barParallelSpecPipeline = __webpack_exports__.barParallelSpecPipeline;
|
@@ -4827,6 +4962,8 @@ exports.dataReshapeFor2D1M = __webpack_exports__.dataReshapeFor2D1M;
|
|
4827
4962
|
exports.execPipeline = __webpack_exports__.execPipeline;
|
4828
4963
|
exports.findMeasureById = __webpack_exports__.findMeasureById;
|
4829
4964
|
exports.foldMeasures = __webpack_exports__.foldMeasures;
|
4965
|
+
exports.i18n = __webpack_exports__.i18n;
|
4966
|
+
exports.intl = __webpack_exports__.intl;
|
4830
4967
|
exports.isPivotChart = __webpack_exports__.isPivotChart;
|
4831
4968
|
exports.isVChart = __webpack_exports__.isVChart;
|
4832
4969
|
exports.isVTable = __webpack_exports__.isVTable;
|
@@ -4902,6 +5039,8 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
4902
5039
|
"areaPercentAdvancedPipeline",
|
4903
5040
|
"areaPercentSpecPipeline",
|
4904
5041
|
"areaSpecPipeline",
|
5042
|
+
"autoFormatter",
|
5043
|
+
"autoNumFormatter",
|
4905
5044
|
"barAdvancedPipeline",
|
4906
5045
|
"barParallelAdvancedPipeline",
|
4907
5046
|
"barParallelSpecPipeline",
|
@@ -4922,6 +5061,8 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
4922
5061
|
"execPipeline",
|
4923
5062
|
"findMeasureById",
|
4924
5063
|
"foldMeasures",
|
5064
|
+
"i18n",
|
5065
|
+
"intl",
|
4925
5066
|
"isPivotChart",
|
4926
5067
|
"isVChart",
|
4927
5068
|
"isVTable",
|