@visactor/vseed 0.4.24 → 0.4.26

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 (145) hide show
  1. package/dist/cjs/index.cjs +2 -2
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/esm/pipeline/advanced/chart/pipes/annotation/annotation.js +2 -1
  4. package/dist/esm/pipeline/advanced/chart/pipes/annotation/annotation.js.map +1 -1
  5. package/dist/esm/pipeline/advanced/chart/pipes/config/column.js +1 -0
  6. package/dist/esm/pipeline/advanced/chart/pipes/config/column.js.map +1 -1
  7. package/dist/esm/pipeline/advanced/chart/pipes/config/line.js +1 -0
  8. package/dist/esm/pipeline/advanced/chart/pipes/config/line.js.map +1 -1
  9. package/dist/esm/pipeline/spec/chart/pipeline/area.js +5 -1
  10. package/dist/esm/pipeline/spec/chart/pipeline/area.js.map +1 -1
  11. package/dist/esm/pipeline/spec/chart/pipeline/areaPercent.js +3 -1
  12. package/dist/esm/pipeline/spec/chart/pipeline/areaPercent.js.map +1 -1
  13. package/dist/esm/pipeline/spec/chart/pipeline/bar.js +5 -1
  14. package/dist/esm/pipeline/spec/chart/pipeline/bar.js.map +1 -1
  15. package/dist/esm/pipeline/spec/chart/pipeline/barParallel.js +5 -1
  16. package/dist/esm/pipeline/spec/chart/pipeline/barParallel.js.map +1 -1
  17. package/dist/esm/pipeline/spec/chart/pipeline/barPercent.js +3 -1
  18. package/dist/esm/pipeline/spec/chart/pipeline/barPercent.js.map +1 -1
  19. package/dist/esm/pipeline/spec/chart/pipeline/column.js +5 -1
  20. package/dist/esm/pipeline/spec/chart/pipeline/column.js.map +1 -1
  21. package/dist/esm/pipeline/spec/chart/pipeline/columnParallel.js +5 -1
  22. package/dist/esm/pipeline/spec/chart/pipeline/columnParallel.js.map +1 -1
  23. package/dist/esm/pipeline/spec/chart/pipeline/columnPercent.js +3 -1
  24. package/dist/esm/pipeline/spec/chart/pipeline/columnPercent.js.map +1 -1
  25. package/dist/esm/pipeline/spec/chart/pipeline/line.js +5 -1
  26. package/dist/esm/pipeline/spec/chart/pipeline/line.js.map +1 -1
  27. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationDifferenceLine.d.ts +2 -0
  28. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationDifferenceLine.js +218 -0
  29. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationDifferenceLine.js.map +1 -0
  30. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationDifferenceLineCommon.d.ts +42 -0
  31. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationDifferenceLineCommon.js +213 -0
  32. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationDifferenceLineCommon.js.map +1 -0
  33. package/dist/esm/pipeline/spec/chart/pipes/annotation/index.d.ts +1 -0
  34. package/dist/esm/pipeline/spec/chart/pipes/annotation/index.js +1 -0
  35. package/dist/esm/pipeline/spec/chart/pipes/region/index.d.ts +1 -0
  36. package/dist/esm/pipeline/spec/chart/pipes/region/index.js +1 -0
  37. package/dist/esm/pipeline/spec/chart/pipes/region/regionPadding.d.ts +2 -0
  38. package/dist/esm/pipeline/spec/chart/pipes/region/regionPadding.js +20 -0
  39. package/dist/esm/pipeline/spec/chart/pipes/region/regionPadding.js.map +1 -0
  40. package/dist/esm/theme/common/annotaion.d.ts +6 -1
  41. package/dist/esm/theme/common/annotaion.js +18 -1
  42. package/dist/esm/theme/common/annotaion.js.map +1 -1
  43. package/dist/esm/theme/dark/area.d.ts +2 -0
  44. package/dist/esm/theme/dark/bar.d.ts +3 -0
  45. package/dist/esm/theme/dark/boxPlot.d.ts +1 -0
  46. package/dist/esm/theme/dark/column.d.ts +3 -0
  47. package/dist/esm/theme/dark/dualAxis.d.ts +1 -0
  48. package/dist/esm/theme/dark/histogram.d.ts +1 -0
  49. package/dist/esm/theme/dark/line.d.ts +1 -0
  50. package/dist/esm/theme/dark/race.d.ts +3 -0
  51. package/dist/esm/theme/dark/raceLine.d.ts +1 -0
  52. package/dist/esm/theme/dark/scatter.d.ts +1 -0
  53. package/dist/esm/theme/light/area.d.ts +2 -0
  54. package/dist/esm/theme/light/bar.d.ts +3 -0
  55. package/dist/esm/theme/light/boxPlot.d.ts +1 -0
  56. package/dist/esm/theme/light/column.d.ts +3 -0
  57. package/dist/esm/theme/light/dualAxis.d.ts +1 -0
  58. package/dist/esm/theme/light/histogram.d.ts +1 -0
  59. package/dist/esm/theme/light/line.d.ts +1 -0
  60. package/dist/esm/theme/light/race.d.ts +3 -0
  61. package/dist/esm/theme/light/raceLine.d.ts +1 -0
  62. package/dist/esm/theme/light/scatter.d.ts +1 -0
  63. package/dist/esm/theme/tokenTheme.js +3 -0
  64. package/dist/esm/theme/tokenTheme.js.map +1 -1
  65. package/dist/esm/types/chartType/area/area.d.ts +11 -1
  66. package/dist/esm/types/chartType/area/zArea.d.ts +309 -0
  67. package/dist/esm/types/chartType/area/zArea.js +3 -1
  68. package/dist/esm/types/chartType/area/zArea.js.map +1 -1
  69. package/dist/esm/types/chartType/areaPercent/areaPercent.d.ts +6 -1
  70. package/dist/esm/types/chartType/areaPercent/zAreaPercent.d.ts +6 -0
  71. package/dist/esm/types/chartType/areaPercent/zAreaPercent.js +2 -1
  72. package/dist/esm/types/chartType/areaPercent/zAreaPercent.js.map +1 -1
  73. package/dist/esm/types/chartType/bar/bar.d.ts +11 -2
  74. package/dist/esm/types/chartType/bar/zBar.d.ts +309 -0
  75. package/dist/esm/types/chartType/bar/zBar.js +3 -1
  76. package/dist/esm/types/chartType/bar/zBar.js.map +1 -1
  77. package/dist/esm/types/chartType/barParallel/barParallel.d.ts +10 -1
  78. package/dist/esm/types/chartType/barParallel/zBarParallel.d.ts +309 -0
  79. package/dist/esm/types/chartType/barParallel/zBarParallel.js +3 -1
  80. package/dist/esm/types/chartType/barParallel/zBarParallel.js.map +1 -1
  81. package/dist/esm/types/chartType/barPercent/barPercent.d.ts +6 -1
  82. package/dist/esm/types/chartType/barPercent/zBarPercent.d.ts +6 -0
  83. package/dist/esm/types/chartType/barPercent/zBarPercent.js +2 -1
  84. package/dist/esm/types/chartType/barPercent/zBarPercent.js.map +1 -1
  85. package/dist/esm/types/chartType/column/column.d.ts +10 -1
  86. package/dist/esm/types/chartType/column/zColumn.d.ts +309 -0
  87. package/dist/esm/types/chartType/column/zColumn.js +3 -1
  88. package/dist/esm/types/chartType/column/zColumn.js.map +1 -1
  89. package/dist/esm/types/chartType/columnParallel/columnParallel.d.ts +10 -1
  90. package/dist/esm/types/chartType/columnParallel/zColumnParallel.d.ts +309 -0
  91. package/dist/esm/types/chartType/columnParallel/zColumnParallel.js +3 -1
  92. package/dist/esm/types/chartType/columnParallel/zColumnParallel.js.map +1 -1
  93. package/dist/esm/types/chartType/columnPercent/columnPercent.d.ts +6 -1
  94. package/dist/esm/types/chartType/columnPercent/zColumnPercent.d.ts +6 -0
  95. package/dist/esm/types/chartType/columnPercent/zColumnPercent.js +2 -1
  96. package/dist/esm/types/chartType/columnPercent/zColumnPercent.js.map +1 -1
  97. package/dist/esm/types/chartType/line/line.d.ts +11 -1
  98. package/dist/esm/types/chartType/line/zLine.d.ts +309 -0
  99. package/dist/esm/types/chartType/line/zLine.js +3 -1
  100. package/dist/esm/types/chartType/line/zLine.js.map +1 -1
  101. package/dist/esm/types/properties/annotation/annotation.d.ts +303 -0
  102. package/dist/esm/types/properties/annotation/annotation.js +3 -1
  103. package/dist/esm/types/properties/annotation/annotation.js.map +1 -1
  104. package/dist/esm/types/properties/annotation/annotationDifferenceLine.d.ts +51 -0
  105. package/dist/esm/types/properties/annotation/annotationDifferenceLine.js +0 -0
  106. package/dist/esm/types/properties/annotation/index.d.ts +2 -0
  107. package/dist/esm/types/properties/annotation/index.js +1 -0
  108. package/dist/esm/types/properties/annotation/zAnnotationDifferenceLine.d.ts +294 -0
  109. package/dist/esm/types/properties/annotation/zAnnotationDifferenceLine.js +29 -0
  110. package/dist/esm/types/properties/annotation/zAnnotationDifferenceLine.js.map +1 -0
  111. package/dist/esm/types/properties/config/annotation/annotation.d.ts +2 -0
  112. package/dist/esm/types/properties/config/annotation/zAnnotation.d.ts +12 -0
  113. package/dist/esm/types/properties/config/annotation/zAnnotation.js +10 -2
  114. package/dist/esm/types/properties/config/annotation/zAnnotation.js.map +1 -1
  115. package/dist/esm/types/properties/config/area.d.ts +24 -0
  116. package/dist/esm/types/properties/config/area.js +2 -0
  117. package/dist/esm/types/properties/config/area.js.map +1 -1
  118. package/dist/esm/types/properties/config/bar.d.ts +36 -0
  119. package/dist/esm/types/properties/config/bar.js +2 -0
  120. package/dist/esm/types/properties/config/bar.js.map +1 -1
  121. package/dist/esm/types/properties/config/boxplot.d.ts +6 -0
  122. package/dist/esm/types/properties/config/column.d.ts +36 -0
  123. package/dist/esm/types/properties/config/column.js +2 -0
  124. package/dist/esm/types/properties/config/column.js.map +1 -1
  125. package/dist/esm/types/properties/config/config.d.ts +180 -0
  126. package/dist/esm/types/properties/config/dualAxis.d.ts +6 -0
  127. package/dist/esm/types/properties/config/histogram.d.ts +6 -0
  128. package/dist/esm/types/properties/config/line.d.ts +12 -0
  129. package/dist/esm/types/properties/config/line.js +2 -0
  130. package/dist/esm/types/properties/config/line.js.map +1 -1
  131. package/dist/esm/types/properties/config/race.d.ts +48 -0
  132. package/dist/esm/types/properties/config/scatter.d.ts +6 -0
  133. package/dist/esm/types/properties/index.d.ts +1 -0
  134. package/dist/esm/types/properties/index.js +1 -0
  135. package/dist/esm/types/properties/regionPadding/index.d.ts +2 -0
  136. package/dist/esm/types/properties/regionPadding/index.js +1 -0
  137. package/dist/esm/types/properties/regionPadding/regionPadding.d.ts +6 -0
  138. package/dist/esm/types/properties/regionPadding/regionPadding.js +0 -0
  139. package/dist/esm/types/properties/regionPadding/zRegionPadding.d.ts +7 -0
  140. package/dist/esm/types/properties/regionPadding/zRegionPadding.js +11 -0
  141. package/dist/esm/types/properties/regionPadding/zRegionPadding.js.map +1 -0
  142. package/dist/esm/types/properties/theme/customTheme.d.ts +360 -0
  143. package/dist/umd/index.js +560 -6
  144. package/dist/umd/index.js.map +1 -1
  145. package/package.json +1 -1
