@visactor/vseed 0.0.5 → 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.
- package/dist/builder/builder/build.d.ts +2 -2
- package/dist/builder/builder/buildSpec.d.ts +2 -2
- package/dist/builder/builder/builder.d.ts +8 -5
- package/dist/dataReshape/constant.d.ts +1 -1
- package/dist/dataReshape/dataReshapeFor1D1M.d.ts +6 -1
- package/dist/dataReshape/dataReshapeFor2D1M.d.ts +6 -1
- package/dist/index.cjs +759 -348
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +518 -107
- package/dist/index.js.map +1 -1
- package/dist/pipeline/advanced/pipes/encoding/{encodingCartesian.d.ts → encodingXY.d.ts} +0 -1
- package/dist/pipeline/advanced/pipes/encoding/encodingYX.d.ts +2 -0
- package/dist/pipeline/advanced/pipes/encoding/index.d.ts +2 -1
- package/dist/pipeline/advanced/pipes/index.d.ts +1 -0
- package/dist/pipeline/advanced/pipes/pivot/index.d.ts +1 -0
- package/dist/pipeline/advanced/pipes/pivot/pivotAdapter.d.ts +2 -0
- package/dist/pipeline/advanced/pipes/reshape/index.d.ts +2 -0
- package/dist/pipeline/advanced/pipes/reshape/pivotReshapeTo1D1M.d.ts +8 -0
- package/dist/pipeline/advanced/pipes/reshape/pivotReshapeTo2D1M.d.ts +8 -0
- package/dist/pipeline/spec/pipeline/area.d.ts +1 -2
- package/dist/pipeline/spec/pipeline/areaPercent.d.ts +1 -2
- package/dist/pipeline/spec/pipeline/column.d.ts +1 -2
- package/dist/pipeline/spec/pipes/dataset/datasetPivot.d.ts +3 -0
- package/dist/pipeline/spec/pipes/dataset/index.d.ts +1 -0
- package/dist/pipeline/spec/pipes/index.d.ts +1 -0
- package/dist/pipeline/spec/pipes/init/index.d.ts +1 -0
- package/dist/pipeline/spec/pipes/init/pivot.d.ts +4 -0
- package/dist/pipeline/spec/pipes/legend/index.d.ts +1 -0
- package/dist/pipeline/spec/pipes/legend/pivotLegend.d.ts +2 -0
- package/dist/pipeline/spec/pipes/pivotChart/index.d.ts +2 -0
- package/dist/pipeline/spec/pipes/pivotChart/pivotAdapter.d.ts +2 -0
- package/dist/pipeline/spec/pipes/pivotChart/pivotIndicators.d.ts +4 -0
- package/dist/types/advancedVSeed.d.ts +3 -2
- package/dist/types/builder/builder.d.ts +3 -3
- package/dist/types/builder/index.d.ts +1 -0
- package/dist/types/builder/spec.d.ts +3 -0
- package/dist/types/pipeline/spec/spec.d.ts +2 -2
- package/dist/types/properties/datasetReshapeInfo/datasetReshapeInfo.d.ts +3 -2
- package/dist/types/properties/datasetReshapeInfo/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { clone as external_remeda_clone, mergeDeep as external_remeda_mergeDeep, pick as external_remeda_pick } from "remeda";
|
1
|
+
import { clone as external_remeda_clone, mergeDeep as external_remeda_mergeDeep, pick as external_remeda_pick, unique } from "remeda";
|
2
2
|
import { z } from "zod";
|
3
|
-
const
|
4
|
-
const
|
5
|
-
const
|
6
|
-
const
|
3
|
+
const constant_FoldMeasureName = '__MeaName__';
|
4
|
+
const constant_FoldMeasureValue = '__MeaValue__';
|
5
|
+
const constant_FoldMeasureId = '__MeaId__';
|
6
|
+
const constant_UnfoldDimensionGroup = '__DimGroup__';
|
7
7
|
const Separator = '-';
|
8
|
-
const unfoldDimensions = (dataset, dimensions, measures, unfoldStartIndex = 0, foldGroupName =
|
8
|
+
const unfoldDimensions = (dataset, dimensions, measures, unfoldStartIndex = 0, foldGroupName = constant_UnfoldDimensionGroup, dimensionsSeparator = Separator)=>{
|
9
9
|
if (unfoldStartIndex < 0 || unfoldStartIndex >= dimensions.length) throw new Error('unfoldStartIndex is out of range');
|
10
10
|
const dimensionsToBeUnfolded = dimensions.slice(unfoldStartIndex);
|
11
11
|
const unfoldInfo = {
|
@@ -26,14 +26,14 @@ const unfoldDimensions = (dataset, dimensions, measures, unfoldStartIndex = 0, f
|
|
26
26
|
datum[foldGroupName] = colorItem;
|
27
27
|
colorItems.push(colorItem);
|
28
28
|
}
|
29
|
-
unfoldInfo.colorItems = colorItems;
|
29
|
+
unfoldInfo.colorItems = unique(colorItems);
|
30
30
|
return {
|
31
31
|
dataset,
|
32
32
|
unfoldInfo
|
33
33
|
};
|
34
34
|
};
|
35
35
|
const generateDimGroupName = (dimensionsToBeGrouped, datum, dimensionsSeparator)=>dimensionsToBeGrouped.map((dim)=>String(datum[dim.id])).join(dimensionsSeparator);
|
36
|
-
const foldMeasures = (dataset, measures, measureId =
|
36
|
+
const foldMeasures = (dataset, measures, measureId = constant_FoldMeasureId, measureName = constant_FoldMeasureName, measureValue = constant_FoldMeasureValue)=>{
|
37
37
|
const foldInfo = {
|
38
38
|
measureId,
|
39
39
|
measureName,
|
@@ -72,27 +72,28 @@ const emptyReshapeResult = {
|
|
72
72
|
groupName: ''
|
73
73
|
}
|
74
74
|
};
|
75
|
-
const dataReshapeFor2D1M = (dataset, dimensions, measures)=>{
|
75
|
+
const dataReshapeFor2D1M = (dataset, dimensions, measures, options)=>{
|
76
|
+
const { foldMeasureId = constant_FoldMeasureId, foldMeasureName = constant_FoldMeasureName, foldMeasureValue = constant_FoldMeasureValue, unfoldDimensionGroup = constant_UnfoldDimensionGroup } = options || {};
|
76
77
|
if (0 === dimensions.length && 0 === measures.length) return emptyReshapeResult;
|
77
|
-
const { dataset: foldedDataset, foldInfo } = foldMeasures(dataset, measures,
|
78
|
+
const { dataset: foldedDataset, foldInfo } = foldMeasures(dataset, measures, foldMeasureId, foldMeasureName, foldMeasureValue);
|
78
79
|
if (0 === dimensions.length) {
|
79
80
|
const { dataset: finalDataset, unfoldInfo } = unfoldDimensions(foldedDataset, [
|
80
81
|
{
|
81
|
-
id:
|
82
|
+
id: foldMeasureId,
|
82
83
|
alias: "\u6307\u6807Id",
|
83
84
|
location: 'dimension'
|
84
85
|
},
|
85
86
|
{
|
86
|
-
id:
|
87
|
+
id: foldMeasureName,
|
87
88
|
alias: "\u6307\u6807\u540D\u79F0",
|
88
89
|
location: 'dimension'
|
89
90
|
}
|
90
91
|
], [
|
91
92
|
{
|
92
|
-
id:
|
93
|
+
id: foldMeasureValue,
|
93
94
|
alias: "\u6307\u6807\u503C"
|
94
95
|
}
|
95
|
-
], 1,
|
96
|
+
], 1, unfoldDimensionGroup);
|
96
97
|
return {
|
97
98
|
dataset: finalDataset,
|
98
99
|
foldInfo,
|
@@ -103,16 +104,16 @@ const dataReshapeFor2D1M = (dataset, dimensions, measures)=>{
|
|
103
104
|
const { dataset: finalDataset, unfoldInfo } = unfoldDimensions(foldedDataset, [
|
104
105
|
...dimensions,
|
105
106
|
{
|
106
|
-
id:
|
107
|
+
id: foldMeasureName,
|
107
108
|
alias: "\u6307\u6807\u540D\u79F0",
|
108
109
|
location: 'dimension'
|
109
110
|
}
|
110
111
|
], [
|
111
112
|
{
|
112
|
-
id:
|
113
|
+
id: foldMeasureValue,
|
113
114
|
alias: "\u6307\u6807\u503C"
|
114
115
|
}
|
115
|
-
], 1,
|
116
|
+
], 1, unfoldDimensionGroup);
|
116
117
|
return {
|
117
118
|
dataset: finalDataset,
|
118
119
|
foldInfo,
|
@@ -133,22 +134,23 @@ const dataReshapeFor1D1M_emptyReshapeResult = {
|
|
133
134
|
colorItems: []
|
134
135
|
}
|
135
136
|
};
|
136
|
-
const dataReshapeFor1D1M_dataReshapeFor1D1M = (dataset, dimensions, measures)=>{
|
137
|
+
const dataReshapeFor1D1M_dataReshapeFor1D1M = (dataset, dimensions, measures, options)=>{
|
138
|
+
const { foldMeasureId = constant_FoldMeasureId, foldMeasureName = constant_FoldMeasureName, foldMeasureValue = constant_FoldMeasureValue, unfoldDimensionGroup = constant_UnfoldDimensionGroup } = options || {};
|
137
139
|
if (0 === dimensions.length && 0 === measures.length) return dataReshapeFor1D1M_emptyReshapeResult;
|
138
|
-
const { dataset: foldedDataset, foldInfo } = foldMeasures(dataset, measures,
|
140
|
+
const { dataset: foldedDataset, foldInfo } = foldMeasures(dataset, measures, foldMeasureId, foldMeasureName, foldMeasureValue);
|
139
141
|
if (0 === dimensions.length) {
|
140
142
|
const { dataset: finalDataset, unfoldInfo } = unfoldDimensions(foldedDataset, [
|
141
143
|
{
|
142
|
-
id:
|
144
|
+
id: foldMeasureName,
|
143
145
|
alias: "\u6307\u6807\u540D\u79F0",
|
144
146
|
location: 'dimension'
|
145
147
|
}
|
146
148
|
], [
|
147
149
|
{
|
148
|
-
id:
|
150
|
+
id: foldMeasureValue,
|
149
151
|
alias: "\u6307\u6807\u503C"
|
150
152
|
}
|
151
|
-
], 0,
|
153
|
+
], 0, unfoldDimensionGroup);
|
152
154
|
return {
|
153
155
|
dataset: finalDataset,
|
154
156
|
foldInfo,
|
@@ -159,16 +161,16 @@ const dataReshapeFor1D1M_dataReshapeFor1D1M = (dataset, dimensions, measures)=>{
|
|
159
161
|
const { dataset: finalDataset, unfoldInfo } = unfoldDimensions(foldedDataset, [
|
160
162
|
...dimensions,
|
161
163
|
{
|
162
|
-
id:
|
164
|
+
id: foldMeasureName,
|
163
165
|
alias: "\u6307\u6807\u540D\u79F0",
|
164
166
|
location: 'dimension'
|
165
167
|
}
|
166
168
|
], [
|
167
169
|
{
|
168
|
-
id:
|
170
|
+
id: foldMeasureValue,
|
169
171
|
alias: "\u6307\u6807\u503C"
|
170
172
|
}
|
171
|
-
], 0,
|
173
|
+
], 0, unfoldDimensionGroup);
|
172
174
|
return {
|
173
175
|
dataset: finalDataset,
|
174
176
|
foldInfo,
|
@@ -189,42 +191,86 @@ const reshapeTo2D1M = (advancedVSeed, context)=>{
|
|
189
191
|
return {
|
190
192
|
...result,
|
191
193
|
dataset: newDatasets,
|
192
|
-
datasetReshapeInfo:
|
193
|
-
|
194
|
-
|
195
|
-
|
194
|
+
datasetReshapeInfo: [
|
195
|
+
{
|
196
|
+
id: '2D1M',
|
197
|
+
foldInfo,
|
198
|
+
unfoldInfo
|
199
|
+
}
|
200
|
+
],
|
196
201
|
dimensions,
|
197
202
|
measures
|
198
203
|
};
|
199
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
|
+
};
|
200
243
|
const encodingXY = (advancedVSeed)=>{
|
201
244
|
const result = {
|
202
245
|
...advancedVSeed
|
203
246
|
};
|
204
247
|
const { datasetReshapeInfo, dimensions } = advancedVSeed;
|
205
248
|
if (!datasetReshapeInfo || !dimensions) return result;
|
206
|
-
const
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
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
|
+
}, []);
|
228
274
|
return {
|
229
275
|
...result,
|
230
276
|
encoding
|
@@ -236,28 +282,31 @@ const encodingYX = (advancedVSeed)=>{
|
|
236
282
|
};
|
237
283
|
const { datasetReshapeInfo, dimensions } = advancedVSeed;
|
238
284
|
if (!datasetReshapeInfo || !dimensions) return result;
|
239
|
-
const
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
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
|
+
}, []);
|
261
310
|
return {
|
262
311
|
...result,
|
263
312
|
encoding
|
@@ -362,11 +411,30 @@ const vchartTheme = (advancedVSeed, context)=>{
|
|
362
411
|
};
|
363
412
|
return result;
|
364
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
|
+
};
|
365
429
|
const lineAdvancedPipeline = [
|
366
430
|
initAdvancedVSeed,
|
367
431
|
autoMeasures,
|
368
432
|
autoDimensions,
|
369
|
-
|
433
|
+
pivotAdapter([
|
434
|
+
reshapeTo2D1M
|
435
|
+
], [
|
436
|
+
pivotReshapeTo2D1M
|
437
|
+
]),
|
370
438
|
encodingXY,
|
371
439
|
vchartBaseConfig,
|
372
440
|
vchartTheme
|
@@ -375,7 +443,11 @@ const barAdvancedPipeline = [
|
|
375
443
|
initAdvancedVSeed,
|
376
444
|
autoMeasures,
|
377
445
|
autoDimensions,
|
378
|
-
|
446
|
+
pivotAdapter([
|
447
|
+
reshapeTo2D1M
|
448
|
+
], [
|
449
|
+
pivotReshapeTo2D1M
|
450
|
+
]),
|
379
451
|
encodingYX,
|
380
452
|
vchartBaseConfig,
|
381
453
|
vchartTheme
|
@@ -384,7 +456,11 @@ const barParallelAdvancedPipeline = [
|
|
384
456
|
initAdvancedVSeed,
|
385
457
|
autoMeasures,
|
386
458
|
autoDimensions,
|
387
|
-
|
459
|
+
pivotAdapter([
|
460
|
+
reshapeTo2D1M
|
461
|
+
], [
|
462
|
+
pivotReshapeTo2D1M
|
463
|
+
]),
|
388
464
|
encodingYX,
|
389
465
|
vchartBaseConfig,
|
390
466
|
vchartTheme
|
@@ -393,7 +469,11 @@ const barPercentAdvancedPipeline = [
|
|
393
469
|
initAdvancedVSeed,
|
394
470
|
autoMeasures,
|
395
471
|
autoDimensions,
|
396
|
-
|
472
|
+
pivotAdapter([
|
473
|
+
reshapeTo2D1M
|
474
|
+
], [
|
475
|
+
pivotReshapeTo2D1M
|
476
|
+
]),
|
397
477
|
encodingYX,
|
398
478
|
vchartBaseConfig,
|
399
479
|
vchartTheme
|
@@ -402,7 +482,11 @@ const columnAdvancedPipeline = [
|
|
402
482
|
initAdvancedVSeed,
|
403
483
|
autoMeasures,
|
404
484
|
autoDimensions,
|
405
|
-
|
485
|
+
pivotAdapter([
|
486
|
+
reshapeTo2D1M
|
487
|
+
], [
|
488
|
+
pivotReshapeTo2D1M
|
489
|
+
]),
|
406
490
|
encodingXY,
|
407
491
|
vchartBaseConfig,
|
408
492
|
vchartTheme
|
@@ -411,7 +495,11 @@ const columnParallelAdvancedPipeline = [
|
|
411
495
|
initAdvancedVSeed,
|
412
496
|
autoMeasures,
|
413
497
|
autoDimensions,
|
414
|
-
|
498
|
+
pivotAdapter([
|
499
|
+
reshapeTo2D1M
|
500
|
+
], [
|
501
|
+
pivotReshapeTo2D1M
|
502
|
+
]),
|
415
503
|
encodingXY,
|
416
504
|
vchartBaseConfig,
|
417
505
|
vchartTheme
|
@@ -420,7 +508,11 @@ const columnPercentAdvancedPipeline = [
|
|
420
508
|
initAdvancedVSeed,
|
421
509
|
autoMeasures,
|
422
510
|
autoDimensions,
|
423
|
-
|
511
|
+
pivotAdapter([
|
512
|
+
reshapeTo2D1M
|
513
|
+
], [
|
514
|
+
pivotReshapeTo2D1M
|
515
|
+
]),
|
424
516
|
encodingXY,
|
425
517
|
vchartBaseConfig,
|
426
518
|
vchartTheme
|
@@ -429,7 +521,11 @@ const areaAdvancedPipeline = [
|
|
429
521
|
initAdvancedVSeed,
|
430
522
|
autoMeasures,
|
431
523
|
autoDimensions,
|
432
|
-
|
524
|
+
pivotAdapter([
|
525
|
+
reshapeTo2D1M
|
526
|
+
], [
|
527
|
+
pivotReshapeTo2D1M
|
528
|
+
]),
|
433
529
|
encodingXY,
|
434
530
|
vchartBaseConfig,
|
435
531
|
vchartTheme
|
@@ -438,7 +534,11 @@ const areaPercentAdvancedPipeline = [
|
|
438
534
|
initAdvancedVSeed,
|
439
535
|
autoMeasures,
|
440
536
|
autoDimensions,
|
441
|
-
|
537
|
+
pivotAdapter([
|
538
|
+
reshapeTo2D1M
|
539
|
+
], [
|
540
|
+
pivotReshapeTo2D1M
|
541
|
+
]),
|
442
542
|
encodingXY,
|
443
543
|
vchartBaseConfig,
|
444
544
|
vchartTheme
|
@@ -452,6 +552,28 @@ const dataset_dataset = (spec, context)=>{
|
|
452
552
|
}
|
453
553
|
};
|
454
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
|
+
});
|
455
577
|
const initColumn = (spec, context)=>{
|
456
578
|
const result = {
|
457
579
|
...spec
|
@@ -488,7 +610,7 @@ const initBarParallel = (spec, context)=>{
|
|
488
610
|
};
|
489
611
|
const { advancedVSeed } = context;
|
490
612
|
const { encoding, datasetReshapeInfo } = advancedVSeed;
|
491
|
-
const { unfoldInfo } = datasetReshapeInfo;
|
613
|
+
const { unfoldInfo } = datasetReshapeInfo[0];
|
492
614
|
if (!encoding[0].y || !encoding[0].x || !encoding[0].group) return result;
|
493
615
|
result.type = 'bar';
|
494
616
|
result.direction = 'horizontal';
|
@@ -537,7 +659,7 @@ const initColumnParallel = (spec, context)=>{
|
|
537
659
|
};
|
538
660
|
const { advancedVSeed } = context;
|
539
661
|
const { encoding, datasetReshapeInfo } = advancedVSeed;
|
540
|
-
const { unfoldInfo } = datasetReshapeInfo;
|
662
|
+
const { unfoldInfo } = datasetReshapeInfo[0];
|
541
663
|
if (!encoding[0].y || !encoding[0].x || !encoding[0].group) return result;
|
542
664
|
result.type = 'bar';
|
543
665
|
result.direction = 'vertical';
|
@@ -550,6 +672,21 @@ const initColumnParallel = (spec, context)=>{
|
|
550
672
|
result.padding = 0;
|
551
673
|
return result;
|
552
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
|
+
};
|
553
690
|
const xBand = (spec)=>{
|
554
691
|
const result = {
|
555
692
|
...spec
|
@@ -575,7 +712,9 @@ const xLinear = (spec)=>{
|
|
575
712
|
{
|
576
713
|
visible: true,
|
577
714
|
type: 'linear',
|
578
|
-
orient: 'bottom'
|
715
|
+
orient: 'bottom',
|
716
|
+
nice: true,
|
717
|
+
zero: true
|
579
718
|
}
|
580
719
|
];
|
581
720
|
return result;
|
@@ -605,7 +744,9 @@ const yLinear = (spec)=>{
|
|
605
744
|
{
|
606
745
|
visible: true,
|
607
746
|
type: 'linear',
|
608
|
-
orient: 'left'
|
747
|
+
orient: 'left',
|
748
|
+
nice: true,
|
749
|
+
zero: true
|
609
750
|
}
|
610
751
|
];
|
611
752
|
return result;
|
@@ -684,13 +825,41 @@ const legend_legend = (spec, context)=>{
|
|
684
825
|
};
|
685
826
|
return result;
|
686
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
|
+
};
|
687
856
|
const color_color = (spec, context)=>{
|
688
857
|
const result = {
|
689
858
|
...spec
|
690
859
|
};
|
691
860
|
const { advancedVSeed } = context;
|
692
861
|
const { datasetReshapeInfo } = advancedVSeed;
|
693
|
-
const { unfoldInfo } = datasetReshapeInfo;
|
862
|
+
const { unfoldInfo } = datasetReshapeInfo[0];
|
694
863
|
const baseConfig = advancedVSeed.baseConfig.vchart;
|
695
864
|
if (!baseConfig || !baseConfig.color) return result;
|
696
865
|
const { color } = baseConfig;
|
@@ -703,7 +872,82 @@ const color_color = (spec, context)=>{
|
|
703
872
|
};
|
704
873
|
return result;
|
705
874
|
};
|
706
|
-
const
|
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 = [
|
707
951
|
initLine,
|
708
952
|
color_color,
|
709
953
|
background_backgroundColor,
|
@@ -714,7 +958,26 @@ const lineSpecPipeline = [
|
|
714
958
|
tooltip_tooltip,
|
715
959
|
legend_legend
|
716
960
|
];
|
717
|
-
const
|
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 = [
|
718
981
|
initColumn,
|
719
982
|
color_color,
|
720
983
|
background_backgroundColor,
|
@@ -725,7 +988,26 @@ const columnSpecPipeline = [
|
|
725
988
|
tooltip_tooltip,
|
726
989
|
legend_legend
|
727
990
|
];
|
728
|
-
const
|
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 = [
|
729
1011
|
initColumnParallel,
|
730
1012
|
color_color,
|
731
1013
|
background_backgroundColor,
|
@@ -736,7 +1018,26 @@ const columnParallelSpecPipeline = [
|
|
736
1018
|
tooltip_tooltip,
|
737
1019
|
legend_legend
|
738
1020
|
];
|
739
|
-
const
|
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 = [
|
740
1041
|
initColumn,
|
741
1042
|
color_color,
|
742
1043
|
background_backgroundColor,
|
@@ -748,7 +1049,27 @@ const columnPercentSpecPipeline = [
|
|
748
1049
|
tooltip_tooltip,
|
749
1050
|
legend_legend
|
750
1051
|
];
|
751
|
-
const
|
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 = [
|
752
1073
|
initBar,
|
753
1074
|
color_color,
|
754
1075
|
background_backgroundColor,
|
@@ -759,7 +1080,26 @@ const barSpecPipeline = [
|
|
759
1080
|
tooltip_tooltip,
|
760
1081
|
legend_legend
|
761
1082
|
];
|
762
|
-
const
|
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 = [
|
763
1103
|
initBarParallel,
|
764
1104
|
color_color,
|
765
1105
|
background_backgroundColor,
|
@@ -770,7 +1110,26 @@ const barParallelSpecPipeline = [
|
|
770
1110
|
tooltip_tooltip,
|
771
1111
|
legend_legend
|
772
1112
|
];
|
773
|
-
const
|
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 = [
|
774
1133
|
initBar,
|
775
1134
|
color_color,
|
776
1135
|
background_backgroundColor,
|
@@ -782,7 +1141,27 @@ const barPercentSpecPipeline = [
|
|
782
1141
|
tooltip_tooltip,
|
783
1142
|
legend_legend
|
784
1143
|
];
|
785
|
-
const
|
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 = [
|
786
1165
|
initArea,
|
787
1166
|
color_color,
|
788
1167
|
background_backgroundColor,
|
@@ -794,7 +1173,27 @@ const areaSpecPipeline = [
|
|
794
1173
|
tooltip_tooltip,
|
795
1174
|
legend_legend
|
796
1175
|
];
|
797
|
-
const
|
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 = [
|
798
1197
|
initArea,
|
799
1198
|
color_color,
|
800
1199
|
background_backgroundColor,
|
@@ -806,15 +1205,26 @@ const areaPercentSpecPipeline = [
|
|
806
1205
|
tooltip_tooltip,
|
807
1206
|
legend_legend
|
808
1207
|
];
|
809
|
-
const
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
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
|
+
];
|
818
1228
|
const buildAdvanced = (builder)=>{
|
819
1229
|
const { chartType } = builder.vseed;
|
820
1230
|
if (!chartType) throw new Error('chartType is nil in buildAdvanced');
|
@@ -1083,10 +1493,11 @@ const zUnfoldInfo = z.object({
|
|
1083
1493
|
colorItems: z.array(z.string()),
|
1084
1494
|
groupName: z.string()
|
1085
1495
|
});
|
1086
|
-
const zDatasetReshapeInfo = z.object({
|
1496
|
+
const zDatasetReshapeInfo = z.array(z.object({
|
1497
|
+
id: z.string(),
|
1087
1498
|
foldInfo: zFoldInfo,
|
1088
1499
|
unfoldInfo: zUnfoldInfo
|
1089
|
-
});
|
1500
|
+
}));
|
1090
1501
|
const zEncoding = z.array(z.object({
|
1091
1502
|
x: z.array(z.string()).optional(),
|
1092
1503
|
y: z.array(z.string()).optional(),
|