@coinbase/cds-mobile-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 (223) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dts/chart/CartesianChart.d.ts +101 -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 +48 -0
  7. package/dts/chart/Path.d.ts.map +1 -0
  8. package/dts/chart/PeriodSelector.d.ts +85 -0
  9. package/dts/chart/PeriodSelector.d.ts.map +1 -0
  10. package/dts/chart/Point.d.ts +103 -0
  11. package/dts/chart/Point.d.ts.map +1 -0
  12. package/dts/chart/area/Area.d.ts +62 -0
  13. package/dts/chart/area/Area.d.ts.map +1 -0
  14. package/dts/chart/area/AreaChart.d.ts +90 -0
  15. package/dts/chart/area/AreaChart.d.ts.map +1 -0
  16. package/dts/chart/area/DottedArea.d.ts +27 -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 +204 -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 +89 -0
  33. package/dts/chart/bar/Bar.d.ts.map +1 -0
  34. package/dts/chart/bar/BarChart.d.ts +97 -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 +7 -0
  43. package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
  44. package/dts/chart/bar/DefaultBarStack.d.ts +7 -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 +12 -0
  51. package/dts/chart/line/DottedLine.d.ts.map +1 -0
  52. package/dts/chart/line/GradientLine.d.ts +45 -0
  53. package/dts/chart/line/GradientLine.d.ts.map +1 -0
  54. package/dts/chart/line/Line.d.ts +78 -0
  55. package/dts/chart/line/Line.d.ts.map +1 -0
  56. package/dts/chart/line/LineChart.d.ts +84 -0
  57. package/dts/chart/line/LineChart.d.ts.map +1 -0
  58. package/dts/chart/line/ReferenceLine.d.ts +91 -0
  59. package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
  60. package/dts/chart/line/SolidLine.d.ts +12 -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 +104 -0
  65. package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
  66. package/dts/chart/scrubber/ScrubberBeacon.d.ts +75 -0
  67. package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +1 -0
  68. package/dts/chart/scrubber/ScrubberProvider.d.ts +17 -0
  69. package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
  70. package/dts/chart/scrubber/index.d.ts +2 -0
  71. package/dts/chart/scrubber/index.d.ts.map +1 -0
  72. package/dts/chart/text/ChartText.d.ts +90 -0
  73. package/dts/chart/text/ChartText.d.ts.map +1 -0
  74. package/dts/chart/text/SmartChartTextGroup.d.ts +55 -0
  75. package/dts/chart/text/SmartChartTextGroup.d.ts.map +1 -0
  76. package/dts/chart/text/index.d.ts +3 -0
  77. package/dts/chart/text/index.d.ts.map +1 -0
  78. package/dts/chart/utils/axis.d.ts +342 -0
  79. package/dts/chart/utils/axis.d.ts.map +1 -0
  80. package/dts/chart/utils/bar.d.ts +20 -0
  81. package/dts/chart/utils/bar.d.ts.map +1 -0
  82. package/dts/chart/utils/chart.d.ts +97 -0
  83. package/dts/chart/utils/chart.d.ts.map +1 -0
  84. package/dts/chart/utils/context.d.ts +95 -0
  85. package/dts/chart/utils/context.d.ts.map +1 -0
  86. package/dts/chart/utils/index.d.ts +8 -0
  87. package/dts/chart/utils/index.d.ts.map +1 -0
  88. package/dts/chart/utils/path.d.ts +107 -0
  89. package/dts/chart/utils/path.d.ts.map +1 -0
  90. package/dts/chart/utils/point.d.ts +75 -0
  91. package/dts/chart/utils/point.d.ts.map +1 -0
  92. package/dts/chart/utils/scale.d.ts +43 -0
  93. package/dts/chart/utils/scale.d.ts.map +1 -0
  94. package/dts/index.d.ts +2 -1
  95. package/dts/index.d.ts.map +1 -1
  96. package/dts/sparkline/Counter.d.ts +7 -2
  97. package/dts/sparkline/Sparkline.d.ts +67 -16
  98. package/dts/sparkline/Sparkline.d.ts.map +1 -1
  99. package/dts/sparkline/SparklineArea.d.ts +10 -4
  100. package/dts/sparkline/SparklineArea.d.ts.map +1 -1
  101. package/dts/sparkline/SparklineAreaPattern.d.ts +12 -4
  102. package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -1
  103. package/dts/sparkline/SparklineGradient.d.ts +21 -10
  104. package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
  105. package/dts/sparkline/__figma__/Sparkline.figma.d.ts +1 -1
  106. package/dts/sparkline/generateSparklineWithId.d.ts +8 -2
  107. package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -1
  108. package/dts/sparkline/index.d.ts +1 -1
  109. package/dts/sparkline/sparkline-interactive/SparklineAccessibleView.d.ts +8 -3
  110. package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +132 -110
  111. package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
  112. package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +22 -9
  113. package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -1
  114. package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +18 -7
  115. package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +9 -4
  116. package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +11 -6
  117. package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts +7 -5
  118. package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts +22 -10
  119. package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +21 -7
  120. package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -1
  121. package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +21 -16
  122. package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +29 -23
  123. package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +22 -14
  124. package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +1 -1
  125. package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts +9 -5
  126. package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts +11 -6
  127. package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts +5 -2
  128. package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +17 -17
  129. package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts +16 -13
  130. package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +106 -98
  131. package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +1 -1
  132. package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts +22 -19
  133. package/esm/chart/CartesianChart.js +241 -0
  134. package/esm/chart/ChartProvider.js +10 -0
  135. package/esm/chart/Path.js +133 -0
  136. package/esm/chart/PeriodSelector.js +136 -0
  137. package/esm/chart/Point.js +111 -0
  138. package/esm/chart/__stories__/CartesianChart.stories.js +476 -0
  139. package/esm/chart/__stories__/Chart.stories.js +79 -0
  140. package/esm/chart/__stories__/PeriodSelector.stories.js +294 -0
  141. package/esm/chart/area/Area.js +85 -0
  142. package/esm/chart/area/AreaChart.js +146 -0
  143. package/esm/chart/area/DottedArea.js +128 -0
  144. package/esm/chart/area/GradientArea.js +110 -0
  145. package/esm/chart/area/SolidArea.js +24 -0
  146. package/esm/chart/area/__stories__/AreaChart.stories.js +100 -0
  147. package/esm/chart/area/index.js +7 -0
  148. package/esm/chart/axis/Axis.js +43 -0
  149. package/esm/chart/axis/XAxis.js +181 -0
  150. package/esm/chart/axis/YAxis.js +170 -0
  151. package/esm/chart/axis/__stories__/Axis.stories.js +277 -0
  152. package/esm/chart/axis/index.js +5 -0
  153. package/esm/chart/bar/Bar.js +67 -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 +514 -0
  157. package/esm/chart/bar/BarStackGroup.js +89 -0
  158. package/esm/chart/bar/DefaultBar.js +78 -0
  159. package/esm/chart/bar/DefaultBarStack.js +82 -0
  160. package/esm/chart/bar/__stories__/BarChart.stories.js +282 -0
  161. package/esm/chart/bar/index.js +9 -0
  162. package/esm/chart/index.js +14 -0
  163. package/esm/chart/line/DottedLine.js +35 -0
  164. package/esm/chart/line/GradientLine.js +62 -0
  165. package/esm/chart/line/Line.js +139 -0
  166. package/esm/chart/line/LineChart.js +115 -0
  167. package/esm/chart/line/ReferenceLine.js +115 -0
  168. package/esm/chart/line/SolidLine.js +31 -0
  169. package/esm/chart/line/__stories__/LineChart.stories.js +2248 -0
  170. package/esm/chart/line/__stories__/ReferenceLine.stories.js +77 -0
  171. package/esm/chart/line/index.js +8 -0
  172. package/esm/chart/scrubber/Scrubber.js +186 -0
  173. package/esm/chart/scrubber/ScrubberBeacon.js +199 -0
  174. package/esm/chart/scrubber/ScrubberProvider.js +143 -0
  175. package/esm/chart/scrubber/index.js +2 -0
  176. package/esm/chart/text/ChartText.js +237 -0
  177. package/esm/chart/text/SmartChartTextGroup.js +210 -0
  178. package/esm/chart/text/index.js +4 -0
  179. package/esm/chart/utils/axis.js +592 -0
  180. package/esm/chart/utils/bar.js +24 -0
  181. package/esm/chart/utils/chart.js +229 -0
  182. package/esm/chart/utils/context.js +15 -0
  183. package/esm/chart/utils/index.js +9 -0
  184. package/esm/chart/utils/path.js +206 -0
  185. package/esm/chart/utils/point.js +118 -0
  186. package/esm/chart/utils/scale.js +48 -0
  187. package/esm/index.js +4 -1
  188. package/esm/sparkline/Sparkline.js +129 -16
  189. package/esm/sparkline/SparklineArea.js +7 -2
  190. package/esm/sparkline/SparklineAreaPattern.js +4 -2
  191. package/esm/sparkline/SparklineGradient.js +4 -0
  192. package/esm/sparkline/generateSparklineWithId.js +3 -2
  193. package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +5 -1
  194. package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +5 -2
  195. package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +4 -0
  196. package/esm/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.js +27 -0
  197. package/package.json +11 -11
  198. package/dts/sparkline/__stories__/Sparkline.stories.d.ts +0 -3
  199. package/dts/sparkline/__stories__/Sparkline.stories.d.ts.map +0 -1
  200. package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts +0 -3
  201. package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts.map +0 -1
  202. package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts +0 -3
  203. package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts.map +0 -1
  204. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts +0 -2
  205. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts.map +0 -1
  206. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts +0 -2
  207. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts.map +0 -1
  208. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts +0 -2
  209. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts.map +0 -1
  210. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts +0 -2
  211. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts.map +0 -1
  212. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts +0 -2
  213. package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts.map +0 -1
  214. package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts +0 -2
  215. package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts.map +0 -1
  216. package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts +0 -2
  217. package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts.map +0 -1
  218. package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts +0 -4
  219. package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts.map +0 -1
  220. package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts +0 -2
  221. package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts.map +0 -1
  222. package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts +0 -2
  223. package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts.map +0 -1