@@ -0,0 +1,218 @@
1
+ import { ANNOTATION_Z_INDEX } from "../../../../utils/constant.js";
2
+ import { buildDifferenceCoordinateDatum, buildDifferenceText, getDifferenceLineStackResolveMode, getRuntimeDifferenceValue, inferDifferenceBracketDirection, inferDifferenceConnectDirection, resolveDifferenceAnchor, usesDifferenceLineElementStackEnd } from "./annotationDifferenceLineCommon.js";
3
+ const DEFAULT_LINE_COLOR = '#BCC1CB';
4
+ const DEFAULT_TEXT_COLOR = '#ffffff';
5
+ const DEFAULT_TEXT_BACKGROUND_COLOR = '#BCC1CB';
6
+ const DEFAULT_TEXT_FONT_SIZE = 12;
7
+ const DEFAULT_EXPAND_DISTANCE = 24;
8
+ const DEFAULT_LINE_WIDTH = 2;
9
+ const DEFAULT_CORNER_RADIUS = 4;
10
+ const DEFAULT_LABEL_PADDING = 4;
11
+ const DEFAULT_END_SYMBOL_SIZE = 12;
12
+ const DEFAULT_END_SYMBOL_REF_X = -4;
13
+ const DEFAULT_BRACKET_EXPAND_DISTANCE = 80;
14
+ const DEFAULT_BRACKET_LINE_DASH = [
15
+ 2,
16
+ 2
17
+ ];
18
+ const getDifferenceLinePath = (index, total)=>1 === total ? 'annotationDifferenceLine' : `annotationDifferenceLine[${index}]`;
19
+ const assertDifferenceLineConfig = (value, path)=>{
20
+ if ('object' != typeof value || null === value || Array.isArray(value)) throw new Error(`${path} must be an object`);
21
+ const start = value.start;
22
+ if ('object' != typeof start || null === start || Array.isArray(start)) throw new Error(`${path}.start is required`);
23
+ if (null == start.selector) throw new Error(`${path}.start.selector is required`);
24
+ const end = value.end;
25
+ if ('object' != typeof end || null === end || Array.isArray(end)) throw new Error(`${path}.end is required`);
26
+ if (null == end.selector) throw new Error(`${path}.end.selector is required`);
27
+ };
28
+ const annotationDifferenceLine_annotationDifferenceLine = (spec, context)=>{
29
+ const { advancedVSeed, vseed } = context;
30
+ const annotationDifferenceLine = advancedVSeed.annotation?.annotationDifferenceLine;
31
+ if (!annotationDifferenceLine) return spec;
32
+ const theme = advancedVSeed.config?.[vseed.chartType]?.annotation?.annotationDifferenceLine;
33
+ const annotationDifferenceLineList = Array.isArray(annotationDifferenceLine) ? annotationDifferenceLine : [
34
+ annotationDifferenceLine
35
+ ];
36
+ const dataset = advancedVSeed.dataset.flat();
37
+ const chartSpec = spec;
38
+ const stackResolveMode = getDifferenceLineStackResolveMode(vseed, advancedVSeed);
39
+ const useElementStackEnd = usesDifferenceLineElementStackEnd(vseed, advancedVSeed);
40
+ const isBracketChart = 'line' === vseed.chartType || 'area' === vseed.chartType;
41
+ const markLine = annotationDifferenceLineList.flatMap((annotationDifferenceLine, index)=>{
42
+ try {
43
+ assertDifferenceLineConfig(annotationDifferenceLine, getDifferenceLinePath(index, annotationDifferenceLineList.length));
44
+ const start = resolveDifferenceAnchor({
45
+ dataset,
46
+ selectorLabel: 'start',
47
+ selectorValue: annotationDifferenceLine.start.selector,
48
+ spec: chartSpec,
49
+ stackResolveMode,
50
+ allowSelectorFallback: !useElementStackEnd
51
+ });
52
+ const end = resolveDifferenceAnchor({
53
+ dataset,
54
+ selectorLabel: 'end',
55
+ selectorValue: annotationDifferenceLine.end.selector,
56
+ spec: chartSpec,
57
+ stackResolveMode,
58
+ allowSelectorFallback: !useElementStackEnd
59
+ });
60
+ if (!start || !end) return [];
61
+ if (start.mode !== end.mode) return [];
62
+ const usesRuntimeStackEnd = useElementStackEnd || ('column' === vseed.chartType || 'bar' === vseed.chartType) && 'element' === start.mode && 'auto' === stackResolveMode;
63
+ const useBracketStyle = isBracketChart || ('column' === vseed.chartType || 'bar' === vseed.chartType) && 'element' === start.mode && 'auto' === stackResolveMode;
64
+ const isStackedBarElementBracket = 'bar' === vseed.chartType && 'element' === start.mode && 'auto' === stackResolveMode;
65
+ const connectDirection = useBracketStyle ? isStackedBarElementBracket ? 'top' : inferDifferenceBracketDirection(start, end) : inferDifferenceConnectDirection(vseed, [
66
+ start.value,
67
+ end.value
68
+ ]);
69
+ const lineColor = annotationDifferenceLine.lineColor ?? theme?.lineColor ?? DEFAULT_LINE_COLOR;
70
+ const textColor = annotationDifferenceLine.textColor ?? theme?.textColor ?? DEFAULT_TEXT_COLOR;
71
+ const textBackgroundColor = annotationDifferenceLine.textBackgroundColor ?? theme?.textBackgroundColor ?? DEFAULT_TEXT_BACKGROUND_COLOR;
72
+ const textFontSize = annotationDifferenceLine.textFontSize ?? theme?.textFontSize ?? DEFAULT_TEXT_FONT_SIZE;
73
+ const differenceType = annotationDifferenceLine.differenceType ?? 'absolute';
74
+ const label = usesRuntimeStackEnd ? {
75
+ visible: true,
76
+ position: 'middle',
77
+ refY: 0,
78
+ formatMethod: (_markData, seriesData)=>{
79
+ try {
80
+ return buildDifferenceText(getRuntimeDifferenceValue({
81
+ anchor: start,
82
+ seriesData,
83
+ useElementStackEnd: usesRuntimeStackEnd
84
+ }), getRuntimeDifferenceValue({
85
+ anchor: end,
86
+ seriesData,
87
+ useElementStackEnd: usesRuntimeStackEnd
88
+ }), differenceType);
89
+ } catch {
90
+ return '';
91
+ }
92
+ },
93
+ style: {
94
+ fill: textColor,
95
+ fontSize: textFontSize
96
+ },
97
+ labelBackground: {
98
+ visible: true,
99
+ padding: DEFAULT_LABEL_PADDING,
100
+ style: {
101
+ fill: textBackgroundColor,
102
+ fillOpacity: 1,
103
+ stroke: lineColor,
104
+ lineWidth: 1,
105
+ cornerRadius: DEFAULT_CORNER_RADIUS
106
+ }
107
+ }
108
+ } : {
109
+ visible: true,
110
+ position: 'middle',
111
+ refY: 0,
112
+ text: buildDifferenceText(start.value, end.value, differenceType),
113
+ style: {
114
+ fill: textColor,
115
+ fontSize: textFontSize
116
+ },
117
+ labelBackground: {
118
+ visible: true,
119
+ padding: DEFAULT_LABEL_PADDING,
120
+ style: {
121
+ fill: textBackgroundColor,
122
+ fillOpacity: 1,
123
+ stroke: lineColor,
124
+ lineWidth: 1,
125
+ cornerRadius: DEFAULT_CORNER_RADIUS
126
+ }
127
+ }
128
+ };
129
+ return [
130
+ {
131
+ type: 'type-step',
132
+ autoRange: true,
133
+ zIndex: ANNOTATION_Z_INDEX,
134
+ connectDirection,
135
+ expandDistance: useBracketStyle ? DEFAULT_BRACKET_EXPAND_DISTANCE : DEFAULT_EXPAND_DISTANCE,
136
+ coordinates: (seriesData, relativeSeries)=>{
137
+ try {
138
+ return [
139
+ buildDifferenceCoordinateDatum({
140
+ anchor: start,
141
+ seriesData,
142
+ relativeSeries,
143
+ useElementStackEnd: usesRuntimeStackEnd
144
+ }),
145
+ buildDifferenceCoordinateDatum({
146
+ anchor: end,
147
+ seriesData,
148
+ relativeSeries,
149
+ useElementStackEnd: usesRuntimeStackEnd
150
+ })
151
+ ];
152
+ } catch {
153
+ return [];
154
+ }
155
+ },
156
+ line: useBracketStyle ? {
157
+ multiSegment: true,
158
+ mainSegmentIndex: 1,
159
+ style: [
160
+ {
161
+ visible: true,
162
+ stroke: lineColor,
163
+ lineWidth: DEFAULT_LINE_WIDTH,
164
+ lineDash: DEFAULT_BRACKET_LINE_DASH
165
+ },
166
+ {
167
+ visible: true,
168
+ stroke: lineColor,
169
+ lineWidth: DEFAULT_LINE_WIDTH
170
+ },
171
+ {
172
+ visible: true,
173
+ stroke: lineColor,
174
+ lineWidth: DEFAULT_LINE_WIDTH,
175
+ lineDash: DEFAULT_BRACKET_LINE_DASH
176
+ }
177
+ ]
178
+ } : {
179
+ style: {
180
+ visible: true,
181
+ stroke: lineColor,
182
+ lineWidth: DEFAULT_LINE_WIDTH,
183
+ lineDash: [
184
+ 0
185
+ ],
186
+ cornerRadius: DEFAULT_CORNER_RADIUS
187
+ }
188
+ },
189
+ label,
190
+ startSymbol: {
191
+ visible: false
192
+ },
193
+ endSymbol: {
194
+ visible: true,
195
+ size: DEFAULT_END_SYMBOL_SIZE,
196
+ refX: DEFAULT_END_SYMBOL_REF_X,
197
+ style: {
198
+ fill: lineColor
199
+ }
200
+ }
201
+ }
202
+ ];
203
+ } catch {
204
+ return [];
205
+ }
206
+ });
207
+ const specMarkLine = chartSpec.markLine || [];
208
+ return {
209
+ ...spec,
210
+ markLine: [
211
+ ...specMarkLine,
212
+ ...markLine
213
+ ]
214
+ };
215
+ };
216
+ export { annotationDifferenceLine_annotationDifferenceLine as annotationDifferenceLine };
217
+
218
+ //# sourceMappingURL=annotationDifferenceLine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline/spec/chart/pipes/annotation/annotationDifferenceLine.js","sources":["../../../../../../../src/pipeline/spec/chart/pipes/annotation/annotationDifferenceLine.ts"],"sourcesContent":["import type { IAreaChartSpec, IBarChartSpec, ICartesianSeries, ILineChartSpec, IMarkLineSpec } from '@visactor/vchart'\nimport type { AnnotationDifferenceLine, VChartSpecPipe } from 'src/types'\nimport { ANNOTATION_Z_INDEX } from '../../../../utils/constant'\nimport {\n buildDifferenceCoordinateDatum,\n buildDifferenceText,\n getDifferenceLineStackResolveMode,\n getRuntimeDifferenceValue,\n inferDifferenceBracketDirection,\n inferDifferenceConnectDirection,\n usesDifferenceLineElementStackEnd,\n resolveDifferenceAnchor,\n} from './annotationDifferenceLineCommon'\n\nconst DEFAULT_LINE_COLOR = '#BCC1CB'\nconst DEFAULT_TEXT_COLOR = '#ffffff'\nconst DEFAULT_TEXT_BACKGROUND_COLOR = '#BCC1CB'\nconst DEFAULT_TEXT_FONT_SIZE = 12\nconst DEFAULT_EXPAND_DISTANCE = 24\nconst DEFAULT_LINE_WIDTH = 2\nconst DEFAULT_CORNER_RADIUS = 4\nconst DEFAULT_LABEL_PADDING = 4\nconst DEFAULT_END_SYMBOL_SIZE = 12\nconst DEFAULT_END_SYMBOL_REF_X = -4\nconst DEFAULT_BRACKET_EXPAND_DISTANCE = 80\nconst DEFAULT_BRACKET_LINE_DASH: [number, number] = [2, 2]\n\nconst getDifferenceLinePath = (index: number, total: number) =>\n total === 1 ? 'annotationDifferenceLine' : `annotationDifferenceLine[${index}]`\n\nconst assertDifferenceLineConfig: (value: unknown, path: string) => asserts value is AnnotationDifferenceLine = (\n value,\n path,\n) => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new Error(`${path} must be an object`)\n }\n\n const start = (value as Record<string, unknown>).start\n if (typeof start !== 'object' || start === null || Array.isArray(start)) {\n throw new Error(`${path}.start is required`)\n }\n if ((start as Record<string, unknown>).selector == null) {\n throw new Error(`${path}.start.selector is required`)\n }\n\n const end = (value as Record<string, unknown>).end\n if (typeof end !== 'object' || end === null || Array.isArray(end)) {\n throw new Error(`${path}.end is required`)\n }\n if ((end as Record<string, unknown>).selector == null) {\n throw new Error(`${path}.end.selector is required`)\n }\n}\n\nexport const annotationDifferenceLine: VChartSpecPipe = (spec, context) => {\n const { advancedVSeed, vseed } = context\n const annotationDifferenceLine = advancedVSeed.annotation?.annotationDifferenceLine\n\n if (!annotationDifferenceLine) {\n return spec\n }\n\n const theme = advancedVSeed.config?.[vseed.chartType as 'column']?.annotation?.annotationDifferenceLine\n const annotationDifferenceLineList = Array.isArray(annotationDifferenceLine)\n ? annotationDifferenceLine\n : [annotationDifferenceLine]\n const dataset = advancedVSeed.dataset.flat()\n const chartSpec = spec as IBarChartSpec | ILineChartSpec | IAreaChartSpec\n const stackResolveMode = getDifferenceLineStackResolveMode(vseed, advancedVSeed)\n const useElementStackEnd = usesDifferenceLineElementStackEnd(vseed, advancedVSeed)\n const isBracketChart = vseed.chartType === 'line' || vseed.chartType === 'area'\n\n const markLine = annotationDifferenceLineList.flatMap((annotationDifferenceLine, index) => {\n try {\n assertDifferenceLineConfig(\n annotationDifferenceLine,\n getDifferenceLinePath(index, annotationDifferenceLineList.length),\n )\n\n const start = resolveDifferenceAnchor({\n dataset,\n selectorLabel: 'start',\n selectorValue: annotationDifferenceLine.start.selector,\n spec: chartSpec,\n stackResolveMode,\n allowSelectorFallback: !useElementStackEnd,\n })\n const end = resolveDifferenceAnchor({\n dataset,\n selectorLabel: 'end',\n selectorValue: annotationDifferenceLine.end.selector,\n spec: chartSpec,\n stackResolveMode,\n allowSelectorFallback: !useElementStackEnd,\n })\n\n if (!start || !end) {\n return []\n }\n\n if (start.mode !== end.mode) {\n return []\n }\n\n const usesRuntimeStackEnd =\n useElementStackEnd ||\n ((vseed.chartType === 'column' || vseed.chartType === 'bar') &&\n start.mode === 'element' &&\n stackResolveMode === 'auto')\n const useBracketStyle =\n isBracketChart ||\n ((vseed.chartType === 'column' || vseed.chartType === 'bar') &&\n start.mode === 'element' &&\n stackResolveMode === 'auto')\n const isStackedBarElementBracket =\n vseed.chartType === 'bar' && start.mode === 'element' && stackResolveMode === 'auto'\n const connectDirection = useBracketStyle\n ? isStackedBarElementBracket\n ? 'top'\n : inferDifferenceBracketDirection(start, end)\n : inferDifferenceConnectDirection(vseed, [start.value, end.value])\n\n const lineColor = annotationDifferenceLine.lineColor ?? theme?.lineColor ?? DEFAULT_LINE_COLOR\n const textColor = annotationDifferenceLine.textColor ?? theme?.textColor ?? DEFAULT_TEXT_COLOR\n const textBackgroundColor =\n annotationDifferenceLine.textBackgroundColor ?? theme?.textBackgroundColor ?? DEFAULT_TEXT_BACKGROUND_COLOR\n const textFontSize = annotationDifferenceLine.textFontSize ?? theme?.textFontSize ?? DEFAULT_TEXT_FONT_SIZE\n const differenceType = annotationDifferenceLine.differenceType ?? 'absolute'\n\n const label = usesRuntimeStackEnd\n ? {\n visible: true,\n position: 'middle',\n refY: 0,\n formatMethod: (_markData: any[], seriesData: any[]) => {\n try {\n return buildDifferenceText(\n getRuntimeDifferenceValue({\n anchor: start,\n seriesData,\n useElementStackEnd: usesRuntimeStackEnd,\n }),\n getRuntimeDifferenceValue({\n anchor: end,\n seriesData,\n useElementStackEnd: usesRuntimeStackEnd,\n }),\n differenceType,\n )\n } catch {\n return ''\n }\n },\n style: {\n fill: textColor,\n fontSize: textFontSize,\n },\n labelBackground: {\n visible: true,\n padding: DEFAULT_LABEL_PADDING,\n style: {\n fill: textBackgroundColor,\n fillOpacity: 1,\n stroke: lineColor,\n lineWidth: 1,\n cornerRadius: DEFAULT_CORNER_RADIUS,\n },\n },\n }\n : {\n visible: true,\n position: 'middle',\n refY: 0,\n text: buildDifferenceText(start.value, end.value, differenceType),\n style: {\n fill: textColor,\n fontSize: textFontSize,\n },\n labelBackground: {\n visible: true,\n padding: DEFAULT_LABEL_PADDING,\n style: {\n fill: textBackgroundColor,\n fillOpacity: 1,\n stroke: lineColor,\n lineWidth: 1,\n cornerRadius: DEFAULT_CORNER_RADIUS,\n },\n },\n }\n\n return [\n {\n type: 'type-step',\n autoRange: true,\n zIndex: ANNOTATION_Z_INDEX,\n connectDirection,\n expandDistance: useBracketStyle ? DEFAULT_BRACKET_EXPAND_DISTANCE : DEFAULT_EXPAND_DISTANCE,\n coordinates: (seriesData: any[], relativeSeries: ICartesianSeries) => {\n try {\n return [\n buildDifferenceCoordinateDatum({\n anchor: start,\n seriesData,\n relativeSeries,\n useElementStackEnd: usesRuntimeStackEnd,\n }),\n buildDifferenceCoordinateDatum({\n anchor: end,\n seriesData,\n relativeSeries,\n useElementStackEnd: usesRuntimeStackEnd,\n }),\n ]\n } catch {\n return []\n }\n },\n line: useBracketStyle\n ? {\n multiSegment: true,\n mainSegmentIndex: 1,\n style: [\n {\n visible: true,\n stroke: lineColor,\n lineWidth: DEFAULT_LINE_WIDTH,\n lineDash: DEFAULT_BRACKET_LINE_DASH,\n },\n {\n visible: true,\n stroke: lineColor,\n lineWidth: DEFAULT_LINE_WIDTH,\n },\n {\n visible: true,\n stroke: lineColor,\n lineWidth: DEFAULT_LINE_WIDTH,\n lineDash: DEFAULT_BRACKET_LINE_DASH,\n },\n ],\n }\n : {\n style: {\n visible: true,\n stroke: lineColor,\n lineWidth: DEFAULT_LINE_WIDTH,\n lineDash: [0],\n cornerRadius: DEFAULT_CORNER_RADIUS,\n },\n },\n label,\n startSymbol: {\n visible: false,\n },\n endSymbol: {\n visible: true,\n size: DEFAULT_END_SYMBOL_SIZE,\n refX: DEFAULT_END_SYMBOL_REF_X,\n style: {\n fill: lineColor,\n },\n },\n } as IMarkLineSpec,\n ]\n } catch {\n return []\n }\n })\n\n const specMarkLine = (chartSpec.markLine as IMarkLineSpec[]) || []\n\n return {\n ...spec,\n markLine: [...specMarkLine, ...markLine],\n }\n}\n"],"names":["DEFAULT_LINE_COLOR","DEFAULT_TEXT_COLOR","DEFAULT_TEXT_BACKGROUND_COLOR","DEFAULT_TEXT_FONT_SIZE","DEFAULT_EXPAND_DISTANCE","DEFAULT_LINE_WIDTH","DEFAULT_CORNER_RADIUS","DEFAULT_LABEL_PADDING","DEFAULT_END_SYMBOL_SIZE","DEFAULT_END_SYMBOL_REF_X","DEFAULT_BRACKET_EXPAND_DISTANCE","DEFAULT_BRACKET_LINE_DASH","getDifferenceLinePath","index","total","assertDifferenceLineConfig","value","path","Array","Error","start","end","annotationDifferenceLine","spec","context","advancedVSeed","vseed","theme","annotationDifferenceLineList","dataset","chartSpec","stackResolveMode","getDifferenceLineStackResolveMode","useElementStackEnd","usesDifferenceLineElementStackEnd","isBracketChart","markLine","resolveDifferenceAnchor","usesRuntimeStackEnd","useBracketStyle","isStackedBarElementBracket","connectDirection","inferDifferenceBracketDirection","inferDifferenceConnectDirection","lineColor","textColor","textBackgroundColor","textFontSize","differenceType","label","_markData","seriesData","buildDifferenceText","getRuntimeDifferenceValue","ANNOTATION_Z_INDEX","relativeSeries","buildDifferenceCoordinateDatum","specMarkLine"],"mappings":";;AAcA,MAAMA,qBAAqB;AAC3B,MAAMC,qBAAqB;AAC3B,MAAMC,gCAAgC;AACtC,MAAMC,yBAAyB;AAC/B,MAAMC,0BAA0B;AAChC,MAAMC,qBAAqB;AAC3B,MAAMC,wBAAwB;AAC9B,MAAMC,wBAAwB;AAC9B,MAAMC,0BAA0B;AAChC,MAAMC,2BAA2B;AACjC,MAAMC,kCAAkC;AACxC,MAAMC,4BAA8C;IAAC;IAAG;CAAE;AAE1D,MAAMC,wBAAwB,CAACC,OAAeC,QAC5CA,AAAU,MAAVA,QAAc,6BAA6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ACAI;oCACA,oBAAoBjB;gCACtB;6BACD;wBACH,EAAE,OAAM;4BACN,OAAO,EAAE;wBACX;oBACF;oBACA,MAAMC,kBACF;wBACE,cAAc;wBACd,kBAAkB;wBAClB,OAAO;4BACL;gCACE,SAAS;gCACT,QAAQK;gCACR,WAAWvC;gCACX,UAAUM;4BACZ;4BACA;gCACE,SAAS;gCACT,QAAQiC;gCACR,WAAWvC;4BACb;4BACA;gCACE,SAAS;gCACT,QAAQuC;gCACR,WAAWvC;gCACX,UAAUM;4BACZ;yBACD;oBACH,IACA;wBACE,OAAO;4BACL,SAAS;4BACT,QAAQiC;4BACR,WAAWvC;4BACX,UAAU;gCAAC;6BAAE;4BACb,cAAcC;wBAChB;oBACF;oBACJ2C;oBACA,aAAa;wBACX,SAAS;oBACX;oBACA,WAAW;wBACT,SAAS;wBACT,MAAMzC;wBACN,MAAMC;wBACN,OAAO;4BACL,MAAMmC;wBACR;oBACF;gBACF;aACD;QACH,EAAE,OAAM;YACN,OAAO,EAAE;QACX;IACF;IAEA,MAAMa,eAAgB3B,UAAU,QAAQ,IAAwB,EAAE;IAElE,OAAO;QACL,GAAGP,IAAI;QACP,UAAU;eAAIkC;eAAiBrB;SAAS;IAC1C;AACF"}
@@ -0,0 +1,42 @@
1
+ import type { IAreaChartSpec, IBarChartSpec, ICartesianSeries, ILineChartSpec } from '@visactor/vchart';
2
+ import type { AdvancedVSeed, Datum, Selector, Selectors, VSeed } from '../../../../../types';
3
+ type DifferenceSelectorLabel = 'start' | 'end';
4
+ type DifferenceChartSpec = IBarChartSpec | ILineChartSpec | IAreaChartSpec;
5
+ export type DifferenceStackResolveMode = 'none' | 'stackTotal' | 'auto';
6
+ export type DifferenceAnchorMode = 'element' | 'stackTotal';
7
+ export type ResolvedDifferenceAnchor = {
8
+ mode: DifferenceAnchorMode;
9
+ selectorLabel: DifferenceSelectorLabel;
10
+ coordinateDatum: Datum;
11
+ matchedDatum?: Datum;
12
+ stackGroupDatum?: Datum;
13
+ bandDatum: Datum;
14
+ bandIndex?: number;
15
+ value: number;
16
+ };
17
+ export declare const getDifferenceLineStackResolveMode: (vseed: VSeed, advancedVSeed: AdvancedVSeed) => DifferenceStackResolveMode;
18
+ export declare const usesDifferenceLineElementStackEnd: (vseed: VSeed, advancedVSeed: AdvancedVSeed) => boolean;
19
+ export declare const resolveDifferenceAnchor: (options: {
20
+ dataset: Datum[];
21
+ selectorLabel: DifferenceSelectorLabel;
22
+ selectorValue: Selector | Selectors;
23
+ spec: DifferenceChartSpec;
24
+ stackResolveMode: DifferenceStackResolveMode;
25
+ allowSelectorFallback?: boolean;
26
+ }) => ResolvedDifferenceAnchor | undefined;
27
+ export declare const getStackRuntimeTotal: (runtimeMatches: Datum[]) => number | undefined;
28
+ export declare const buildDifferenceCoordinateDatum: (options: {
29
+ anchor: ResolvedDifferenceAnchor;
30
+ seriesData: Datum[];
31
+ relativeSeries: ICartesianSeries;
32
+ useElementStackEnd?: boolean;
33
+ }) => Record<string | number, any>;
34
+ export declare const getRuntimeDifferenceValue: (options: {
35
+ anchor: ResolvedDifferenceAnchor;
36
+ seriesData: Datum[];
37
+ useElementStackEnd?: boolean;
38
+ }) => number;
39
+ export declare const buildDifferenceText: (startValue: number, endValue: number, differenceType?: "absolute" | "percent") => string;
40
+ export declare const inferDifferenceConnectDirection: (vseed: VSeed, values: [number, number]) => "left" | "top" | "right" | "bottom";
41
+ export declare const inferDifferenceBracketDirection: (start: ResolvedDifferenceAnchor, end: ResolvedDifferenceAnchor) => "left" | "right";
42
+ export {};
@@ -0,0 +1,213 @@
1
+ import { isDimensionSelector, isFieldSelector, isMeasureSelector, isPartialDatumSelector, isValueSelector, selector } from "../../../../../dataSelector/index.js";
2
+ import { hasMultipleMeasureInSingleView, isBarLikeChart } from "../../../../utils/index.js";
3
+ import { isSubset } from "./utils.js";
4
+ const STACK_END_FIELD = '__VCHART_STACK_END';
5
+ const toArray = (value)=>{
6
+ if (Array.isArray(value)) return value;
7
+ return null == value ? [] : [
8
+ value
9
+ ];
10
+ };
11
+ const getDifferenceBandFields = (spec)=>toArray('horizontal' === spec.direction ? spec.yField : spec.xField);
12
+ const getDifferenceValueField = (spec)=>{
13
+ const valueField = toArray('horizontal' === spec.direction ? spec.xField : spec.yField)[0];
14
+ if (!valueField) throw new Error('annotationDifferenceLine requires a value field in the target chart spec');
15
+ return valueField;
16
+ };
17
+ const normalizeDifferenceValue = (value, selectorLabel, field)=>{
18
+ const numberValue = Number(value);
19
+ if (Number.isNaN(numberValue)) throw new Error(`annotationDifferenceLine ${selectorLabel} selector resolved to a non-numeric value on field "${field}"`);
20
+ return numberValue;
21
+ };
22
+ const buildStackGroupDatum = (datum, bandFields)=>Object.fromEntries(bandFields.map((field)=>[
23
+ field,
24
+ datum[field]
25
+ ]));
26
+ const resolveBandIndex = (dataset, bandDatum)=>{
27
+ const bandIndex = dataset.findIndex((datum)=>isSubset(bandDatum, datum));
28
+ return bandIndex >= 0 ? bandIndex : void 0;
29
+ };
30
+ const buildFallbackSelectorDatum = (selectorValue)=>{
31
+ const selectorList = Array.isArray(selectorValue) ? selectorValue : [
32
+ selectorValue
33
+ ];
34
+ const fallbackDatum = {};
35
+ for (const currentSelector of selectorList){
36
+ if (isValueSelector(currentSelector) || isFieldSelector(currentSelector)) return;
37
+ if (isMeasureSelector(currentSelector)) {
38
+ const operator = currentSelector.operator || currentSelector.op;
39
+ const selectorValues = Array.isArray(currentSelector.value) ? currentSelector.value : [
40
+ currentSelector.value
41
+ ];
42
+ if (![
43
+ '=',
44
+ '=='
45
+ ].includes(operator) || 1 !== selectorValues.length) return;
46
+ fallbackDatum[currentSelector.field] = selectorValues[0];
47
+ continue;
48
+ }
49
+ if (isDimensionSelector(currentSelector)) {
50
+ const operator = currentSelector.operator || currentSelector.op;
51
+ const selectorValues = Array.isArray(currentSelector.value) ? currentSelector.value : [
52
+ currentSelector.value
53
+ ];
54
+ if ('in' !== operator || 1 !== selectorValues.length) return;
55
+ fallbackDatum[currentSelector.field] = selectorValues[0];
56
+ continue;
57
+ }
58
+ if (isPartialDatumSelector(currentSelector)) {
59
+ Object.assign(fallbackDatum, currentSelector);
60
+ continue;
61
+ }
62
+ return;
63
+ }
64
+ return Object.keys(fallbackDatum).length > 0 ? fallbackDatum : void 0;
65
+ };
66
+ const inferFallbackValue = (fallbackDatum, valueField, bandFields)=>{
67
+ if (valueField in fallbackDatum) return fallbackDatum[valueField];
68
+ const numericCandidateKeys = Object.keys(fallbackDatum).filter((key)=>{
69
+ if (key === valueField || bandFields.includes(key)) return false;
70
+ return 'number' == typeof fallbackDatum[key];
71
+ });
72
+ if (1 !== numericCandidateKeys.length) return;
73
+ return fallbackDatum[numericCandidateKeys[0]];
74
+ };
75
+ const resolveFallbackAnchor = (options)=>{
76
+ const { dataset, selectorLabel, selectorValue, valueField, bandFields } = options;
77
+ const fallbackDatum = buildFallbackSelectorDatum(selectorValue);
78
+ if (!fallbackDatum) return;
79
+ const inferredValue = inferFallbackValue(fallbackDatum, valueField, bandFields);
80
+ if (void 0 === inferredValue) return;
81
+ const coordinateDatum = {
82
+ ...fallbackDatum,
83
+ [valueField]: inferredValue
84
+ };
85
+ const bandDatum = buildStackGroupDatum(coordinateDatum, bandFields);
86
+ try {
87
+ return {
88
+ mode: 'element',
89
+ selectorLabel,
90
+ coordinateDatum,
91
+ matchedDatum: fallbackDatum,
92
+ bandDatum,
93
+ bandIndex: resolveBandIndex(dataset, bandDatum),
94
+ value: normalizeDifferenceValue(inferredValue, selectorLabel, valueField)
95
+ };
96
+ } catch {
97
+ return;
98
+ }
99
+ };
100
+ const hasMixedSigns = (values)=>{
101
+ const nonZeroValues = values.filter((value)=>0 !== value);
102
+ return nonZeroValues.some((value)=>value > 0) && nonZeroValues.some((value)=>value < 0);
103
+ };
104
+ const getDifferenceLineStackResolveMode = (vseed, advancedVSeed)=>{
105
+ const hasMultipleMeasure = hasMultipleMeasureInSingleView(advancedVSeed.reshapeMeasures ?? []);
106
+ if (!hasMultipleMeasure) return 'none';
107
+ if ('column' === vseed.chartType) return 'auto';
108
+ if ('bar' === vseed.chartType) return 'auto';
109
+ return 'none';
110
+ };
111
+ const usesDifferenceLineElementStackEnd = (vseed, advancedVSeed)=>'area' === vseed.chartType && hasMultipleMeasureInSingleView(advancedVSeed.reshapeMeasures ?? []);
112
+ const resolveDifferenceAnchor = (options)=>{
113
+ const { dataset, selectorLabel, selectorValue, spec, stackResolveMode, allowSelectorFallback = true } = options;
114
+ const matches = dataset.filter((datum)=>selector(datum, selectorValue));
115
+ const valueField = getDifferenceValueField(spec);
116
+ const bandFields = getDifferenceBandFields(spec);
117
+ if (0 === matches.length) return 'none' === stackResolveMode && allowSelectorFallback ? resolveFallbackAnchor({
118
+ dataset,
119
+ selectorLabel,
120
+ selectorValue,
121
+ valueField,
122
+ bandFields
123
+ }) : void 0;
124
+ if ('none' === stackResolveMode || 'auto' === stackResolveMode && 1 === matches.length) {
125
+ if (1 !== matches.length) throw new Error(`annotationDifferenceLine ${selectorLabel} selector must resolve to exactly one datum, got ${matches.length}`);
126
+ const bandDatum = buildStackGroupDatum(matches[0], bandFields);
127
+ return {
128
+ mode: 'element',
129
+ selectorLabel,
130
+ coordinateDatum: matches[0],
131
+ matchedDatum: matches[0],
132
+ bandDatum,
133
+ bandIndex: resolveBandIndex(dataset, bandDatum),
134
+ value: normalizeDifferenceValue(matches[0][valueField], selectorLabel, valueField)
135
+ };
136
+ }
137
+ const stackGroups = new Map();
138
+ matches.forEach((datum)=>{
139
+ const stackGroupDatum = buildStackGroupDatum(datum, bandFields);
140
+ stackGroups.set(JSON.stringify(stackGroupDatum), stackGroupDatum);
141
+ });
142
+ if (1 !== stackGroups.size) throw new Error(`annotationDifferenceLine ${selectorLabel} selector must resolve to exactly one stack group, got ${stackGroups.size}`);
143
+ const stackGroupDatum = Array.from(stackGroups.values())[0];
144
+ const groupRows = dataset.filter((datum)=>isSubset(stackGroupDatum, datum));
145
+ if ('auto' === stackResolveMode && groupRows.length !== matches.length) throw new Error(`annotationDifferenceLine ${selectorLabel} selector must resolve to exactly one stack element or one full stack group`);
146
+ const groupValues = groupRows.map((datum)=>normalizeDifferenceValue(datum[valueField], selectorLabel, valueField));
147
+ if (hasMixedSigns(groupValues)) throw new Error('annotationDifferenceLine does not support mixed-sign stack totals in v1');
148
+ return {
149
+ mode: 'stackTotal',
150
+ selectorLabel,
151
+ coordinateDatum: stackGroupDatum,
152
+ matchedDatum: matches[0],
153
+ stackGroupDatum,
154
+ bandDatum: stackGroupDatum,
155
+ bandIndex: resolveBandIndex(dataset, stackGroupDatum),
156
+ value: groupValues.reduce((sum, value)=>sum + value, 0)
157
+ };
158
+ };
159
+ const getStackRuntimeTotal = (runtimeMatches)=>{
160
+ const stackEndValues = runtimeMatches.map((datum)=>Number(datum[STACK_END_FIELD]));
161
+ if (stackEndValues.some((value)=>Number.isNaN(value))) return;
162
+ if (hasMixedSigns(stackEndValues)) throw new Error('annotationDifferenceLine does not support mixed-sign runtime stack totals in v1');
163
+ return stackEndValues.some((value)=>value < 0) ? Math.min(...stackEndValues) : Math.max(...stackEndValues);
164
+ };
165
+ const buildDifferenceCoordinateDatum = (options)=>{
166
+ const { anchor, seriesData, relativeSeries, useElementStackEnd = false } = options;
167
+ if (!anchor.stackGroupDatum) {
168
+ const runtimeMatches = anchor.matchedDatum ? seriesData.filter((datum)=>isSubset(anchor.matchedDatum, datum)) : [];
169
+ if (!useElementStackEnd) return runtimeMatches[0] ?? anchor.coordinateDatum;
170
+ const runtimeMatch = runtimeMatches[0];
171
+ const runtimeStackEnd = Number(runtimeMatch?.[STACK_END_FIELD]);
172
+ return {
173
+ ...runtimeMatch ?? anchor.coordinateDatum,
174
+ [relativeSeries.getStackValueField()]: Number.isNaN(runtimeStackEnd) ? anchor.value : runtimeStackEnd
175
+ };
176
+ }
177
+ const runtimeMatches = seriesData.filter((datum)=>isSubset(anchor.stackGroupDatum, datum));
178
+ const runtimeStackTotal = getStackRuntimeTotal(runtimeMatches);
179
+ return {
180
+ ...runtimeMatches[0] ?? anchor.coordinateDatum,
181
+ [relativeSeries.getStackValueField()]: runtimeStackTotal ?? anchor.value
182
+ };
183
+ };
184
+ const getRuntimeDifferenceValue = (options)=>{
185
+ const { anchor, seriesData, useElementStackEnd = false } = options;
186
+ if (anchor.stackGroupDatum) {
187
+ const runtimeMatches = seriesData.filter((datum)=>isSubset(anchor.stackGroupDatum, datum));
188
+ return getStackRuntimeTotal(runtimeMatches) ?? anchor.value;
189
+ }
190
+ if (!useElementStackEnd || !anchor.matchedDatum) return anchor.value;
191
+ const runtimeMatch = seriesData.find((datum)=>isSubset(anchor.matchedDatum, datum));
192
+ const runtimeStackEnd = Number(runtimeMatch?.[STACK_END_FIELD]);
193
+ return Number.isNaN(runtimeStackEnd) ? anchor.value : runtimeStackEnd;
194
+ };
195
+ const buildDifferenceText = (startValue, endValue, differenceType = 'absolute')=>{
196
+ if ('percent' === differenceType) {
197
+ if (0 === startValue) throw new Error('annotationDifferenceLine percent difference cannot be computed because start value is 0');
198
+ return `${((endValue - startValue) / startValue * 100).toFixed(0)}%`;
199
+ }
200
+ return `${endValue - startValue}`;
201
+ };
202
+ const inferDifferenceConnectDirection = (vseed, values)=>{
203
+ const isNegativeSide = values.every((value)=>value < 0);
204
+ if (isBarLikeChart(vseed)) return isNegativeSide ? 'left' : 'right';
205
+ return isNegativeSide ? 'bottom' : 'top';
206
+ };
207
+ const inferDifferenceBracketDirection = (start, end)=>{
208
+ if (void 0 === start.bandIndex || void 0 === end.bandIndex) return 'right';
209
+ return start.bandIndex <= end.bandIndex ? 'right' : 'left';
210
+ };
211
+ export { buildDifferenceCoordinateDatum, buildDifferenceText, getDifferenceLineStackResolveMode, getRuntimeDifferenceValue, getStackRuntimeTotal, inferDifferenceBracketDirection, inferDifferenceConnectDirection, resolveDifferenceAnchor, usesDifferenceLineElementStackEnd };
212
+
213
+ //# sourceMappingURL=annotationDifferenceLineCommon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline/spec/chart/pipes/annotation/annotationDifferenceLineCommon.js","sources":["../../../../../../../src/pipeline/spec/chart/pipes/annotation/annotationDifferenceLineCommon.ts"],"sourcesContent":["import type { IAreaChartSpec, IBarChartSpec, ICartesianSeries, ILineChartSpec } from '@visactor/vchart'\nimport {\n isDimensionSelector,\n isFieldSelector,\n isMeasureSelector,\n isPartialDatumSelector,\n isValueSelector,\n selector,\n} from '../../../../../dataSelector'\nimport { hasMultipleMeasureInSingleView, isBarLikeChart } from 'src/pipeline/utils'\nimport type { AdvancedVSeed, Datum, Selector, Selectors, VSeed } from 'src/types'\nimport { isSubset } from './utils'\n\ntype DifferenceSelectorLabel = 'start' | 'end'\ntype DifferenceChartSpec = IBarChartSpec | ILineChartSpec | IAreaChartSpec\nexport type DifferenceStackResolveMode = 'none' | 'stackTotal' | 'auto'\nexport type DifferenceAnchorMode = 'element' | 'stackTotal'\n\nexport type ResolvedDifferenceAnchor = {\n mode: DifferenceAnchorMode\n selectorLabel: DifferenceSelectorLabel\n coordinateDatum: Datum\n matchedDatum?: Datum\n stackGroupDatum?: Datum\n bandDatum: Datum\n bandIndex?: number\n value: number\n}\n\nconst STACK_END_FIELD = '__VCHART_STACK_END'\n\nconst toArray = <T>(value: T | T[] | undefined | null): T[] => {\n if (Array.isArray(value)) {\n return value\n }\n\n return value === undefined || value === null ? [] : [value]\n}\n\nconst getDifferenceBandFields = (spec: DifferenceChartSpec): string[] => {\n return toArray((spec.direction === 'horizontal' ? spec.yField : spec.xField) as string | string[] | undefined)\n}\n\nconst getDifferenceValueField = (spec: DifferenceChartSpec): string => {\n const valueField = toArray(\n (spec.direction === 'horizontal' ? spec.xField : spec.yField) as string | string[] | undefined,\n )[0]\n\n if (!valueField) {\n throw new Error('annotationDifferenceLine requires a value field in the target chart spec')\n }\n\n return valueField\n}\n\nconst normalizeDifferenceValue = (value: unknown, selectorLabel: DifferenceSelectorLabel, field: string): number => {\n const numberValue = Number(value)\n\n if (Number.isNaN(numberValue)) {\n throw new Error(\n `annotationDifferenceLine ${selectorLabel} selector resolved to a non-numeric value on field \"${field}\"`,\n )\n }\n\n return numberValue\n}\n\nconst buildStackGroupDatum = (datum: Datum, bandFields: string[]) => {\n return Object.fromEntries(bandFields.map((field) => [field, datum[field]])) as Datum\n}\n\nconst resolveBandIndex = (dataset: Datum[], bandDatum: Datum) => {\n const bandIndex = dataset.findIndex((datum) => isSubset(bandDatum, datum))\n\n return bandIndex >= 0 ? bandIndex : undefined\n}\n\nconst buildFallbackSelectorDatum = (selectorValue: Selector | Selectors): Datum | undefined => {\n const selectorList = Array.isArray(selectorValue) ? selectorValue : [selectorValue]\n const fallbackDatum: Datum = {}\n\n for (const currentSelector of selectorList) {\n if (isValueSelector(currentSelector) || isFieldSelector(currentSelector)) {\n return undefined\n }\n\n if (isMeasureSelector(currentSelector)) {\n const operator = currentSelector.operator || currentSelector.op\n const selectorValues = Array.isArray(currentSelector.value) ? currentSelector.value : [currentSelector.value]\n\n if (!['=', '=='].includes(operator as string) || selectorValues.length !== 1) {\n return undefined\n }\n\n fallbackDatum[currentSelector.field] = selectorValues[0]\n continue\n }\n\n if (isDimensionSelector(currentSelector)) {\n const operator = currentSelector.operator || currentSelector.op\n const selectorValues = Array.isArray(currentSelector.value) ? currentSelector.value : [currentSelector.value]\n\n if (operator !== 'in' || selectorValues.length !== 1) {\n return undefined\n }\n\n fallbackDatum[currentSelector.field] = selectorValues[0]\n continue\n }\n\n if (isPartialDatumSelector(currentSelector)) {\n Object.assign(fallbackDatum, currentSelector)\n continue\n }\n\n return undefined\n }\n\n return Object.keys(fallbackDatum).length > 0 ? fallbackDatum : undefined\n}\n\nconst inferFallbackValue = (fallbackDatum: Datum, valueField: string, bandFields: string[]) => {\n if (valueField in fallbackDatum) {\n return fallbackDatum[valueField]\n }\n\n const numericCandidateKeys = Object.keys(fallbackDatum).filter((key) => {\n if (key === valueField || bandFields.includes(key)) {\n return false\n }\n\n return typeof fallbackDatum[key] === 'number'\n })\n\n if (numericCandidateKeys.length !== 1) {\n return undefined\n }\n\n return fallbackDatum[numericCandidateKeys[0]]\n}\n\nconst resolveFallbackAnchor = (options: {\n dataset: Datum[]\n selectorLabel: DifferenceSelectorLabel\n selectorValue: Selector | Selectors\n valueField: string\n bandFields: string[]\n}): ResolvedDifferenceAnchor | undefined => {\n const { dataset, selectorLabel, selectorValue, valueField, bandFields } = options\n const fallbackDatum = buildFallbackSelectorDatum(selectorValue)\n\n if (!fallbackDatum) {\n return undefined\n }\n\n const inferredValue = inferFallbackValue(fallbackDatum, valueField, bandFields)\n\n if (inferredValue === undefined) {\n return undefined\n }\n\n const coordinateDatum = {\n ...fallbackDatum,\n [valueField]: inferredValue,\n }\n const bandDatum = buildStackGroupDatum(coordinateDatum, bandFields)\n\n try {\n return {\n mode: 'element',\n selectorLabel,\n coordinateDatum,\n matchedDatum: fallbackDatum,\n bandDatum,\n bandIndex: resolveBandIndex(dataset, bandDatum),\n value: normalizeDifferenceValue(inferredValue, selectorLabel, valueField),\n }\n } catch {\n return undefined\n }\n}\n\nconst hasMixedSigns = (values: number[]) => {\n const nonZeroValues = values.filter((value) => value !== 0)\n\n return nonZeroValues.some((value) => value > 0) && nonZeroValues.some((value) => value < 0)\n}\n\nexport const getDifferenceLineStackResolveMode = (\n vseed: VSeed,\n advancedVSeed: AdvancedVSeed,\n): DifferenceStackResolveMode => {\n const hasMultipleMeasure = hasMultipleMeasureInSingleView(advancedVSeed.reshapeMeasures ?? [])\n\n if (!hasMultipleMeasure) {\n return 'none'\n }\n\n if (vseed.chartType === 'column') {\n return 'auto'\n }\n\n if (vseed.chartType === 'bar') {\n return 'auto'\n }\n\n return 'none'\n}\n\nexport const usesDifferenceLineElementStackEnd = (vseed: VSeed, advancedVSeed: AdvancedVSeed) => {\n return vseed.chartType === 'area' && hasMultipleMeasureInSingleView(advancedVSeed.reshapeMeasures ?? [])\n}\n\nexport const resolveDifferenceAnchor = (options: {\n dataset: Datum[]\n selectorLabel: DifferenceSelectorLabel\n selectorValue: Selector | Selectors\n spec: DifferenceChartSpec\n stackResolveMode: DifferenceStackResolveMode\n allowSelectorFallback?: boolean\n}): ResolvedDifferenceAnchor | undefined => {\n const { dataset, selectorLabel, selectorValue, spec, stackResolveMode, allowSelectorFallback = true } = options\n const matches = dataset.filter((datum) => selector(datum, selectorValue))\n const valueField = getDifferenceValueField(spec)\n const bandFields = getDifferenceBandFields(spec)\n\n if (matches.length === 0) {\n return stackResolveMode === 'none' && allowSelectorFallback\n ? resolveFallbackAnchor({ dataset, selectorLabel, selectorValue, valueField, bandFields })\n : undefined\n }\n\n if (stackResolveMode === 'none' || (stackResolveMode === 'auto' && matches.length === 1)) {\n if (matches.length !== 1) {\n throw new Error(\n `annotationDifferenceLine ${selectorLabel} selector must resolve to exactly one datum, got ${matches.length}`,\n )\n }\n\n const bandDatum = buildStackGroupDatum(matches[0], bandFields)\n\n return {\n mode: 'element',\n selectorLabel,\n coordinateDatum: matches[0],\n matchedDatum: matches[0],\n bandDatum,\n bandIndex: resolveBandIndex(dataset, bandDatum),\n value: normalizeDifferenceValue(matches[0][valueField], selectorLabel, valueField),\n }\n }\n const stackGroups = new Map<string, Datum>()\n\n matches.forEach((datum) => {\n const stackGroupDatum = buildStackGroupDatum(datum, bandFields)\n stackGroups.set(JSON.stringify(stackGroupDatum), stackGroupDatum)\n })\n\n if (stackGroups.size !== 1) {\n throw new Error(\n `annotationDifferenceLine ${selectorLabel} selector must resolve to exactly one stack group, got ${stackGroups.size}`,\n )\n }\n\n const stackGroupDatum = Array.from(stackGroups.values())[0]\n const groupRows = dataset.filter((datum) => isSubset(stackGroupDatum, datum))\n\n if (stackResolveMode === 'auto' && groupRows.length !== matches.length) {\n throw new Error(\n `annotationDifferenceLine ${selectorLabel} selector must resolve to exactly one stack element or one full stack group`,\n )\n }\n const groupValues = groupRows.map((datum) => normalizeDifferenceValue(datum[valueField], selectorLabel, valueField))\n\n if (hasMixedSigns(groupValues)) {\n throw new Error('annotationDifferenceLine does not support mixed-sign stack totals in v1')\n }\n\n return {\n mode: 'stackTotal',\n selectorLabel,\n coordinateDatum: stackGroupDatum,\n matchedDatum: matches[0],\n stackGroupDatum,\n bandDatum: stackGroupDatum,\n bandIndex: resolveBandIndex(dataset, stackGroupDatum),\n value: groupValues.reduce((sum, value) => sum + value, 0),\n }\n}\n\nexport const getStackRuntimeTotal = (runtimeMatches: Datum[]) => {\n const stackEndValues = runtimeMatches.map((datum) => Number(datum[STACK_END_FIELD]))\n\n if (stackEndValues.some((value) => Number.isNaN(value))) {\n return undefined\n }\n\n if (hasMixedSigns(stackEndValues)) {\n throw new Error('annotationDifferenceLine does not support mixed-sign runtime stack totals in v1')\n }\n\n return stackEndValues.some((value) => value < 0) ? Math.min(...stackEndValues) : Math.max(...stackEndValues)\n}\n\nexport const buildDifferenceCoordinateDatum = (options: {\n anchor: ResolvedDifferenceAnchor\n seriesData: Datum[]\n relativeSeries: ICartesianSeries\n useElementStackEnd?: boolean\n}) => {\n const { anchor, seriesData, relativeSeries, useElementStackEnd = false } = options\n\n if (!anchor.stackGroupDatum) {\n const runtimeMatches = anchor.matchedDatum\n ? seriesData.filter((datum) => isSubset(anchor.matchedDatum as Datum, datum))\n : []\n\n if (!useElementStackEnd) {\n return runtimeMatches[0] ?? anchor.coordinateDatum\n }\n\n const runtimeMatch = runtimeMatches[0]\n const runtimeStackEnd = Number(runtimeMatch?.[STACK_END_FIELD])\n\n return {\n ...(runtimeMatch ?? anchor.coordinateDatum),\n [relativeSeries.getStackValueField()]: Number.isNaN(runtimeStackEnd) ? anchor.value : runtimeStackEnd,\n }\n }\n\n const runtimeMatches = seriesData.filter((datum) => isSubset(anchor.stackGroupDatum as Datum, datum))\n const runtimeStackTotal = getStackRuntimeTotal(runtimeMatches)\n\n return {\n ...(runtimeMatches[0] ?? anchor.coordinateDatum),\n [relativeSeries.getStackValueField()]: runtimeStackTotal ?? anchor.value,\n }\n}\n\nexport const getRuntimeDifferenceValue = (options: {\n anchor: ResolvedDifferenceAnchor\n seriesData: Datum[]\n useElementStackEnd?: boolean\n}) => {\n const { anchor, seriesData, useElementStackEnd = false } = options\n\n if (anchor.stackGroupDatum) {\n const runtimeMatches = seriesData.filter((datum) => isSubset(anchor.stackGroupDatum as Datum, datum))\n return getStackRuntimeTotal(runtimeMatches) ?? anchor.value\n }\n\n if (!useElementStackEnd || !anchor.matchedDatum) {\n return anchor.value\n }\n\n const runtimeMatch = seriesData.find((datum) => isSubset(anchor.matchedDatum as Datum, datum))\n const runtimeStackEnd = Number(runtimeMatch?.[STACK_END_FIELD])\n\n return Number.isNaN(runtimeStackEnd) ? anchor.value : runtimeStackEnd\n}\n\nexport const buildDifferenceText = (\n startValue: number,\n endValue: number,\n differenceType: 'absolute' | 'percent' = 'absolute',\n) => {\n if (differenceType === 'percent') {\n if (startValue === 0) {\n throw new Error('annotationDifferenceLine percent difference cannot be computed because start value is 0')\n }\n\n return `${(((endValue - startValue) / startValue) * 100).toFixed(0)}%`\n }\n\n return `${endValue - startValue}`\n}\n\nexport const inferDifferenceConnectDirection = (vseed: VSeed, values: [number, number]) => {\n const isNegativeSide = values.every((value) => value < 0)\n\n if (isBarLikeChart(vseed)) {\n return isNegativeSide ? 'left' : 'right'\n }\n\n return isNegativeSide ? 'bottom' : 'top'\n}\n\nexport const inferDifferenceBracketDirection = (\n start: ResolvedDifferenceAnchor,\n end: ResolvedDifferenceAnchor,\n): 'left' | 'right' => {\n if (start.bandIndex === undefined || end.bandIndex === undefined) {\n return 'right'\n }\n\n return start.bandIndex <= end.bandIndex ? 'right' : 'left'\n}\n"],"names":["STACK_END_FIELD","toArray","value","Array","getDifferenceBandFields","spec","getDifferenceValueField","valueField","Error","normalizeDifferenceValue","selectorLabel","field","numberValue","Number","buildStackGroupDatum","datum","bandFields","Object","resolveBandIndex","dataset","bandDatum","bandIndex","isSubset","undefined","buildFallbackSelectorDatum","selectorValue","selectorList","fallbackDatum","currentSelector","isValueSelector","isFieldSelector","isMeasureSelector","operator","selectorValues","isDimensionSelector","isPartialDatumSelector","inferFallbackValue","numericCandidateKeys","key","resolveFallbackAnchor","options","inferredValue","coordinateDatum","hasMixedSigns","values","nonZeroValues","getDifferenceLineStackResolveMode","vseed","advancedVSeed","hasMultipleMeasure","hasMultipleMeasureInSingleView","usesDifferenceLineElementStackEnd","resolveDifferenceAnchor","stackResolveMode","allowSelectorFallback","matches","selector","stackGroups","Map","stackGroupDatum","JSON","groupRows","groupValues","sum","getStackRuntimeTotal","runtimeMatches","stackEndValues","Math","buildDifferenceCoordinateDatum","anchor","seriesData","relativeSeries","useElementStackEnd","runtimeMatch","runtimeStackEnd","runtimeStackTotal","getRuntimeDifferenceValue","buildDifferenceText","startValue","endValue","differenceType","inferDifferenceConnectDirection","isNegativeSide","isBarLikeChart","inferDifferenceBracketDirection","start","end"],"mappings":";;;AA6BA,MAAMA,kBAAkB;AAExB,MAAMC,UAAU,CAAIC;IAClB,IAAIC,MAAM,OAAO,CAACD,QAChB,OAAOA;IAGT,OAAOA,QAAAA,QAAwC,EAAE,GAAG;QAACA;KAAM;AAC7D;AAEA,MAAME,0BAA0B,CAACC,OACxBJ,QAASI,AAAmB,iBAAnBA,KAAK,SAAS,GAAoBA,KAAK,MAAM,GAAGA,KAAK,MAAM;AAG7E,MAAMC,0BAA0B,CAACD;IAC/B,MAAME,aAAaN,QAChBI,AAAmB,iBAAnBA,KAAK,SAAS,GAAoBA,KAAK,MAAM,GAAGA,KAAK,MAAM,CAC7D,CAAC,EAAE;IAEJ,IAAI,CAACE,YACH,MAAM,IAAIC,MAAM;IAGlB,OAAOD;AACT;AAEA,MAAME,2BAA2B,CAACP,OAAgBQ,eAAwCC;IACxF,MAAMC,cAAcC,OAAOX;IAE3B,IAAIW,OAAO,KAAK,CAACD,cACf,MAAM,IAAIJ,MACR,CAAC,yBAAyB,EAAEE,cAAc,oDAAoD,EAAEC,MAAM,CAAC,CAAC;IAI5G,OAAOC;AACT;AAEA,MAAME,uBAAuB,CAACC,OAAcC,aACnCC,OAAO,WAAW,CAACD,WAAW,GAAG,CAAC,CAACL,QAAU;YA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,sBAAsB,CAACH,OAAO,YAAY,EAC7C,OAAOA,OAAO,KAAK;IAGrB,MAAMI,eAAeH,WAAW,IAAI,CAAC,CAACvD,QAAUO,SAAS+C,OAAO,YAAY,EAAWtD;IACvF,MAAM2D,kBAAkB7D,OAAO4D,cAAc,CAACzE,gBAAgB;IAE9D,OAAOa,OAAO,KAAK,CAAC6D,mBAAmBL,OAAO,KAAK,GAAGK;AACxD;AAEO,MAAMG,sBAAsB,CACjCC,YACAC,UACAC,iBAAyC,UAAU;IAEnD,IAAIA,AAAmB,cAAnBA,gBAA8B;QAChC,IAAIF,AAAe,MAAfA,YACF,MAAM,IAAItE,MAAM;QAGlB,OAAO,GAAI,AAAEuE,CAAAA,CAAAA,WAAWD,UAAS,IAAKA,aAAc,GAAE,EAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACxE;IAEA,OAAO,GAAGC,WAAWD,YAAY;AACnC;AAEO,MAAMG,kCAAkC,CAAClC,OAAcH;IAC5D,MAAMsC,iBAAiBtC,OAAO,KAAK,CAAC,CAAC1C,QAAUA,QAAQ;IAEvD,IAAIiF,eAAepC,QACjB,OAAOmC,iBAAiB,SAAS;IAGnC,OAAOA,iBAAiB,WAAW;AACrC;AAEO,MAAME,kCAAkC,CAC7CC,OACAC;IAEA,IAAID,AAAoB9D,WAApB8D,MAAM,SAAS,IAAkBC,AAAkB/D,WAAlB+D,IAAI,SAAS,EAChD,OAAO;IAGT,OAAOD,MAAM,SAAS,IAAIC,IAAI,SAAS,GAAG,UAAU;AACtD"}
@@ -2,6 +2,7 @@ export { annotationPointOfDualAxis } from './annotationPointOfDualAxis';
2
2
  export { annotationPoint } from './annotationPoint';
