@visactor/vseed 0.0.13 → 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/index.js CHANGED
@@ -266,30 +266,40 @@ const FoldMeasureName = '__MeaName__';
266
266
  const FoldMeasureValue = '__MeaValue__';
267
267
  const FoldMeasureId = '__MeaId__';
268
268
  const UnfoldDimensionGroup = '__DimGroup__';
269
+ const UnfoldDimensionGroupId = '__DimGroupID__';
269
270
  const Separator = '-';
270
271
  const ORIGINAL_DATA = '__OriginalData__';
271
- const unfoldDimensions = (dataset, dimensions, measures, unfoldStartIndex = 0, foldGroupName = UnfoldDimensionGroup, dimensionsSeparator = Separator)=>{
272
+ const unfoldDimensions = (dataset, dimensions, measures, unfoldStartIndex = 0, unfoldGroupName = UnfoldDimensionGroup, unfoldGroupId = UnfoldDimensionGroupId, foldMeasureId = FoldMeasureId, dimensionsSeparator = Separator)=>{
272
273
  if (unfoldStartIndex < 0 || unfoldStartIndex >= dimensions.length) throw new Error('unfoldStartIndex is out of range');
273
274
  const dimensionsToBeUnfolded = dimensions.slice(unfoldStartIndex);
274
275
  const unfoldInfo = {
275
- groupName: foldGroupName,
276
- colorItems: []
276
+ groupName: unfoldGroupName,
277
+ groupId: unfoldGroupId,
278
+ colorItems: [],
279
+ colorIdMap: {}
277
280
  };
278
281
  if (0 === dimensions.length || 0 === measures.length) return {
279
282
  dataset,
280
283
  unfoldInfo: {
281
- groupName: foldGroupName,
282
- colorItems: []
284
+ groupName: unfoldGroupName,
285
+ groupId: unfoldGroupId,
286
+ colorItems: [],
287
+ colorIdMap: {}
283
288
  }
284
289
  };
285
290
  const colorItems = [];
291
+ const colorMap = {};
286
292
  for(let i = 0; i < dataset.length; i++){
287
293
  const datum = dataset[i];
288
- const colorItem = generateDimGroupName(dimensionsToBeUnfolded, datum, dimensionsSeparator);
289
- datum[foldGroupName] = colorItem;
290
- colorItems.push(colorItem);
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;
291
300
  }
292
301
  unfoldInfo.colorItems = unique(colorItems);
302
+ unfoldInfo.colorIdMap = colorMap;
293
303
  return {
294
304
  dataset,
295
305
  unfoldInfo
@@ -315,7 +325,7 @@ const foldMeasures = (dataset, measures, measureId = FoldMeasureId, measureName
315
325
  const { id, alias } = measure;
316
326
  datum[id] = dataset[i][id];
317
327
  datum[measureId] = id;
318
- datum[measureName] = alias;
328
+ datum[measureName] = alias || id;
319
329
  datum[measureValue] = dataset[i][id];
320
330
  foldInfo.foldMap[id] = alias;
321
331
  result[index++] = datum;
@@ -334,12 +344,14 @@ const emptyReshapeResult = {
334
344
  measureValue: ''
335
345
  },
336
346
  unfoldInfo: {
347
+ groupName: '',
348
+ groupId: '',
337
349
  colorItems: [],
338
- groupName: ''
350
+ colorIdMap: {}
339
351
  }
340
352
  };
341
353
  const dataReshapeFor2D1M = (dataset, dimensions, measures, options)=>{
342
- const { foldMeasureId = FoldMeasureId, foldMeasureName = FoldMeasureName, foldMeasureValue = FoldMeasureValue, unfoldDimensionGroup = UnfoldDimensionGroup } = options || {};
354
+ const { foldMeasureId = FoldMeasureId, foldMeasureName = FoldMeasureName, foldMeasureValue = FoldMeasureValue, unfoldDimensionGroup = UnfoldDimensionGroup, unfoldDimensionGroupId = UnfoldDimensionGroupId } = options || {};
343
355
  if (0 === dimensions.length && 0 === measures.length) return emptyReshapeResult;
344
356
  const { dataset: foldedDataset, foldInfo } = foldMeasures(dataset, measures, foldMeasureId, foldMeasureName, foldMeasureValue);
345
357
  if (0 === dimensions.length) {
@@ -359,7 +371,7 @@ const dataReshapeFor2D1M = (dataset, dimensions, measures, options)=>{
359
371
  id: foldMeasureValue,
360
372
  alias: i18n`指标值`
361
373
  }
362
- ], 1, unfoldDimensionGroup);
374
+ ], 1, unfoldDimensionGroup, unfoldDimensionGroupId, foldMeasureId);
363
375
  return {
364
376
  dataset: finalDataset,
365
377
  foldInfo,
@@ -379,7 +391,7 @@ const dataReshapeFor2D1M = (dataset, dimensions, measures, options)=>{
379
391
  id: foldMeasureValue,
380
392
  alias: i18n`指标值`
381
393
  }
382
- ], 1, unfoldDimensionGroup);
394
+ ], 1, unfoldDimensionGroup, unfoldDimensionGroupId, foldMeasureId);
383
395
  return {
384
396
  dataset: finalDataset,
385
397
  foldInfo,
@@ -397,11 +409,13 @@ const dataReshapeFor1D1M_emptyReshapeResult = {
397
409
  },
398
410
  unfoldInfo: {
399
411
  groupName: '',
400
- colorItems: []
412
+ groupId: '',
413
+ colorItems: [],
414
+ colorIdMap: {}
401
415
  }
402
416
  };
