@coinbase/cds-web-visualization 3.3.0 → 3.4.0-beta.2

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 (204) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dts/chart/CartesianChart.d.ts +36 -0
  3. package/dts/chart/CartesianChart.d.ts.map +1 -0
  4. package/dts/chart/ChartProvider.d.ts +6 -0
  5. package/dts/chart/ChartProvider.d.ts.map +1 -0
  6. package/dts/chart/Path.d.ts +34 -0
  7. package/dts/chart/Path.d.ts.map +1 -0
  8. package/dts/chart/PeriodSelector.d.ts +61 -0
  9. package/dts/chart/PeriodSelector.d.ts.map +1 -0
  10. package/dts/chart/Point.d.ts +153 -0
  11. package/dts/chart/Point.d.ts.map +1 -0
  12. package/dts/chart/area/Area.d.ts +48 -0
  13. package/dts/chart/area/Area.d.ts.map +1 -0
  14. package/dts/chart/area/AreaChart.d.ts +52 -0
  15. package/dts/chart/area/AreaChart.d.ts.map +1 -0
  16. package/dts/chart/area/DottedArea.d.ts +68 -0
  17. package/dts/chart/area/DottedArea.d.ts.map +1 -0
  18. package/dts/chart/area/GradientArea.d.ts +30 -0
  19. package/dts/chart/area/GradientArea.d.ts.map +1 -0
  20. package/dts/chart/area/SolidArea.d.ts +8 -0
  21. package/dts/chart/area/SolidArea.d.ts.map +1 -0
  22. package/dts/chart/area/index.d.ts +6 -0
  23. package/dts/chart/area/index.d.ts.map +1 -0
  24. package/dts/chart/axis/Axis.d.ts +208 -0
  25. package/dts/chart/axis/Axis.d.ts.map +1 -0
  26. package/dts/chart/axis/XAxis.d.ts +16 -0
  27. package/dts/chart/axis/XAxis.d.ts.map +1 -0
  28. package/dts/chart/axis/YAxis.d.ts +21 -0
  29. package/dts/chart/axis/YAxis.d.ts.map +1 -0
  30. package/dts/chart/axis/index.d.ts +4 -0
  31. package/dts/chart/axis/index.d.ts.map +1 -0
  32. package/dts/chart/bar/Bar.d.ts +91 -0
  33. package/dts/chart/bar/Bar.d.ts.map +1 -0
  34. package/dts/chart/bar/BarChart.d.ts +53 -0
  35. package/dts/chart/bar/BarChart.d.ts.map +1 -0
  36. package/dts/chart/bar/BarPlot.d.ts +29 -0
  37. package/dts/chart/bar/BarPlot.d.ts.map +1 -0
  38. package/dts/chart/bar/BarStack.d.ts +111 -0
  39. package/dts/chart/bar/BarStack.d.ts.map +1 -0
  40. package/dts/chart/bar/BarStackGroup.d.ts +35 -0
  41. package/dts/chart/bar/BarStackGroup.d.ts.map +1 -0
  42. package/dts/chart/bar/DefaultBar.d.ts +17 -0
  43. package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
  44. package/dts/chart/bar/DefaultBarStack.d.ts +16 -0
  45. package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -0
  46. package/dts/chart/bar/index.d.ts +8 -0
  47. package/dts/chart/bar/index.d.ts.map +1 -0
  48. package/dts/chart/index.d.ts +13 -0
  49. package/dts/chart/index.d.ts.map +1 -0
  50. package/dts/chart/line/DottedLine.d.ts +14 -0
  51. package/dts/chart/line/DottedLine.d.ts.map +1 -0
  52. package/dts/chart/line/GradientLine.d.ts +42 -0
  53. package/dts/chart/line/GradientLine.d.ts.map +1 -0
  54. package/dts/chart/line/Line.d.ts +80 -0
  55. package/dts/chart/line/Line.d.ts.map +1 -0
  56. package/dts/chart/line/LineChart.d.ts +59 -0
  57. package/dts/chart/line/LineChart.d.ts.map +1 -0
  58. package/dts/chart/line/ReferenceLine.d.ts +131 -0
  59. package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
  60. package/dts/chart/line/SolidLine.d.ts +14 -0
  61. package/dts/chart/line/SolidLine.d.ts.map +1 -0
  62. package/dts/chart/line/index.d.ts +7 -0
  63. package/dts/chart/line/index.d.ts.map +1 -0
  64. package/dts/chart/scrubber/Scrubber.d.ts +149 -0
  65. package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
  66. package/dts/chart/scrubber/ScrubberBeacon.d.ts +93 -0
  67. package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +1 -0
  68. package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts +7 -0
  69. package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts.map +1 -0
  70. package/dts/chart/scrubber/ScrubberProvider.d.ts +17 -0
  71. package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
  72. package/dts/chart/scrubber/index.d.ts +2 -0
  73. package/dts/chart/scrubber/index.d.ts.map +1 -0
  74. package/dts/chart/text/ChartText.d.ts +114 -0
  75. package/dts/chart/text/ChartText.d.ts.map +1 -0
  76. package/dts/chart/text/SmartChartTextGroup.d.ts +55 -0
  77. package/dts/chart/text/SmartChartTextGroup.d.ts.map +1 -0
  78. package/dts/chart/text/index.d.ts +3 -0
  79. package/dts/chart/text/index.d.ts.map +1 -0
  80. package/dts/chart/utils/axis.d.ts +342 -0
  81. package/dts/chart/utils/axis.d.ts.map +1 -0
  82. package/dts/chart/utils/bar.d.ts +20 -0
  83. package/dts/chart/utils/bar.d.ts.map +1 -0
  84. package/dts/chart/utils/chart.d.ts +97 -0
  85. package/dts/chart/utils/chart.d.ts.map +1 -0
  86. package/dts/chart/utils/context.d.ts +95 -0
  87. package/dts/chart/utils/context.d.ts.map +1 -0
  88. package/dts/chart/utils/index.d.ts +8 -0
  89. package/dts/chart/utils/index.d.ts.map +1 -0
  90. package/dts/chart/utils/path.d.ts +107 -0
  91. package/dts/chart/utils/path.d.ts.map +1 -0
  92. package/dts/chart/utils/point.d.ts +75 -0
  93. package/dts/chart/utils/point.d.ts.map +1 -0
  94. package/dts/chart/utils/scale.d.ts +43 -0
  95. package/dts/chart/utils/scale.d.ts.map +1 -0
  96. package/dts/index.d.ts +2 -1
  97. package/dts/index.d.ts.map +1 -1
  98. package/dts/sparkline/Counter.d.ts +7 -2
  99. package/dts/sparkline/Sparkline.d.ts +61 -16
  100. package/dts/sparkline/Sparkline.d.ts.map +1 -1
  101. package/dts/sparkline/SparklineArea.d.ts +12 -4
  102. package/dts/sparkline/SparklineArea.d.ts.map +1 -1
  103. package/dts/sparkline/SparklineAreaPattern.d.ts +12 -4
  104. package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -1
  105. package/dts/sparkline/SparklineGradient.d.ts +21 -10
  106. package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
  107. package/dts/sparkline/SparklinePath.d.ts +8 -6
  108. package/dts/sparkline/__figma__/Sparkline.figma.d.ts +1 -1
  109. package/dts/sparkline/generateSparklineWithId.d.ts +8 -2
  110. package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -1
  111. package/dts/sparkline/index.d.ts +1 -1
  112. package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts +9 -5
  113. package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +168 -118
  114. package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
  115. package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +22 -9
  116. package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -1
  117. package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +4 -2
  118. package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts +4 -2
  119. package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +5 -3
  120. package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +11 -6
  121. package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +21 -7
  122. package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -1
  123. package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +21 -16
  124. package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +17 -12
  125. package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts +23 -10
  126. package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts +12 -12
  127. package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +22 -14
  128. package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +1 -1
  129. package/dts/sparkline/sparkline-interactive/fade.d.ts +1 -1
  130. package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +11 -11
  131. package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +101 -93
  132. package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +1 -1
  133. package/esm/chart/CartesianChart.css +1 -0
  134. package/esm/chart/CartesianChart.js +258 -0
  135. package/esm/chart/ChartProvider.js +10 -0
  136. package/esm/chart/Path.js +89 -0
  137. package/esm/chart/PeriodSelector.css +1 -0
  138. package/esm/chart/PeriodSelector.js +126 -0
  139. package/esm/chart/Point.css +2 -0
  140. package/esm/chart/Point.js +171 -0
  141. package/esm/chart/area/Area.js +85 -0
  142. package/esm/chart/area/AreaChart.js +164 -0
  143. package/esm/chart/area/DottedArea.js +141 -0
  144. package/esm/chart/area/GradientArea.js +111 -0
  145. package/esm/chart/area/SolidArea.js +29 -0
  146. package/esm/chart/area/index.js +7 -0
  147. package/esm/chart/axis/Axis.js +46 -0
  148. package/esm/chart/axis/XAxis.css +2 -0
  149. package/esm/chart/axis/XAxis.js +195 -0
  150. package/esm/chart/axis/YAxis.css +2 -0
  151. package/esm/chart/axis/YAxis.js +183 -0
  152. package/esm/chart/axis/index.js +5 -0
  153. package/esm/chart/bar/Bar.js +59 -0
  154. package/esm/chart/bar/BarChart.js +147 -0
  155. package/esm/chart/bar/BarPlot.js +96 -0
  156. package/esm/chart/bar/BarStack.js +519 -0
  157. package/esm/chart/bar/BarStackGroup.js +96 -0
  158. package/esm/chart/bar/DefaultBar.js +64 -0
  159. package/esm/chart/bar/DefaultBarStack.js +60 -0
  160. package/esm/chart/bar/index.js +9 -0
  161. package/esm/chart/index.js +14 -0
  162. package/esm/chart/line/DottedLine.js +38 -0
  163. package/esm/chart/line/GradientLine.js +58 -0
  164. package/esm/chart/line/Line.js +159 -0
  165. package/esm/chart/line/LineChart.js +120 -0
  166. package/esm/chart/line/ReferenceLine.js +142 -0
  167. package/esm/chart/line/SolidLine.js +34 -0
  168. package/esm/chart/line/index.js +8 -0
  169. package/esm/chart/scrubber/Scrubber.js +483 -0
  170. package/esm/chart/scrubber/ScrubberBeacon.js +195 -0
  171. package/esm/chart/scrubber/ScrubberBeaconLabel.js +33 -0
  172. package/esm/chart/scrubber/ScrubberProvider.js +228 -0
  173. package/esm/chart/scrubber/index.js +2 -0
  174. package/esm/chart/text/ChartText.js +236 -0
  175. package/esm/chart/text/SmartChartTextGroup.js +226 -0
  176. package/esm/chart/text/index.js +4 -0
  177. package/esm/chart/utils/axis.js +593 -0
  178. package/esm/chart/utils/bar.js +24 -0
  179. package/esm/chart/utils/chart.js +229 -0
  180. package/esm/chart/utils/context.js +15 -0
  181. package/esm/chart/utils/index.js +9 -0
  182. package/esm/chart/utils/path.js +204 -0
  183. package/esm/chart/utils/point.js +118 -0
  184. package/esm/chart/utils/scale.js +48 -0
  185. package/esm/index.js +4 -1
  186. package/esm/sparkline/Sparkline.js +129 -15
  187. package/esm/sparkline/SparklineArea.js +7 -2
  188. package/esm/sparkline/SparklineAreaPattern.js +4 -2
  189. package/esm/sparkline/SparklineGradient.js +16 -58
  190. package/esm/sparkline/generateSparklineWithId.js +3 -2
  191. package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +5 -1
  192. package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +5 -2
  193. package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +4 -0
  194. package/package.json +15 -11
  195. package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts +0 -374
  196. package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts.map +0 -1
  197. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts +0 -2
  198. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts.map +0 -1
  199. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts +0 -2
  200. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts.map +0 -1
  201. package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts +0 -87
  202. package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts.map +0 -1
  203. package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts +0 -2
  204. package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts.map +0 -1