@@ -0,0 +1,277 @@
1
+ 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); }
2
+ import { memo, useCallback, useMemo } from 'react';
3
+ import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
4
+ import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
5
+ import { CartesianChart } from '../../CartesianChart';
6
+ import { LineChart, SolidLine } from '../../line';
7
+ import { Line } from '../../line/Line';
8
+ import { Scrubber } from '../../scrubber/Scrubber';
9
+ import { XAxis, YAxis } from '..';
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ const defaultChartHeight = 250;
12
+ const ThinSolidLine = /*#__PURE__*/memo(props => /*#__PURE__*/_jsx(SolidLine, _extends({}, props, {
13
+ strokeWidth: 1
14
+ })));
15
+ const Simple = () => {
16
+ const data = [{
17
+ name: 'Page A',
18
+ uv: 4000,
19
+ pv: 2400,
20
+ amt: 2400
21
+ }, {
22
+ name: 'Page B',
23
+ uv: 3000,
24
+ pv: 1398,
25
+ amt: 2210
26
+ }, {
27
+ name: 'Page C',
28
+ uv: 2000,
29
+ pv: 9800,
30
+ amt: 2290
31
+ }, {
32
+ name: 'Page D',
33
+ uv: 2780,
34
+ pv: 3908,
35
+ amt: 2000
36
+ }, {
37
+ name: 'Page E',
38
+ uv: 1890,
39
+ pv: 4800,
40
+ amt: 2181
41
+ }, {
42
+ name: 'Page F',
43
+ uv: 2390,
44
+ pv: 3800,
45
+ amt: 2500
46
+ }, {
47
+ name: 'Page G',
48
+ uv: 3490,
49
+ pv: 4300,
50
+ amt: 2100
51
+ }];
52
+ const pageViews = data.map(d => d.pv);
53
+ const pageNames = data.map(d => d.name);
54
+ const pageUniqueVisitors = data.map(d => d.uv);
55
+ return /*#__PURE__*/_jsx(LineChart, {
56
+ enableScrubbing: true,
57
+ showXAxis: true,
58
+ showYAxis: true,
59
+ height: defaultChartHeight,
60
+ inset: 32,
61
+ series: [{
62
+ id: 'pageViews',
63
+ data: pageViews,
64
+ label: 'Page Views',
65
+ color: '#8884d8',
66
+ curve: 'monotone'
67
+ }, {
68
+ id: 'uniqueVisitors',
69
+ data: pageUniqueVisitors,
70
+ label: 'Unique Visitors',
71
+ color: '#82ca9d',
72
+ curve: 'monotone'
73
+ }],
74
+ xAxis: {
75
+ data: pageNames,
76
+ showLine: true,
77
+ showGrid: true,
78
+ showTickMarks: true,
79
+ GridLineComponent: ThinSolidLine,
80
+ position: 'bottom',
81
+ requestedTickCount: 5
82
+ },
83
+ yAxis: {
84
+ domain: {
85
+ min: 0
86
+ },
87
+ showGrid: true,
88
+ showLine: true,
89
+ showTickMarks: true,
90
+ GridLineComponent: ThinSolidLine,
91
+ position: 'left',
92
+ requestedTickCount: 5
93
+ },
94
+ children: /*#__PURE__*/_jsx(Scrubber, {})
95
+ });
96
+ };
97
+ const TimeOfDayAxesExample = () => {
98
+ const theme = useTheme();
99
+ const lineA = [5, 5, 10, 90, 85, 70, 30, 25, 25];
100
+ const lineB = [90, 85, 70, 25, 23, 40, 45, 40, 50];
101
+ const timeData = useMemo(() => [new Date(2023, 7, 31), new Date(2023, 7, 31, 12), new Date(2023, 8, 1), new Date(2023, 8, 1, 12), new Date(2023, 8, 2), new Date(2023, 8, 2, 12), new Date(2023, 8, 3), new Date(2023, 8, 3, 12), new Date(2023, 8, 4)].map(d => d.getTime()), []);
102
+ const dateFormatter = useCallback(index => {
103
+ return new Date(timeData[index]).toLocaleDateString('en-US', {
104
+ month: '2-digit',
105
+ day: '2-digit'
106
+ });
107
+ }, [timeData]);
108
+ const timeOfDayFormatter = useCallback(index => {
109
+ return new Date(timeData[index]).toLocaleTimeString('en-US', {
110
+ hour: '2-digit'
111
+ });
112
+ }, [timeData]);
113
+ const timeOfDayTicks = useMemo(() => {
114
+ return timeData.map((d, index) => index);
115
+ }, [timeData]);
116
+ const dateTicks = useMemo(() => {
117
+ return timeData.map((d, index) => index).filter(d => d % 2 === 0);
118
+ }, [timeData]);
119
+ return /*#__PURE__*/_jsxs(LineChart, {
120
+ enableScrubbing: true,
121
+ curve: "monotone",
122
+ height: defaultChartHeight,
123
+ series: [{
124
+ id: 'lineA',
125
+ data: lineA,
126
+ color: theme.color.accentBoldBlue
127
+ }, {
128
+ id: 'lineB',
129
+ data: lineB,
130
+ color: theme.color.accentBoldGreen
131
+ }],
132
+ yAxis: {
133
+ domain: {
134
+ min: 0,
135
+ max: 100
136
+ }
137
+ },
138
+ children: [/*#__PURE__*/_jsx(XAxis, {
139
+ showLine: true,
140
+ showTickMarks: true,
141
+ position: "top",
142
+ tickLabelFormatter: dateFormatter,
143
+ ticks: dateTicks
144
+ }), /*#__PURE__*/_jsx(XAxis, {
145
+ showGrid: true,
146
+ showLine: true,
147
+ showTickMarks: true,
148
+ tickLabelFormatter: timeOfDayFormatter,
149
+ ticks: timeOfDayTicks
150
+ }), /*#__PURE__*/_jsx(Scrubber, {})]
151
+ });
152
+ };
153
+ const MultipleYAxesExample = () => /*#__PURE__*/_jsxs(CartesianChart, {
154
+ enableScrubbing: true,
155
+ height: defaultChartHeight,
156
+ series: [{
157
+ id: 'linear',
158
+ yAxisId: 'linearAxis',
159
+ data: [1, 10, 30, 50, 70, 90, 100],
160
+ label: 'linear'
161
+ }, {
162
+ id: 'log',
163
+ yAxisId: 'logAxis',
164
+ data: [1, 10, 30, 50, 70, 90, 100],
165
+ label: 'log'
166
+ }],
167
+ xAxis: {
168
+ data: [1, 10, 30, 50, 70, 90, 100]
169
+ },
170
+ yAxis: [{
171
+ id: 'linearAxis',
172
+ scaleType: 'linear'
173
+ }, {
174
+ id: 'logAxis',
175
+ scaleType: 'log'
176
+ }],
177
+ children: [/*#__PURE__*/_jsx(XAxis, {
178
+ showLine: true,
179
+ showTickMarks: true
180
+ }), /*#__PURE__*/_jsx(YAxis, {
181
+ showLine: true,
182
+ showTickMarks: true,
183
+ axisId: "logAxis",
184
+ position: "left"
185
+ }), /*#__PURE__*/_jsx(YAxis, {
186
+ showLine: true,
187
+ showTickMarks: true,
188
+ axisId: "linearAxis",
189
+ position: "left"
190
+ }), /*#__PURE__*/_jsx(Line, {
191
+ curve: "natural",
192
+ seriesId: "linear"
193
+ }), /*#__PURE__*/_jsx(Line, {
194
+ curve: "natural",
195
+ seriesId: "log"
196
+ }), /*#__PURE__*/_jsx(Scrubber, {})]
197
+ });
198
+ const DomainLimitType = _ref => {
199
+ let {
200
+ limit
201
+ } = _ref;
202
+ const exponentialData = [1, 2, 4, 8, 15, 30, 65, 140, 280, 580, 1200, 2400, 4800, 9500, 19000, 38000, 75000, 150000];
203
+ return /*#__PURE__*/_jsxs(CartesianChart, {
204
+ enableScrubbing: true,
205
+ height: defaultChartHeight,
206
+ series: [{
207
+ id: 'growthLinear',
208
+ data: exponentialData,
209
+ color: '#10b981',
210
+ yAxisId: 'linear'
211
+ }, {
212
+ id: 'growthExponential',
213
+ data: exponentialData,
214
+ color: '#10b981',
215
+ yAxisId: 'exponential'
216
+ }],
217
+ yAxis: [{
218
+ id: 'linear',
219
+ scaleType: 'linear',
220
+ domainLimit: limit
221
+ }, {
222
+ id: 'exponential',
223
+ scaleType: 'log',
224
+ domainLimit: limit
225
+ }],
226
+ children: [/*#__PURE__*/_jsx(Line, {
227
+ showArea: true,
228
+ curve: "natural",
229
+ seriesId: "growthLinear"
230
+ }), /*#__PURE__*/_jsx(Line, {
231
+ showArea: true,
232
+ curve: "natural",
233
+ seriesId: "growthExponential"
234
+ }), /*#__PURE__*/_jsx(XAxis, {
235
+ showLine: true
236
+ }), /*#__PURE__*/_jsx(YAxis, {
237
+ showLine: true,
238
+ showTickMarks: true,
239
+ axisId: "exponential",
240
+ position: "left",
241
+ requestedTickCount: 6,
242
+ tickLabelFormatter: value => value.toLocaleString(),
243
+ width: 70
244
+ }), /*#__PURE__*/_jsx(YAxis, {
245
+ showLine: true,
246
+ showTickMarks: true,
247
+ axisId: "linear",
248
+ tickLabelFormatter: value => value.toLocaleString(),
249
+ width: 70
250
+ }), /*#__PURE__*/_jsx(Scrubber, {})]
251
+ });
252
+ };
253
+ const AxisStories = () => {
254
+ return /*#__PURE__*/_jsxs(ExampleScreen, {
255
+ children: [/*#__PURE__*/_jsx(Example, {
256
+ title: "Basic",
257
+ children: /*#__PURE__*/_jsx(Simple, {})
258
+ }), /*#__PURE__*/_jsx(Example, {
259
+ title: "Time of Day",
260
+ children: /*#__PURE__*/_jsx(TimeOfDayAxesExample, {})
261
+ }), /*#__PURE__*/_jsx(Example, {
262
+ title: "Multiple Axes on Same Side",
263
+ children: /*#__PURE__*/_jsx(MultipleYAxesExample, {})
264
+ }), /*#__PURE__*/_jsx(Example, {
265
+ title: "Strict Domain Limit",
266
+ children: /*#__PURE__*/_jsx(DomainLimitType, {
267
+ limit: "strict"
268
+ })
269
+ }), /*#__PURE__*/_jsx(Example, {
270
+ title: "Nice Domain Limit",
271
+ children: /*#__PURE__*/_jsx(DomainLimitType, {
272
+ limit: "nice"
273
+ })
274
+ })]
275
+ });
276
+ };
277
+ export default AxisStories;
@@ -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,67 @@
1
+ import React, { memo, useMemo } from 'react';
2
+ import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
3
+ import { getBarPath } from '../utils';
4
+ import { DefaultBar } from './DefaultBar';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ /**
7
+ * Simple bar component that renders a single bar at the specified position.
8
+ *
9
+ * This component is intentionally kept simple - it just renders a static bar at the given
10
+ * x, y, width, height coordinates. Complex positioning logic (like handling stacks,
11
+ * groups, gaps, etc.) should be handled by parent components like BarChart or BarStack.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * <Bar x={10} y={20} width={50} height={100} fill="blue" />
16
+ * ```
17
+ */
18
+ export const Bar = /*#__PURE__*/memo(_ref => {
19
+ let {
20
+ x,
21
+ y,
22
+ width,
23
+ height,
24
+ originY,
25
+ dataX,
26
+ dataY,
27
+ BarComponent = DefaultBar,
28
+ fill,
29
+ fillOpacity = 1,
30
+ stroke,
31
+ strokeWidth,
32
+ borderRadius = 4,
33
+ roundTop = true,
34
+ roundBottom = true
35
+ } = _ref;
36
+ const theme = useTheme();
37
+
38
+ // Use theme color as default if no fill is provided
39
+ const effectiveFill = fill != null ? fill : theme.color.fgPrimary;
40
+ const borderRadiusPixels = useMemo(() => borderRadius != null ? borderRadius : 0, [borderRadius]);
41
+ const barPath = useMemo(() => {
42
+ return getBarPath(x, y, width, height, borderRadiusPixels, roundTop, roundBottom);
43
+ }, [x, y, width, height, borderRadiusPixels, roundTop, roundBottom]);
44
+ const effectiveOriginY = originY != null ? originY : y + height;
45
+ if (!barPath) {
46
+ return null;
47
+ }
48
+
49
+ // Always use the BarComponent for rendering
50
+ return /*#__PURE__*/_jsx(BarComponent, {
51
+ borderRadius: borderRadius,
52
+ d: barPath,
53
+ dataX: dataX,
54
+ dataY: dataY,
55
+ fill: effectiveFill,
56
+ fillOpacity: fillOpacity,
57
+ height: height,
58
+ originY: effectiveOriginY,
59
+ roundBottom: roundBottom,
60
+ roundTop: roundTop,
61
+ stroke: stroke,
62
+ strokeWidth: strokeWidth,
63
+ width: width,
64
+ x: x,
65
+ y: y
66
+ });
67
+ });
@@ -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 _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); }
5
+ 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; }
6
+ import { forwardRef, memo, useMemo } from 'react';
7
+ import { XAxis, YAxis } from '../axis';
8
+ import { CartesianChart } from '../CartesianChart';
9
+ import { defaultChartInset, defaultStackId, getChartInset } from '../utils';
10
+ import { BarPlot } from './BarPlot';
11
+
12
+ /**
13
+ * Series type specifically for bar charts - supports both single numbers and tuples,
14
+ * and allows individual customization of Bar props per series.
15
+ */
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 = _objectWithoutPropertiesLoose(_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 ? 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 _extends({}, s, {
58
+ stackId: (_s$stackId = s.stackId) != null ? _s$stackId : defaultStackId
59
+ });
60
+ });
61
+ }, [chartSeries, stacked]);
62
+ const seriesToRender = transformedSeries != null ? 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 _extends({}, s, {
70
+ stackId: (_s$stackId2 = s.stackId) != null ? _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 = _objectWithoutPropertiesLoose(_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 = _objectWithoutPropertiesLoose(_ref3, _excluded3);
97
+ const xAxisConfig = {
98
+ scaleType: xScaleType != null ? 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 ? 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 : _extends({
119
+ min: 0
120
+ }, yDomain),
121
+ domainLimit: yDomainLimit,
122
+ range: yRange
123
+ };
124
+ return /*#__PURE__*/_jsxs(CartesianChart, _extends({}, chartProps, {
125
+ ref: ref,
126
+ inset: calculatedInset,
127
+ series: seriesToRender,
128
+ xAxis: xAxisConfig,
129
+ yAxis: yAxisConfig,
130
+ children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _extends({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _extends({
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 ? 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 { ClipPath, Defs, G, Rect } from 'react-native-svg';
3
+ import { useCartesianChartContext } from '../ChartProvider';
4
+ import { defaultAxisId } from '../utils';
5
+ import { BarStackGroup } from './BarStackGroup';
6
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
7
+ /**
8
+ * BarPlot component that handles multiple series with proper stacking coordination.
9
+ * Groups series by stack ID + y-axis ID combination and renders BarStackGroup for each group.
10
+ * This allows series with different y-axes to be rendered side by side while preventing
11
+ * cross-axis stacking (e.g., comparing $1M vs $1B companies on different scales).
12
+ */
13
+ export const BarPlot = /*#__PURE__*/memo(_ref => {
14
+ let {
15
+ seriesIds,
16
+ barPadding = 0.1,
17
+ BarComponent: defaultBarComponent,
18
+ fillOpacity: defaultFillOpacity,
19
+ stroke: defaultStroke,
20
+ strokeWidth: defaultStrokeWidth,
21
+ borderRadius: defaultBorderRadius,
22
+ roundBaseline,
23
+ BarStackComponent,
24
+ stackGap,
25
+ barMinSize,
26
+ stackMinSize
27
+ } = _ref;
28
+ const {
29
+ series: allSeries,
30
+ drawingArea
31
+ } = useCartesianChartContext();
32
+ const clipPathId = useId();
33
+ const targetSeries = useMemo(() => {
34
+ // Then filter by seriesIds if provided
35
+ if (seriesIds !== undefined) {
36
+ return allSeries.filter(s => seriesIds.includes(s.id));
37
+ }
38
+ return allSeries;
39
+ }, [allSeries, seriesIds]);
40
+ const stackGroups = useMemo(() => {
41
+ const groups = new Map();
42
+
43
+ // Group series into stacks based on stackId + yAxisId combination
44
+ targetSeries.forEach(series => {
45
+ var _series$yAxisId;
46
+ const yAxisId = (_series$yAxisId = series.yAxisId) != null ? _series$yAxisId : defaultAxisId;
47
+ const stackId = series.stackId || "individual-" + series.id;
48
+ const stackKey = stackId + ":" + yAxisId;
49
+ if (!groups.has(stackKey)) {
50
+ groups.set(stackKey, {
51
+ stackId: stackKey,
52
+ series: [],
53
+ yAxisId: series.yAxisId
54
+ });
55
+ }
56
+ const group = groups.get(stackKey);
57
+ group.series.push(series);
58
+ });
59
+ return Array.from(groups.values());
60
+ }, [targetSeries]);
61
+ if (!drawingArea) {
62
+ return null;
63
+ }
64
+ return /*#__PURE__*/_jsxs(_Fragment, {
65
+ children: [/*#__PURE__*/_jsx(Defs, {
66
+ children: /*#__PURE__*/_jsx(ClipPath, {
67
+ id: clipPathId,
68
+ children: /*#__PURE__*/_jsx(Rect, {
69
+ height: drawingArea.height,
70
+ width: drawingArea.width,
71
+ x: drawingArea.x,
72
+ y: drawingArea.y
73
+ })
74
+ })
75
+ }), /*#__PURE__*/_jsx(G, {
76
+ clipPath: "url(#" + clipPathId + ")",
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
+ });