@coinbase/cds-mobile-visualization 3.4.0-beta.9 → 3.6.1

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 (174) hide show
  1. package/CHANGELOG.md +150 -0
  2. package/dts/chart/CartesianChart.d.ts +92 -7
  3. package/dts/chart/CartesianChart.d.ts.map +1 -1
  4. package/dts/chart/ChartContextBridge.d.ts.map +1 -1
  5. package/dts/chart/ChartProvider.d.ts +3 -0
  6. package/dts/chart/ChartProvider.d.ts.map +1 -1
  7. package/dts/chart/Path.d.ts +43 -13
  8. package/dts/chart/Path.d.ts.map +1 -1
  9. package/dts/chart/PeriodSelector.d.ts +20 -5
  10. package/dts/chart/PeriodSelector.d.ts.map +1 -1
  11. package/dts/chart/area/Area.d.ts +14 -11
  12. package/dts/chart/area/Area.d.ts.map +1 -1
  13. package/dts/chart/area/AreaChart.d.ts +33 -9
  14. package/dts/chart/area/AreaChart.d.ts.map +1 -1
  15. package/dts/chart/area/DottedArea.d.ts.map +1 -1
  16. package/dts/chart/area/GradientArea.d.ts.map +1 -1
  17. package/dts/chart/area/SolidArea.d.ts.map +1 -1
  18. package/dts/chart/axis/Axis.d.ts +22 -42
  19. package/dts/chart/axis/Axis.d.ts.map +1 -1
  20. package/dts/chart/axis/XAxis.d.ts +6 -0
  21. package/dts/chart/axis/XAxis.d.ts.map +1 -1
  22. package/dts/chart/axis/YAxis.d.ts +1 -0
  23. package/dts/chart/axis/YAxis.d.ts.map +1 -1
  24. package/dts/chart/bar/Bar.d.ts +59 -51
  25. package/dts/chart/bar/Bar.d.ts.map +1 -1
  26. package/dts/chart/bar/BarChart.d.ts +56 -11
  27. package/dts/chart/bar/BarChart.d.ts.map +1 -1
  28. package/dts/chart/bar/BarPlot.d.ts +2 -1
  29. package/dts/chart/bar/BarPlot.d.ts.map +1 -1
  30. package/dts/chart/bar/BarStack.d.ts +45 -20
  31. package/dts/chart/bar/BarStack.d.ts.map +1 -1
  32. package/dts/chart/bar/BarStackGroup.d.ts +2 -1
  33. package/dts/chart/bar/BarStackGroup.d.ts.map +1 -1
  34. package/dts/chart/bar/DefaultBar.d.ts.map +1 -1
  35. package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -1
  36. package/dts/chart/bar/PercentageBarChart.d.ts +106 -0
  37. package/dts/chart/bar/PercentageBarChart.d.ts.map +1 -0
  38. package/dts/chart/bar/index.d.ts +1 -0
  39. package/dts/chart/bar/index.d.ts.map +1 -1
  40. package/dts/chart/gradient/Gradient.d.ts +5 -0
  41. package/dts/chart/gradient/Gradient.d.ts.map +1 -1
  42. package/dts/chart/index.d.ts +1 -0
  43. package/dts/chart/index.d.ts.map +1 -1
  44. package/dts/chart/legend/DefaultLegendEntry.d.ts +5 -0
  45. package/dts/chart/legend/DefaultLegendEntry.d.ts.map +1 -0
  46. package/dts/chart/legend/DefaultLegendShape.d.ts +5 -0
  47. package/dts/chart/legend/DefaultLegendShape.d.ts.map +1 -0
  48. package/dts/chart/legend/Legend.d.ts +168 -0
  49. package/dts/chart/legend/Legend.d.ts.map +1 -0
  50. package/dts/chart/legend/index.d.ts +4 -0
  51. package/dts/chart/legend/index.d.ts.map +1 -0
  52. package/dts/chart/line/DottedLine.d.ts.map +1 -1
  53. package/dts/chart/line/Line.d.ts +23 -19
  54. package/dts/chart/line/Line.d.ts.map +1 -1
  55. package/dts/chart/line/LineChart.d.ts +26 -9
  56. package/dts/chart/line/LineChart.d.ts.map +1 -1
  57. package/dts/chart/line/ReferenceLine.d.ts +1 -0
  58. package/dts/chart/line/ReferenceLine.d.ts.map +1 -1
  59. package/dts/chart/line/SolidLine.d.ts.map +1 -1
  60. package/dts/chart/point/Point.d.ts +26 -2
  61. package/dts/chart/point/Point.d.ts.map +1 -1
  62. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +32 -2
  63. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -1
  64. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +2 -1
  65. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -1
  66. package/dts/chart/scrubber/Scrubber.d.ts +86 -17
  67. package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
  68. package/dts/chart/scrubber/ScrubberAccessibilityView.d.ts +12 -0
  69. package/dts/chart/scrubber/ScrubberAccessibilityView.d.ts.map +1 -0
  70. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +10 -0
  71. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -1
  72. package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +16 -1
  73. package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +1 -1
  74. package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -1
  75. package/dts/chart/utils/axis.d.ts +45 -10
  76. package/dts/chart/utils/axis.d.ts.map +1 -1
  77. package/dts/chart/utils/bar.d.ts +195 -0
  78. package/dts/chart/utils/bar.d.ts.map +1 -1
  79. package/dts/chart/utils/chart.d.ts +32 -0
  80. package/dts/chart/utils/chart.d.ts.map +1 -1
  81. package/dts/chart/utils/context.d.ts +21 -6
  82. package/dts/chart/utils/context.d.ts.map +1 -1
  83. package/dts/chart/utils/gradient.d.ts +3 -1
  84. package/dts/chart/utils/gradient.d.ts.map +1 -1
  85. package/dts/chart/utils/path.d.ts +26 -0
  86. package/dts/chart/utils/path.d.ts.map +1 -1
  87. package/dts/chart/utils/point.d.ts +24 -12
  88. package/dts/chart/utils/point.d.ts.map +1 -1
  89. package/dts/chart/utils/scale.d.ts +11 -0
  90. package/dts/chart/utils/scale.d.ts.map +1 -1
  91. package/dts/chart/utils/scrubber.d.ts +2 -1
  92. package/dts/chart/utils/scrubber.d.ts.map +1 -1
  93. package/dts/chart/utils/transition.d.ts +63 -22
  94. package/dts/chart/utils/transition.d.ts.map +1 -1
  95. package/dts/sparkline/Sparkline.d.ts +2 -1
  96. package/dts/sparkline/Sparkline.d.ts.map +1 -1
  97. package/dts/sparkline/SparklineArea.d.ts +2 -1
  98. package/dts/sparkline/SparklineArea.d.ts.map +1 -1
  99. package/dts/sparkline/SparklineGradient.d.ts +2 -1
  100. package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
  101. package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +2 -1
  102. package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
  103. package/esm/chart/CartesianChart.js +176 -82
  104. package/esm/chart/ChartContextBridge.js +14 -3
  105. package/esm/chart/ChartProvider.js +2 -2
  106. package/esm/chart/Path.js +68 -31
  107. package/esm/chart/PeriodSelector.js +5 -1
  108. package/esm/chart/__stories__/CartesianChart.stories.js +16 -80
  109. package/esm/chart/__stories__/ChartAccessibility.stories.js +721 -0
  110. package/esm/chart/__stories__/ChartTransitions.stories.js +625 -0
  111. package/esm/chart/__stories__/PeriodSelector.stories.js +99 -1
  112. package/esm/chart/area/Area.js +21 -9
  113. package/esm/chart/area/AreaChart.js +18 -13
  114. package/esm/chart/area/DottedArea.js +28 -18
  115. package/esm/chart/area/GradientArea.js +14 -7
  116. package/esm/chart/area/SolidArea.js +6 -2
  117. package/esm/chart/area/__stories__/AreaChart.stories.js +47 -5
  118. package/esm/chart/axis/Axis.js +5 -41
  119. package/esm/chart/axis/XAxis.js +116 -47
  120. package/esm/chart/axis/YAxis.js +105 -26
  121. package/esm/chart/axis/__stories__/Axis.stories.js +324 -48
  122. package/esm/chart/bar/Bar.js +17 -15
  123. package/esm/chart/bar/BarChart.js +38 -33
  124. package/esm/chart/bar/BarPlot.js +40 -45
  125. package/esm/chart/bar/BarStack.js +92 -475
  126. package/esm/chart/bar/BarStackGroup.js +37 -27
  127. package/esm/chart/bar/DefaultBar.js +41 -18
  128. package/esm/chart/bar/DefaultBarStack.js +25 -9
  129. package/esm/chart/bar/PercentageBarChart.js +99 -0
  130. package/esm/chart/bar/__stories__/BarChart.stories.js +721 -54
  131. package/esm/chart/bar/__stories__/PercentageBarChart.stories.js +833 -0
  132. package/esm/chart/bar/index.js +1 -0
  133. package/esm/chart/gradient/Gradient.js +2 -1
  134. package/esm/chart/index.js +1 -0
  135. package/esm/chart/legend/DefaultLegendEntry.js +42 -0
  136. package/esm/chart/legend/DefaultLegendShape.js +64 -0
  137. package/esm/chart/legend/Legend.js +59 -0
  138. package/esm/chart/legend/__stories__/Legend.stories.js +574 -0
  139. package/esm/chart/legend/index.js +3 -0
  140. package/esm/chart/line/DottedLine.js +6 -2
  141. package/esm/chart/line/Line.js +42 -38
  142. package/esm/chart/line/LineChart.js +36 -12
  143. package/esm/chart/line/SolidLine.js +6 -2
  144. package/esm/chart/line/__stories__/LineChart.stories.js +236 -590
  145. package/esm/chart/line/__stories__/ReferenceLine.stories.js +95 -1
  146. package/esm/chart/point/Point.js +35 -36
  147. package/esm/chart/scrubber/DefaultScrubberBeacon.js +41 -38
  148. package/esm/chart/scrubber/DefaultScrubberLabel.js +26 -10
  149. package/esm/chart/scrubber/Scrubber.js +67 -35
  150. package/esm/chart/scrubber/ScrubberAccessibilityView.js +177 -0
  151. package/esm/chart/scrubber/ScrubberBeaconGroup.js +30 -22
  152. package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +35 -8
  153. package/esm/chart/scrubber/ScrubberProvider.js +29 -24
  154. package/esm/chart/scrubber/__stories__/Scrubber.stories.js +946 -0
  155. package/esm/chart/utils/axis.js +88 -44
  156. package/esm/chart/utils/bar.js +829 -0
  157. package/esm/chart/utils/chart.js +34 -7
  158. package/esm/chart/utils/context.js +7 -0
  159. package/esm/chart/utils/gradient.js +8 -4
  160. package/esm/chart/utils/path.js +91 -61
  161. package/esm/chart/utils/point.js +92 -39
  162. package/esm/chart/utils/scale.js +13 -2
  163. package/esm/chart/utils/scrubber.js +12 -5
  164. package/esm/chart/utils/transition.js +116 -60
  165. package/esm/sparkline/Sparkline.js +2 -1
  166. package/esm/sparkline/SparklineArea.js +2 -1
  167. package/esm/sparkline/SparklineGradient.js +2 -1
  168. package/esm/sparkline/__figma__/Sparkline.figma.js +1 -1
  169. package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +2 -1
  170. package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +1 -1
  171. package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +1 -1
  172. package/esm/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.js +2 -0
  173. package/package.json +5 -6
  174. package/esm/chart/__stories__/Chart.stories.js +0 -77