@@ -0,0 +1,183 @@
1
+ const _excluded = ["axisId", "position", "showGrid", "requestedTickCount", "ticks", "tickLabelFormatter", "style", "className", "styles", "classNames", "GridLineComponent", "tickMarkLabelGap", "width", "minTickLabelGap", "showTickMarks", "showLine", "tickMarkSize", "tickInterval"];
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
8
+ 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; }
9
+ import { memo, useCallback, useEffect, useId, useMemo } from 'react';
10
+ import { cx } from '@coinbase/cds-web';
11
+ import { AnimatePresence, m as motion } from 'framer-motion';
12
+ import { useCartesianChartContext } from '../ChartProvider';
13
+ import { DottedLine } from '../line/DottedLine';
14
+ import { ReferenceLine } from '../line/ReferenceLine';
15
+ import { SmartChartTextGroup } from '../text/SmartChartTextGroup';
16
+ import { getAxisTicksData, isCategoricalScale } from '../utils';
17
+ import { axisLineStyles, axisTickLabelsInitialAnimationVariants, axisTickMarkStyles, axisUpdateAnimationVariants } from './Axis';
18
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
+ const axisTickMarkCss = "cds-axisTickMarkCss-au2toz5";
20
+ const axisLineCss = "cds-axisLineCss-akmofp5";
21
+ export const YAxis = /*#__PURE__*/memo(_ref => {
22
+ let {
23
+ axisId,
24
+ position = 'right',
25
+ showGrid,
26
+ requestedTickCount,
27
+ ticks,
28
+ tickLabelFormatter,
29
+ style,
30
+ className,
31
+ styles,
32
+ classNames,
33
+ GridLineComponent = DottedLine,
34
+ tickMarkLabelGap = 8,
35
+ width = 44,
36
+ minTickLabelGap = 0,
37
+ showTickMarks,
38
+ showLine,
39
+ tickMarkSize = 4,
40
+ tickInterval
41
+ } = _ref,
42
+ props = _objectWithoutProperties(_ref, _excluded);
43
+ const registrationId = useId();
44
+ const {
45
+ animate,
46
+ getYScale,
47
+ getYAxis,
48
+ registerAxis,
49
+ unregisterAxis,
50
+ getAxisBounds
51
+ } = useCartesianChartContext();
52
+ const yScale = getYScale(axisId);
53
+ const yAxis = getYAxis(axisId);
54
+ const axisBounds = getAxisBounds(registrationId);
55
+ useEffect(() => {
56
+ registerAxis(registrationId, position, width);
57
+ return () => unregisterAxis(registrationId);
58
+ }, [registrationId, registerAxis, unregisterAxis, position, width]);
59
+ const formatTick = useCallback(value => {
60
+ var _tickLabelFormatter;
61
+ // If we have string labels and no custom formatter, use the labels
62
+ const axisData = yAxis === null || yAxis === void 0 ? void 0 : yAxis.data;
63
+ const hasStringLabels = axisData && Array.isArray(axisData) && typeof axisData[0] === 'string';
64
+ if (hasStringLabels && !tickLabelFormatter && axisData[value] !== undefined) {
65
+ // Use the string label from the data array
66
+ return axisData[value];
67
+ }
68
+
69
+ // Otherwise use the formatter (if provided) or the value itself
70
+ return (_tickLabelFormatter = tickLabelFormatter === null || tickLabelFormatter === void 0 ? void 0 : tickLabelFormatter(value)) !== null && _tickLabelFormatter !== void 0 ? _tickLabelFormatter : value;
71
+ }, [yAxis === null || yAxis === void 0 ? void 0 : yAxis.data, tickLabelFormatter]);
72
+
73
+ // Use D3 to get the ticks data
74
+ // Result contains each tick value and its axis position
75
+ const ticksData = useMemo(() => {
76
+ if (!yScale) return [];
77
+
78
+ // Check if we have string labels
79
+ const axisData = yAxis === null || yAxis === void 0 ? void 0 : yAxis.data;
80
+ const hasStringLabels = axisData && Array.isArray(axisData) && typeof axisData[0] === 'string';
81
+
82
+ // For band scales, we need categories
83
+ let categories;
84
+ if (hasStringLabels) {
85
+ categories = axisData;
86
+ } else if (isCategoricalScale(yScale)) {
87
+ // For band scales without explicit string data, generate numeric categories
88
+ // based on the domain of the scale
89
+ const domain = yScale.domain();
90
+ categories = domain.map(String);
91
+ }
92
+
93
+ // For numeric data or no explicit data, use default tick generation
94
+ return getAxisTicksData({
95
+ scaleFunction: yScale,
96
+ ticks,
97
+ requestedTickCount: tickInterval !== undefined ? undefined : requestedTickCount !== null && requestedTickCount !== void 0 ? requestedTickCount : 5,
98
+ categories,
99
+ tickInterval: tickInterval
100
+ });
101
+ }, [ticks, yScale, requestedTickCount, tickInterval, yAxis === null || yAxis === void 0 ? void 0 : yAxis.data]);
102
+ const chartTextData = useMemo(() => {
103
+ if (!axisBounds) return null;
104
+ return ticksData.map(tick => {
105
+ const tickOffset = tickMarkLabelGap + (showTickMarks ? tickMarkSize : 0);
106
+ const labelX = position === 'left' ? axisBounds.x + axisBounds.width - tickOffset : axisBounds.x + tickOffset;
107
+ return {
108
+ x: labelX,
109
+ y: tick.position,
110
+ label: formatTick(tick.tick),
111
+ chartTextProps: {
112
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.tickLabel,
113
+ color: 'var(--color-fgMuted)',
114
+ verticalAlignment: 'middle',
115
+ style: styles === null || styles === void 0 ? void 0 : styles.tickLabel,
116
+ horizontalAlignment: position === 'left' ? 'right' : 'left'
117
+ }
118
+ };
119
+ });
120
+ }, [axisBounds, ticksData, tickMarkLabelGap, showTickMarks, tickMarkSize, position, formatTick, classNames === null || classNames === void 0 ? void 0 : classNames.tickLabel, styles === null || styles === void 0 ? void 0 : styles.tickLabel]);
121
+ if (!yScale) return;
122
+ return /*#__PURE__*/_jsxs("g", _objectSpread(_objectSpread({
123
+ className: cx(className, classNames === null || classNames === void 0 ? void 0 : classNames.root),
124
+ "data-axis": "y",
125
+ "data-position": position,
126
+ style: _objectSpread(_objectSpread({}, style), styles === null || styles === void 0 ? void 0 : styles.root)
127
+ }, props), {}, {
128
+ children: [showGrid && /*#__PURE__*/_jsx(AnimatePresence, {
129
+ initial: false,
130
+ children: ticksData.map((tick, index) => {
131
+ const horizontalLine = /*#__PURE__*/_jsx(ReferenceLine, {
132
+ LineComponent: GridLineComponent,
133
+ dataY: tick.tick,
134
+ yAxisId: axisId
135
+ });
136
+ return animate ? /*#__PURE__*/_jsx(motion.g, {
137
+ animate: "animate",
138
+ exit: "exit",
139
+ initial: "initial",
140
+ variants: axisUpdateAnimationVariants,
141
+ children: horizontalLine
142
+ }, "grid-".concat(tick.tick, "-").concat(index)) : /*#__PURE__*/_jsx("g", {
143
+ children: horizontalLine
144
+ }, "grid-".concat(tick.tick, "-").concat(index));
145
+ })
146
+ }), chartTextData && /*#__PURE__*/_jsx(AnimatePresence, {
147
+ children: /*#__PURE__*/_jsx(motion.g, {
148
+ animate: "animate",
149
+ exit: "exit",
150
+ initial: "initial",
151
+ variants: animate ? axisTickLabelsInitialAnimationVariants : undefined,
152
+ children: /*#__PURE__*/_jsx(SmartChartTextGroup, {
153
+ prioritizeEndLabels: true,
154
+ labels: chartTextData,
155
+ minGap: minTickLabelGap
156
+ })
157
+ })
158
+ }), axisBounds && showTickMarks && /*#__PURE__*/_jsx("g", {
159
+ "data-testid": "tick-marks",
160
+ children: ticksData.map((tick, index) => {
161
+ const tickX = position === 'left' ? axisBounds.x + axisBounds.width : axisBounds.x;
162
+ const tickMarkSizePixels = tickMarkSize;
163
+ const tickX2 = position === 'left' ? axisBounds.x + axisBounds.width - tickMarkSizePixels : axisBounds.x + tickMarkSizePixels;
164
+ return /*#__PURE__*/_jsx("line", {
165
+ className: cx(axisTickMarkCss, classNames === null || classNames === void 0 ? void 0 : classNames.tickMark),
166
+ style: styles === null || styles === void 0 ? void 0 : styles.tickMark,
167
+ x1: tickX,
168
+ x2: tickX2,
169
+ y1: tick.position,
170
+ y2: tick.position
171
+ }, "tick-mark-".concat(tick.tick, "-").concat(index));
172
+ })
173
+ }), axisBounds && showLine && /*#__PURE__*/_jsx("line", {
174
+ className: cx(axisLineCss, classNames === null || classNames === void 0 ? void 0 : classNames.line),
175
+ style: styles === null || styles === void 0 ? void 0 : styles.line,
176
+ x1: position === 'left' ? axisBounds.x + axisBounds.width : axisBounds.x,
177
+ x2: position === 'left' ? axisBounds.x + axisBounds.width : axisBounds.x,
178
+ y1: axisBounds.y,
179
+ y2: axisBounds.y + axisBounds.height
180
+ })]
181
+ }));
182
+ });
183
+ import "./YAxis.css";
@@ -0,0 +1,5 @@
1
+ // codegen:start {preset: barrel, include: ./*.tsx, exclude: ./__stories__/*.tsx}
2
+ export * from './Axis';
3
+ export * from './XAxis';
4
+ export * from './YAxis';
5
+ // codegen:end
@@ -0,0 +1,59 @@
1
+ import React, { memo, useMemo } from 'react';
2
+ import { getBarPath } from '../utils';
3
+ import { DefaultBar } from './';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ /**
6
+ * Simple bar component that renders a single bar at the specified position.
7
+ *
8
+ * This component is intentionally kept simple - it just renders a bar at the given
9
+ * x, y, width, height coordinates. Complex positioning logic (like handling stacks,
10
+ * groups, gaps, etc.) should be handled by parent components like BarChart or BarStack.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * <Bar x={10} y={20} width={50} height={100} fill="blue" />
15
+ * ```
16
+ */
17
+ export const Bar = /*#__PURE__*/memo(_ref => {
18
+ let {
19
+ x,
20
+ y,
21
+ width,
22
+ height,
23
+ originY,
24
+ dataX,
25
+ dataY,
26
+ BarComponent = DefaultBar,
27
+ fill = 'var(--color-fgPrimary)',
28
+ fillOpacity = 1,
29
+ stroke,
30
+ strokeWidth,
31
+ borderRadius = 4,
32
+ roundTop = true,
33
+ roundBottom = true
34
+ } = _ref;
35
+ const barPath = useMemo(() => {
36
+ return getBarPath(x, y, width, height, borderRadius, roundTop, roundBottom);
37
+ }, [x, y, width, height, borderRadius, roundTop, roundBottom]);
38
+ const effectiveOriginY = originY !== null && originY !== void 0 ? originY : y + height;
39
+ if (!barPath) {
40
+ return null;
41
+ }
42
+ return /*#__PURE__*/_jsx(BarComponent, {
43
+ borderRadius: borderRadius,
44
+ d: barPath,
45
+ dataX: dataX,
46
+ dataY: dataY,
47
+ fill: fill,
48
+ fillOpacity: fillOpacity,
49
+ height: height,
50
+ originY: effectiveOriginY,
51
+ roundBottom: roundBottom,
52
+ roundTop: roundTop,
53
+ stroke: stroke,
54
+ strokeWidth: strokeWidth,
55
+ width: width,
56
+ x: x,
57
+ y: y
58
+ });
59
+ });
@@ -0,0 +1,147 @@
1
+ const _excluded = ["series", "stacked", "showXAxis", "showYAxis", "xAxis", "yAxis", "inset", "children", "barPadding", "BarComponent", "fillOpacity", "stroke", "strokeWidth", "borderRadius", "roundBaseline", "BarStackComponent", "stackGap", "barMinSize", "stackMinSize"],
2
+ _excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range"],
3
+ _excluded3 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"];
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
7
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
8
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
10
+ 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; }
11
+ import { forwardRef, memo, useMemo } from 'react';
12
+ import { XAxis, YAxis } from '../axis';
13
+ import { CartesianChart } from '../CartesianChart';
14
+ import { defaultChartInset, defaultStackId, getChartInset } from '../utils';
15
+ import { BarPlot } from './BarPlot';
16
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
+ export const BarChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
18
+ let {
19
+ series,
20
+ stacked,
21
+ showXAxis,
22
+ showYAxis,
23
+ xAxis,
24
+ yAxis,
25
+ inset: userInset,
26
+ children,
27
+ barPadding,
28
+ BarComponent,
29
+ fillOpacity,
30
+ stroke,
31
+ strokeWidth,
32
+ borderRadius,
33
+ roundBaseline,
34
+ BarStackComponent,
35
+ stackGap,
36
+ barMinSize,
37
+ stackMinSize
38
+ } = _ref,
39
+ chartProps = _objectWithoutProperties(_ref, _excluded);
40
+ const calculatedInset = useMemo(() => getChartInset(userInset, defaultChartInset), [userInset]);
41
+
42
+ // Convert BarSeries to Series for Chart context
43
+ const chartSeries = useMemo(() => {
44
+ return series === null || series === void 0 ? void 0 : series.map(s => ({
45
+ id: s.id,
46
+ data: s.data,
47
+ label: s.label,
48
+ color: s.color,
49
+ yAxisId: s.yAxisId,
50
+ stackId: s.stackId
51
+ }));
52
+ }, [series]);
53
+ const transformedSeries = useMemo(() => {
54
+ if (!stacked || !chartSeries) return chartSeries;
55
+ return chartSeries.map(s => {
56
+ var _s$stackId;
57
+ return _objectSpread(_objectSpread({}, s), {}, {
58
+ stackId: (_s$stackId = s.stackId) !== null && _s$stackId !== void 0 ? _s$stackId : defaultStackId
59
+ });
60
+ });
61
+ }, [chartSeries, stacked]);
62
+ const seriesToRender = transformedSeries !== null && transformedSeries !== void 0 ? transformedSeries : chartSeries;
63
+
64
+ // Keep the original series with bar-specific props for BarPlot
65
+ const barSeriesToRender = useMemo(() => {
66
+ if (!stacked || !series) return series;
67
+ return series.map(s => {
68
+ var _s$stackId2;
69
+ return _objectSpread(_objectSpread({}, s), {}, {
70
+ stackId: (_s$stackId2 = s.stackId) !== null && _s$stackId2 !== void 0 ? _s$stackId2 : defaultStackId
71
+ });
72
+ });
73
+ }, [series, stacked]);
74
+
75
+ // Split axis props into config props for Chart and visual props for axis components
76
+ const _ref2 = xAxis || {},
77
+ {
78
+ scaleType: xScaleType,
79
+ data: xData,
80
+ categoryPadding: xCategoryPadding,
81
+ domain: xDomain,
82
+ domainLimit: xDomainLimit,
83
+ range: xRange
84
+ } = _ref2,
85
+ xAxisVisualProps = _objectWithoutProperties(_ref2, _excluded2);
86
+ const _ref3 = yAxis || {},
87
+ {
88
+ scaleType: yScaleType,
89
+ data: yData,
90
+ categoryPadding: yCategoryPadding,
91
+ domain: yDomain,
92
+ domainLimit: yDomainLimit,
93
+ range: yRange,
94
+ id: yAxisId
95
+ } = _ref3,
96
+ yAxisVisualProps = _objectWithoutProperties(_ref3, _excluded3);
97
+ const xAxisConfig = {
98
+ scaleType: xScaleType !== null && xScaleType !== void 0 ? xScaleType : 'band',
99
+ data: xData,
100
+ categoryPadding: xCategoryPadding,
101
+ domain: xDomain,
102
+ domainLimit: xDomainLimit,
103
+ range: xRange
104
+ };
105
+ const hasNegativeValues = useMemo(() => {
106
+ if (!series) return false;
107
+ return series.some(s => {
108
+ var _s$data;
109
+ return (_s$data = s.data) === null || _s$data === void 0 ? void 0 : _s$data.some(value => typeof value === 'number' && value < 0 || Array.isArray(value) && value.some(v => typeof v === 'number' && v < 0));
110
+ });
111
+ }, [series]);
112
+
113
+ // Set default min domain to 0 for area chart, but only if there are no negative values
114
+ const yAxisConfig = {
115
+ scaleType: yScaleType,
116
+ data: yData,
117
+ categoryPadding: yCategoryPadding,
118
+ domain: hasNegativeValues ? yDomain : _objectSpread({
119
+ min: 0
120
+ }, yDomain),
121
+ domainLimit: yDomainLimit,
122
+ range: yRange
123
+ };
124
+ return /*#__PURE__*/_jsxs(CartesianChart, _objectSpread(_objectSpread({}, chartProps), {}, {
125
+ ref: ref,
126
+ inset: calculatedInset,
127
+ series: seriesToRender,
128
+ xAxis: xAxisConfig,
129
+ yAxis: yAxisConfig,
130
+ children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _objectSpread({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _objectSpread({
131
+ axisId: yAxisId
132
+ }, yAxisVisualProps)), /*#__PURE__*/_jsx(BarPlot, {
133
+ BarComponent: BarComponent,
134
+ BarStackComponent: BarStackComponent,
135
+ barMinSize: barMinSize,
136
+ barPadding: barPadding,
137
+ borderRadius: borderRadius,
138
+ fillOpacity: fillOpacity,
139
+ roundBaseline: roundBaseline,
140
+ seriesIds: barSeriesToRender === null || barSeriesToRender === void 0 ? void 0 : barSeriesToRender.map(s => s.id),
141
+ stackGap: stackGap,
142
+ stackMinSize: stackMinSize,
143
+ stroke: stroke,
144
+ strokeWidth: strokeWidth
145
+ }), children]
146
+ }));
147
+ }));
@@ -0,0 +1,96 @@
1
+ import { memo, useId, useMemo } from 'react';
2
+ import { useCartesianChartContext } from '../ChartProvider';
3
+ import { defaultAxisId } from '../utils';
4
+ import { BarStackGroup } from './BarStackGroup';
5
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
6
+ /**
7
+ * BarPlot component that handles multiple series with proper stacking coordination.
8
+ * Groups series by stack ID + y-axis ID combination and renders BarStackGroup for each group.
9
+ * This allows series with different y-axes to be rendered side by side while preventing
10
+ * cross-axis stacking (e.g., comparing $1M vs $1B companies on different scales).
11
+ */
12
+ export const BarPlot = /*#__PURE__*/memo(_ref => {
13
+ let {
14
+ seriesIds,
15
+ barPadding = 0.1,
16
+ BarComponent: defaultBarComponent,
17
+ fillOpacity: defaultFillOpacity,
18
+ stroke: defaultStroke,
19
+ strokeWidth: defaultStrokeWidth,
20
+ borderRadius: defaultBorderRadius,
21
+ roundBaseline,
22
+ BarStackComponent,
23
+ stackGap,
24
+ barMinSize,
25
+ stackMinSize
26
+ } = _ref;
27
+ const {
28
+ series: allSeries,
29
+ drawingArea
30
+ } = useCartesianChartContext();
31
+ const clipPathId = useId();
32
+ const targetSeries = useMemo(() => {
33
+ // Then filter by seriesIds if provided
34
+ if (seriesIds !== undefined) {
35
+ return allSeries.filter(s => seriesIds.includes(s.id));
36
+ }
37
+ return allSeries;
38
+ }, [allSeries, seriesIds]);
39
+ const stackGroups = useMemo(() => {
40
+ const groups = new Map();
41
+
42
+ // Group series into stacks based on stackId + yAxisId combination
43
+ targetSeries.forEach(series => {
44
+ var _series$yAxisId;
45
+ const yAxisId = (_series$yAxisId = series.yAxisId) !== null && _series$yAxisId !== void 0 ? _series$yAxisId : defaultAxisId;
46
+ const stackId = series.stackId || "individual-".concat(series.id);
47
+ const stackKey = "".concat(stackId, ":").concat(yAxisId);
48
+ if (!groups.has(stackKey)) {
49
+ groups.set(stackKey, {
50
+ stackId: stackKey,
51
+ series: [],
52
+ yAxisId: series.yAxisId
53
+ });
54
+ }
55
+ const group = groups.get(stackKey);
56
+ group.series.push(series);
57
+ });
58
+ return Array.from(groups.values());
59
+ }, [targetSeries]);
60
+ if (!drawingArea) {
61
+ return null;
62
+ }
63
+ return /*#__PURE__*/_jsxs(_Fragment, {
64
+ children: [/*#__PURE__*/_jsx("defs", {
65
+ children: /*#__PURE__*/_jsx("clipPath", {
66
+ id: clipPathId,
67
+ children: /*#__PURE__*/_jsx("rect", {
68
+ height: drawingArea.height,
69
+ width: drawingArea.width,
70
+ x: drawingArea.x,
71
+ y: drawingArea.y
72
+ })
73
+ })
74
+ }), /*#__PURE__*/_jsx("g", {
75
+ clipPath: "url(#".concat(clipPathId, ")"),
76
+ "data-testid": "whoa",
77
+ children: stackGroups.map((group, stackIndex) => /*#__PURE__*/_jsx(BarStackGroup, {
78
+ BarComponent: defaultBarComponent,
79
+ BarStackComponent: BarStackComponent,
80
+ barMinSize: barMinSize,
81
+ barPadding: barPadding,
82
+ borderRadius: defaultBorderRadius,
83
+ fillOpacity: defaultFillOpacity,
84
+ roundBaseline: roundBaseline,
85
+ series: group.series,
86
+ stackGap: stackGap,
87
+ stackIndex: stackIndex,
88
+ stackMinSize: stackMinSize,
89
+ stroke: defaultStroke,
90
+ strokeWidth: defaultStrokeWidth,
91
+ totalStacks: stackGroups.length,
92
+ yAxisId: group.yAxisId
93
+ }, group.stackId))
94
+ })]
95
+ });
96
+ });