@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.
@@ -19,6 +19,8 @@ export declare class Builder implements VSeedBuilder {
19
19
  };
20
20
  unfoldInfo: {
21
21
  colorItems: string[];
22
+ groupId: string;
23
+ colorIdMap: Record<string, string>;
22
24
  groupName: string;
23
25
  };
24
26
  }[];
@@ -5555,6 +5557,8 @@ export declare class Builder implements VSeedBuilder {
5555
5557
  };
5556
5558
  unfoldInfo: {
5557
5559
  colorItems: string[];
5560
+ groupId: string;
5561
+ colorIdMap: Record<string, string>;
5558
5562
  groupName: string;
5559
5563
  };
5560
5564
  }[];
@@ -8355,6 +8359,8 @@ export declare class Builder implements VSeedBuilder {
8355
8359
  };
8356
8360
  unfoldInfo: {
8357
8361
  colorItems: string[];
8362
+ groupId: string;
8363
+ colorIdMap: Record<string, string>;
8358
8364
  groupName: string;
8359
8365
  };
8360
8366
  }[];
@@ -2,5 +2,6 @@ export declare const FoldMeasureName = "__MeaName__";
2
2
  export declare const FoldMeasureValue = "__MeaValue__";
3
3
  export declare const FoldMeasureId = "__MeaId__";
4
4
  export declare const UnfoldDimensionGroup = "__DimGroup__";
5
+ export declare const UnfoldDimensionGroupId = "__DimGroupID__";
5
6
  export declare const Separator = "-";
6
7
  export declare const ORIGINAL_DATA = "__OriginalData__";
