@visactor/vseed 0.0.4 → 0.0.6

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 (56) hide show
  1. package/dist/builder/builder/build.d.ts +2 -2
  2. package/dist/builder/builder/buildSpec.d.ts +2 -2
  3. package/dist/builder/builder/builder.d.ts +8 -5
  4. package/dist/dataReshape/constant.d.ts +1 -1
  5. package/dist/dataReshape/dataReshapeFor1D1M.d.ts +6 -1
  6. package/dist/dataReshape/dataReshapeFor2D1M.d.ts +6 -1
  7. package/dist/index.cjs +1762 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.js +1545 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/pipeline/advanced/pipes/encoding/{encodingCartesian.d.ts → encodingXY.d.ts} +0 -1
  12. package/dist/pipeline/advanced/pipes/encoding/encodingYX.d.ts +2 -0
  13. package/dist/pipeline/advanced/pipes/encoding/index.d.ts +2 -1
  14. package/dist/pipeline/advanced/pipes/index.d.ts +1 -0
  15. package/dist/pipeline/advanced/pipes/pivot/index.d.ts +1 -0
  16. package/dist/pipeline/advanced/pipes/pivot/pivotAdapter.d.ts +2 -0
  17. package/dist/pipeline/advanced/pipes/reshape/index.d.ts +2 -0
  18. package/dist/pipeline/advanced/pipes/reshape/pivotReshapeTo1D1M.d.ts +8 -0
  19. package/dist/pipeline/advanced/pipes/reshape/pivotReshapeTo2D1M.d.ts +8 -0
  20. package/dist/pipeline/spec/pipeline/area.d.ts +1 -2
  21. package/dist/pipeline/spec/pipeline/areaPercent.d.ts +1 -2
  22. package/dist/pipeline/spec/pipeline/column.d.ts +1 -2
  23. package/dist/pipeline/spec/pipes/dataset/datasetPivot.d.ts +3 -0
  24. package/dist/pipeline/spec/pipes/dataset/index.d.ts +1 -0
  25. package/dist/pipeline/spec/pipes/index.d.ts +1 -0
  26. package/dist/pipeline/spec/pipes/init/index.d.ts +1 -0
  27. package/dist/pipeline/spec/pipes/init/pivot.d.ts +4 -0
  28. package/dist/pipeline/spec/pipes/legend/index.d.ts +1 -0
  29. package/dist/pipeline/spec/pipes/legend/pivotLegend.d.ts +2 -0
  30. package/dist/pipeline/spec/pipes/pivotChart/index.d.ts +2 -0
  31. package/dist/pipeline/spec/pipes/pivotChart/pivotAdapter.d.ts +2 -0
  32. package/dist/pipeline/spec/pipes/pivotChart/pivotIndicators.d.ts +4 -0
  33. package/dist/types/advancedVSeed.d.ts +3 -2
  34. package/dist/types/builder/builder.d.ts +3 -3
  35. package/dist/types/builder/index.d.ts +1 -0
  36. package/dist/types/builder/spec.d.ts +3 -0
  37. package/dist/types/pipeline/spec/spec.d.ts +2 -2
  38. package/dist/types/properties/datasetReshapeInfo/datasetReshapeInfo.d.ts +3 -2
  39. package/dist/types/properties/datasetReshapeInfo/index.d.ts +1 -1
  40. package/package.json +1 -1
  41. package/dist/.rsdoctor/chunkGraph/0 +0 -1
  42. package/dist/.rsdoctor/configs/0 +0 -1
  43. package/dist/.rsdoctor/envinfo/0 +0 -1
  44. package/dist/.rsdoctor/errors/0 +0 -1
  45. package/dist/.rsdoctor/loader/0 +0 -1
  46. package/dist/.rsdoctor/manifest.json +0 -52
  47. package/dist/.rsdoctor/moduleCodeMap/0 +0 -1
  48. package/dist/.rsdoctor/moduleGraph/0 +0 -1
  49. package/dist/.rsdoctor/otherReports/0 +0 -1
  50. package/dist/.rsdoctor/packageGraph/0 +0 -1
  51. package/dist/.rsdoctor/plugin/0 +0 -1
  52. package/dist/.rsdoctor/resolver/0 +0 -1
  53. package/dist/.rsdoctor/summary/0 +0 -1
  54. package/dist/index.html +0 -1
  55. package/dist/static/js/271.b02e15b2.js +0 -16
  56. package/dist/static/js/index.7ac2af0b.js +0 -1
