@visactor/vseed 0.0.12 → 0.0.14
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 +9 -0
- package/dist/dataReshape/constant.d.ts +1 -0
- package/dist/dataReshape/dataReshapeFor1D1M.d.ts +1 -0
- package/dist/dataReshape/dataReshapeFor2D1M.d.ts +1 -0
- package/dist/dataReshape/unfoldDimensions.d.ts +1 -1
- package/dist/i18n/i18n.d.ts +17 -0
- package/dist/i18n/index.d.ts +1 -0
- package/dist/index.cjs +273 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +216 -53
- 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 +10 -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/datasetReshapeInfo/datasetReshapeInfo.d.ts +6 -0
- package/dist/types/properties/measures/measures.d.ts +8 -8
- package/dist/types/vseed.d.ts +13 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { clone as external_remeda_clone, groupBy, isArray, isNumber, isString, mergeDeep as external_remeda_mergeDeep, omit, pick as external_remeda_pick, unique } from "remeda";
|
1
|
+
import { clone as external_remeda_clone, groupBy, isArray, isEmpty, isNullish, isNumber, isString, mergeDeep as external_remeda_mergeDeep, omit, pick as external_remeda_pick, unique } from "remeda";
|
2
2
|
import { z } from "zod";
|
3
3
|
const initAdvancedVSeed = (advancedVSeed, context)=>{
|
4
4
|
const { vseed } = context;
|
@@ -23,6 +23,32 @@ const isPivotChart = (vseed)=>{
|
|
23
23
|
const hasMeasureGroup = measures && measures.find((measure)=>measure && measure.children);
|
24
24
|
return hasRowOrColumnDimension || hasMeasureGroup;
|
25
25
|
};
|
26
|
+
var i18n_namespaceObject = JSON.parse('{"指标名称":{"en-US":"MeasureName","zh-CN":"指标名称"},"指标Id":{"en-US":"MeasureId","zh-CN":"指标Id"},"指标值":{"en-US":"MeasureValue","zh-CN":"指标值"}}');
|
27
|
+
class Intl {
|
28
|
+
static instance;
|
29
|
+
translateMap = i18n_namespaceObject;
|
30
|
+
locale = 'zh-CN';
|
31
|
+
canTranslate = (value)=>!!this.translateMap[value];
|
32
|
+
i18n = (segments, ...values)=>{
|
33
|
+
const text = segments.map((segment, index)=>segment + (values[index] || '')).join('');
|
34
|
+
const translatedText = this.translateMap?.[text]?.[this.locale];
|
35
|
+
if (isNullish(translatedText)) {
|
36
|
+
console.warn(`i18n ${this.locale} no translate: ${text}`);
|
37
|
+
return text;
|
38
|
+
}
|
39
|
+
return translatedText;
|
40
|
+
};
|
41
|
+
setLocale = (locale)=>{
|
42
|
+
this.locale = locale;
|
43
|
+
};
|
44
|
+
getLocale = ()=>this.locale;
|
45
|
+
static getInstance() {
|
46
|
+
if (!Intl.instance) Intl.instance = new Intl();
|
47
|
+
return Intl.instance;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
const intl = Intl.getInstance();
|
51
|
+
const i18n = intl.i18n;
|
26
52
|
const createNumFormatter = (format)=>{
|
27
53
|
const { type = 'number', ratio = 1, symbol = '', thousandSeparator = true, decimalPlaces = 2, round = 'round', prefix = '', suffix = '' } = format || {};
|
28
54
|
return (value)=>{
|
@@ -47,7 +73,83 @@ const createNumFormatter = (format)=>{
|
|
47
73
|
return `${prefix}${numStr}${typeSymbol}${symbol}${suffix}`;
|
48
74
|
};
|
49
75
|
};
|
76
|
+
const autoNumFormatter = (value, locale = intl.getLocale())=>{
|
77
|
+
if (null == value) return String(value);
|
78
|
+
const num = Number(value);
|
79
|
+
if (Number.isNaN(num)) return String(value);
|
80
|
+
const countDecimalPlaces = (num)=>{
|
81
|
+
if (Number.isInteger(num)) return 0;
|
82
|
+
const str = num.toString();
|
83
|
+
if (str.indexOf('e-') > -1) return parseInt(str.split('e-')[1]);
|
84
|
+
const decimalPart = str.split('.')[1];
|
85
|
+
if (!decimalPart) return 0;
|
86
|
+
const decimalPlaces = decimalPart.replace(/0+$/, '').length;
|
87
|
+
return Math.max(2, decimalPlaces);
|
88
|
+
};
|
89
|
+
const numFormat = {
|
90
|
+
type: 'number',
|
91
|
+
decimalPlaces: countDecimalPlaces(num),
|
92
|
+
round: 'round',
|
93
|
+
thousandSeparator: true
|
94
|
+
};
|
95
|
+
const rules = NUMBER_FORMAT_RULES[locale] || NUMBER_FORMAT_RULES['default'];
|
96
|
+
for (const rule of rules)if (num >= rule.threshold) {
|
97
|
+
numFormat.ratio = rule.ratio;
|
98
|
+
numFormat.symbol = rule.symbol;
|
99
|
+
break;
|
100
|
+
}
|
101
|
+
return createNumFormatter(numFormat)(value);
|
102
|
+
};
|
103
|
+
const NUMBER_FORMAT_RULES = {
|
104
|
+
'zh-CN': [
|
105
|
+
{
|
106
|
+
threshold: 100000000,
|
107
|
+
ratio: 100000000,
|
108
|
+
symbol: "\u4EBF"
|
109
|
+
},
|
110
|
+
{
|
111
|
+
threshold: 10000,
|
112
|
+
ratio: 10000,
|
113
|
+
symbol: "\u4E07"
|
114
|
+
}
|
115
|
+
],
|
116
|
+
'en-US': [
|
117
|
+
{
|
118
|
+
threshold: 1000000000,
|
119
|
+
ratio: 1000000000,
|
120
|
+
symbol: 'B'
|
121
|
+
},
|
122
|
+
{
|
123
|
+
threshold: 1000000,
|
124
|
+
ratio: 1000000,
|
125
|
+
symbol: 'M'
|
126
|
+
},
|
127
|
+
{
|
128
|
+
threshold: 1000,
|
129
|
+
ratio: 1000,
|
130
|
+
symbol: 'K'
|
131
|
+
}
|
132
|
+
],
|
133
|
+
default: [
|
134
|
+
{
|
135
|
+
threshold: 1000000000,
|
136
|
+
ratio: 1000000000,
|
137
|
+
symbol: 'B'
|
138
|
+
},
|
139
|
+
{
|
140
|
+
threshold: 1000000,
|
141
|
+
ratio: 1000000,
|
142
|
+
symbol: 'M'
|
143
|
+
},
|
144
|
+
{
|
145
|
+
threshold: 1000,
|
146
|
+
ratio: 1000,
|
147
|
+
symbol: 'K'
|
148
|
+
}
|
149
|
+
]
|
150
|
+
};
|
50
151
|
const createFormatter = (format)=>createNumFormatter(format);
|
152
|
+
const autoFormatter = (value, locale)=>autoNumFormatter(value, locale);
|
51
153
|
function findMeasureById(measures, id) {
|
52
154
|
if (!measures) return;
|
53
155
|
const stack = [
|
@@ -164,30 +266,40 @@ const FoldMeasureName = '__MeaName__';
|
|
164
266
|
const FoldMeasureValue = '__MeaValue__';
|
165
267
|
const FoldMeasureId = '__MeaId__';
|
166
268
|
const UnfoldDimensionGroup = '__DimGroup__';
|
269
|
+
const UnfoldDimensionGroupId = '__DimGroupID__';
|
167
270
|
const Separator = '-';
|
168
271
|
const ORIGINAL_DATA = '__OriginalData__';
|
169
|
-
const unfoldDimensions = (dataset, dimensions, measures, unfoldStartIndex = 0,
|
272
|
+
const unfoldDimensions = (dataset, dimensions, measures, unfoldStartIndex = 0, unfoldGroupName = UnfoldDimensionGroup, unfoldGroupId = UnfoldDimensionGroupId, foldMeasureId = FoldMeasureId, dimensionsSeparator = Separator)=>{
|
170
273
|
if (unfoldStartIndex < 0 || unfoldStartIndex >= dimensions.length) throw new Error('unfoldStartIndex is out of range');
|
171
274
|
const dimensionsToBeUnfolded = dimensions.slice(unfoldStartIndex);
|
172
275
|
const unfoldInfo = {
|
173
|
-
groupName:
|
174
|
-
|
276
|
+
groupName: unfoldGroupName,
|
277
|
+
groupId: unfoldGroupId,
|
278
|
+
colorItems: [],
|
279
|
+
colorIdMap: {}
|
175
280
|
};
|
176
281
|
if (0 === dimensions.length || 0 === measures.length) return {
|
177
282
|
dataset,
|
178
283
|
unfoldInfo: {
|
179
|
-
groupName:
|
180
|
-
|
284
|
+
groupName: unfoldGroupName,
|
285
|
+
groupId: unfoldGroupId,
|
286
|
+
colorItems: [],
|
287
|
+
colorIdMap: {}
|
181
288
|
}
|
182
289
|
};
|
183
290
|
const colorItems = [];
|
291
|
+
const colorMap = {};
|
184
292
|
for(let i = 0; i < dataset.length; i++){
|
185
293
|
const datum = dataset[i];
|
186
|
-
const
|
187
|
-
datum[
|
188
|
-
|
294
|
+
const colorName = generateDimGroupName(dimensionsToBeUnfolded, datum, dimensionsSeparator);
|
295
|
+
const colorId = colorName + (datum[foldMeasureId] || '');
|
296
|
+
datum[unfoldGroupName] = colorName;
|
297
|
+
datum[unfoldGroupId] = colorId;
|
298
|
+
colorItems.push(colorId);
|
299
|
+
colorMap[colorId] = colorName;
|
189
300
|
}
|
190
301
|
unfoldInfo.colorItems = unique(colorItems);
|
302
|
+
unfoldInfo.colorIdMap = colorMap;
|
191
303
|
return {
|
192
304
|
dataset,
|
193
305
|
unfoldInfo
|
@@ -213,7 +325,7 @@ const foldMeasures = (dataset, measures, measureId = FoldMeasureId, measureName
|
|
213
325
|
const { id, alias } = measure;
|
214
326
|
datum[id] = dataset[i][id];
|
215
327
|
datum[measureId] = id;
|
216
|
-
datum[measureName] = alias;
|
328
|
+
datum[measureName] = alias || id;
|
217
329
|
datum[measureValue] = dataset[i][id];
|
218
330
|
foldInfo.foldMap[id] = alias;
|
219
331
|
result[index++] = datum;
|
@@ -232,32 +344,34 @@ const emptyReshapeResult = {
|
|
232
344
|
measureValue: ''
|
233
345
|
},
|
234
346
|
unfoldInfo: {
|
347
|
+
groupName: '',
|
348
|
+
groupId: '',
|
235
349
|
colorItems: [],
|
236
|
-
|
350
|
+
colorIdMap: {}
|
237
351
|
}
|
238
352
|
};
|
239
353
|
const dataReshapeFor2D1M = (dataset, dimensions, measures, options)=>{
|
240
|
-
const { foldMeasureId = FoldMeasureId, foldMeasureName = FoldMeasureName, foldMeasureValue = FoldMeasureValue, unfoldDimensionGroup = UnfoldDimensionGroup } = options || {};
|
354
|
+
const { foldMeasureId = FoldMeasureId, foldMeasureName = FoldMeasureName, foldMeasureValue = FoldMeasureValue, unfoldDimensionGroup = UnfoldDimensionGroup, unfoldDimensionGroupId = UnfoldDimensionGroupId } = options || {};
|
241
355
|
if (0 === dimensions.length && 0 === measures.length) return emptyReshapeResult;
|
242
356
|
const { dataset: foldedDataset, foldInfo } = foldMeasures(dataset, measures, foldMeasureId, foldMeasureName, foldMeasureValue);
|
243
357
|
if (0 === dimensions.length) {
|
244
358
|
const { dataset: finalDataset, unfoldInfo } = unfoldDimensions(foldedDataset, [
|
245
359
|
{
|
246
360
|
id: foldMeasureId,
|
247
|
-
alias:
|
361
|
+
alias: i18n`指标Id`,
|
248
362
|
location: 'dimension'
|
249
363
|
},
|
250
364
|
{
|
251
365
|
id: foldMeasureName,
|
252
|
-
alias:
|
366
|
+
alias: i18n`指标名称`,
|
253
367
|
location: 'dimension'
|
254
368
|
}
|
255
369
|
], [
|
256
370
|
{
|
257
371
|
id: foldMeasureValue,
|
258
|
-
alias:
|
372
|
+
alias: i18n`指标值`
|
259
373
|
}
|
260
|
-
], 1, unfoldDimensionGroup);
|
374
|
+
], 1, unfoldDimensionGroup, unfoldDimensionGroupId, foldMeasureId);
|
261
375
|
return {
|
262
376
|
dataset: finalDataset,
|
263
377
|
foldInfo,
|
@@ -269,15 +383,15 @@ const dataReshapeFor2D1M = (dataset, dimensions, measures, options)=>{
|
|
269
383
|
...dimensions,
|
270
384
|
{
|
271
385
|
id: foldMeasureName,
|
272
|
-
alias:
|
386
|
+
alias: i18n`指标名称`,
|
273
387
|
location: 'dimension'
|
274
388
|
}
|
275
389
|
], [
|
276
390
|
{
|
277
391
|
id: foldMeasureValue,
|
278
|
-
alias:
|
392
|
+
alias: i18n`指标值`
|
279
393
|
}
|
280
|
-
], 1, unfoldDimensionGroup);
|
394
|
+
], 1, unfoldDimensionGroup, unfoldDimensionGroupId, foldMeasureId);
|
281
395
|
return {
|
282
396
|
dataset: finalDataset,
|
283
397
|
foldInfo,
|
@@ -295,26 +409,28 @@ const dataReshapeFor1D1M_emptyReshapeResult = {
|
|
295
409
|
},
|
296
410
|
unfoldInfo: {
|
297
411
|
groupName: '',
|
298
|
-
|
412
|
+
groupId: '',
|
413
|
+
colorItems: [],
|
414
|
+
colorIdMap: {}
|
299
415
|
}
|
300
416
|
};
|
301
417
|
const dataReshapeFor1D1M = (dataset, dimensions, measures, options)=>{
|
302
|
-
const { foldMeasureId = FoldMeasureId, foldMeasureName = FoldMeasureName, foldMeasureValue = FoldMeasureValue, unfoldDimensionGroup = UnfoldDimensionGroup } = options || {};
|
418
|
+
const { foldMeasureId = FoldMeasureId, foldMeasureName = FoldMeasureName, foldMeasureValue = FoldMeasureValue, unfoldDimensionGroup = UnfoldDimensionGroup, unfoldDimensionGroupId = UnfoldDimensionGroupId } = options || {};
|
303
419
|
if (0 === dimensions.length && 0 === measures.length) return dataReshapeFor1D1M_emptyReshapeResult;
|
304
420
|
const { dataset: foldedDataset, foldInfo } = foldMeasures(dataset, measures, foldMeasureId, foldMeasureName, foldMeasureValue);
|
305
421
|
if (0 === dimensions.length) {
|
306
422
|
const { dataset: finalDataset, unfoldInfo } = unfoldDimensions(foldedDataset, [
|
307
423
|
{
|
308
424
|
id: foldMeasureName,
|
309
|
-
alias:
|
425
|
+
alias: i18n`指标名称`,
|
310
426
|
location: 'dimension'
|
311
427
|
}
|
312
428
|
], [
|
313
429
|
{
|
314
430
|
id: foldMeasureValue,
|
315
|
-
alias:
|
431
|
+
alias: i18n`指标值`
|
316
432
|
}
|
317
|
-
], 0, unfoldDimensionGroup);
|
433
|
+
], 0, unfoldDimensionGroup, unfoldDimensionGroupId, foldMeasureId);
|
318
434
|
return {
|
319
435
|
dataset: finalDataset,
|
320
436
|
foldInfo,
|
@@ -326,15 +442,15 @@ const dataReshapeFor1D1M = (dataset, dimensions, measures, options)=>{
|
|
326
442
|
...dimensions,
|
327
443
|
{
|
328
444
|
id: foldMeasureName,
|
329
|
-
alias:
|
445
|
+
alias: i18n`指标名称`,
|
330
446
|
location: 'dimension'
|
331
447
|
}
|
332
448
|
], [
|
333
449
|
{
|
334
450
|
id: foldMeasureValue,
|
335
|
-
alias:
|
451
|
+
alias: i18n`指标值`
|
336
452
|
}
|
337
|
-
], 0, unfoldDimensionGroup);
|
453
|
+
], 0, unfoldDimensionGroup, unfoldDimensionGroupId, foldMeasureId);
|
338
454
|
return {
|
339
455
|
dataset: finalDataset,
|
340
456
|
foldInfo,
|
@@ -474,7 +590,6 @@ const encodingXY = (advancedVSeed)=>{
|
|
474
590
|
if (!datasetReshapeInfo || !dimensions) return result;
|
475
591
|
const encoding = datasetReshapeInfo.reduce((prev, cur)=>{
|
476
592
|
const { foldInfo, unfoldInfo } = cur;
|
477
|
-
const isSingleDimension = 1 === dimensions.length;
|
478
593
|
const isZeroDimension = 0 === dimensions.length;
|
479
594
|
const x = [
|
480
595
|
isZeroDimension ? foldInfo.measureName : dimensions[0].id
|
@@ -483,7 +598,7 @@ const encodingXY = (advancedVSeed)=>{
|
|
483
598
|
foldInfo.measureValue
|
484
599
|
];
|
485
600
|
const group = [
|
486
|
-
|
601
|
+
unfoldInfo.groupId
|
487
602
|
];
|
488
603
|
const color = [
|
489
604
|
foldInfo.measureName
|
@@ -512,7 +627,6 @@ const encodingYX = (advancedVSeed)=>{
|
|
512
627
|
const encoding = datasetReshapeInfo.reduce((prev, cur)=>{
|
513
628
|
const { foldInfo, unfoldInfo } = cur;
|
514
629
|
const isZeroDimension = 0 === dimensions.length;
|
515
|
-
const isSingleDimension = 1 === dimensions.length;
|
516
630
|
const y = [
|
517
631
|
isZeroDimension ? foldInfo.measureName : dimensions[0].id
|
518
632
|
];
|
@@ -520,7 +634,7 @@ const encodingYX = (advancedVSeed)=>{
|
|
520
634
|
foldInfo.measureValue
|
521
635
|
];
|
522
636
|
const group = [
|
523
|
-
|
637
|
+
unfoldInfo.groupId
|
524
638
|
];
|
525
639
|
const color = [
|
526
640
|
foldInfo.measureName
|
@@ -552,13 +666,13 @@ const encodingPolar = (advancedVSeed)=>{
|
|
552
666
|
foldInfo.measureValue
|
553
667
|
];
|
554
668
|
const angle = [
|
555
|
-
unfoldInfo.
|
669
|
+
unfoldInfo.groupId
|
556
670
|
];
|
557
671
|
const group = [
|
558
|
-
unfoldInfo.
|
672
|
+
unfoldInfo.groupId
|
559
673
|
];
|
560
674
|
const color = [
|
561
|
-
unfoldInfo.
|
675
|
+
unfoldInfo.groupId
|
562
676
|
];
|
563
677
|
return [
|
564
678
|
...prev,
|
@@ -712,8 +826,17 @@ const annotation_annotation = (advancedVSeed, context)=>{
|
|
712
826
|
annotation
|
713
827
|
};
|
714
828
|
};
|
829
|
+
const locale_locale = (advancedVSeed, context)=>{
|
830
|
+
const { vseed } = context;
|
831
|
+
const { locale } = vseed;
|
832
|
+
return {
|
833
|
+
...advancedVSeed,
|
834
|
+
locale: locale || 'zh-CN'
|
835
|
+
};
|
836
|
+
};
|
715
837
|
const lineAdvancedPipeline = [
|
716
838
|
initAdvancedVSeed,
|
839
|
+
locale_locale,
|
717
840
|
autoMeasures,
|
718
841
|
autoDimensions,
|
719
842
|
pivotAdapter([
|
@@ -730,6 +853,7 @@ const lineAdvancedPipeline = [
|
|
730
853
|
];
|
731
854
|
const barAdvancedPipeline = [
|
732
855
|
initAdvancedVSeed,
|
856
|
+
locale_locale,
|
733
857
|
autoMeasures,
|
734
858
|
autoDimensions,
|
735
859
|
pivotAdapter([
|
@@ -746,6 +870,7 @@ const barAdvancedPipeline = [
|
|
746
870
|
];
|
747
871
|
const barParallelAdvancedPipeline = [
|
748
872
|
initAdvancedVSeed,
|
873
|
+
locale_locale,
|
749
874
|
autoMeasures,
|
750
875
|
autoDimensions,
|
751
876
|
pivotAdapter([
|
@@ -762,6 +887,7 @@ const barParallelAdvancedPipeline = [
|
|
762
887
|
];
|
763
888
|
const barPercentAdvancedPipeline = [
|
764
889
|
initAdvancedVSeed,
|
890
|
+
locale_locale,
|
765
891
|
autoMeasures,
|
766
892
|
autoDimensions,
|
767
893
|
pivotAdapter([
|
@@ -778,6 +904,7 @@ const barPercentAdvancedPipeline = [
|
|
778
904
|
];
|
779
905
|
const columnAdvancedPipeline = [
|
780
906
|
initAdvancedVSeed,
|
907
|
+
locale_locale,
|
781
908
|
autoMeasures,
|
782
909
|
autoDimensions,
|
783
910
|
pivotAdapter([
|
@@ -794,6 +921,7 @@ const columnAdvancedPipeline = [
|
|
794
921
|
];
|
795
922
|
const columnParallelAdvancedPipeline = [
|
796
923
|
initAdvancedVSeed,
|
924
|
+
locale_locale,
|
797
925
|
autoMeasures,
|
798
926
|
autoDimensions,
|
799
927
|
pivotAdapter([
|
@@ -810,6 +938,7 @@ const columnParallelAdvancedPipeline = [
|
|
810
938
|
];
|
811
939
|
const columnPercentAdvancedPipeline = [
|
812
940
|
initAdvancedVSeed,
|
941
|
+
locale_locale,
|
813
942
|
autoMeasures,
|
814
943
|
autoDimensions,
|
815
944
|
pivotAdapter([
|
@@ -826,6 +955,7 @@ const columnPercentAdvancedPipeline = [
|
|
826
955
|
];
|
827
956
|
const areaAdvancedPipeline = [
|
828
957
|
initAdvancedVSeed,
|
958
|
+
locale_locale,
|
829
959
|
autoMeasures,
|
830
960
|
autoDimensions,
|
831
961
|
pivotAdapter([
|
@@ -842,6 +972,7 @@ const areaAdvancedPipeline = [
|
|
842
972
|
];
|
843
973
|
const areaPercentAdvancedPipeline = [
|
844
974
|
initAdvancedVSeed,
|
975
|
+
locale_locale,
|
845
976
|
autoMeasures,
|
846
977
|
autoDimensions,
|
847
978
|
pivotAdapter([
|
@@ -858,6 +989,7 @@ const areaPercentAdvancedPipeline = [
|
|
858
989
|
];
|
859
990
|
const pieAdvancedPipeline = [
|
860
991
|
initAdvancedVSeed,
|
992
|
+
locale_locale,
|
861
993
|
autoMeasures,
|
862
994
|
autoDimensions,
|
863
995
|
pivotAdapter([
|
@@ -1161,13 +1293,14 @@ const xBand = (spec, context)=>{
|
|
1161
1293
|
return result;
|
1162
1294
|
};
|
1163
1295
|
const ANNOTATION_Z_INDEX = 1000;
|
1164
|
-
const LINEAR_AXIS_INNER_OFFSET_TOP =
|
1296
|
+
const LINEAR_AXIS_INNER_OFFSET_TOP = 7;
|
1165
1297
|
const xLinear = (spec, context)=>{
|
1166
1298
|
const result = {
|
1167
1299
|
...spec
|
1168
1300
|
};
|
1169
1301
|
const { advancedVSeed, vseed } = context;
|
1170
1302
|
const { chartType } = vseed;
|
1303
|
+
const { locale } = advancedVSeed;
|
1171
1304
|
const config = advancedVSeed.config?.[chartType]?.xAxis;
|
1172
1305
|
if (!result.axes) result.axes = [];
|
1173
1306
|
if (!config) {
|
@@ -1193,6 +1326,7 @@ const xLinear = (spec, context)=>{
|
|
1193
1326
|
min,
|
1194
1327
|
label: {
|
1195
1328
|
visible: label?.visible,
|
1329
|
+
formatMethod: (value)=>autoFormatter(value, locale),
|
1196
1330
|
style: {
|
1197
1331
|
fill: label?.labelColor,
|
1198
1332
|
angle: label?.labelAngle,
|
@@ -1342,6 +1476,7 @@ const yLinear = (spec, context)=>{
|
|
1342
1476
|
};
|
1343
1477
|
const { advancedVSeed, vseed } = context;
|
1344
1478
|
const { chartType } = vseed;
|
1479
|
+
const { locale } = advancedVSeed;
|
1345
1480
|
const config = advancedVSeed.config?.[chartType]?.yAxis;
|
1346
1481
|
if (!result.axes) result.axes = [];
|
1347
1482
|
if (!config) {
|
@@ -1367,6 +1502,7 @@ const yLinear = (spec, context)=>{
|
|
1367
1502
|
min,
|
1368
1503
|
label: {
|
1369
1504
|
visible: label?.visible,
|
1505
|
+
formatMethod: (value)=>autoFormatter(value, locale),
|
1370
1506
|
style: {
|
1371
1507
|
fill: label?.labelColor,
|
1372
1508
|
angle: label?.labelAngle,
|
@@ -1478,10 +1614,11 @@ const tooltip_tooltip = (spec, context)=>{
|
|
1478
1614
|
const measure = findMeasureById(measures, id);
|
1479
1615
|
if (!measure) return String(value);
|
1480
1616
|
const { format = {}, autoFormat = true } = measure;
|
1481
|
-
if (format
|
1617
|
+
if (!isEmpty(format)) {
|
1482
1618
|
const formatter = createFormatter(format);
|
1483
1619
|
return formatter(value);
|
1484
1620
|
}
|
1621
|
+
if (autoFormat) return autoFormatter(value);
|
1485
1622
|
return String(value);
|
1486
1623
|
}
|
1487
1624
|
}
|
@@ -1499,10 +1636,11 @@ const tooltip_tooltip = (spec, context)=>{
|
|
1499
1636
|
const measure = findMeasureById(measures, id);
|
1500
1637
|
if (!measure) return String(value);
|
1501
1638
|
const { format = {}, autoFormat = true } = measure;
|
1502
|
-
if (format
|
1639
|
+
if (!isEmpty(format)) {
|
1503
1640
|
const formatter = createFormatter(format);
|
1504
1641
|
return formatter(value);
|
1505
1642
|
}
|
1643
|
+
if (autoFormat) return autoFormatter(value);
|
1506
1644
|
return String(value);
|
1507
1645
|
}
|
1508
1646
|
}
|
@@ -1516,23 +1654,30 @@ const label_label = (spec, context)=>{
|
|
1516
1654
|
...spec
|
1517
1655
|
};
|
1518
1656
|
const { advancedVSeed } = context;
|
1519
|
-
const { measures, datasetReshapeInfo } = advancedVSeed;
|
1657
|
+
const { measures, datasetReshapeInfo, locale } = advancedVSeed;
|
1520
1658
|
const baseConfig = advancedVSeed.baseConfig.vchart;
|
1521
1659
|
if (!baseConfig || !baseConfig.label) return result;
|
1522
|
-
const { measureId } = datasetReshapeInfo[0].foldInfo;
|
1660
|
+
const { measureId, measureValue } = datasetReshapeInfo[0].foldInfo;
|
1523
1661
|
const { label } = baseConfig;
|
1524
1662
|
const { enable } = label;
|
1525
1663
|
result.label = {
|
1526
1664
|
visible: enable,
|
1527
1665
|
formatMethod: (value, datum)=>{
|
1528
|
-
const
|
1529
|
-
const
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
const
|
1534
|
-
|
1535
|
-
|
1666
|
+
const result = [];
|
1667
|
+
const formatValue = (value)=>{
|
1668
|
+
const id = datum[measureId];
|
1669
|
+
const measure = findMeasureById(measures, id);
|
1670
|
+
if (!measure) return value;
|
1671
|
+
const { format = {}, autoFormat = true } = measure;
|
1672
|
+
if (!isEmpty(format)) {
|
1673
|
+
const formatter = createFormatter(format);
|
1674
|
+
return formatter(value);
|
1675
|
+
}
|
1676
|
+
if (autoFormat) return autoFormatter(value, locale);
|
1677
|
+
return String(value);
|
1678
|
+
};
|
1679
|
+
result.push(formatValue(datum[measureValue]));
|
1680
|
+
return result.join(' ');
|
1536
1681
|
}
|
1537
1682
|
};
|
1538
1683
|
return result;
|
@@ -1542,6 +1687,8 @@ const discreteLegend = (spec, context)=>{
|
|
1542
1687
|
...spec
|
1543
1688
|
};
|
1544
1689
|
const { advancedVSeed } = context;
|
1690
|
+
const { datasetReshapeInfo } = advancedVSeed;
|
1691
|
+
const { unfoldInfo } = datasetReshapeInfo[0];
|
1545
1692
|
const baseConfig = advancedVSeed.baseConfig.vchart;
|
1546
1693
|
if (!baseConfig || !baseConfig.legend) return result;
|
1547
1694
|
const { legend } = baseConfig;
|
@@ -1615,6 +1762,7 @@ const discreteLegend = (spec, context)=>{
|
|
1615
1762
|
}
|
1616
1763
|
},
|
1617
1764
|
label: {
|
1765
|
+
formatMethod: (value)=>unfoldInfo.colorIdMap[String(value)] ?? value,
|
1618
1766
|
style: {
|
1619
1767
|
fontSize: labelFontSize,
|
1620
1768
|
fill: labelFontColor,
|
@@ -1642,6 +1790,10 @@ const pivotDiscreteLegend = (spec, context)=>{
|
|
1642
1790
|
if (!baseConfig || !baseConfig.legend) return result;
|
1643
1791
|
const { datasetReshapeInfo } = advancedVSeed;
|
1644
1792
|
const colorItems = unique(datasetReshapeInfo.flatMap((d)=>d.unfoldInfo.colorItems));
|
1793
|
+
const colorIdMap = datasetReshapeInfo.reduce((prev, cur)=>({
|
1794
|
+
...prev,
|
1795
|
+
...cur.unfoldInfo.colorIdMap
|
1796
|
+
}), {});
|
1645
1797
|
const { legend, color } = baseConfig;
|
1646
1798
|
const { colorScheme } = color;
|
1647
1799
|
const { enable, position = 'bottom', labelFontColor, labelFontSize = 12, labelFontWeight, maxSize, border, shapeType = 'rectRound' } = legend || {};
|
@@ -1716,6 +1868,7 @@ const pivotDiscreteLegend = (spec, context)=>{
|
|
1716
1868
|
}
|
1717
1869
|
},
|
1718
1870
|
label: {
|
1871
|
+
formatMethod: (value)=>colorIdMap[String(value)] ?? value,
|
1719
1872
|
style: {
|
1720
1873
|
fontSize: labelFontSize,
|
1721
1874
|
fill: labelFontColor,
|
@@ -1748,11 +1901,19 @@ const color_color = (spec, context)=>{
|
|
1748
1901
|
if (!baseConfig || !baseConfig.color) return result;
|
1749
1902
|
const { color } = baseConfig;
|
1750
1903
|
const { colorScheme, colorMapping } = color;
|
1904
|
+
const mappingList = [];
|
1905
|
+
if (colorMapping) Object.entries(colorMapping).forEach(([key, value])=>{
|
1906
|
+
const idMap = Object.entries(unfoldInfo.colorIdMap).filter(([_, v])=>key === v);
|
1907
|
+
for (const [colorId] of idMap)mappingList.push([
|
1908
|
+
colorId,
|
1909
|
+
value
|
1910
|
+
]);
|
1911
|
+
});
|
1751
1912
|
result.color = {
|
1752
1913
|
type: 'ordinal',
|
1753
1914
|
domain: unfoldInfo.colorItems,
|
1754
1915
|
range: colorScheme,
|
1755
|
-
specified:
|
1916
|
+
specified: Object.fromEntries(mappingList)
|
1756
1917
|
};
|
1757
1918
|
return result;
|
1758
1919
|
};
|
@@ -2233,8 +2394,7 @@ const lineStyle_lineStyle = (spec, context)=>{
|
|
2233
2394
|
},
|
2234
2395
|
style: {
|
2235
2396
|
curveType: curveType,
|
2236
|
-
|
2237
|
-
fillOpacity: lineColorOpacity,
|
2397
|
+
strokeOpacity: lineColorOpacity,
|
2238
2398
|
stroke: lineColor,
|
2239
2399
|
lineWidth: lineWidth,
|
2240
2400
|
lineDash: lineDash
|
@@ -2569,7 +2729,7 @@ const annotationArea_annotationArea = (spec, context)=>{
|
|
2569
2729
|
right: 'insideRight'
|
2570
2730
|
};
|
2571
2731
|
const markArea = annotationAreaList.flatMap((annotationArea)=>{
|
2572
|
-
const { selector: selectorPoint, text = '', textPosition = 'top', textColor = '#ffffff', textFontSize = 12, textFontWeight = 400, textAlign = 'center', textBaseline = 'top', backgroundBorderColor, backgroundBorderRadius = 4, backgroundBorderWidth = 1, backgroundColor = '#191d24', backgroundPadding =
|
2732
|
+
const { selector: selectorPoint, text = '', textPosition = 'top', textColor = '#ffffff', textFontSize = 12, textFontWeight = 400, textAlign = 'center', textBaseline = 'top', backgroundBorderColor, backgroundBorderRadius = 4, backgroundBorderWidth = 1, backgroundColor = '#191d24', backgroundPadding = 10, backgroundVisible = true, outerPadding = 4, areaColor = '#888888', areaColorOpacity = 0.15, areaBorderColor, areaBorderRadius, areaBorderWidth } = annotationArea;
|
2573
2733
|
const dataset = advancedVSeed.dataset.flat();
|
2574
2734
|
const selectedData = dataset.filter((datum)=>selector_selector(datum, selectorPoint));
|
2575
2735
|
return {
|
@@ -3432,6 +3592,7 @@ class Builder {
|
|
3432
3592
|
_spec = null;
|
3433
3593
|
constructor(vseed){
|
3434
3594
|
this._vseed = vseed;
|
3595
|
+
this._vseed.locale = vseed.locale || intl.getLocale();
|
3435
3596
|
}
|
3436
3597
|
build = ()=>build(this);
|
3437
3598
|
buildSpec = (advanced)=>buildSpec(this, advanced);
|
@@ -4040,7 +4201,7 @@ const zMeasure = z.object({
|
|
4040
4201
|
alias: z.string().optional(),
|
4041
4202
|
visible: z.boolean().default(true).optional(),
|
4042
4203
|
autoFormat: z.boolean().default(true).optional(),
|
4043
|
-
format: zNumFormat.optional()
|
4204
|
+
format: zNumFormat["default"]({}).optional()
|
4044
4205
|
});
|
4045
4206
|
const zMeasureGroup = z.object({
|
4046
4207
|
id: z.string(),
|
@@ -4059,6 +4220,8 @@ const zFoldInfo = z.object({
|
|
4059
4220
|
});
|
4060
4221
|
const zUnfoldInfo = z.object({
|
4061
4222
|
colorItems: z.array(z.string()),
|
4223
|
+
groupId: z.string(),
|
4224
|
+
colorIdMap: z.record(z.string(), z.string()),
|
4062
4225
|
groupName: z.string()
|
4063
4226
|
});
|
4064
4227
|
const zDatasetReshapeInfo = z.array(z.object({
|
@@ -4675,6 +4838,6 @@ const zCustomThemeConfig = z.object({
|
|
4675
4838
|
});
|
4676
4839
|
const zCustomTheme = z.record(z.string(), zCustomThemeConfig).optional();
|
4677
4840
|
const zTheme = z.string();
|
4678
|
-
export { Builder, FoldMeasureId, FoldMeasureName, FoldMeasureValue, ORIGINAL_DATA, Separator, UnfoldDimensionGroup, areaAdvancedPipeline, areaPercentAdvancedPipeline, areaPercentSpecPipeline, areaSpecPipeline, barAdvancedPipeline, barParallelAdvancedPipeline, barParallelSpecPipeline, barPercentAdvancedPipeline, barPercentSpecPipeline, barSpecPipeline, columnAdvancedPipeline, columnParallelAdvancedPipeline, columnParallelSpecPipeline, columnPercentAdvancedPipeline, columnPercentSpecPipeline, columnSpecPipeline, createFormatter, createNumFormatter, darkTheme, dataReshapeFor1D1M, dataReshapeFor2D1M, execPipeline, findMeasureById, foldMeasures, isPivotChart, isVChart, isVTable, lightTheme, lineAdvancedPipeline, lineSpecPipeline, pieAdvancedPipeline, pieSpecPipeline, all_registerAll as registerAll, registerArea, registerAreaPercent, registerBar, registerBarParallel, registerBarPercent, registerColumn, registerColumnParallel, registerColumnPercent, registerCustomTheme, registerDarkTheme, registerLightTheme, registerLine, unfoldDimensions, zAnnotation, zAnnotationArea, zAnnotationHorizontalLine, zAnnotationPoint, zAnnotationVerticalLine, zAreaStyle, zAxis, zBackgroundColor, zBarStyle, zBaseConfig, zChartType, zColor, zConfig, zCrosshairLine, zCrosshairRect, zCustomTheme, zCustomThemeConfig, zDataset, zDatasetReshapeInfo, zDatum, zDimension, zDimensions, zEncoding, zFoldInfo, zLabel, zLegend, zLineStyle, zMarkStyle, zMeasure, zMeasureGroup, zMeasures, zNumFormat, zPointStyle, zStackCornerRadius, zTheme, zTooltip, zUnfoldInfo, zXBandAxis, zXLinearAxis, zYBandAxis, zYLinearAxis };
|
4841
|
+
export { Builder, FoldMeasureId, FoldMeasureName, FoldMeasureValue, ORIGINAL_DATA, Separator, UnfoldDimensionGroup, UnfoldDimensionGroupId, areaAdvancedPipeline, areaPercentAdvancedPipeline, areaPercentSpecPipeline, areaSpecPipeline, autoFormatter, autoNumFormatter, barAdvancedPipeline, barParallelAdvancedPipeline, barParallelSpecPipeline, barPercentAdvancedPipeline, barPercentSpecPipeline, barSpecPipeline, columnAdvancedPipeline, columnParallelAdvancedPipeline, columnParallelSpecPipeline, columnPercentAdvancedPipeline, columnPercentSpecPipeline, columnSpecPipeline, createFormatter, createNumFormatter, darkTheme, dataReshapeFor1D1M, dataReshapeFor2D1M, execPipeline, findMeasureById, foldMeasures, i18n, intl, isPivotChart, isVChart, isVTable, lightTheme, lineAdvancedPipeline, lineSpecPipeline, pieAdvancedPipeline, pieSpecPipeline, all_registerAll as registerAll, registerArea, registerAreaPercent, registerBar, registerBarParallel, registerBarPercent, registerColumn, registerColumnParallel, registerColumnPercent, registerCustomTheme, registerDarkTheme, registerLightTheme, registerLine, unfoldDimensions, zAnnotation, zAnnotationArea, zAnnotationHorizontalLine, zAnnotationPoint, zAnnotationVerticalLine, zAreaStyle, zAxis, zBackgroundColor, zBarStyle, zBaseConfig, zChartType, zColor, zConfig, zCrosshairLine, zCrosshairRect, zCustomTheme, zCustomThemeConfig, zDataset, zDatasetReshapeInfo, zDatum, zDimension, zDimensions, zEncoding, zFoldInfo, zLabel, zLegend, zLineStyle, zMarkStyle, zMeasure, zMeasureGroup, zMeasures, zNumFormat, zPointStyle, zStackCornerRadius, zTheme, zTooltip, zUnfoldInfo, zXBandAxis, zXLinearAxis, zYBandAxis, zYLinearAxis };
|
4679
4842
|
|
4680
4843
|
//# sourceMappingURL=index.js.map
|