@@ -11,6 +11,7 @@ export declare const dataReshapeFor1D1M: (dataset: Dataset, dimensions: Dimensio
11
11
  foldMeasureName?: string;
12
12
  foldMeasureValue?: string;
13
13
  unfoldDimensionGroup?: string;
14
+ unfoldDimensionGroupId?: string;
14
15
  }) => {
15
16
  dataset: Dataset;
16
17
  foldInfo: FoldInfo;
@@ -11,6 +11,7 @@ export declare const dataReshapeFor2D1M: (dataset: Dataset, dimensions: Dimensio
11
11
  foldMeasureName?: string;
12
12
  foldMeasureValue?: string;
13
13
  unfoldDimensionGroup?: string;
14
+ unfoldDimensionGroupId?: string;
14
15
  }) => {
15
16
  dataset: Dataset;
16
17
  foldInfo: FoldInfo;
@@ -5,7 +5,7 @@ import type { UnfoldInfo } from '../types';
5
5
  * 展开指定的维度
6
6
  * @description 第一步: 根据指定的维度, 将多个维度展开为N个指标(取决于维值去重后的数量), 随后合并成一个维度.
7
7
  */
8
- export declare const unfoldDimensions: (dataset: Dataset, dimensions: Dimension[], measures: Measure[], unfoldStartIndex?: number, foldGroupName?: string, dimensionsSeparator?: string) => {
8
+ export declare const unfoldDimensions: (dataset: Dataset, dimensions: Dimension[], measures: Measure[], unfoldStartIndex?: number, unfoldGroupName?: string, unfoldGroupId?: string, foldMeasureId?: string, dimensionsSeparator?: string) => {
9
9
  dataset: Dataset;
10
10
  unfoldInfo: UnfoldInfo;
11
11
  };
package/dist/index.cjs CHANGED
@@ -77,6 +77,7 @@ __webpack_require__.d(__webpack_exports__, {
77
77
  registerArea: ()=>registerArea,
78
78
  findMeasureById: ()=>findMeasureById,
79
79
  zDataset: ()=>zDataset,
80
+ UnfoldDimensionGroupId: ()=>UnfoldDimensionGroupId,
80
81
  zNumFormat: ()=>zNumFormat,
81
82
  barPercentAdvancedPipeline: ()=>barPercentAdvancedPipeline,
82
83
  areaPercentAdvancedPipeline: ()=>areaPercentAdvancedPipeline,
@@ -390,30 +391,40 @@ const FoldMeasureName = '__MeaName__';
390
391
  const FoldMeasureValue = '__MeaValue__';
391
392
  const FoldMeasureId = '__MeaId__';
392
393
  const UnfoldDimensionGroup = '__DimGroup__';
394
+ const UnfoldDimensionGroupId = '__DimGroupID__';
393
395
  const Separator = '-';
394
396
  const ORIGINAL_DATA = '__OriginalData__';
395
- const unfoldDimensions = (dataset, dimensions, measures, unfoldStartIndex = 0, foldGroupName = UnfoldDimensionGroup, dimensionsSeparator = Separator)=>{
397
+ const unfoldDimensions = (dataset, dimensions, measures, unfoldStartIndex = 0, unfoldGroupName = UnfoldDimensionGroup, unfoldGroupId = UnfoldDimensionGroupId, foldMeasureId = FoldMeasureId, dimensionsSeparator = Separator)=>{
396
398
  if (unfoldStartIndex < 0 || unfoldStartIndex >= dimensions.length) throw new Error('unfoldStartIndex is out of range');
397
399
  const dimensionsToBeUnfolded = dimensions.slice(unfoldStartIndex);
398
400
  const unfoldInfo = {
399
- groupName: foldGroupName,
400
- colorItems: []
401
+ groupName: unfoldGroupName,
402
+ groupId: unfoldGroupId,
403
+ colorItems: [],
404
+ colorIdMap: {}
401
405
  };
402
406
  if (0 === dimensions.length || 0 === measures.length) return {
403
407
  dataset,
404
408
  unfoldInfo: {
405
- groupName: foldGroupName,
406
- colorItems: []
409
+ groupName: unfoldGroupName,
410
+ groupId: unfoldGroupId,
411
+ colorItems: [],
412
+ colorIdMap: {}
407
413
  }
408
414
  };
409
415
  const colorItems = [];
416
+ const colorMap = {};
410
417
  for(let i = 0; i < dataset.length; i++){
411
418
  const datum = dataset[i];
412
- const colorItem = generateDimGroupName(dimensionsToBeUnfolded, datum, dimensionsSeparator);
413
- datum[foldGroupName] = colorItem;
414
- colorItems.push(colorItem);
419
+ const colorName = generateDimGroupName(dimensionsToBeUnfolded, datum, dimensionsSeparator);
420
+ const colorId = colorName + (datum[foldMeasureId] || '');
421
+ datum[unfoldGroupName] = colorName;
422
+ datum[unfoldGroupId] = colorId;
423
+ colorItems.push(colorId);
424
+ colorMap[colorId] = colorName;
415
425
  }
416
426
  unfoldInfo.colorItems = (0, external_remeda_namespaceObject.unique)(colorItems);
427
+ unfoldInfo.colorIdMap = colorMap;
417
428
  return {
418
429
  dataset,
419
430
  unfoldInfo
@@ -439,7 +450,7 @@ const foldMeasures = (dataset, measures, measureId = FoldMeasureId, measureName
439
450
  const { id, alias } = measure;
440
451
  datum[id] = dataset[i][id];
441
452
  datum[measureId] = id;
442
- datum[measureName] = alias;
453
+ datum[measureName] = alias || id;
443
454
  datum[measureValue] = dataset[i][id];
444
455
  foldInfo.foldMap[id] = alias;
445
456
  result[index++] = datum;
@@ -458,12 +469,14 @@ const emptyReshapeResult = {
458
469
  measureValue: ''
459
470
  },
460
471
  unfoldInfo: {
472
+ groupName: '',
473
+ groupId: '',
461
474
  colorItems: [],
462
- groupName: ''
475
+ colorIdMap: {}
463
476
  }
464
477
  };
465
478
  const dataReshapeFor2D1M = (dataset, dimensions, measures, options)=>{
466
- const { foldMeasureId = FoldMeasureId, foldMeasureName = FoldMeasureName, foldMeasureValue = FoldMeasureValue, unfoldDimensionGroup = UnfoldDimensionGroup } = options || {};
479
+ const { foldMeasureId = FoldMeasureId, foldMeasureName = FoldMeasureName, foldMeasureValue = FoldMeasureValue, unfoldDimensionGroup = UnfoldDimensionGroup, unfoldDimensionGroupId = UnfoldDimensionGroupId } = options || {};
467
480
  if (0 === dimensions.length && 0 === measures.length) return emptyReshapeResult;
468
481
  const { dataset: foldedDataset, foldInfo } = foldMeasures(dataset, measures, foldMeasureId, foldMeasureName, foldMeasureValue);
469
482
  if (0 === dimensions.length) {
@@ -483,7 +496,7 @@ const dataReshapeFor2D1M = (dataset, dimensions, measures, options)=>{
483
496
  id: foldMeasureValue,
484
497
  alias: i18n`指标值`
485
498
  }
486
- ], 1, unfoldDimensionGroup);
499
+ ], 1, unfoldDimensionGroup, unfoldDimensionGroupId, foldMeasureId);
487
500
  return {
488
501
  dataset: finalDataset,
489
502
  foldInfo,
@@ -503,7 +516,7 @@ const dataReshapeFor2D1M = (dataset, dimensions, measures, options)=>{
503
516
  id: foldMeasureValue,
504
517
  alias: i18n`指标值`
505
518
  }
506
- ], 1, unfoldDimensionGroup);
519
+ ], 1, unfoldDimensionGroup, unfoldDimensionGroupId, foldMeasureId);
507
520
  return {
508
521
  dataset: finalDataset,
509
522
  foldInfo,
@@ -521,11 +534,13 @@ const dataReshapeFor1D1M_emptyReshapeResult = {
521
534
  },
522
535
  unfoldInfo: {
523
536
  groupName: '',
524
- colorItems: []
537
+ groupId: '',
538
+ colorItems: [],
539
+ colorIdMap: {}
525
540
  }
526
541
  };
527
542
  const dataReshapeFor1D1M = (dataset, dimensions, measures, options)=>{
528
- const { foldMeasureId = FoldMeasureId, foldMeasureName = FoldMeasureName, foldMeasureValue = FoldMeasureValue, unfoldDimensionGroup = UnfoldDimensionGroup } = options || {};
543
+ const { foldMeasureId = FoldMeasureId, foldMeasureName = FoldMeasureName, foldMeasureValue = FoldMeasureValue, unfoldDimensionGroup = UnfoldDimensionGroup, unfoldDimensionGroupId = UnfoldDimensionGroupId } = options || {};
529
544
  if (0 === dimensions.length && 0 === measures.length) return dataReshapeFor1D1M_emptyReshapeResult;
530
545
  const { dataset: foldedDataset, foldInfo } = foldMeasures(dataset, measures, foldMeasureId, foldMeasureName, foldMeasureValue);
531
546
  if (0 === dimensions.length) {
@@ -540,7 +555,7 @@ const dataReshapeFor1D1M = (dataset, dimensions, measures, options)=>{
540
555
  id: foldMeasureValue,
541
556
  alias: i18n`指标值`
542
557
  }
543
- ], 0, unfoldDimensionGroup);
558
+ ], 0, unfoldDimensionGroup, unfoldDimensionGroupId, foldMeasureId);
544
559
  return {
545
560
  dataset: finalDataset,
546
561
  foldInfo,
@@ -560,7 +575,7 @@ const dataReshapeFor1D1M = (dataset, dimensions, measures, options)=>{
560
575
  id: foldMeasureValue,
561
576
  alias: i18n`指标值`
562
577
  }
563
- ], 0, unfoldDimensionGroup);
578
+ ], 0, unfoldDimensionGroup, unfoldDimensionGroupId, foldMeasureId);
564
579
  return {
565
580
  dataset: finalDataset,
566
581
  foldInfo,
@@ -700,7 +715,6 @@ const encodingXY = (advancedVSeed)=>{
700
715
  if (!datasetReshapeInfo || !dimensions) return result;
701
716
  const encoding = datasetReshapeInfo.reduce((prev, cur)=>{
702
717
  const { foldInfo, unfoldInfo } = cur;
703
- const isSingleDimension = 1 === dimensions.length;
704
718
  const isZeroDimension = 0 === dimensions.length;
705
719
  const x = [
706
720
  isZeroDimension ? foldInfo.measureName : dimensions[0].id
@@ -709,7 +723,7 @@ const encodingXY = (advancedVSeed)=>{
709
723
  foldInfo.measureValue
710
724
  ];
711
725
  const group = [
712
- isSingleDimension || isZeroDimension ? foldInfo.measureName : unfoldInfo.groupName
726
+ unfoldInfo.groupId
713
727
  ];
714
728
  const color = [
715
729
  foldInfo.measureName
@@ -738,7 +752,6 @@ const encodingYX = (advancedVSeed)=>{
738
752
  const encoding = datasetReshapeInfo.reduce((prev, cur)=>{
739
753
  const { foldInfo, unfoldInfo } = cur;
740
754
  const isZeroDimension = 0 === dimensions.length;
741
- const isSingleDimension = 1 === dimensions.length;
742
755
  const y = [
743
756
  isZeroDimension ? foldInfo.measureName : dimensions[0].id
744
757
  ];
@@ -746,7 +759,7 @@ const encodingYX = (advancedVSeed)=>{
746
759
  foldInfo.measureValue
747
760
  ];
748
761
  const group = [
749
- isSingleDimension || isZeroDimension ? foldInfo.measureName : unfoldInfo.groupName
762
+ unfoldInfo.groupId
750
763
  ];
751
764
  const color = [
752
765
  foldInfo.measureName
@@ -778,13 +791,13 @@ const encodingPolar = (advancedVSeed)=>{
778
791
  foldInfo.measureValue
779
792
  ];
780
793
  const angle = [
781
- unfoldInfo.groupName
794
+ unfoldInfo.groupId
782
795
  ];
783
796
  const group = [
784
- unfoldInfo.groupName
797
+ unfoldInfo.groupId
785
798
  ];
786
799
  const color = [
787
- unfoldInfo.groupName
800
+ unfoldInfo.groupId
788
801
  ];
789
802
  return [
790
803
  ...prev,
@@ -1769,22 +1782,27 @@ const label_label = (spec, context)=>{
1769
1782
  const { measures, datasetReshapeInfo, locale } = advancedVSeed;
1770
1783
  const baseConfig = advancedVSeed.baseConfig.vchart;
1771
1784
  if (!baseConfig || !baseConfig.label) return result;
1772
- const { measureId } = datasetReshapeInfo[0].foldInfo;
1785
+ const { measureId, measureValue } = datasetReshapeInfo[0].foldInfo;
1773
1786
  const { label } = baseConfig;
1774
1787
  const { enable } = label;
1775
1788
  result.label = {
1776
1789
  visible: enable,
1777
1790
  formatMethod: (value, datum)=>{
1778
- const id = datum[measureId];
1779
- const measure = findMeasureById(measures, id);
1780
- if (!measure) return value;
1781
- const { format = {}, autoFormat = true } = measure;
1782
- if (!(0, external_remeda_namespaceObject.isEmpty)(format)) {
1783
- const formatter = createFormatter(format);
1784
- return formatter(value);
1785
- }
1786
- if (autoFormat) return autoFormatter(value, locale);
1787
- return String(value);
1791
+ const result = [];
1792
+ const formatValue = (value)=>{
1793
+ const id = datum[measureId];
1794
+ const measure = findMeasureById(measures, id);
1795
+ if (!measure) return value;
1796
+ const { format = {}, autoFormat = true } = measure;
1797
+ if (!(0, external_remeda_namespaceObject.isEmpty)(format)) {
1798
+ const formatter = createFormatter(format);
1799
+ return formatter(value);
1800
+ }
1801
+ if (autoFormat) return autoFormatter(value, locale);
1802
+ return String(value);
1803
+ };
1804
+ result.push(formatValue(datum[measureValue]));
1805
+ return result.join(' ');
1788
1806
  }
1789
1807
  };
1790
1808
  return result;
@@ -1794,6 +1812,8 @@ const discreteLegend = (spec, context)=>{
1794
1812
  ...spec
1795
1813
  };
1796
1814
  const { advancedVSeed } = context;
1815
+ const { datasetReshapeInfo } = advancedVSeed;
1816
+ const { unfoldInfo } = datasetReshapeInfo[0];
1797
1817
  const baseConfig = advancedVSeed.baseConfig.vchart;
1798
1818
  if (!baseConfig || !baseConfig.legend) return result;
1799
1819
  const { legend } = baseConfig;
@@ -1867,6 +1887,7 @@ const discreteLegend = (spec, context)=>{
1867
1887
  }
1868
1888
  },
1869
1889
  label: {
1890
+ formatMethod: (value)=>unfoldInfo.colorIdMap[String(value)] ?? value,
1870
1891
  style: {
1871
1892
  fontSize: labelFontSize,
1872
1893
  fill: labelFontColor,
@@ -1894,6 +1915,10 @@ const pivotDiscreteLegend = (spec, context)=>{
1894
1915
  if (!baseConfig || !baseConfig.legend) return result;
1895
1916
  const { datasetReshapeInfo } = advancedVSeed;
1896
1917
  const colorItems = (0, external_remeda_namespaceObject.unique)(datasetReshapeInfo.flatMap((d)=>d.unfoldInfo.colorItems));
1918
+ const colorIdMap = datasetReshapeInfo.reduce((prev, cur)=>({
1919
+ ...prev,
1920
+ ...cur.unfoldInfo.colorIdMap
1921
+ }), {});
1897
1922
  const { legend, color } = baseConfig;
1898
1923
  const { colorScheme } = color;
1899
1924
  const { enable, position = 'bottom', labelFontColor, labelFontSize = 12, labelFontWeight, maxSize, border, shapeType = 'rectRound' } = legend || {};
@@ -1968,6 +1993,7 @@ const pivotDiscreteLegend = (spec, context)=>{
1968
1993
  }
1969
1994
  },
1970
1995
  label: {
1996
+ formatMethod: (value)=>colorIdMap[String(value)] ?? value,
1971
1997
  style: {
1972
1998
  fontSize: labelFontSize,
1973
1999
  fill: labelFontColor,
@@ -2000,11 +2026,19 @@ const color_color = (spec, context)=>{
2000
2026
  if (!baseConfig || !baseConfig.color) return result;
2001
2027
  const { color } = baseConfig;
2002
2028
  const { colorScheme, colorMapping } = color;
2029
+ const mappingList = [];
2030
+ if (colorMapping) Object.entries(colorMapping).forEach(([key, value])=>{
2031
+ const idMap = Object.entries(unfoldInfo.colorIdMap).filter(([_, v])=>key === v);
2032
+ for (const [colorId] of idMap)mappingList.push([
2033
+ colorId,
2034
+ value
2035
+ ]);
2036
+ });
2003
2037
  result.color = {
2004
2038
  type: 'ordinal',
2005
2039
  domain: unfoldInfo.colorItems,
2006
2040
  range: colorScheme,
2007
- specified: colorMapping
2041
+ specified: Object.fromEntries(mappingList)
2008
2042
  };
2009
2043
  return result;
2010
2044
  };
@@ -2485,8 +2519,7 @@ const lineStyle_lineStyle = (spec, context)=>{
2485
2519
  },
2486
2520
  style: {
2487
2521
  curveType: curveType,
2488
- fill: lineColor,
2489
- fillOpacity: lineColorOpacity,
2522
+ strokeOpacity: lineColorOpacity,
2490
2523
  stroke: lineColor,
2491
2524
  lineWidth: lineWidth,
2492
2525
  lineDash: lineDash
@@ -2821,7 +2854,7 @@ const annotationArea_annotationArea = (spec, context)=>{
2821
2854
  right: 'insideRight'
2822
2855
  };
2823
2856
  const markArea = annotationAreaList.flatMap((annotationArea)=>{
2824
- 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;
2857
+ 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;
2825
2858
  const dataset = advancedVSeed.dataset.flat();
2826
2859
  const selectedData = dataset.filter((datum)=>selector_selector(datum, selectorPoint));
2827
2860
  return {
@@ -4313,6 +4346,8 @@ const zFoldInfo = external_zod_namespaceObject.z.object({
4313
4346
  });
4314
4347
  const zUnfoldInfo = external_zod_namespaceObject.z.object({
4315
4348
  colorItems: external_zod_namespaceObject.z.array(external_zod_namespaceObject.z.string()),
4349
+ groupId: external_zod_namespaceObject.z.string(),
4350
+ colorIdMap: external_zod_namespaceObject.z.record(external_zod_namespaceObject.z.string(), external_zod_namespaceObject.z.string()),
4316
4351
  groupName: external_zod_namespaceObject.z.string()
4317
4352
  });
4318
4353
  const zDatasetReshapeInfo = external_zod_namespaceObject.z.array(external_zod_namespaceObject.z.object({
@@ -4936,6 +4971,7 @@ exports.FoldMeasureValue = __webpack_exports__.FoldMeasureValue;
4936
4971
  exports.ORIGINAL_DATA = __webpack_exports__.ORIGINAL_DATA;
4937
4972
  exports.Separator = __webpack_exports__.Separator;
4938
4973
  exports.UnfoldDimensionGroup = __webpack_exports__.UnfoldDimensionGroup;
4974
+ exports.UnfoldDimensionGroupId = __webpack_exports__.UnfoldDimensionGroupId;
4939
4975
  exports.areaAdvancedPipeline = __webpack_exports__.areaAdvancedPipeline;
4940
4976
  exports.areaPercentAdvancedPipeline = __webpack_exports__.areaPercentAdvancedPipeline;
4941
4977
  exports.areaPercentSpecPipeline = __webpack_exports__.areaPercentSpecPipeline;
@@ -5035,6 +5071,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
5035
5071
  "ORIGINAL_DATA",
5036
5072
  "Separator",
5037
5073
  "UnfoldDimensionGroup",
5074
+ "UnfoldDimensionGroupId",
5038
5075
  "areaAdvancedPipeline",
5039
5076
  "areaPercentAdvancedPipeline",
5040
5077
  "areaPercentSpecPipeline",