3
3
  export { annotationVerticalLine } from './annotationVerticalLine';
4
4
  export { annotationHorizontalLine } from './annotationHorizontalLine';
5
+ export { annotationDifferenceLine } from './annotationDifferenceLine';
5
6
  export { annotationArea } from './annotationArea';
6
7
  export { annotationAreaBand } from './annotationAreaBand';
7
8
  export { splitLine } from './splitLine';
@@ -2,6 +2,7 @@ export { annotationPointOfDualAxis } from "./annotationPointOfDualAxis.js";
2
2
  export { annotationPoint } from "./annotationPoint.js";
3
3
  export { annotationVerticalLine } from "./annotationVerticalLine.js";
4
4
  export { annotationHorizontalLine } from "./annotationHorizontalLine.js";
5
+ export { annotationDifferenceLine } from "./annotationDifferenceLine.js";
5
6
  export { annotationArea } from "./annotationArea.js";
6
7
  export { annotationAreaBand } from "./annotationAreaBand.js";
7
8
  export { splitLine } from "./splitLine.js";
@@ -1 +1,2 @@
1
1
  export * from './addRegionPadding';
2
+ export * from './regionPadding';
@@ -1 +1,2 @@
1
1
  export * from "./addRegionPadding.js";
2
+ export * from "./regionPadding.js";
@@ -0,0 +1,2 @@
1
+ import type { VChartSpecPipe } from '../../../../../types';
2
+ export declare const regionPadding: VChartSpecPipe;
@@ -0,0 +1,20 @@
1
+ const regionPadding = (spec, context)=>{
2
+ const chartConfig = context.advancedVSeed.config?.[context.vseed.chartType];
3
+ const padding = chartConfig?.regionPadding;
4
+ if (null == padding || !Array.isArray(spec.region)) return spec;
5
+ const region = spec.region;
6
+ if (0 === region.length) return spec;
7
+ return {
8
+ ...spec,
9
+ region: [
10
+ {
11
+ ...region[0],
12
+ padding
13
+ },
14
+ ...region.slice(1)
15
+ ]
16
+ };
17
+ };
18
+ export { regionPadding };
19
+
20
+ //# sourceMappingURL=regionPadding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline/spec/chart/pipes/region/regionPadding.js","sources":["../../../../../../../src/pipeline/spec/chart/pipes/region/regionPadding.ts"],"sourcesContent":["import type { RegionPadding, VChartSpecPipe } from 'src/types'\n\ntype RegionPaddingConfig = {\n regionPadding?: RegionPadding\n}\n\nexport const regionPadding: VChartSpecPipe = (spec, context) => {\n const chartConfig = context.advancedVSeed.config?.[context.vseed.chartType] as RegionPaddingConfig | undefined\n const padding = chartConfig?.regionPadding\n\n if (padding == null || !Array.isArray((spec as { region?: unknown }).region)) {\n return spec\n }\n\n const region = (spec as { region: Array<Record<string, unknown>> }).region\n if (region.length === 0) {\n return spec\n }\n\n return {\n ...spec,\n region: [\n {\n ...region[0],\n padding,\n },\n ...region.slice(1),\n ],\n }\n}\n"],"names":["regionPadding","spec","context","chartConfig","padding","Array","region"],"mappings":"AAMO,MAAMA,gBAAgC,CAACC,MAAMC;IAClD,MAAMC,cAAcD,QAAQ,aAAa,CAAC,MAAM,EAAE,CAACA,QAAQ,KAAK,CAAC,SAAS,CAAC;IAC3E,MAAME,UAAUD,aAAa;IAE7B,IAAIC,AAAW,QAAXA,WAAmB,CAACC,MAAM,OAAO,CAAEJ,KAA8B,MAAM,GACzE,OAAOA;IAGT,MAAMK,SAAUL,KAAoD,MAAM;IAC1E,IAAIK,AAAkB,MAAlBA,OAAO,MAAM,EACf,OAAOL;IAGT,OAAO;QACL,GAAGA,IAAI;QACP,QAAQ;YACN;gBACE,GAAGK,MAAM,CAAC,EAAE;gBACZF;YACF;eACGE,OAAO,KAAK,CAAC;SACjB;IACH;AACF"}