@@ -1,3 +1,77 @@
1
+ const _excluded = ["staggerDelay"];
2
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
+ import { defaultAxisId as fallbackAxisId } from './axis';
5
+ import { evaluateGradientAtValue } from './gradient';
6
+ import { defaultTransition } from './transition';
7
+
8
+ /**
9
+ * A bar-specific transition that extends Transition with stagger support.
10
+ * When `staggerDelay` is provided, bars will animate with increasing delays
11
+ * based on their position along the category axis (vertical: left-to-right,
12
+ * horizontal: top-to-bottom).
13
+ *
14
+ * @example
15
+ * // Bars stagger in from left to right over 250ms, each animating for 750ms
16
+ * { type: 'timing', duration: 750, staggerDelay: 250 }
17
+ */
18
+
19
+ /**
20
+ * Computes a bar's normalized [0, 1] position along the category axis, used for
21
+ * stagger-delay calculations.
22
+ *
23
+ * Vertical charts stagger left-to-right (x axis); horizontal charts stagger
24
+ * top-to-bottom (y axis). Returns 0 when the drawing area has no extent.
25
+ *
26
+ * @param layout - The layout of the chart
27
+ * @param x - Bar's left edge in pixels
28
+ * @param y - Bar's top edge in pixels
29
+ */
30
+ export const getNormalizedStagger = (layout, x, y, drawingArea) => {
31
+ if (layout === 'horizontal') {
32
+ return drawingArea.height > 0 ? (y - drawingArea.y) / drawingArea.height : 0;
33
+ }
34
+ return drawingArea.width > 0 ? (x - drawingArea.x) / drawingArea.width : 0;
35
+ };
36
+
37
+ /**
38
+ * Strips `staggerDelay` from a transition and computes a positional delay.
39
+ *
40
+ * @param transition - The transition config (may include staggerDelay)
41
+ * @param normalizedPosition - The bar's normalized position along the category axis (0–1)
42
+ * @returns A standard Transition with computed delay
43
+ */
44
+ export const withStaggerDelayTransition = (transition, normalizedPosition) => {
45
+ var _baseTransition$delay;
46
+ if (!transition) return null;
47
+ const {
48
+ staggerDelay
49
+ } = transition,
50
+ baseTransition = _objectWithoutPropertiesLoose(transition, _excluded);
51
+ if (!staggerDelay) return transition;
52
+ return _extends({}, baseTransition, {
53
+ delay: ((_baseTransition$delay = baseTransition == null ? void 0 : baseTransition.delay) != null ? _baseTransition$delay : 0) + normalizedPosition * staggerDelay
54
+ });
55
+ };
56
+
57
+ /**
58
+ * Default bar enter transition. Uses the default spring with a stagger delay
59
+ * so bars spring into place from left to right.
60
+ * `{ type: 'spring', stiffness: 900, damping: 120, staggerDelay: 250 }`
61
+ */
62
+ export const defaultBarEnterTransition = _extends({}, defaultTransition, {
63
+ staggerDelay: 250
64
+ });
65
+
66
+ /**
67
+ * Default bar enter opacity transition.
68
+ * `{ type: 'timing', duration: 200 }`
69
+ */
70
+ export const defaultBarEnterOpacityTransition = {
71
+ type: 'timing',
72
+ duration: 200
73
+ };
74
+
1
75
  /**
2
76
  * Calculates the size adjustment needed for bars when accounting for gaps between them.
3
77
  * This function helps determine how much to reduce each bar's width to accommodate
@@ -21,4 +95,759 @@ export function getBarSizeAdjustment(barCount, gapSize) {
21
95
  return 0;
22
96
  }
23
97
  return gapSize * (barCount - 1) / barCount;
98
+ }
99
+ /**
100
+ * Groups bar series into stack groups scoped by stackId + axis IDs.
101
+ *
102
+ * Series with no `stackId` are treated as independent stacks keyed by series id.
103
+ * Axis IDs are included in the group key so series on different axes never stack together.
104
+ */
105
+ export function getStackGroups(series, defaultAxisId) {
106
+ if (defaultAxisId === void 0) {
107
+ defaultAxisId = fallbackAxisId;
108
+ }
109
+ const groups = {};
110
+ series.forEach(entry => {
111
+ var _entry$xAxisId, _entry$yAxisId;
112
+ const xAxisId = (_entry$xAxisId = entry.xAxisId) != null ? _entry$xAxisId : defaultAxisId;
113
+ const yAxisId = (_entry$yAxisId = entry.yAxisId) != null ? _entry$yAxisId : defaultAxisId;
114
+ const stackId = entry.stackId || "individual-" + entry.id;
115
+ const stackKey = stackId + ":" + xAxisId + ":" + yAxisId;
116
+ if (!groups[stackKey]) {
117
+ groups[stackKey] = {
118
+ stackId: stackKey,
119
+ series: [],
120
+ xAxisId: entry.xAxisId,
121
+ yAxisId: entry.yAxisId
122
+ };
123
+ }
124
+ groups[stackKey].series.push(entry);
125
+ });
126
+ return Object.values(groups);
127
+ }
128
+ /**
129
+ * Applies proportional gap distribution to a stack of bars, maintaining total stack length.
130
+ * Gaps are only inserted between bars that have `shouldApplyGap = true`.
131
+ * Positive (above-baseline) and negative (below-baseline) groups are gapped independently.
132
+ *
133
+ * @param bars - Array of bar items with current valuePos and length
134
+ * @param stackGap - Gap size in pixels between adjacent bars
135
+ * @param layout - The layout of the chart
136
+ * @param baseline - Pixel position of the zero value on the value axis
137
+ * @returns New array of bars with adjusted valuePos and length
138
+ */
139
+ function applyStackGap(bars, stackGap, layout, baseline) {
140
+ if (!stackGap || bars.length <= 1) return bars;
141
+ const result = [...bars];
142
+ const barsAboveBaseline = bars.filter(bar => {
143
+ const [bottom, top] = [...bar.dataValue].sort((a, b) => a - b);
144
+ return bottom >= 0 && top !== bottom && bar.shouldApplyGap;
145
+ });
146
+ const barsBelowBaseline = bars.filter(bar => {
147
+ const [bottom, top] = [...bar.dataValue].sort((a, b) => a - b);
148
+ return top <= 0 && bottom !== top && bar.shouldApplyGap;
149
+ });
150
+ const applyGapGroup = (group, growing) => {
151
+ if (group.length <= 1) return;
152
+ const totalGapSpace = stackGap * (group.length - 1);
153
+ const totalDataLength = group.reduce((sum, bar) => sum + bar.length, 0);
154
+ const lengthReduction = totalGapSpace / totalDataLength;
155
+ const sortedBars = growing ? [...group].sort((a, b) => b.valuePos - a.valuePos) : [...group].sort((a, b) => a.valuePos - b.valuePos);
156
+ let currentEdge = baseline;
157
+ sortedBars.forEach((bar, index) => {
158
+ const newLength = bar.length * (1 - lengthReduction);
159
+ let newValuePos;
160
+ if (growing) {
161
+ newValuePos = currentEdge - newLength;
162
+ currentEdge = newValuePos - (index < sortedBars.length - 1 ? stackGap : 0);
163
+ } else {
164
+ newValuePos = currentEdge;
165
+ currentEdge = newValuePos + newLength + (index < sortedBars.length - 1 ? stackGap : 0);
166
+ }
167
+ const barIndex = result.findIndex(b => b.seriesId === bar.seriesId);
168
+ if (barIndex !== -1) {
169
+ result[barIndex] = _extends({}, result[barIndex], {
170
+ length: newLength,
171
+ valuePos: newValuePos
172
+ });
173
+ }
174
+ });
175
+ };
176
+
177
+ // Positive bars: grow up in vertical (decreasing Y), grow right in horizontal (increasing X)
178
+ applyGapGroup(barsAboveBaseline, layout === 'vertical');
179
+ // Negative bars: grow down in vertical (increasing Y), grow left in horizontal (decreasing X)
180
+ applyGapGroup(barsBelowBaseline, layout !== 'vertical');
181
+ return result;
182
+ }
183
+
184
+ /**
185
+ * Computes per-bar initial animation origin positions for bar entrance animations.
186
+ *
187
+ * Bars are stacked from the baseline in their respective directions so they start at
188
+ * distinct, non-overlapping positions with the gap already applied:
189
+ * - Positive bars: stack rightward (horizontal) / upward (vertical) from the baseline.
190
+ * - Negative bars: stack leftward (horizontal) / downward (vertical) from the baseline.
191
+ *
192
+ * The bar closest to the baseline always gets index 0 and starts exactly at the baseline.
193
+ *
194
+ * @param bars - Array of bar items with final valuePos, length, and dataValue
195
+ * @param initialBarMinSizes - Per-bar initial sizes in pixels for entrance animation
196
+ * @param stackGap - Gap between adjacent bars in pixels
197
+ * @param baseline - Pixel position of the zero value on the value axis
198
+ * @param layout - The layout of the chart
199
+ * @returns Array of origin positions (one per bar, parallel to input), all defaulting to baseline
200
+ */
201
+ function getBarOrigins(bars, initialBarMinSizes, stackGap, baseline, layout) {
202
+ const result = bars.map(() => baseline);
203
+ if (bars.length === 0 || initialBarMinSizes.every(size => !size)) return result;
204
+ const isPositive = bar => {
205
+ const [lo, hi] = [...bar.dataValue].sort((a, b) => a - b);
206
+ return lo >= 0 && hi !== lo;
207
+ };
208
+ const isNegative = bar => {
209
+ const [lo, hi] = [...bar.dataValue].sort((a, b) => a - b);
210
+ return hi <= 0 && hi !== lo;
211
+ };
212
+ const positiveBars = bars.map((bar, i) => ({
213
+ bar,
214
+ i
215
+ })).filter(_ref => {
216
+ let {
217
+ bar
218
+ } = _ref;
219
+ return isPositive(bar);
220
+ }).sort((a, b) => layout === 'vertical' ? b.bar.valuePos - a.bar.valuePos : a.bar.valuePos - b.bar.valuePos);
221
+ if (layout === 'vertical') {
222
+ let currentPositive = baseline;
223
+ positiveBars.forEach((_ref2, idx) => {
224
+ var _initialBarMinSizes$i;
225
+ let {
226
+ i
227
+ } = _ref2;
228
+ const initialSize = (_initialBarMinSizes$i = initialBarMinSizes[i]) != null ? _initialBarMinSizes$i : 0;
229
+ currentPositive -= initialSize;
230
+ result[i] = currentPositive;
231
+ if (idx < positiveBars.length - 1) {
232
+ currentPositive -= stackGap;
233
+ }
234
+ });
235
+ } else {
236
+ let currentPositive = baseline;
237
+ positiveBars.forEach((_ref3, idx) => {
238
+ var _initialBarMinSizes$i2;
239
+ let {
240
+ i
241
+ } = _ref3;
242
+ const initialSize = (_initialBarMinSizes$i2 = initialBarMinSizes[i]) != null ? _initialBarMinSizes$i2 : 0;
243
+ result[i] = currentPositive;
244
+ currentPositive += initialSize;
245
+ if (idx < positiveBars.length - 1) {
246
+ currentPositive += stackGap;
247
+ }
248
+ });
249
+ }
250
+ const negativeBars = bars.map((bar, i) => ({
251
+ bar,
252
+ i
253
+ })).filter(_ref4 => {
254
+ let {
255
+ bar
256
+ } = _ref4;
257
+ return isNegative(bar);
258
+ }).sort((a, b) => layout === 'vertical' ? a.bar.valuePos - b.bar.valuePos : b.bar.valuePos + b.bar.length - (a.bar.valuePos + a.bar.length));
259
+ if (layout === 'vertical') {
260
+ let currentNegative = baseline;
261
+ negativeBars.forEach((_ref5, idx) => {
262
+ var _initialBarMinSizes$i3;
263
+ let {
264
+ i
265
+ } = _ref5;
266
+ const initialSize = (_initialBarMinSizes$i3 = initialBarMinSizes[i]) != null ? _initialBarMinSizes$i3 : 0;
267
+ result[i] = currentNegative;
268
+ currentNegative += initialSize;
269
+ if (idx < negativeBars.length - 1) {
270
+ currentNegative += stackGap;
271
+ }
272
+ });
273
+ } else {
274
+ let currentNegative = baseline;
275
+ negativeBars.forEach((_ref6, idx) => {
276
+ var _initialBarMinSizes$i4;
277
+ let {
278
+ i
279
+ } = _ref6;
280
+ const initialSize = (_initialBarMinSizes$i4 = initialBarMinSizes[i]) != null ? _initialBarMinSizes$i4 : 0;
281
+ currentNegative -= initialSize;
282
+ result[i] = currentNegative;
283
+ if (idx < negativeBars.length - 1) {
284
+ currentNegative -= stackGap;
285
+ }
286
+ });
287
+ }
288
+ return result;
289
+ }
290
+
291
+ /**
292
+ * Computes stack clip origin [start, end] that covers the bounding box
293
+ * of all bars at their stacked starting positions (as computed by `getBarOrigins`).
294
+ *
295
+ * This is passed to `DefaultBarStack` so the clip animation starts in sync with the
296
+ * individual bar animations — no bars leak outside the clip on frame 0.
297
+ *
298
+ * @param barOrigins - Per-bar initial origins from `getBarOrigins`
299
+ * @param barMinSizes - Per-bar minimum sizes in pixels (or a uniform value)
300
+ * @returns [originStart, originEnd] or undefined when barMinSize is 0 / no bars
301
+ */
302
+ export function getStackOrigin(barOrigins, barMinSizes) {
303
+ if (barOrigins.length === 0) return undefined;
304
+ const minSizes = Array.isArray(barMinSizes) ? barMinSizes : barOrigins.map(() => barMinSizes);
305
+ let rangeStart = Number.POSITIVE_INFINITY;
306
+ let rangeEnd = Number.NEGATIVE_INFINITY;
307
+ for (let i = 0; i < barOrigins.length; i++) {
308
+ var _minSizes$i;
309
+ const minSize = (_minSizes$i = minSizes[i]) != null ? _minSizes$i : 0;
310
+ if (minSize <= 0) continue;
311
+ const barStart = barOrigins[i];
312
+ const barEnd = barStart + minSize;
313
+ rangeStart = Math.min(rangeStart, barStart, barEnd);
314
+ rangeEnd = Math.max(rangeEnd, barStart, barEnd);
315
+ }
316
+ if (!Number.isFinite(rangeStart) || !Number.isFinite(rangeEnd)) return undefined;
317
+ return [rangeStart, rangeEnd];
318
+ }
319
+ function getInitialBarMinSizes(bars, barMinSize, stackMinSize) {
320
+ const perBarMinFromBarMinSize = barMinSize != null ? barMinSize : 0;
321
+ if (bars.length === 0) return [];
322
+ if (!stackMinSize) {
323
+ return bars.map(() => perBarMinFromBarMinSize);
324
+ }
325
+ const totalBarLength = bars.reduce((sum, bar) => sum + bar.length, 0);
326
+ const perBarMinFromStack = totalBarLength ? bars.map(bar => stackMinSize * bar.length / totalBarLength) : bars.map(() => stackMinSize / bars.length);
327
+ return perBarMinFromStack.map(stackMin => Math.max(perBarMinFromBarMinSize, stackMin));
328
+ }
329
+
330
+ /**
331
+ * Computes the initial clip rect used for stack enter animations.
332
+ */
333
+ export function getStackInitialClipRect(stackRect, layout, origin) {
334
+ const {
335
+ x,
336
+ y,
337
+ width,
338
+ height
339
+ } = stackRect;
340
+ if (Array.isArray(origin)) {
341
+ const [originStart, originEnd] = origin;
342
+ if (layout === 'vertical') {
343
+ return {
344
+ x,
345
+ y: originStart,
346
+ width,
347
+ height: originEnd - originStart
348
+ };
349
+ }
350
+ return {
351
+ x: originStart,
352
+ y,
353
+ width: originEnd - originStart,
354
+ height
355
+ };
356
+ }
357
+ const initialSize = 1;
358
+ if (layout === 'vertical') {
359
+ const valueBaseline = origin != null ? origin : y + height;
360
+ return {
361
+ x,
362
+ y: valueBaseline,
363
+ width,
364
+ height: initialSize
365
+ };
366
+ }
367
+ const valueBaseline = origin != null ? origin : x;
368
+ return {
369
+ x: valueBaseline,
370
+ y,
371
+ width: initialSize,
372
+ height
373
+ };
374
+ }
375
+
376
+ /**
377
+ * Expands bars that are shorter than `barMinSize` to the minimum size.
378
+ * Non-expanded bars are scaled down proportionally to keep the total bar length constant,
379
+ * preventing stacked bars from overflowing the chart area.
380
+ *
381
+ * Bars are then repositioned from the baseline, preserving original gaps between them.
382
+ *
383
+ * @param bars - Array of bar items with current valuePos and length
384
+ * @param barMinSize - Minimum bar size in pixels
385
+ * @param layout - The layout of the chart
386
+ * @param baseline - Pixel position of the zero value on the value axis
387
+ * @returns New array of bars with adjusted valuePos and length
388
+ */
389
+ function applyBarMinSize(bars, barMinSize, layout, baseline) {
390
+ if (!barMinSize || bars.length === 0) return bars;
391
+ const originalTotalLength = bars.reduce((sum, bar) => sum + bar.length, 0);
392
+ const needsExpansion = bars.map(bar => bar.length < barMinSize);
393
+ const expandedTotalLength = bars.reduce((sum, bar, i) => sum + (needsExpansion[i] ? barMinSize : bar.length), 0);
394
+ let finalLengths;
395
+ if (expandedTotalLength > originalTotalLength) {
396
+ // Scale down non-expanded bars to keep total bar length constant
397
+ const spaceForExpanded = needsExpansion.filter(Boolean).length * barMinSize;
398
+ const spaceForNonExpanded = Math.max(0, originalTotalLength - spaceForExpanded);
399
+ const nonExpandedOrigTotal = bars.reduce((sum, bar, i) => !needsExpansion[i] ? sum + bar.length : sum, 0);
400
+ const scaleFactor = nonExpandedOrigTotal > 0 ? spaceForNonExpanded / nonExpandedOrigTotal : 0;
401
+ finalLengths = bars.map((bar, i) => needsExpansion[i] ? barMinSize : bar.length * scaleFactor);
402
+ } else {
403
+ finalLengths = bars.map((bar, i) => needsExpansion[i] ? barMinSize : bar.length);
404
+ }
405
+ const expandedBars = bars.map((bar, i) => _extends({}, bar, {
406
+ length: finalLengths[i]
407
+ }));
408
+ const newPositions = new Map();
409
+
410
+ // Range bars (shouldApplyGap=false) float at data-defined coordinates independent of the
411
+ // baseline. Restacking them from the zero baseline would place them off-screen when the
412
+ // y-axis domain doesn't include 0 (e.g., a price chart with domain [28000, 37000]).
413
+ // Instead, expand them in-place, centered on their original midpoint.
414
+ for (let i = 0; i < bars.length; i++) {
415
+ if (bars[i].shouldApplyGap === false) {
416
+ const originalMid = bars[i].valuePos + bars[i].length / 2;
417
+ newPositions.set(bars[i].seriesId, {
418
+ valuePos: originalMid - expandedBars[i].length / 2,
419
+ length: expandedBars[i].length
420
+ });
421
+ }
422
+ }
423
+
424
+ // Stacked bars (shouldApplyGap=true/undefined): classify by which side of the baseline
425
+ // they're on and restack from the baseline outward.
426
+ const stackedSortedBars = [...expandedBars].filter(bar => bar.shouldApplyGap !== false).sort((a, b) => a.valuePos - b.valuePos);
427
+ if (stackedSortedBars.length > 0) {
428
+ // Classify using dataValue to correctly identify which side of the baseline each bar is on,
429
+ // independent of the current valuePos (which hasn't been repositioned yet).
430
+ const barsAboveBaseline = stackedSortedBars.filter(bar => {
431
+ const [bottom, top] = [...bar.dataValue].sort((a, b) => a - b);
432
+ return layout === 'vertical' ? bottom >= 0 && top !== bottom : top <= 0 && top !== bottom;
433
+ });
434
+ const barsBelowBaseline = stackedSortedBars.filter(bar => {
435
+ const [bottom, top] = [...bar.dataValue].sort((a, b) => a - b);
436
+ return layout === 'vertical' ? top <= 0 && top !== bottom : bottom >= 0 && top !== bottom;
437
+ });
438
+
439
+ // Restack bars above baseline (growing away from it in the positive direction)
440
+ let currentAbove = baseline;
441
+ for (let i = barsAboveBaseline.length - 1; i >= 0; i--) {
442
+ const bar = barsAboveBaseline[i];
443
+ const newValuePos = currentAbove - bar.length;
444
+ newPositions.set(bar.seriesId, {
445
+ valuePos: newValuePos,
446
+ length: bar.length
447
+ });
448
+ if (i > 0) {
449
+ const nextBar = barsAboveBaseline[i - 1];
450
+ const originalCurrent = bars.find(b => b.seriesId === bar.seriesId);
451
+ const originalNext = bars.find(b => b.seriesId === nextBar.seriesId);
452
+ const originalGap = originalCurrent.valuePos - (originalNext.valuePos + originalNext.length);
453
+ currentAbove = newValuePos - originalGap;
454
+ }
455
+ }
456
+
457
+ // Restack bars below baseline (growing away from it in the negative direction)
458
+ let currentBelow = baseline;
459
+ for (let i = 0; i < barsBelowBaseline.length; i++) {
460
+ const bar = barsBelowBaseline[i];
461
+ newPositions.set(bar.seriesId, {
462
+ valuePos: currentBelow,
463
+ length: bar.length
464
+ });
465
+ if (i < barsBelowBaseline.length - 1) {
466
+ const nextBar = barsBelowBaseline[i + 1];
467
+ const originalCurrent = bars.find(b => b.seriesId === bar.seriesId);
468
+ const originalNext = bars.find(b => b.seriesId === nextBar.seriesId);
469
+ const originalGap = originalNext.valuePos - (originalCurrent.valuePos + originalCurrent.length);
470
+ currentBelow = currentBelow + bar.length + originalGap;
471
+ }
472
+ }
473
+ }
474
+ return expandedBars.map(bar => {
475
+ const newPos = newPositions.get(bar.seriesId);
476
+ if (newPos) return _extends({}, bar, {
477
+ valuePos: newPos.valuePos,
478
+ length: newPos.length
479
+ });
480
+ return bar;
481
+ });
482
+ }
483
+
484
+ /**
485
+ * Scales a stack of bars up so the total stack extent meets `stackMinSize`.
486
+ * For a single bar, the bar is expanded away from the baseline.
487
+ * For multiple bars, all bars are scaled proportionally, preserving relative gaps.
488
+ *
489
+ * @param bars - Array of bar items with current valuePos and length
490
+ * @param stackMinSize - Minimum stack size in pixels
491
+ * @param stackSize - Current total pixel extent of the stack
492
+ * @param stackBounds - Current bounding rect of the stack
493
+ * @param layout - The layout of the chart
494
+ * @param indexPos - Pixel position along the categorical (index) axis
495
+ * @param thickness - Bar thickness in pixels
496
+ * @param baseline - Pixel position of the zero value on the value axis
497
+ * @returns Updated bars and stackBounds; unchanged if stackSize >= stackMinSize
498
+ */
499
+ function applyStackMinSize(bars, stackMinSize, stackSize, stackBounds, layout, indexPos, thickness, baseline) {
500
+ if (!stackMinSize || stackSize >= stackMinSize) return {
501
+ bars,
502
+ stackBounds
503
+ };
504
+ if (bars.length === 0) return {
505
+ bars,
506
+ stackBounds
507
+ };
508
+ let updatedBars = [...bars];
509
+ let updatedBounds = _extends({}, stackBounds);
510
+ if (bars.length === 1) {
511
+ const bar = bars[0];
512
+ const sizeIncrease = stackMinSize - bar.length;
513
+ const [bottom, top] = [...bar.dataValue].sort((a, b) => a - b);
514
+ let newValuePos;
515
+ const newLength = stackMinSize;
516
+ if (bottom >= 0 && top !== bottom) {
517
+ // Bar is on the positive side: vertical→expands upward (↑), horizontal→expands rightward (→)
518
+ newValuePos = layout === 'vertical' ? bar.valuePos - sizeIncrease : bar.valuePos;
519
+ } else if (top <= 0 && top !== bottom) {
520
+ // Bar is on the negative side: vertical→expands downward (↓), horizontal→expands leftward (←)
521
+ newValuePos = layout === 'vertical' ? bar.valuePos : bar.valuePos - sizeIncrease;
522
+ } else {
523
+ // Bar spans baseline or is zero: expand equally in both directions
524
+ newValuePos = bar.valuePos - sizeIncrease / 2;
525
+ }
526
+ updatedBars = [_extends({}, bar, {
527
+ valuePos: newValuePos,
528
+ length: newLength
529
+ })];
530
+ updatedBounds = {
531
+ x: layout === 'vertical' ? indexPos : newValuePos,
532
+ y: layout === 'vertical' ? newValuePos : indexPos,
533
+ width: layout === 'vertical' ? thickness : newLength,
534
+ height: layout === 'vertical' ? newLength : thickness
535
+ };
536
+ } else {
537
+ const totalBarLength = bars.reduce((sum, bar) => sum + bar.length, 0);
538
+ const totalGapLength = stackSize - totalBarLength;
539
+ const requiredBarLength = stackMinSize - totalGapLength;
540
+ const barScaleFactor = requiredBarLength / totalBarLength;
541
+ const sortedBars = [...bars].sort((a, b) => a.valuePos - b.valuePos);
542
+
543
+ // For vertical: positive bars are above baseline (smaller Y), negative bars are below (larger Y)
544
+ // For horizontal: positive bars are right of baseline (larger X), negative bars are left (smaller X)
545
+ const barsOnPositiveSide = layout === 'vertical' ? sortedBars.filter(bar => bar.valuePos + bar.length <= baseline) : sortedBars.filter(bar => bar.valuePos >= baseline);
546
+ const barsOnNegativeSide = layout === 'vertical' ? sortedBars.filter(bar => bar.valuePos >= baseline) : sortedBars.filter(bar => bar.valuePos + bar.length <= baseline);
547
+ const newPositions = new Map();
548
+ if (layout === 'vertical') {
549
+ // Stack from baseline upward (decreasing valuePos) for positive bars
550
+ let currentPos = baseline;
551
+ for (let i = barsOnPositiveSide.length - 1; i >= 0; i--) {
552
+ const bar = barsOnPositiveSide[i];
553
+ const newLength = bar.length * barScaleFactor;
554
+ const newValuePos = currentPos - newLength;
555
+ newPositions.set(bar.seriesId, {
556
+ valuePos: newValuePos,
557
+ length: newLength
558
+ });
559
+ if (i > 0) {
560
+ const nextBar = barsOnPositiveSide[i - 1];
561
+ const originalGap = bar.valuePos - (nextBar.valuePos + nextBar.length);
562
+ currentPos = newValuePos - originalGap;
563
+ }
564
+ }
565
+ // Stack from baseline downward (increasing valuePos) for negative bars
566
+ let currentPosBelow = baseline;
567
+ for (let i = 0; i < barsOnNegativeSide.length; i++) {
568
+ const bar = barsOnNegativeSide[i];
569
+ const newLength = bar.length * barScaleFactor;
570
+ newPositions.set(bar.seriesId, {
571
+ valuePos: currentPosBelow,
572
+ length: newLength
573
+ });
574
+ if (i < barsOnNegativeSide.length - 1) {
575
+ const nextBar = barsOnNegativeSide[i + 1];
576
+ const originalGap = nextBar.valuePos - (bar.valuePos + bar.length);
577
+ currentPosBelow = currentPosBelow + newLength + originalGap;
578
+ }
579
+ }
580
+ } else {
581
+ // Stack from baseline rightward (increasing valuePos) for positive bars
582
+ let currentPos = baseline;
583
+ for (let i = 0; i < barsOnPositiveSide.length; i++) {
584
+ const bar = barsOnPositiveSide[i];
585
+ const newLength = bar.length * barScaleFactor;
586
+ newPositions.set(bar.seriesId, {
587
+ valuePos: currentPos,
588
+ length: newLength
589
+ });
590
+ if (i < barsOnPositiveSide.length - 1) {
591
+ const nextBar = barsOnPositiveSide[i + 1];
592
+ const originalGap = nextBar.valuePos - (bar.valuePos + bar.length);
593
+ currentPos = currentPos + newLength + originalGap;
594
+ }
595
+ }
596
+ // Stack from baseline leftward (decreasing valuePos) for negative bars
597
+ let currentPosLeft = baseline;
598
+ for (let i = barsOnNegativeSide.length - 1; i >= 0; i--) {
599
+ const bar = barsOnNegativeSide[i];
600
+ const newLength = bar.length * barScaleFactor;
601
+ const newValuePos = currentPosLeft - newLength;
602
+ newPositions.set(bar.seriesId, {
603
+ valuePos: newValuePos,
604
+ length: newLength
605
+ });
606
+ if (i > 0) {
607
+ const nextBar = barsOnNegativeSide[i - 1];
608
+ const originalGap = bar.valuePos - (nextBar.valuePos + nextBar.length);
609
+ currentPosLeft = newValuePos - originalGap;
610
+ }
611
+ }
612
+ }
613
+ updatedBars = bars.map(bar => {
614
+ const newPos = newPositions.get(bar.seriesId);
615
+ if (!newPos) return bar;
616
+ return _extends({}, bar, {
617
+ length: newPos.length,
618
+ valuePos: newPos.valuePos
619
+ });
620
+ });
621
+ const newMinValuePos = Math.min(...updatedBars.map(bar => bar.valuePos));
622
+ const newMaxValuePos = Math.max(...updatedBars.map(bar => bar.valuePos + bar.length));
623
+ updatedBounds = {
624
+ x: layout === 'vertical' ? indexPos : newMinValuePos,
625
+ y: layout === 'vertical' ? newMinValuePos : indexPos,
626
+ width: layout === 'vertical' ? thickness : newMaxValuePos - newMinValuePos,
627
+ height: layout === 'vertical' ? newMaxValuePos - newMinValuePos : thickness
628
+ };
629
+ }
630
+ return {
631
+ bars: updatedBars,
632
+ stackBounds: updatedBounds
633
+ };
634
+ }
635
+
636
+ /**
637
+ * Applies border-radius flags to a sorted stack of bars.
638
+ *
639
+ * Faces at the outer edges of the stack remain rounded; faces where two bars
640
+ * touch internally are squared. When `stackGap` is non-zero every face keeps
641
+ * its rounded corner because all bars are visually separated.
642
+ *
643
+ * @param bars - Bars with `roundTop`/`roundBottom` flags and position data
644
+ * @param layout - The layout of the chart
645
+ * @param stackGap - Pixel gap between adjacent bars (non-zero ⇒ all faces stay rounded)
646
+ * @returns New array of bars with corrected `roundTop`/`roundBottom` flags
647
+ */
648
+ function applyBorderRadiusLogic(bars, layout, stackGap) {
649
+ if (bars.length === 0) return bars;
650
+
651
+ // Sort from "lower coordinate" face to "higher coordinate" face along the value axis:
652
+ // Vertical → descending valuePos (largest Y first = closest to baseline)
653
+ // Horizontal → ascending valuePos (smallest X first = closest to baseline)
654
+ const sortedBars = layout === 'vertical' ? [...bars].sort((a, b) => b.valuePos - a.valuePos) : [...bars].sort((a, b) => a.valuePos - b.valuePos);
655
+ return sortedBars.map((a, index) => {
656
+ const barBefore = index > 0 ? sortedBars[index - 1] : null;
657
+ const barAfter = index < sortedBars.length - 1 ? sortedBars[index + 1] : null;
658
+
659
+ // shouldRoundLower: face with the smaller coordinate (top in vertical, left in horizontal)
660
+ const shouldRoundLower = (layout === 'vertical' ? index === sortedBars.length - 1 : index === 0) || Boolean(a.shouldApplyGap && stackGap) || !a.shouldApplyGap && barAfter !== null && barAfter.valuePos + barAfter.length !== a.valuePos;
661
+
662
+ // shouldRoundHigher: face with the larger coordinate (bottom in vertical, right in horizontal)
663
+ const shouldRoundHigher = (layout === 'vertical' ? index === 0 : index === sortedBars.length - 1) || Boolean(a.shouldApplyGap && stackGap) || !a.shouldApplyGap && barBefore !== null && barBefore.valuePos !== a.valuePos + a.length;
664
+ return _extends({}, a, {
665
+ roundTop: Boolean(a.roundTop && (layout === 'vertical' ? shouldRoundLower : shouldRoundHigher)),
666
+ roundBottom: Boolean(a.roundBottom && (layout === 'vertical' ? shouldRoundHigher : shouldRoundLower))
667
+ });
668
+ });
669
+ }
670
+
671
+ /**
672
+ * Threshold for treating a position as touching the baseline.
673
+ * Positions within this distance are considered at the baseline for rounding purposes.
674
+ */
675
+ export const EPSILON = 1e-4;
676
+
677
+ /**
678
+ * Computes and clamps the stack baseline position on the value axis.
679
+ *
680
+ * - If the full domain is positive, baseline is domain min.
681
+ * - If the full domain is negative, baseline is domain max.
682
+ * - If the domain crosses zero, baseline is 0.
683
+ */
684
+ export function getStackBaseline(valueScale, stackRect, layout) {
685
+ const [domainMin, domainMax] = valueScale.domain();
686
+ const baselineValue = domainMin >= 0 ? domainMin : domainMax <= 0 ? domainMax : 0;
687
+ const baselinePos = valueScale(baselineValue);
688
+ if (layout === 'vertical') {
689
+ return Math.max(stackRect.y, Math.min(baselinePos != null ? baselinePos : stackRect.y + stackRect.height, stackRect.y + stackRect.height));
690
+ }
691
+ return Math.max(stackRect.x, Math.min(baselinePos != null ? baselinePos : stackRect.x, stackRect.x + stackRect.width));
692
+ }
693
+ function getStackBoundsForLayout(layout, indexPos, thickness, minValuePos, stackSize) {
694
+ if (layout === 'vertical') {
695
+ return {
696
+ x: indexPos,
697
+ y: minValuePos,
698
+ width: thickness,
699
+ height: stackSize
700
+ };
701
+ }
702
+ return {
703
+ x: minValuePos,
704
+ y: indexPos,
705
+ width: stackSize,
706
+ height: thickness
707
+ };
708
+ }
709
+ function getStackSizeForLayout(layout, stackRect) {
710
+ return layout === 'vertical' ? stackRect.height : stackRect.width;
711
+ }
712
+
713
+ /**
714
+ * Computes the positioned bar entries and bounding rect for a single stack at one category index.
715
+ *
716
+ * This is the pure computation extracted from `BarStack`'s `useMemo` so it can be tested
717
+ * independently and reused across contexts.
718
+ *
719
+ * @param params.series - Series configs for this stack
720
+ * @param params.seriesData - Stacked data for each series, keyed by series id
721
+ * @param params.categoryIndex - Index of the category being rendered
722
+ * @param params.indexPos - Pixel position along the categorical axis
723
+ * @param params.thickness - Bar thickness in pixels
724
+ * @param params.valueScale - Scale function for the value axis
725
+ * @param params.seriesGradients - Precomputed gradient configs per series (undefined entries are skipped)
726
+ * @param params.roundBaseline - Whether to round the face touching the baseline
727
+ * @param params.layout - The layout of the chart
728
+ * @param params.baseline - Pixel position of the zero value on the value axis
729
+ * @param params.stackGap - Gap between adjacent bars in pixels
730
+ * @param params.barMinSize - Minimum individual bar size in pixels
731
+ * @param params.stackMinSize - Minimum total stack size in pixels
732
+ * @param params.defaultFill - Fallback fill color when a series has no color or gradient
733
+ * @returns Positioned bar entries and the stack's bounding rect
734
+ */
735
+ export function getBars(params) {
736
+ const {
737
+ series,
738
+ seriesData,
739
+ categoryIndex,
740
+ categoryValue,
741
+ indexPos,
742
+ thickness,
743
+ valueScale,
744
+ seriesGradients,
745
+ roundBaseline,
746
+ layout,
747
+ baseline,
748
+ stackGap,
749
+ barMinSize,
750
+ stackMinSize,
751
+ defaultFill,
752
+ borderRadius,
753
+ defaultFillOpacity,
754
+ defaultStroke,
755
+ defaultStrokeWidth,
756
+ defaultBarComponent
757
+ } = params;
758
+ let allBars = [];
759
+ series.forEach(s => {
760
+ var _valueScale, _valueScale2;
761
+ const data = seriesData[s.id];
762
+ if (!data) return;
763
+ const value = data[categoryIndex];
764
+ if (value === null || value === undefined) return;
765
+ const originalData = s.data;
766
+ const originalValue = originalData == null ? void 0 : originalData[categoryIndex];
767
+ const shouldApplyGap = !Array.isArray(originalValue);
768
+ const [bottom, top] = [...value].sort((a, b) => a - b);
769
+ const edgeBottom = (_valueScale = valueScale(bottom)) != null ? _valueScale : baseline;
770
+ const edgeTop = (_valueScale2 = valueScale(top)) != null ? _valueScale2 : baseline;
771
+ const roundTop = roundBaseline || Math.abs(edgeTop - baseline) >= EPSILON;
772
+ const roundBottom = roundBaseline || Math.abs(edgeBottom - baseline) >= EPSILON;
773
+ const length = Math.abs(edgeBottom - edgeTop);
774
+ const valuePos = Math.min(edgeBottom, edgeTop);
775
+ if (length <= 0) return;
776
+ let barFill = s.color || defaultFill;
777
+ const seriesGradientConfig = seriesGradients.find(g => (g == null ? void 0 : g.seriesId) === s.id);
778
+ if (seriesGradientConfig && originalValue !== null && originalValue !== undefined) {
779
+ var _seriesGradientConfig;
780
+ const axis = (_seriesGradientConfig = seriesGradientConfig.gradient.axis) != null ? _seriesGradientConfig : 'y';
781
+ let evalValue;
782
+ if (axis === 'x') {
783
+ evalValue = layout === 'vertical' ? categoryIndex : Array.isArray(originalValue) ? originalValue[1] : originalValue;
784
+ } else {
785
+ evalValue = layout === 'vertical' ? Array.isArray(originalValue) ? originalValue[1] : originalValue : categoryIndex;
786
+ }
787
+ const evaluatedColor = evaluateGradientAtValue(seriesGradientConfig.stops, evalValue, seriesGradientConfig.scale);
788
+ if (evaluatedColor) {
789
+ barFill = evaluatedColor;
790
+ }
791
+ }
792
+ allBars.push({
793
+ seriesId: s.id,
794
+ valuePos,
795
+ length,
796
+ dataValue: value,
797
+ fill: barFill,
798
+ roundTop,
799
+ roundBottom,
800
+ shouldApplyGap,
801
+ BarComponent: s.BarComponent,
802
+ x: 0,
803
+ y: 0,
804
+ width: 0,
805
+ height: 0,
806
+ origin: 0
807
+ });
808
+ });
809
+
810
+ // Apply proportional gap distribution to maintain total stack length
811
+ if (stackGap && allBars.length > 1) {
812
+ allBars = applyStackGap(allBars, stackGap, layout, baseline);
813
+ }
814
+
815
+ // Apply barMinSize constraints
816
+ if (barMinSize) {
817
+ allBars = applyBarMinSize(allBars, barMinSize, layout, baseline);
818
+ }
819
+ allBars = applyBorderRadiusLogic(allBars, layout, stackGap);
820
+
821
+ // Apply stackMinSize constraints
822
+ if (stackMinSize && allBars.length > 0) {
823
+ const minValuePos = Math.min(...allBars.map(bar => bar.valuePos));
824
+ const maxValuePos = Math.max(...allBars.map(bar => bar.valuePos + bar.length));
825
+ const stackSize = maxValuePos - minValuePos;
826
+ const stackBounds = getStackBoundsForLayout(layout, indexPos, thickness, minValuePos, stackSize);
827
+ const result = applyStackMinSize(allBars, stackMinSize, stackSize, stackBounds, layout, indexPos, thickness, baseline);
828
+ allBars = result.bars;
829
+
830
+ // Reapply border radius logic only if we actually scaled
831
+ const newStackSize = getStackSizeForLayout(layout, result.stackBounds);
832
+ if (newStackSize < stackMinSize) {
833
+ allBars = applyBorderRadiusLogic(allBars, layout, stackGap);
834
+ }
835
+ }
836
+ const initialBarMinSizes = getInitialBarMinSizes(allBars, barMinSize, stackMinSize);
837
+ const barOrigins = getBarOrigins(allBars, initialBarMinSizes, stackGap != null ? stackGap : 0, baseline, layout);
838
+ return allBars.map((bar, i) => _extends({}, bar, {
839
+ x: layout === 'vertical' ? indexPos : bar.valuePos,
840
+ y: layout === 'vertical' ? bar.valuePos : indexPos,
841
+ width: layout === 'vertical' ? thickness : bar.length,
842
+ height: layout === 'vertical' ? bar.length : thickness,
843
+ dataX: layout === 'vertical' ? categoryValue : bar.dataValue,
844
+ dataY: layout === 'vertical' ? bar.dataValue : categoryValue,
845
+ origin: barOrigins[i],
846
+ borderRadius,
847
+ fillOpacity: defaultFillOpacity,
848
+ stroke: defaultStroke,
849
+ strokeWidth: defaultStrokeWidth,
850
+ minSize: initialBarMinSizes[i],
851
+ BarComponent: bar.BarComponent || defaultBarComponent
852
+ }));
24
853
  }