package/dist/index.js ADDED
@@ -0,0 +1,1545 @@
1
+ import { clone as external_remeda_clone, mergeDeep as external_remeda_mergeDeep, pick as external_remeda_pick, unique } from "remeda";
2
+ import { z } from "zod";
3
+ const constant_FoldMeasureName = '__MeaName__';
4
+ const constant_FoldMeasureValue = '__MeaValue__';
5
+ const constant_FoldMeasureId = '__MeaId__';
6
+ const constant_UnfoldDimensionGroup = '__DimGroup__';
7
+ const Separator = '-';
8
+ const unfoldDimensions = (dataset, dimensions, measures, unfoldStartIndex = 0, foldGroupName = constant_UnfoldDimensionGroup, dimensionsSeparator = Separator)=>{
9
+ if (unfoldStartIndex < 0 || unfoldStartIndex >= dimensions.length) throw new Error('unfoldStartIndex is out of range');
10
+ const dimensionsToBeUnfolded = dimensions.slice(unfoldStartIndex);
11
+ const unfoldInfo = {
12
+ groupName: foldGroupName,
13
+ colorItems: []
14
+ };
15
+ if (0 === dimensions.length || 0 === measures.length) return {
16
+ dataset,
17
+ unfoldInfo: {
18
+ groupName: foldGroupName,
19
+ colorItems: []
20
+ }
21
+ };
22
+ const colorItems = [];
23
+ for(let i = 0; i < dataset.length; i++){
24
+ const datum = dataset[i];
25
+ const colorItem = generateDimGroupName(dimensionsToBeUnfolded, datum, dimensionsSeparator);
26
+ datum[foldGroupName] = colorItem;
27
+ colorItems.push(colorItem);
28
+ }
29
+ unfoldInfo.colorItems = unique(colorItems);
30
+ return {
31
+ dataset,
32
+ unfoldInfo
33
+ };
34
+ };
35
+ const generateDimGroupName = (dimensionsToBeGrouped, datum, dimensionsSeparator)=>dimensionsToBeGrouped.map((dim)=>String(datum[dim.id])).join(dimensionsSeparator);
36
+ const foldMeasures = (dataset, measures, measureId = constant_FoldMeasureId, measureName = constant_FoldMeasureName, measureValue = constant_FoldMeasureValue)=>{
37
+ const foldInfo = {
38
+ measureId,
39
+ measureName,
40
+ measureValue,
41
+ foldMap: {}
42
+ };
43
+ const result = new Array(dataset.length * measures.length);
44
+ let index = 0;
45
+ for(let i = 0; i < dataset.length; i++)for(let j = 0; j < measures.length; j++){
46
+ const datum = {
47
+ ...dataset[i]
48
+ };
49
+ const measure = measures[j];
50
+ const { id, alias } = measure;
51
+ datum[measureId] = id;
52
+ datum[measureName] = alias;
53
+ datum[measureValue] = dataset[i][id];
54
+ foldInfo.foldMap[id] = alias;
55
+ result[index++] = datum;
56
+ }
57
+ return {
58
+ dataset: result,
59
+ foldInfo
60
+ };
61
+ };
62
+ const emptyReshapeResult = {
63
+ dataset: [],
64
+ foldInfo: {
65
+ foldMap: {},
66
+ measureId: '',
67
+ measureName: '',
68
+ measureValue: ''
69
+ },
70
+ unfoldInfo: {
71
+ colorItems: [],
72
+ groupName: ''
73
+ }
74
+ };
75
+ const dataReshapeFor2D1M = (dataset, dimensions, measures, options)=>{
76
+ const { foldMeasureId = constant_FoldMeasureId, foldMeasureName = constant_FoldMeasureName, foldMeasureValue = constant_FoldMeasureValue, unfoldDimensionGroup = constant_UnfoldDimensionGroup } = options || {};
77
+ if (0 === dimensions.length && 0 === measures.length) return emptyReshapeResult;
78
+ const { dataset: foldedDataset, foldInfo } = foldMeasures(dataset, measures, foldMeasureId, foldMeasureName, foldMeasureValue);
79
+ if (0 === dimensions.length) {
80
+ const { dataset: finalDataset, unfoldInfo } = unfoldDimensions(foldedDataset, [
81
+ {
82
+ id: foldMeasureId,
83
+ alias: "\u6307\u6807Id",
84
+ location: 'dimension'
85
+ },
86
+ {
87
+ id: foldMeasureName,
88
+ alias: "\u6307\u6807\u540D\u79F0",
89
+ location: 'dimension'
90
+ }
91
+ ], [
92
+ {
93
+ id: foldMeasureValue,
94
+ alias: "\u6307\u6807\u503C"
95
+ }
96
+ ], 1, unfoldDimensionGroup);
97
+ return {
98
+ dataset: finalDataset,
99
+ foldInfo,
100
+ unfoldInfo
101
+ };
102
+ }
103
+ {
104
+ const { dataset: finalDataset, unfoldInfo } = unfoldDimensions(foldedDataset, [
105
+ ...dimensions,
106
+ {
107
+ id: foldMeasureName,
108
+ alias: "\u6307\u6807\u540D\u79F0",
109
+ location: 'dimension'
110
+ }
111
+ ], [
112
+ {
113
+ id: foldMeasureValue,
114
+ alias: "\u6307\u6807\u503C"
115
+ }
116
+ ], 1, unfoldDimensionGroup);
117
+ return {
118
+ dataset: finalDataset,
119
+ foldInfo,
120
+ unfoldInfo
121
+ };
122
+ }
123
+ };
124
+ const dataReshapeFor1D1M_emptyReshapeResult = {
125
+ dataset: [],
126
+ foldInfo: {
127
+ foldMap: {},
128
+ measureId: '',
129
+ measureName: '',
130
+ measureValue: ''
131
+ },
132
+ unfoldInfo: {
133
+ groupName: '',
134
+ colorItems: []
135
+ }
136
+ };
137
+ const dataReshapeFor1D1M_dataReshapeFor1D1M = (dataset, dimensions, measures, options)=>{
138
+ const { foldMeasureId = constant_FoldMeasureId, foldMeasureName = constant_FoldMeasureName, foldMeasureValue = constant_FoldMeasureValue, unfoldDimensionGroup = constant_UnfoldDimensionGroup } = options || {};
139
+ if (0 === dimensions.length && 0 === measures.length) return dataReshapeFor1D1M_emptyReshapeResult;
140
+ const { dataset: foldedDataset, foldInfo } = foldMeasures(dataset, measures, foldMeasureId, foldMeasureName, foldMeasureValue);
141
+ if (0 === dimensions.length) {
142
+ const { dataset: finalDataset, unfoldInfo } = unfoldDimensions(foldedDataset, [
143
+ {
144
+ id: foldMeasureName,
145
+ alias: "\u6307\u6807\u540D\u79F0",
146
+ location: 'dimension'
147
+ }
148
+ ], [
149
+ {
150
+ id: foldMeasureValue,
151
+ alias: "\u6307\u6807\u503C"
152
+ }
153
+ ], 0, unfoldDimensionGroup);
154
+ return {
155
+ dataset: finalDataset,
156
+ foldInfo,
157
+ unfoldInfo
158
+ };
159
+ }
160
+ {
161
+ const { dataset: finalDataset, unfoldInfo } = unfoldDimensions(foldedDataset, [
162
+ ...dimensions,
163
+ {
164
+ id: foldMeasureName,
165
+ alias: "\u6307\u6807\u540D\u79F0",
166
+ location: 'dimension'
167
+ }
168
+ ], [
169
+ {
170
+ id: foldMeasureValue,
171
+ alias: "\u6307\u6807\u503C"
172
+ }
173
+ ], 0, unfoldDimensionGroup);
174
+ return {
175
+ dataset: finalDataset,
176
+ foldInfo,
177
+ unfoldInfo
178
+ };
179
+ }
180
+ };
181
+ const reshapeTo2D1M = (advancedVSeed, context)=>{
182
+ const result = {
183
+ ...advancedVSeed
184
+ };
185
+ const { vseed } = context;
186
+ const { dataset } = vseed;
187
+ const { dimensions, measures } = advancedVSeed;
188
+ if (!measures || !dimensions || !dataset) return result;
189
+ if (0 === measures.length) throw new Error('measures can not be empty');
190
+ const { dataset: newDatasets, foldInfo, unfoldInfo } = dataReshapeFor2D1M(dataset, dimensions, measures);
191
+ return {
192
+ ...result,
193
+ dataset: newDatasets,
194
+ datasetReshapeInfo: [
195
+ {
196
+ id: '2D1M',
197
+ foldInfo,
198
+ unfoldInfo
199
+ }
200
+ ],
201
+ dimensions,
202
+ measures
203
+ };
204
+ };
205
+ const pivotReshapeTo2D1M = (advancedVSeed, context)=>{
206
+ const result = {
207
+ ...advancedVSeed
208
+ };
209
+ const { vseed } = context;
210
+ const { dataset } = vseed;
211
+ const { dimensions, measures } = advancedVSeed;
212
+ if (!measures || !dimensions) return result;
213
+ const measureGroups = [];
214
+ if (measures) measures.forEach((measure)=>{
215
+ if (measure.children && measure.children.length > 0) measureGroups.push(measure);
216
+ });
217
+ const newDatasets = [];
218
+ const datasetReshapeInfo = [];
219
+ measureGroups.forEach((measureGroup)=>{
220
+ const measures = measureGroup.children;
221
+ if (!measures) return;
222
+ const groupId = measureGroup.id;
223
+ const { dataset: newSubDataset, foldInfo, unfoldInfo } = dataReshapeFor2D1M(dataset, dimensions, measures, {
224
+ foldMeasureId: constant_FoldMeasureId + groupId,
225
+ foldMeasureName: constant_FoldMeasureName + groupId,
226
+ foldMeasureValue: constant_FoldMeasureValue + groupId,
227
+ unfoldDimensionGroup: constant_UnfoldDimensionGroup + groupId
228
+ });
229
+ const reshapeInfo = {
230
+ id: groupId,
231
+ foldInfo,
232
+ unfoldInfo
233
+ };
234
+ newDatasets.push(newSubDataset);
235
+ datasetReshapeInfo.push(reshapeInfo);
236
+ });
237
+ return {
238
+ ...result,
239
+ dataset: newDatasets,
240
+ datasetReshapeInfo: datasetReshapeInfo
241
+ };
242
+ };
243
+ const encodingXY = (advancedVSeed)=>{
244
+ const result = {
245
+ ...advancedVSeed
246
+ };
247
+ const { datasetReshapeInfo, dimensions } = advancedVSeed;
248
+ if (!datasetReshapeInfo || !dimensions) return result;
249
+ const encoding = datasetReshapeInfo.reduce((prev, cur)=>{
250
+ const { foldInfo, unfoldInfo } = cur;
251
+ const isSingleDimension = 0 === dimensions.length;
252
+ const x = [
253
+ isSingleDimension ? foldInfo.measureName : dimensions[0].id
254
+ ];
255
+ const y = [
256
+ foldInfo.measureValue
257
+ ];
258
+ const group = [
259
+ isSingleDimension ? foldInfo.measureName : unfoldInfo.groupName
260
+ ];
261
+ const color = [
262
+ foldInfo.measureName
263
+ ];
264
+ return [
265
+ ...prev,
266
+ {
267
+ x,
268
+ y,
269
+ group,
270
+ color
271
+ }
272
+ ];
273
+ }, []);
274
+ return {
275
+ ...result,
276
+ encoding
277
+ };
278
+ };
279
+ const encodingYX = (advancedVSeed)=>{
280
+ const result = {
281
+ ...advancedVSeed
282
+ };
283
+ const { datasetReshapeInfo, dimensions } = advancedVSeed;
284
+ if (!datasetReshapeInfo || !dimensions) return result;
285
+ const encoding = datasetReshapeInfo.reduce((prev, cur)=>{
286
+ const { foldInfo, unfoldInfo } = cur;
287
+ const isSingleDimension = 0 === dimensions.length;
288
+ const y = [
289
+ isSingleDimension ? foldInfo.measureName : dimensions[0].id
290
+ ];
291
+ const x = [
292
+ foldInfo.measureValue
293
+ ];
294
+ const group = [
295
+ isSingleDimension ? foldInfo.measureName : unfoldInfo.groupName
296
+ ];
297
+ const color = [
298
+ foldInfo.measureName
299
+ ];
300
+ return [
301
+ ...prev,
302
+ {
303
+ x,
304
+ y,
305
+ group,
306
+ color
307
+ }
308
+ ];
309
+ }, []);
310
+ return {
311
+ ...result,
312
+ encoding
313
+ };
314
+ };
315
+ const initAdvancedVSeed = (advancedVSeed, context)=>{
316
+ const { vseed } = context;
317
+ const { chartType = 'table' } = vseed;
318
+ return {
319
+ ...advancedVSeed,
320
+ chartType
321
+ };
322
+ };
323
+ const autoMeasures = (advancedVSeed, context)=>{
324
+ const result = {
325
+ ...advancedVSeed
326
+ };
327
+ const { vseed } = context;
328
+ const { measures, dataset } = vseed;
329
+ if (!dataset) throw new Error('dataset is required');
330
+ if (0 === dataset.length) return result;
331
+ if (measures) {
332
+ result.measures = measures;
333
+ return result;
334
+ }
335
+ const top100dataset = dataset.slice(0, 100);
336
+ const sample = top100dataset.reduce((prev, cur)=>({
337
+ ...prev,
338
+ ...cur
339
+ }), {});
340
+ result.measures = Object.keys(sample).filter((key)=>top100dataset.some((item)=>'number' == typeof item[key]) && ![
341
+ '',
342
+ null,
343
+ void 0
344
+ ].includes(key)).map((measure)=>({
345
+ id: measure,
346
+ alias: measure
347
+ }));
348
+ return result;
349
+ };
350
+ const autoDimensions = (advancedVSeed, context)=>{
351
+ const result = {
352
+ ...advancedVSeed
353
+ };
354
+ const { vseed } = context;
355
+ const { dimensions, dataset } = vseed;
356
+ const { measures = [] } = advancedVSeed;
357
+ if (!dataset) throw new Error('dataset is required');
358
+ if (0 === dataset.length) return result;
359
+ if (dimensions) {
360
+ result.dimensions = dimensions;
361
+ return result;
362
+ }
363
+ const top100dataset = dataset.slice(0, 100);
364
+ const sample = top100dataset.reduce((prev, cur)=>({
365
+ ...prev,
366
+ ...cur
367
+ }), {});
368
+ result.dimensions = Object.keys(sample).filter((key)=>top100dataset.some((item)=>'string' == typeof item[key]) && ![
369
+ '',
370
+ null,
371
+ void 0
372
+ ].includes(key) && !measures.some((measure)=>measure.id === key)).map((dim)=>({
373
+ id: dim,
374
+ alias: dim,
375
+ location: 'dimension'
376
+ }));
377
+ return result;
378
+ };
379
+ const vchartBaseConfig = (advancedVSeed, context)=>{
380
+ const { vseed } = context;
381
+ const result = {
382
+ ...advancedVSeed
383
+ };
384
+ const config = external_remeda_pick(vseed, [
385
+ 'backgroundColor',
386
+ 'color',
387
+ 'label',
388
+ 'legend',
389
+ 'tooltip'
390
+ ]);
391
+ result.baseConfig = {
392
+ vchart: {
393
+ ...config
394
+ }
395
+ };
396
+ return result;
397
+ };
398
+ const vchartTheme = (advancedVSeed, context)=>{
399
+ const { customTheme, vseed } = context;
400
+ const { theme = 'light' } = vseed;
401
+ const result = {
402
+ ...advancedVSeed
403
+ };
404
+ if (!customTheme || !customTheme[theme]) return result;
405
+ const config = result.baseConfig?.vchart;
406
+ const themeConfig = customTheme?.[theme].baseConfig?.vchart;
407
+ if (!themeConfig || !config) return result;
408
+ const mergedConfig = external_remeda_mergeDeep(themeConfig, external_remeda_clone(config));
409
+ result.baseConfig = {
410
+ vchart: mergedConfig
411
+ };
412
+ return result;
413
+ };
414
+ const execPipeline = (pipeline, context, initialValue = {})=>{
415
+ const result = pipeline.reduce((prev, cur)=>cur(prev, context), initialValue);
416
+ return result;
417
+ };
418
+ const isVTable = (chartType)=>[
419
+ 'table',
420
+ 'pivotTable'
421
+ ].includes(chartType);
422
+ const isVChart = (chartType)=>!isVTable(chartType);
423
+ const pivotAdapter = (pipeline, pivotPipeline)=>(advancedVSeed, context)=>{
424
+ const { vseed } = context;
425
+ const { measures } = vseed;
426
+ if (measures && measures.find((measure)=>measure && measure.children)) return execPipeline(pivotPipeline, context, advancedVSeed);
427
+ return execPipeline(pipeline, context, advancedVSeed);
428
+ };
429
+ const lineAdvancedPipeline = [
430
+ initAdvancedVSeed,
431
+ autoMeasures,
432
+ autoDimensions,
433
+ pivotAdapter([
434
+ reshapeTo2D1M
435
+ ], [
436
+ pivotReshapeTo2D1M
437
+ ]),
438
+ encodingXY,
439
+ vchartBaseConfig,
440
+ vchartTheme
441
+ ];
442
+ const barAdvancedPipeline = [
443
+ initAdvancedVSeed,
444
+ autoMeasures,
445
+ autoDimensions,
446
+ pivotAdapter([
447
+ reshapeTo2D1M
448
+ ], [
449
+ pivotReshapeTo2D1M
450
+ ]),
451
+ encodingYX,
452
+ vchartBaseConfig,
453
+ vchartTheme
454
+ ];
455
+ const barParallelAdvancedPipeline = [
456
+ initAdvancedVSeed,
457
+ autoMeasures,
458
+ autoDimensions,
459
+ pivotAdapter([
460
+ reshapeTo2D1M
461
+ ], [
462
+ pivotReshapeTo2D1M
463
+ ]),
464
+ encodingYX,
465
+ vchartBaseConfig,
466
+ vchartTheme
467
+ ];
468
+ const barPercentAdvancedPipeline = [
469
+ initAdvancedVSeed,
470
+ autoMeasures,
471
+ autoDimensions,
472
+ pivotAdapter([
473
+ reshapeTo2D1M
474
+ ], [
475
+ pivotReshapeTo2D1M
476
+ ]),
477
+ encodingYX,
478
+ vchartBaseConfig,
479
+ vchartTheme
480
+ ];
481
+ const columnAdvancedPipeline = [
482
+ initAdvancedVSeed,
483
+ autoMeasures,
484
+ autoDimensions,
485
+ pivotAdapter([
486
+ reshapeTo2D1M
487
+ ], [
488
+ pivotReshapeTo2D1M
489
+ ]),
490
+ encodingXY,
491
+ vchartBaseConfig,
492
+ vchartTheme
493
+ ];
494
+ const columnParallelAdvancedPipeline = [
495
+ initAdvancedVSeed,
496
+ autoMeasures,
497
+ autoDimensions,
498
+ pivotAdapter([
499
+ reshapeTo2D1M
500
+ ], [
501
+ pivotReshapeTo2D1M
502
+ ]),
503
+ encodingXY,
504
+ vchartBaseConfig,
505
+ vchartTheme
506
+ ];
507
+ const columnPercentAdvancedPipeline = [
508
+ initAdvancedVSeed,
509
+ autoMeasures,
510
+ autoDimensions,
511
+ pivotAdapter([
512
+ reshapeTo2D1M
513
+ ], [
514
+ pivotReshapeTo2D1M
515
+ ]),
516
+ encodingXY,
517
+ vchartBaseConfig,
518
+ vchartTheme
519
+ ];
520
+ const areaAdvancedPipeline = [
521
+ initAdvancedVSeed,
522
+ autoMeasures,
523
+ autoDimensions,
524
+ pivotAdapter([
525
+ reshapeTo2D1M
526
+ ], [
527
+ pivotReshapeTo2D1M
528
+ ]),
529
+ encodingXY,
530
+ vchartBaseConfig,
531
+ vchartTheme
532
+ ];
533
+ const areaPercentAdvancedPipeline = [
534
+ initAdvancedVSeed,
535
+ autoMeasures,
536
+ autoDimensions,
537
+ pivotAdapter([
538
+ reshapeTo2D1M
539
+ ], [
540
+ pivotReshapeTo2D1M
541
+ ]),
542
+ encodingXY,
543
+ vchartBaseConfig,
544
+ vchartTheme
545
+ ];
546
+ const dataset_dataset = (spec, context)=>{
547
+ const { advancedVSeed } = context;
548
+ return {
549
+ ...spec,
550
+ data: {
551
+ values: advancedVSeed.dataset
552
+ }
553
+ };
554
+ };
555
+ const datasetPivot = (spec, context)=>{
556
+ const result = {
557
+ ...spec
558
+ };
559
+ const { advancedVSeed } = context;
560
+ const { dataset, datasetReshapeInfo } = advancedVSeed;
561
+ const records = dataset.reduce((pre, cur, index)=>{
562
+ const id = datasetReshapeInfo[index].id;
563
+ pre[id] = cur;
564
+ return pre;
565
+ }, {});
566
+ return {
567
+ ...result,
568
+ records: records
569
+ };
570
+ };
571
+ const datasetPivotPlaceholder = (spec)=>({
572
+ ...spec,
573
+ data: {
574
+ id: 'placeholderDataId'
575
+ }
576
+ });
577
+ const initColumn = (spec, context)=>{
578
+ const result = {
579
+ ...spec
580
+ };
581
+ const { advancedVSeed } = context;
582
+ const { encoding } = advancedVSeed;
583
+ if (!encoding[0].y || !encoding[0].x || !encoding[0].group) return result;
584
+ result.type = 'bar';
585
+ result.direction = 'vertical';
586
+ result.xField = encoding[0].x[0];
587
+ result.yField = encoding[0].y[0];
588
+ result.seriesField = encoding[0].group[0];
589
+ result.padding = 0;
590
+ return result;
591
+ };
592
+ const initBar = (spec, context)=>{
593
+ const result = {
594
+ ...spec
595
+ };
596
+ const { advancedVSeed } = context;
597
+ const { encoding } = advancedVSeed;
598
+ if (!encoding[0].y || !encoding[0].x || !encoding[0].group) return result;
599
+ result.type = 'bar';
600
+ result.direction = 'horizontal';
601
+ result.yField = encoding[0].y?.[0];
602
+ result.xField = encoding[0].x?.[0];
603
+ result.seriesField = encoding[0].group?.[0];
604
+ result.padding = 0;
605
+ return result;
606
+ };
607
+ const initBarParallel = (spec, context)=>{
608
+ const result = {
609
+ ...spec
610
+ };
611
+ const { advancedVSeed } = context;
612
+ const { encoding, datasetReshapeInfo } = advancedVSeed;
613
+ const { unfoldInfo } = datasetReshapeInfo[0];
614
+ if (!encoding[0].y || !encoding[0].x || !encoding[0].group) return result;
615
+ result.type = 'bar';
616
+ result.direction = 'horizontal';
617
+ result.yField = [
618
+ encoding[0].y[0],
619
+ unfoldInfo.groupName
620
+ ];
621
+ result.xField = encoding[0].x[0];
622
+ result.seriesField = encoding[0].group[0];
623
+ result.padding = 0;
624
+ return result;
625
+ };
626
+ const initArea = (spec, context)=>{
627
+ const result = {
628
+ ...spec
629
+ };
630
+ const { advancedVSeed } = context;
631
+ const { encoding } = advancedVSeed;
632
+ if (!encoding[0].y || !encoding[0].x || !encoding[0].group) return result;
633
+ result.type = 'area';
634
+ result.direction = 'vertical';
635
+ result.xField = encoding[0].x[0];
636
+ result.yField = encoding[0].y[0];
637
+ result.seriesField = encoding[0].group[0];
638
+ result.padding = 0;
639
+ return result;
640
+ };
641
+ const initLine = (spec, context)=>{
642
+ const result = {
643
+ ...spec
644
+ };
645
+ const { advancedVSeed } = context;
646
+ const { encoding } = advancedVSeed;
647
+ if (!encoding[0].y || !encoding[0].x || !encoding[0].group) return result;
648
+ result.type = 'line';
649
+ result.direction = 'vertical';
650
+ result.xField = encoding[0].x[0];
651
+ result.yField = encoding[0].y[0];
652
+ result.seriesField = encoding[0].group[0];
653
+ result.padding = 0;
654
+ return result;
655
+ };
656
+ const initColumnParallel = (spec, context)=>{
657
+ const result = {
658
+ ...spec
659
+ };
660
+ const { advancedVSeed } = context;
661
+ const { encoding, datasetReshapeInfo } = advancedVSeed;
662
+ const { unfoldInfo } = datasetReshapeInfo[0];
663
+ if (!encoding[0].y || !encoding[0].x || !encoding[0].group) return result;
664
+ result.type = 'bar';
665
+ result.direction = 'vertical';
666
+ result.xField = [
667
+ encoding[0].x[0],
668
+ unfoldInfo.groupName
669
+ ];
670
+ result.yField = encoding[0].y[0];
671
+ result.seriesField = encoding[0].group[0];
672
+ result.padding = 0;
673
+ return result;
674
+ };
675
+ const initPivot = (spec)=>{
676
+ const result = {
677
+ ...spec
678
+ };
679
+ return {
680
+ ...result,
681
+ rows: [],
682
+ columns: [],
683
+ indicators: [],
684
+ records: [],
685
+ widthMode: 'adaptive',
686
+ heightMode: 'adaptive',
687
+ indicatorsAsCol: false
688
+ };
689
+ };
690
+ const xBand = (spec)=>{
691
+ const result = {
692
+ ...spec
693
+ };
694
+ if (!result.axes) result.axes = [];
695
+ result.axes = [
696
+ ...result.axes,
697
+ {
698
+ visible: true,
699
+ type: 'band',
700
+ orient: 'bottom'
701
+ }
702
+ ];
703
+ return result;
704
+ };
705
+ const xLinear = (spec)=>{
706
+ const result = {
707
+ ...spec
708
+ };
709
+ if (!result.axes) result.axes = [];
710
+ result.axes = [
711
+ ...result.axes,
712
+ {
713
+ visible: true,
714
+ type: 'linear',
715
+ orient: 'bottom',
716
+ nice: true,
717
+ zero: true
718
+ }
719
+ ];
720
+ return result;
721
+ };
722
+ const yBand = (spec)=>{
723
+ const result = {
724
+ ...spec
725
+ };
726
+ if (!result.axes) result.axes = [];
727
+ result.axes = [
728
+ ...result.axes,
729
+ {
730
+ visible: true,
731
+ type: 'band',
732
+ orient: 'left'
733
+ }
734
+ ];
735
+ return result;
736
+ };
737
+ const yLinear = (spec)=>{
738
+ const result = {
739
+ ...spec
740
+ };
741
+ if (!result.axes) result.axes = [];
742
+ result.axes = [
743
+ ...result.axes,
744
+ {
745
+ visible: true,
746
+ type: 'linear',
747
+ orient: 'left',
748
+ nice: true,
749
+ zero: true
750
+ }
751
+ ];
752
+ return result;
753
+ };
754
+ const percent = (spec, context)=>{
755
+ const result = {
756
+ ...spec
757
+ };
758
+ result.percent = true;
759
+ return result;
760
+ };
761
+ const stack = (spec, context)=>{
762
+ const result = {
763
+ ...spec
764
+ };
765
+ result.stack = true;
766
+ return result;
767
+ };
768
+ const background_backgroundColor = (spec, context)=>{
769
+ const result = {
770
+ ...spec
771
+ };
772
+ const { advancedVSeed } = context;
773
+ const { baseConfig } = advancedVSeed;
774
+ if (!baseConfig?.vchart) return result;
775
+ const { backgroundColor } = baseConfig.vchart;
776
+ return {
777
+ ...result,
778
+ background: backgroundColor
779
+ };
780
+ };
781
+ const defaultTooltip = {
782
+ enable: true
783
+ };
784
+ const tooltip_tooltip = (spec, context)=>{
785
+ const result = {
786
+ ...spec
787
+ };
788
+ const { advancedVSeed } = context;
789
+ const baseConfig = advancedVSeed.baseConfig.vchart;
790
+ const { tooltip = defaultTooltip } = baseConfig;
791
+ const { enable } = tooltip;
792
+ result.tooltip = {
793
+ visible: enable
794
+ };
795
+ return result;
796
+ };
797
+ const label_label = (spec, context)=>{
798
+ const result = {
799
+ ...spec
800
+ };
801
+ const { advancedVSeed } = context;
802
+ const baseConfig = advancedVSeed.baseConfig.vchart;
803
+ if (!baseConfig || !baseConfig.label) return result;
804
+ const { label } = baseConfig;
805
+ const { enable } = label;
806
+ result.label = {
807
+ visible: enable
808
+ };
809
+ return result;
810
+ };
811
+ const defaultLegend = {
812
+ enable: true
813
+ };
814
+ const legend_legend = (spec, context)=>{
815
+ const result = {
816
+ ...spec
817
+ };
818
+ const { advancedVSeed } = context;
819
+ const baseConfig = advancedVSeed.baseConfig.vchart;
820
+ if (!baseConfig || !baseConfig.legend) return result;
821
+ const { legend = defaultLegend } = baseConfig;
822
+ const { enable } = legend;
823
+ result.legends = {
824
+ visible: enable
825
+ };
826
+ return result;
827
+ };
828
+ const pivotLegend = (spec, context)=>{
829
+ const result = {
830
+ ...spec
831
+ };
832
+ const { advancedVSeed } = context;
833
+ const baseConfig = advancedVSeed.baseConfig.vchart;
834
+ if (!baseConfig || !baseConfig.legend) return result;
835
+ const { datasetReshapeInfo } = advancedVSeed;
836
+ const colorItems = unique(datasetReshapeInfo.flatMap((d)=>d.unfoldInfo.colorItems));
837
+ const { legend, color } = baseConfig;
838
+ const { enable } = legend;
839
+ const { colorScheme } = color;
840
+ result.legends = {
841
+ visible: enable,
842
+ alignSelf: 'end',
843
+ type: 'discrete',
844
+ position: 'start',
845
+ data: colorItems.map((d, index)=>({
846
+ label: d,
847
+ shape: {
848
+ symbolType: 'square',
849
+ fill: colorScheme[index]
850
+ }
851
+ })),
852
+ orient: 'bottom'
853
+ };
854
+ return result;
855
+ };
856
+ const color_color = (spec, context)=>{
857
+ const result = {
858
+ ...spec
859
+ };
860
+ const { advancedVSeed } = context;
861
+ const { datasetReshapeInfo } = advancedVSeed;
862
+ const { unfoldInfo } = datasetReshapeInfo[0];
863
+ const baseConfig = advancedVSeed.baseConfig.vchart;
864
+ if (!baseConfig || !baseConfig.color) return result;
865
+ const { color } = baseConfig;
866
+ const { colorScheme, colorMapping } = color;
867
+ result.color = {
868
+ type: 'ordinal',
869
+ domain: unfoldInfo.colorItems,
870
+ range: colorScheme,
871
+ specified: colorMapping
872
+ };
873
+ return result;
874
+ };
875
+ const pivotAdapter_pivotAdapter = (pipeline, pivotPipeline)=>(spec, context)=>{
876
+ const { advancedVSeed } = context;
877
+ const { measures } = advancedVSeed;
878
+ if (measures && measures.find((measure)=>measure && measure.children)) return execPipeline(pivotPipeline, context, spec);
879
+ return execPipeline(pipeline, context, spec);
880
+ };
881
+ const pivotIndicators = (chartPipeline)=>(spec, context)=>{
882
+ const result = {
883
+ ...spec
884
+ };
885
+ const { advancedVSeed } = context;
886
+ const { measures, datasetReshapeInfo, encoding } = advancedVSeed;
887
+ const colorItems = unique(datasetReshapeInfo.flatMap((d)=>d.unfoldInfo.colorItems));
888
+ const indicators = datasetReshapeInfo.map((reshapeInfo, index)=>{
889
+ const measure = measures?.find((d)=>d.id === reshapeInfo.id);
890
+ const newEncoding = [
891
+ encoding[index]
892
+ ];
893
+ const newDatasetReshapeInfo = [
894
+ {
895
+ ...reshapeInfo,
896
+ unfoldInfo: {
897
+ ...reshapeInfo.unfoldInfo,
898
+ colorItems
899
+ }
900
+ }
901
+ ];
902
+ const newContext = {
903
+ ...context,
904
+ advancedVSeed: {
905
+ ...advancedVSeed,
906
+ datasetReshapeInfo: newDatasetReshapeInfo,
907
+ encoding: newEncoding
908
+ }
909
+ };
910
+ const chartSpec = execPipeline(chartPipeline, newContext, {});
911
+ return {
912
+ indicatorKey: reshapeInfo.id,
913
+ title: measure?.alias,
914
+ cellType: 'chart',
915
+ chartModule: 'vchart',
916
+ chartSpec: chartSpec,
917
+ style: {
918
+ padding: [
919
+ 1,
920
+ 1,
921
+ 0,
922
+ 1
923
+ ]
924
+ }
925
+ };
926
+ });
927
+ return {
928
+ ...result,
929
+ indicators: indicators
930
+ };
931
+ };
932
+ const pivotIndicators_pivotIndicatorsAsRow = (spec)=>{
933
+ const result = {
934
+ ...spec
935
+ };
936
+ return {
937
+ ...result,
938
+ indicatorsAsCol: false
939
+ };
940
+ };
941
+ const pivotIndicators_pivotIndicatorsAsCol = (spec)=>{
942
+ const result = {
943
+ ...spec
944
+ };
945
+ return {
946
+ ...result,
947
+ indicatorsAsCol: true
948
+ };
949
+ };
950
+ const line = [
951
+ initLine,
952
+ color_color,
953
+ background_backgroundColor,
954
+ dataset_dataset,
955
+ xBand,
956
+ yLinear,
957
+ label_label,
958
+ tooltip_tooltip,
959
+ legend_legend
960
+ ];
961
+ const pivotLine = [
962
+ initPivot,
963
+ pivotIndicators_pivotIndicatorsAsRow,
964
+ datasetPivot,
965
+ pivotIndicators([
966
+ initLine,
967
+ color_color,
968
+ background_backgroundColor,
969
+ datasetPivotPlaceholder,
970
+ xBand,
971
+ yLinear,
972
+ label_label,
973
+ tooltip_tooltip
974
+ ]),
975
+ pivotLegend
976
+ ];
977
+ const lineSpecPipeline = [
978
+ pivotAdapter_pivotAdapter(line, pivotLine)
979
+ ];
980
+ const column = [
981
+ initColumn,
982
+ color_color,
983
+ background_backgroundColor,
984
+ dataset_dataset,
985
+ xBand,
986
+ yLinear,
987
+ label_label,
988
+ tooltip_tooltip,
989
+ legend_legend
990
+ ];
991
+ const pivotColumn = [
992
+ initPivot,
993
+ pivotIndicators_pivotIndicatorsAsRow,
994
+ datasetPivot,
995
+ pivotIndicators([
996
+ initColumn,
997
+ color_color,
998
+ background_backgroundColor,
999
+ datasetPivotPlaceholder,
1000
+ xBand,
1001
+ yLinear,
1002
+ label_label,
1003
+ tooltip_tooltip
1004
+ ]),
1005
+ pivotLegend
1006
+ ];
1007
+ const columnSpecPipeline = [
1008
+ pivotAdapter_pivotAdapter(column, pivotColumn)
1009
+ ];
1010
+ const columnParallel = [
1011
+ initColumnParallel,
1012
+ color_color,
1013
+ background_backgroundColor,
1014
+ dataset_dataset,
1015
+ xBand,
1016
+ yLinear,
1017
+ label_label,
1018
+ tooltip_tooltip,
1019
+ legend_legend
1020
+ ];
1021
+ const pivotColumnParallel = [
1022
+ initPivot,
1023
+ pivotIndicators_pivotIndicatorsAsRow,
1024
+ datasetPivot,
1025
+ pivotIndicators([
1026
+ initColumnParallel,
1027
+ color_color,
1028
+ background_backgroundColor,
1029
+ datasetPivotPlaceholder,
1030
+ xBand,
1031
+ yLinear,
1032
+ label_label,
1033
+ tooltip_tooltip
1034
+ ]),
1035
+ pivotLegend
1036
+ ];
1037
+ const columnParallelSpecPipeline = [
1038
+ pivotAdapter_pivotAdapter(columnParallel, pivotColumnParallel)
1039
+ ];
1040
+ const columnPercent = [
1041
+ initColumn,
1042
+ color_color,
1043
+ background_backgroundColor,
1044
+ percent,
1045
+ dataset_dataset,
1046
+ xBand,
1047
+ yLinear,
1048
+ label_label,
1049
+ tooltip_tooltip,
1050
+ legend_legend
1051
+ ];
1052
+ const pivotColumnPercent = [
1053
+ initPivot,
1054
+ pivotIndicators_pivotIndicatorsAsRow,
1055
+ datasetPivot,
1056
+ pivotIndicators([
1057
+ initColumn,
1058
+ color_color,
1059
+ percent,
1060
+ background_backgroundColor,
1061
+ datasetPivotPlaceholder,
1062
+ xBand,
1063
+ yLinear,
1064
+ label_label,
1065
+ tooltip_tooltip
1066
+ ]),
1067
+ pivotLegend
1068
+ ];
1069
+ const columnPercentSpecPipeline = [
1070
+ pivotAdapter_pivotAdapter(columnPercent, pivotColumnPercent)
1071
+ ];
1072
+ const bar = [
1073
+ initBar,
1074
+ color_color,
1075
+ background_backgroundColor,
1076
+ dataset_dataset,
1077
+ xLinear,
1078
+ yBand,
1079
+ label_label,
1080
+ tooltip_tooltip,
1081
+ legend_legend
1082
+ ];
1083
+ const pivotBar = [
1084
+ initPivot,
1085
+ pivotIndicators_pivotIndicatorsAsCol,
1086
+ datasetPivot,
1087
+ pivotIndicators([
1088
+ initBar,
1089
+ color_color,
1090
+ background_backgroundColor,
1091
+ datasetPivotPlaceholder,
1092
+ yBand,
1093
+ label_label,
1094
+ label_label,
1095
+ tooltip_tooltip
1096
+ ]),
1097
+ pivotLegend
1098
+ ];
1099
+ const barSpecPipeline = [
1100
+ pivotAdapter_pivotAdapter(bar, pivotBar)
1101
+ ];
1102
+ const barParallel = [
1103
+ initBarParallel,
1104
+ color_color,
1105
+ background_backgroundColor,
1106
+ dataset_dataset,
1107
+ xLinear,
1108
+ yBand,
1109
+ label_label,
1110
+ tooltip_tooltip,
1111
+ legend_legend
1112
+ ];
1113
+ const pivotBarParallel = [
1114
+ initPivot,
1115
+ pivotIndicators_pivotIndicatorsAsCol,
1116
+ datasetPivot,
1117
+ pivotIndicators([
1118
+ initBarParallel,
1119
+ color_color,
1120
+ background_backgroundColor,
1121
+ datasetPivotPlaceholder,
1122
+ yBand,
1123
+ xLinear,
1124
+ label_label,
1125
+ tooltip_tooltip
1126
+ ]),
1127
+ pivotLegend
1128
+ ];
1129
+ const barParallelSpecPipeline = [
1130
+ pivotAdapter_pivotAdapter(barParallel, pivotBarParallel)
1131
+ ];
1132
+ const barPercent = [
1133
+ initBar,
1134
+ color_color,
1135
+ background_backgroundColor,
1136
+ percent,
1137
+ dataset_dataset,
1138
+ xLinear,
1139
+ yBand,
1140
+ label_label,
1141
+ tooltip_tooltip,
1142
+ legend_legend
1143
+ ];
1144
+ const pivotBarPercent = [
1145
+ initPivot,
1146
+ pivotIndicators_pivotIndicatorsAsCol,
1147
+ datasetPivot,
1148
+ pivotIndicators([
1149
+ initBar,
1150
+ color_color,
1151
+ background_backgroundColor,
1152
+ percent,
1153
+ datasetPivotPlaceholder,
1154
+ yBand,
1155
+ xLinear,
1156
+ label_label,
1157
+ tooltip_tooltip
1158
+ ]),
1159
+ pivotLegend
1160
+ ];
1161
+ const barPercentSpecPipeline = [
1162
+ pivotAdapter_pivotAdapter(barPercent, pivotBarPercent)
1163
+ ];
1164
+ const area_area = [
1165
+ initArea,
1166
+ color_color,
1167
+ background_backgroundColor,
1168
+ stack,
1169
+ dataset_dataset,
1170
+ xBand,
1171
+ yLinear,
1172
+ label_label,
1173
+ tooltip_tooltip,
1174
+ legend_legend
1175
+ ];
1176
+ const pivotArea = [
1177
+ initPivot,
1178
+ pivotIndicators_pivotIndicatorsAsRow,
1179
+ datasetPivot,
1180
+ pivotIndicators([
1181
+ initArea,
1182
+ color_color,
1183
+ background_backgroundColor,
1184
+ stack,
1185
+ datasetPivotPlaceholder,
1186
+ xBand,
1187
+ yLinear,
1188
+ label_label,
1189
+ tooltip_tooltip
1190
+ ]),
1191
+ pivotLegend
1192
+ ];
1193
+ const areaSpecPipeline = [
1194
+ pivotAdapter_pivotAdapter(area_area, pivotArea)
1195
+ ];
1196
+ const areaPercent = [
1197
+ initArea,
1198
+ color_color,
1199
+ background_backgroundColor,
1200
+ percent,
1201
+ dataset_dataset,
1202
+ xBand,
1203
+ yLinear,
1204
+ label_label,
1205
+ tooltip_tooltip,
1206
+ legend_legend
1207
+ ];
1208
+ const pivotAreaPercent = [
1209
+ initPivot,
1210
+ pivotIndicators_pivotIndicatorsAsRow,
1211
+ datasetPivot,
1212
+ pivotIndicators([
1213
+ initArea,
1214
+ color_color,
1215
+ background_backgroundColor,
1216
+ percent,
1217
+ datasetPivotPlaceholder,
1218
+ xBand,
1219
+ yLinear,
1220
+ label_label,
1221
+ tooltip_tooltip
1222
+ ]),
1223
+ pivotLegend
1224
+ ];
1225
+ const areaPercentSpecPipeline = [
1226
+ pivotAdapter_pivotAdapter(areaPercent, pivotAreaPercent)
1227
+ ];
1228
+ const buildAdvanced = (builder)=>{
1229
+ const { chartType } = builder.vseed;
1230
+ if (!chartType) throw new Error('chartType is nil in buildAdvanced');
1231
+ const pipeline = builder.getAdvancedPipeline(chartType);
1232
+ if (!pipeline) throw new Error(`no advanced pipeline for chartType ${chartType}`);
1233
+ const context = {
1234
+ vseed: builder.vseed,
1235
+ customTheme: builder.getThemeMap()
1236
+ };
1237
+ try {
1238
+ return execPipeline(pipeline, context);
1239
+ } catch (e) {
1240
+ console.error(e);
1241
+ throw new Error("buildAdvanced error, see error info in console");
1242
+ }
1243
+ };
1244
+ const buildSpec = (builder, advancedVSeed)=>{
1245
+ const { chartType } = builder.vseed;
1246
+ if (!chartType) throw new Error('chartType is nil in buildSpec');
1247
+ const pipeline = builder.getSpecPipeline(chartType);
1248
+ if (!pipeline) throw new Error(`no spec pipeline for chartType ${chartType}`);
1249
+ const context = {
1250
+ vseed: builder.vseed,
1251
+ advancedVSeed
1252
+ };
1253
+ try {
1254
+ return execPipeline(pipeline, context);
1255
+ } catch (e) {
1256
+ console.error(e);
1257
+ throw new Error("buildSpec error, see error info in console");
1258
+ }
1259
+ };
1260
+ const build = (builder)=>{
1261
+ console.log('debug vseed', builder.vseed);
1262
+ const advancedVSeed = builder.buildAdvanced();
1263
+ console.log('debug advancedVSeed', advancedVSeed);
1264
+ if (!advancedVSeed) throw new Error('advancedVSeed is null');
1265
+ const spec = builder.buildSpec(advancedVSeed);
1266
+ console.log('debug spec', spec);
1267
+ return spec;
1268
+ };
1269
+ class Builder {
1270
+ _vseed;
1271
+ _advancedVSeed = null;
1272
+ constructor(vseed){
1273
+ this._vseed = vseed;
1274
+ }
1275
+ build = ()=>build(this);
1276
+ buildSpec = (advanced)=>buildSpec(this, advanced);
1277
+ buildAdvanced = ()=>buildAdvanced(this);
1278
+ getAdvancedPipeline = (chartType)=>Builder._advancedPipelineMap[chartType];
1279
+ getSpecPipeline = (chartType)=>Builder._specPipelineMap[chartType];
1280
+ getTheme = (themeKey)=>Builder._themeMap[themeKey];
1281
+ getThemeMap = ()=>Builder._themeMap;
1282
+ get vseed() {
1283
+ return this._vseed;
1284
+ }
1285
+ set vseed(value) {
1286
+ this._vseed = value;
1287
+ }
1288
+ get advancedVSeed() {
1289
+ return this._advancedVSeed;
1290
+ }
1291
+ set advancedVSeed(value) {
1292
+ this._advancedVSeed = value;
1293
+ }
1294
+ static _advancedPipelineMap = {};
1295
+ static _specPipelineMap = {};
1296
+ static _themeMap = {};
1297
+ static from = (vseed)=>new Builder(vseed);
1298
+ }
1299
+ const registerColumn = ()=>{
1300
+ Builder._advancedPipelineMap.column = columnAdvancedPipeline;
1301
+ Builder._specPipelineMap.column = columnSpecPipeline;
1302
+ };
1303
+ const registerBar = ()=>{
1304
+ Builder._advancedPipelineMap.bar = barAdvancedPipeline;
1305
+ Builder._specPipelineMap.bar = barSpecPipeline;
1306
+ };
1307
+ const registerLine = ()=>{
1308
+ Builder._advancedPipelineMap.line = lineAdvancedPipeline;
1309
+ Builder._specPipelineMap.line = lineSpecPipeline;
1310
+ };
1311
+ const registerArea = ()=>{
1312
+ Builder._advancedPipelineMap.area = areaAdvancedPipeline;
1313
+ Builder._specPipelineMap.area = areaSpecPipeline;
1314
+ };
1315
+ const registerAreaPercent = ()=>{
1316
+ Builder._advancedPipelineMap.areaPercent = areaPercentAdvancedPipeline;
1317
+ Builder._specPipelineMap.areaPercent = areaPercentSpecPipeline;
1318
+ };
1319
+ const registerBarPercent = ()=>{
1320
+ Builder._advancedPipelineMap.barPercent = barPercentAdvancedPipeline;
1321
+ Builder._specPipelineMap.barPercent = barPercentSpecPipeline;
1322
+ };
1323
+ const registerColumnPercent = ()=>{
1324
+ Builder._advancedPipelineMap.columnPercent = columnPercentAdvancedPipeline;
1325
+ Builder._specPipelineMap.columnPercent = columnPercentSpecPipeline;
1326
+ };
1327
+ const registerColumnParallel = ()=>{
1328
+ Builder._advancedPipelineMap.columnParallel = columnParallelAdvancedPipeline;
1329
+ Builder._specPipelineMap.columnParallel = columnParallelSpecPipeline;
1330
+ };
1331
+ const registerBarParallel = ()=>{
1332
+ Builder._advancedPipelineMap.barParallel = barParallelAdvancedPipeline;
1333
+ Builder._specPipelineMap.barParallel = barParallelSpecPipeline;
1334
+ };
1335
+ const darkTheme = ()=>({
1336
+ baseConfig: {
1337
+ vtable: {
1338
+ backgroundColor: '#141414'
1339
+ },
1340
+ vchart: {
1341
+ backgroundColor: '#141414',
1342
+ color: {
1343
+ colorScheme: [
1344
+ '#2E62F1',
1345
+ '#4DC36A',
1346
+ '#FF8406',
1347
+ '#FFCC00',
1348
+ '#4F44CF',
1349
+ '#5AC8FA',
1350
+ '#003A8C',
1351
+ '#B08AE2',
1352
+ '#FF6341',
1353
+ '#98DD62'
1354
+ ]
1355
+ },
1356
+ label: {
1357
+ enable: true
1358
+ },
1359
+ tooltip: {
1360
+ enable: true
1361
+ },
1362
+ legend: {
1363
+ enable: true
1364
+ }
1365
+ }
1366
+ }
1367
+ });
1368
+ const lightTheme = ()=>({
1369
+ baseConfig: {
1370
+ vtable: {
1371
+ backgroundColor: '#ffffff'
1372
+ },
1373
+ vchart: {
1374
+ backgroundColor: '#ffffff',
1375
+ color: {
1376
+ colorScheme: [
1377
+ '#8D72F6',
1378
+ '#5766EC',
1379
+ '#66A3FE',
1380
+ '#51D5E6',
1381
+ '#4EC0B3',
1382
+ '#F9DF90',
1383
+ '#F9AD71',
1384
+ '#ED8888',
1385
+ '#E9A0C3',
1386
+ '#D77DD3'
1387
+ ]
1388
+ },
1389
+ label: {
1390
+ enable: true
1391
+ },
1392
+ tooltip: {
1393
+ enable: true
1394
+ },
1395
+ legend: {
1396
+ enable: true
1397
+ }
1398
+ }
1399
+ }
1400
+ });
1401
+ const registerCustomTheme = (key, themeConfig)=>{
1402
+ Builder._themeMap[key] = themeConfig;
1403
+ };
1404
+ const registerLightTheme = ()=>{
1405
+ registerCustomTheme('light', lightTheme());
1406
+ };
1407
+ const registerDarkTheme = ()=>{
1408
+ registerCustomTheme('dark', darkTheme());
1409
+ };
1410
+ const all_registerAll = ()=>{
1411
+ registerLine();
1412
+ registerColumn();
1413
+ registerColumnParallel();
1414
+ registerColumnPercent();
1415
+ registerBar();
1416
+ registerBarParallel();
1417
+ registerBarPercent();
1418
+ registerArea();
1419
+ registerAreaPercent();
1420
+ registerLightTheme();
1421
+ registerDarkTheme();
1422
+ };
1423
+ const zChartType = z["enum"]([
1424
+ 'table',
1425
+ 'pivotTable',
1426
+ 'line',
1427
+ 'column',
1428
+ 'columnPercent',
1429
+ 'columnParallel',
1430
+ 'bar',
1431
+ 'barPercent',
1432
+ 'barParallel',
1433
+ 'area',
1434
+ 'areaPercent',
1435
+ 'rose',
1436
+ 'pie',
1437
+ 'donut',
1438
+ 'dualAxis'
1439
+ ]);
1440
+ const zDatum = z.record(z.string().or(z.number()), z.any());
1441
+ const zDataset = z.array(zDatum);
1442
+ const zDimension = z.object({
1443
+ id: z.string(),
1444
+ alias: z.string().optional(),
1445
+ visible: z.boolean().default(true).optional(),
1446
+ location: z["enum"]([
1447
+ 'dimension',
1448
+ 'rowDimension',
1449
+ 'columnDimension'
1450
+ ])
1451
+ });
1452
+ const zDimensions = z.array(zDimension).optional();
1453
+ const zMeasure = z.object({
1454
+ id: z.string(),
1455
+ alias: z.string().optional(),
1456
+ visible: z.boolean().default(true).optional(),
1457
+ autoFormat: z.boolean().default(true).optional(),
1458
+ format: z.object({
1459
+ type: z["enum"]([
1460
+ 'number',
1461
+ 'percent',
1462
+ 'permille'
1463
+ ]).optional().default('number'),
1464
+ ratio: z.number().optional().default(1),
1465
+ symbol: z.string().optional().default(''),
1466
+ thousandSeparator: z.boolean().optional().default(false),
1467
+ decimalPlaces: z.number().optional().default(2),
1468
+ round: z["enum"]([
1469
+ 'round',
1470
+ 'floor',
1471
+ 'ceil'
1472
+ ]).optional().default('round'),
1473
+ prefix: z.string().optional().default(''),
1474
+ suffix: z.string().optional().default('')
1475
+ }).optional()
1476
+ });
1477
+ const zMeasureGroup = z.object({
1478
+ id: z.string(),
1479
+ alias: z.string().optional(),
1480
+ visible: z.boolean().default(true).optional(),
1481
+ get children () {
1482
+ return z.array(zMeasureGroup.or(zMeasure)).optional();
1483
+ }
1484
+ });
1485
+ const zMeasures = z.array(zMeasureGroup.or(zMeasure)).optional();
1486
+ const zFoldInfo = z.object({
1487
+ foldMap: z.record(z.string(), z.string().or(z.undefined())),
1488
+ measureId: z.string(),
1489
+ measureName: z.string(),
1490
+ measureValue: z.string()
1491
+ });
1492
+ const zUnfoldInfo = z.object({
1493
+ colorItems: z.array(z.string()),
1494
+ groupName: z.string()
1495
+ });
1496
+ const zDatasetReshapeInfo = z.array(z.object({
1497
+ id: z.string(),
1498
+ foldInfo: zFoldInfo,
1499
+ unfoldInfo: zUnfoldInfo
1500
+ }));
1501
+ const zEncoding = z.array(z.object({
1502
+ x: z.array(z.string()).optional(),
1503
+ y: z.array(z.string()).optional(),
1504
+ color: z.array(z.string()).optional(),
1505
+ group: z.array(z.string()).optional(),
1506
+ angle: z.array(z.string()).optional(),
1507
+ radius: z.array(z.string()).optional(),
1508
+ tooltip: z.array(z.string()).optional()
1509
+ }));
1510
+ const zBackgroundColor = z.string().default('transparent').optional();
1511
+ const zLabel = z.object({
1512
+ enable: z.boolean().default(true).optional()
1513
+ });
1514
+ const zColor = z.object({
1515
+ colorScheme: z.array(z.string()).optional(),
1516
+ colorMapping: z.record(z.string(), z.string()).optional()
1517
+ });
1518
+ const zTooltip = z.object({
1519
+ enable: z.boolean().default(true).optional()
1520
+ });
1521
+ const zLegend = z.object({
1522
+ enable: z.boolean().default(true).optional()
1523
+ });
1524
+ const zVChartBaseConfig = z.object({
1525
+ backgroundColor: zBackgroundColor,
1526
+ label: zLabel.optional(),
1527
+ color: zColor.optional(),
1528
+ tooltip: zTooltip.optional(),
1529
+ legend: zLegend.optional()
1530
+ });
1531
+ const zVTableBaseConfig = z.object({
1532
+ backgroundColor: zBackgroundColor
1533
+ });
1534
+ const zBaseConfig = z.object({
1535
+ vchart: zVChartBaseConfig.optional(),
1536
+ vtable: zVTableBaseConfig.optional()
1537
+ });
1538
+ const zCustomThemeConfig = z.object({
1539
+ baseConfig: zBaseConfig.optional()
1540
+ });
1541
+ const zCustomTheme = z.record(z.string(), zCustomThemeConfig).optional();
1542
+ const zTheme = z.string();
1543
+ export { Builder, areaAdvancedPipeline, areaPercentAdvancedPipeline, areaPercentSpecPipeline, areaSpecPipeline, barAdvancedPipeline, barParallelAdvancedPipeline, barParallelSpecPipeline, barPercentAdvancedPipeline, barPercentSpecPipeline, barSpecPipeline, columnAdvancedPipeline, columnParallelAdvancedPipeline, columnParallelSpecPipeline, columnPercentAdvancedPipeline, columnPercentSpecPipeline, columnSpecPipeline, darkTheme, dataReshapeFor1D1M_dataReshapeFor1D1M as dataReshapeFor1D1M, dataReshapeFor2D1M, execPipeline, foldMeasures, isVChart, isVTable, lightTheme, lineAdvancedPipeline, lineSpecPipeline, all_registerAll as registerAll, registerArea, registerAreaPercent, registerBar, registerBarParallel, registerBarPercent, registerColumn, registerColumnParallel, registerColumnPercent, registerCustomTheme, registerDarkTheme, registerLightTheme, registerLine, unfoldDimensions, zBackgroundColor, zBaseConfig, zChartType, zColor, zCustomTheme, zCustomThemeConfig, zDataset, zDatasetReshapeInfo, zDatum, zDimension, zDimensions, zEncoding, zFoldInfo, zLabel, zLegend, zMeasure, zMeasureGroup, zMeasures, zTheme, zTooltip, zUnfoldInfo };
1544
+
1545
+ //# sourceMappingURL=index.js.map