403
417
  const dataReshapeFor1D1M = (dataset, dimensions, measures, options)=>{
404
- const { foldMeasureId = FoldMeasureId, foldMeasureName = FoldMeasureName, foldMeasureValue = FoldMeasureValue, unfoldDimensionGroup = UnfoldDimensionGroup } = options || {};
418
+ const { foldMeasureId = FoldMeasureId, foldMeasureName = FoldMeasureName, foldMeasureValue = FoldMeasureValue, unfoldDimensionGroup = UnfoldDimensionGroup, unfoldDimensionGroupId = UnfoldDimensionGroupId } = options || {};
405
419
  if (0 === dimensions.length && 0 === measures.length) return dataReshapeFor1D1M_emptyReshapeResult;
406
420
  const { dataset: foldedDataset, foldInfo } = foldMeasures(dataset, measures, foldMeasureId, foldMeasureName, foldMeasureValue);
407
421
  if (0 === dimensions.length) {
@@ -416,7 +430,7 @@ const dataReshapeFor1D1M = (dataset, dimensions, measures, options)=>{
416
430
  id: foldMeasureValue,
417
431
  alias: i18n`指标值`
418
432
  }
419
- ], 0, unfoldDimensionGroup);
433
+ ], 0, unfoldDimensionGroup, unfoldDimensionGroupId, foldMeasureId);
420
434
  return {
421
435
  dataset: finalDataset,
422
436
  foldInfo,
@@ -436,7 +450,7 @@ const dataReshapeFor1D1M = (dataset, dimensions, measures, options)=>{
436
450
  id: foldMeasureValue,
437
451
  alias: i18n`指标值`
438
452
  }
439
- ], 0, unfoldDimensionGroup);
453
+ ], 0, unfoldDimensionGroup, unfoldDimensionGroupId, foldMeasureId);
440
454
  return {
441
455
  dataset: finalDataset,
442
456
  foldInfo,
@@ -576,7 +590,6 @@ const encodingXY = (advancedVSeed)=>{
576
590
  if (!datasetReshapeInfo || !dimensions) return result;
577
591
  const encoding = datasetReshapeInfo.reduce((prev, cur)=>{
578
592
  const { foldInfo, unfoldInfo } = cur;
579
- const isSingleDimension = 1 === dimensions.length;
580
593
  const isZeroDimension = 0 === dimensions.length;
581
594
  const x = [
582
595
  isZeroDimension ? foldInfo.measureName : dimensions[0].id
@@ -585,7 +598,7 @@ const encodingXY = (advancedVSeed)=>{
585
598
  foldInfo.measureValue
586
599
  ];
587
600
  const group = [
588
- isSingleDimension || isZeroDimension ? foldInfo.measureName : unfoldInfo.groupName
601
+ unfoldInfo.groupId
589
602
  ];
590
603
  const color = [
591
604
  foldInfo.measureName
@@ -614,7 +627,6 @@ const encodingYX = (advancedVSeed)=>{
614
627
  const encoding = datasetReshapeInfo.reduce((prev, cur)=>{
615
628
  const { foldInfo, unfoldInfo } = cur;
616
629
  const isZeroDimension = 0 === dimensions.length;
617
- const isSingleDimension = 1 === dimensions.length;
618
630
  const y = [
619
631
  isZeroDimension ? foldInfo.measureName : dimensions[0].id
620
632
  ];
@@ -622,7 +634,7 @@ const encodingYX = (advancedVSeed)=>{
622
634
  foldInfo.measureValue
623
635
  ];
624
636
  const group = [
625
- isSingleDimension || isZeroDimension ? foldInfo.measureName : unfoldInfo.groupName
637
+ unfoldInfo.groupId
626
638
  ];
627
639
  const color = [
628
640
  foldInfo.measureName
@@ -654,13 +666,13 @@ const encodingPolar = (advancedVSeed)=>{
654
666
  foldInfo.measureValue
655
667
  ];
656
668
  const angle = [
657
- unfoldInfo.groupName
669
+ unfoldInfo.groupId
658
670
  ];
659
671
  const group = [
660
- unfoldInfo.groupName
672
+ unfoldInfo.groupId
661
673
  ];
662
674
  const color = [
663
- unfoldInfo.groupName
675
+ unfoldInfo.groupId
664
676
  ];
665
677
  return [
666
678
  ...prev,
@@ -1645,22 +1657,27 @@ const label_label = (spec, context)=>{
1645
1657
  const { measures, datasetReshapeInfo, locale } = advancedVSeed;
1646
1658
  const baseConfig = advancedVSeed.baseConfig.vchart;
1647
1659
  if (!baseConfig || !baseConfig.label) return result;
1648
- const { measureId } = datasetReshapeInfo[0].foldInfo;
1660
+ const { measureId, measureValue } = datasetReshapeInfo[0].foldInfo;
1649
1661
  const { label } = baseConfig;
1650
1662
  const { enable } = label;
1651
1663
  result.label = {
1652
1664
  visible: enable,
1653
1665
  formatMethod: (value, datum)=>{
1654
- const id = datum[measureId];
1655
- const measure = findMeasureById(measures, id);
1656
- if (!measure) return value;
1657
- const { format = {}, autoFormat = true } = measure;
1658
- if (!isEmpty(format)) {
1659
- const formatter = createFormatter(format);
1660
- return formatter(value);
1661
- }
1662
- if (autoFormat) return autoFormatter(value, locale);
1663
- return String(value);
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(' ');
1664
1681
  }
1665
1682
  };
1666
1683
  return result;
@@ -1670,6 +1687,8 @@ const discreteLegend = (spec, context)=>{
1670
1687
  ...spec
1671
1688
  };
1672
1689
  const { advancedVSeed } = context;
1690
+ const { datasetReshapeInfo } = advancedVSeed;
1691
+ const { unfoldInfo } = datasetReshapeInfo[0];
1673
1692
  const baseConfig = advancedVSeed.baseConfig.vchart;
1674
1693
  if (!baseConfig || !baseConfig.legend) return result;
1675
1694
  const { legend } = baseConfig;
@@ -1743,6 +1762,7 @@ const discreteLegend = (spec, context)=>{
1743
1762
  }
1744
1763
  },
1745
1764
  label: {
1765
+ formatMethod: (value)=>unfoldInfo.colorIdMap[String(value)] ?? value,
1746
1766
  style: {
1747
1767
  fontSize: labelFontSize,
1748
1768
  fill: labelFontColor,
@@ -1770,6 +1790,10 @@ const pivotDiscreteLegend = (spec, context)=>{
1770
1790
  if (!baseConfig || !baseConfig.legend) return result;
1771
1791
  const { datasetReshapeInfo } = advancedVSeed;
1772
1792
  const colorItems = unique(datasetReshapeInfo.flatMap((d)=>d.unfoldInfo.colorItems));
1793
+ const colorIdMap = datasetReshapeInfo.reduce((prev, cur)=>({
1794
+ ...prev,
1795
+ ...cur.unfoldInfo.colorIdMap
1796
+ }), {});
1773
1797
  const { legend, color } = baseConfig;
1774
1798
  const { colorScheme } = color;
1775
1799
  const { enable, position = 'bottom', labelFontColor, labelFontSize = 12, labelFontWeight, maxSize, border, shapeType = 'rectRound' } = legend || {};
@@ -1844,6 +1868,7 @@ const pivotDiscreteLegend = (spec, context)=>{
1844
1868
  }
1845
1869
  },
1846
1870
  label: {
1871
+ formatMethod: (value)=>colorIdMap[String(value)] ?? value,
1847
1872
  style: {
1848
1873
  fontSize: labelFontSize,
1849
1874
  fill: labelFontColor,
@@ -1876,11 +1901,19 @@ const color_color = (spec, context)=>{
1876
1901
  if (!baseConfig || !baseConfig.color) return result;
1877
1902
  const { color } = baseConfig;
1878
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
+ });
1879
1912
  result.color = {
1880
1913
  type: 'ordinal',
1881
1914
  domain: unfoldInfo.colorItems,
1882
1915
  range: colorScheme,
1883
- specified: colorMapping
1916
+ specified: Object.fromEntries(mappingList)
1884
1917
  };
1885
1918
  return result;
1886
1919
  };
@@ -2361,8 +2394,7 @@ const lineStyle_lineStyle = (spec, context)=>{
2361
2394
  },
2362
2395
  style: {
2363
2396
  curveType: curveType,
2364
- fill: lineColor,
2365
- fillOpacity: lineColorOpacity,
2397
+ strokeOpacity: lineColorOpacity,
2366
2398
  stroke: lineColor,
2367
2399
  lineWidth: lineWidth,
2368
2400
  lineDash: lineDash
@@ -2697,7 +2729,7 @@ const annotationArea_annotationArea = (spec, context)=>{
2697
2729
  right: 'insideRight'
2698
2730
  };
2699
2731
  const markArea = annotationAreaList.flatMap((annotationArea)=>{
2700
- const { selector: selectorPoint, text = '', textPosition = 'top', textColor = '#ffffff', textFontSize = 12, textFontWeight = 400, textAlign = 'center', textBaseline = 'top', backgroundBorderColor, backgroundBorderRadius = 4, backgroundBorderWidth = 1, backgroundColor = '#191d24', backgroundPadding = 4, backgroundVisible = true, outerPadding = 0, areaColor = '#888888', areaColorOpacity = 0.15, areaBorderColor, areaBorderRadius, areaBorderWidth } = annotationArea;
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;
2701
2733
  const dataset = advancedVSeed.dataset.flat();
2702
2734
  const selectedData = dataset.filter((datum)=>selector_selector(datum, selectorPoint));
2703
2735
  return {
@@ -4188,6 +4220,8 @@ const zFoldInfo = z.object({
4188
4220
  });
4189
4221
  const zUnfoldInfo = z.object({
4190
4222
  colorItems: z.array(z.string()),
4223
+ groupId: z.string(),
4224
+ colorIdMap: z.record(z.string(), z.string()),
4191
4225
  groupName: z.string()
4192
4226
  });
4193
4227
  const zDatasetReshapeInfo = z.array(z.object({
@@ -4804,6 +4838,6 @@ const zCustomThemeConfig = z.object({
4804
4838
  });
4805
4839
  const zCustomTheme = z.record(z.string(), zCustomThemeConfig).optional();
4806
4840
  const zTheme = z.string();
4807
- export { Builder, FoldMeasureId, FoldMeasureName, FoldMeasureValue, ORIGINAL_DATA, Separator, UnfoldDimensionGroup, 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 };
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 };
4808
4842
 
4809
4843
  //# sourceMappingURL=index.js.map