@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,294 @@
1
+ const _excluded = ["label"];
2
+ 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; }
3
+ 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); }
4
+ import { forwardRef, memo, useMemo, useState } from 'react';
5
+ import { View } from 'react-native';
6
+ import { assets } from '@coinbase/cds-common/internal/data/assets';
7
+ import { useTabsContext } from '@coinbase/cds-common/tabs/TabsContext';
8
+ import { IconButton } from '@coinbase/cds-mobile/buttons';
9
+ import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
10
+ import { Box, HStack, VStack } from '@coinbase/cds-mobile/layout';
11
+ import { SegmentedTab } from '@coinbase/cds-mobile/tabs/SegmentedTab';
12
+ import { TextHeadline, TextLabel1 } from '@coinbase/cds-mobile/typography';
13
+ import { LiveTabLabel, PeriodSelector, PeriodSelectorActiveIndicator } from '../PeriodSelector';
14
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
+ export default {
16
+ component: PeriodSelector,
17
+ title: 'Components/Chart/PeriodSelector'
18
+ };
19
+ const Example = _ref => {
20
+ let {
21
+ children,
22
+ title,
23
+ description
24
+ } = _ref;
25
+ return /*#__PURE__*/_jsxs(VStack, {
26
+ gap: 2,
27
+ children: [/*#__PURE__*/_jsx(TextHeadline, {
28
+ children: title
29
+ }), description, children]
30
+ });
31
+ };
32
+ const PeriodSelectorExample = () => {
33
+ const tabs = [{
34
+ id: '1H',
35
+ label: '1H'
36
+ }, {
37
+ id: '1D',
38
+ label: '1D'
39
+ }, {
40
+ id: '1W',
41
+ label: '1W'
42
+ }, {
43
+ id: '1M',
44
+ label: '1M'
45
+ }, {
46
+ id: '1Y',
47
+ label: '1Y'
48
+ }, {
49
+ id: 'All',
50
+ label: 'All'
51
+ }];
52
+ const [activeTab, setActiveTab] = useState(tabs[0]);
53
+ return /*#__PURE__*/_jsx(PeriodSelector, {
54
+ activeTab: activeTab,
55
+ onChange: tab => setActiveTab(tab),
56
+ tabs: tabs
57
+ });
58
+ };
59
+ const MinWidthPeriodSelectorExample = () => {
60
+ const tabs = [{
61
+ id: '1H',
62
+ label: '1H'
63
+ }, {
64
+ id: '1D',
65
+ label: '1D'
66
+ }, {
67
+ id: '1W',
68
+ label: '1W'
69
+ }, {
70
+ id: '1M',
71
+ label: '1M'
72
+ }, {
73
+ id: '1Y',
74
+ label: '1Y'
75
+ }, {
76
+ id: 'All',
77
+ label: 'All'
78
+ }];
79
+ const [activeTab, setActiveTab] = useState(tabs[0]);
80
+ return /*#__PURE__*/_jsx(PeriodSelector, {
81
+ activeTab: activeTab,
82
+ gap: 2,
83
+ onChange: tab => setActiveTab(tab),
84
+ tabs: tabs,
85
+ width: "fit-content"
86
+ });
87
+ };
88
+ const LivePeriodSelectorExample = () => {
89
+ const tabs = useMemo(() => [{
90
+ id: '1H',
91
+ label: /*#__PURE__*/_jsx(LiveTabLabel, {})
92
+ }, {
93
+ id: '1D',
94
+ label: '1D'
95
+ }, {
96
+ id: '1W',
97
+ label: '1W'
98
+ }, {
99
+ id: '1M',
100
+ label: '1M'
101
+ }, {
102
+ id: '1Y',
103
+ label: '1Y'
104
+ }, {
105
+ id: 'All',
106
+ label: 'All'
107
+ }], []);
108
+ const [activeTab, setActiveTab] = useState(tabs[0]);
109
+ const isLive = useMemo(() => (activeTab == null ? void 0 : activeTab.id) === '1H', [activeTab]);
110
+ const activeBackground = useMemo(() => !isLive ? 'bgPrimaryWash' : 'bgNegativeWash', [isLive]);
111
+ return /*#__PURE__*/_jsx(PeriodSelector, {
112
+ activeBackground: activeBackground,
113
+ activeTab: activeTab,
114
+ onChange: setActiveTab,
115
+ tabs: tabs
116
+ });
117
+ };
118
+ const TooManyPeriodsSelectorExample = () => {
119
+ const theme = useTheme();
120
+ const tabs = useMemo(() => [{
121
+ id: '1H',
122
+ label: /*#__PURE__*/_jsx(LiveTabLabel, {})
123
+ }, {
124
+ id: '1D',
125
+ label: '1D'
126
+ }, {
127
+ id: '1W',
128
+ label: '1W'
129
+ }, {
130
+ id: '1M',
131
+ label: '1M'
132
+ }, {
133
+ id: 'YTD',
134
+ label: 'YTD'
135
+ }, {
136
+ id: '1Y',
137
+ label: '1Y'
138
+ }, {
139
+ id: '5Y',
140
+ label: '5Y'
141
+ }, {
142
+ id: 'All',
143
+ label: 'All'
144
+ }], []);
145
+ const [activeTab, setActiveTab] = useState(tabs[0]);
146
+ const isLive = useMemo(() => (activeTab == null ? void 0 : activeTab.id) === '1H', [activeTab]);
147
+ const activeBackground = useMemo(() => !isLive ? 'bgPrimaryWash' : 'bgNegativeWash', [isLive]);
148
+ const gradientOverlayStyles = useMemo(() => [{
149
+ position: 'absolute',
150
+ right: 0,
151
+ bottom: 0,
152
+ top: 0,
153
+ width: theme.space[4],
154
+ backgroundColor: theme.color.bgPrimary,
155
+ opacity: 0.8
156
+ }], [theme.space, theme.color.bgPrimary]);
157
+ return /*#__PURE__*/_jsxs(HStack, {
158
+ alignItems: "center",
159
+ justifyContent: "space-between",
160
+ maxWidth: "100%",
161
+ overflow: "hidden",
162
+ width: "100%",
163
+ children: [/*#__PURE__*/_jsxs(Box, {
164
+ flexGrow: 1,
165
+ overflow: "hidden",
166
+ position: "relative",
167
+ children: [/*#__PURE__*/_jsx(Box, {
168
+ overflow: "scroll",
169
+ paddingEnd: 2,
170
+ children: /*#__PURE__*/_jsx(PeriodSelector, {
171
+ activeBackground: activeBackground,
172
+ activeTab: activeTab,
173
+ gap: 1,
174
+ justifyContent: "flex-start",
175
+ onChange: setActiveTab,
176
+ tabs: tabs,
177
+ width: "fit-content"
178
+ })
179
+ }), /*#__PURE__*/_jsx(View, {
180
+ pointerEvents: "none",
181
+ style: gradientOverlayStyles
182
+ })]
183
+ }), /*#__PURE__*/_jsx(IconButton, {
184
+ compact: true,
185
+ accessibilityLabel: "Configure chart",
186
+ flexShrink: 0,
187
+ height: 36,
188
+ name: "filter",
189
+ variant: "secondary"
190
+ })]
191
+ });
192
+ };
193
+ const btcColor = assets.btc.color;
194
+ const BTCActiveIndicator = /*#__PURE__*/memo(props => /*#__PURE__*/_jsx(PeriodSelectorActiveIndicator, _extends({}, props, {
195
+ background: btcColor + "1A"
196
+ })));
197
+ const BTCActiveExcludingLiveIndicator = /*#__PURE__*/memo(props => {
198
+ const theme = useTheme();
199
+ const {
200
+ activeTab
201
+ } = useTabsContext();
202
+ const isLive = useMemo(() => (activeTab == null ? void 0 : activeTab.id) === '1H', [activeTab]);
203
+ const backgroundColor = useMemo(() => isLive ? theme.color.bgNegativeWash : btcColor + "1A", [isLive, theme.color.bgNegativeWash]);
204
+ return /*#__PURE__*/_jsx(PeriodSelectorActiveIndicator, _extends({}, props, {
205
+ background: backgroundColor
206
+ }));
207
+ });
208
+ const BTCTab = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref2, ref) => {
209
+ let {
210
+ label
211
+ } = _ref2,
212
+ props = _objectWithoutPropertiesLoose(_ref2, _excluded);
213
+ const {
214
+ activeTab
215
+ } = useTabsContext();
216
+ const isActive = (activeTab == null ? void 0 : activeTab.id) === props.id;
217
+ const textColor = isActive ? btcColor : undefined;
218
+ return /*#__PURE__*/_jsx(SegmentedTab, _extends({
219
+ ref: ref,
220
+ label: /*#__PURE__*/_jsx(TextLabel1, {
221
+ dangerouslySetColor: textColor,
222
+ children: label
223
+ })
224
+ }, props));
225
+ }));
226
+ const ColoredPeriodSelectorExample = () => {
227
+ const tabs = [{
228
+ id: '1H',
229
+ label: /*#__PURE__*/_jsx(LiveTabLabel, {
230
+ dangerouslySetColor: btcColor
231
+ })
232
+ }, {
233
+ id: '1D',
234
+ label: '1D'
235
+ }, {
236
+ id: '1W',
237
+ label: '1W'
238
+ }, {
239
+ id: '1M',
240
+ label: '1M'
241
+ }, {
242
+ id: '1Y',
243
+ label: '1Y'
244
+ }, {
245
+ id: 'All',
246
+ label: 'All'
247
+ }];
248
+ const [activeTab, setActiveTab] = useState(tabs[0]);
249
+ return /*#__PURE__*/_jsx(PeriodSelector, {
250
+ TabComponent: BTCTab,
251
+ TabsActiveIndicatorComponent: BTCActiveIndicator,
252
+ activeTab: activeTab,
253
+ onChange: tab => setActiveTab(tab),
254
+ tabs: tabs
255
+ });
256
+ };
257
+ const ColoredExcludingLivePeriodSelectorExample = () => {
258
+ const tabs = [{
259
+ id: '1H',
260
+ label: /*#__PURE__*/_jsx(LiveTabLabel, {})
261
+ }, {
262
+ id: '1D',
263
+ label: '1D'
264
+ }, {
265
+ id: '1W',
266
+ label: '1W'
267
+ }, {
268
+ id: '1M',
269
+ label: '1M'
270
+ }, {
271
+ id: '1Y',
272
+ label: '1Y'
273
+ }, {
274
+ id: 'All',
275
+ label: 'All'
276
+ }];
277
+ const [activeTab, setActiveTab] = useState(tabs[0]);
278
+ return /*#__PURE__*/_jsx(PeriodSelector, {
279
+ TabComponent: BTCTab,
280
+ TabsActiveIndicatorComponent: BTCActiveExcludingLiveIndicator,
281
+ activeTab: activeTab,
282
+ onChange: tab => setActiveTab(tab),
283
+ tabs: tabs
284
+ });
285
+ };
286
+ export const All = () => {
287
+ return /*#__PURE__*/_jsx(VStack, {
288
+ gap: 2,
289
+ children: /*#__PURE__*/_jsx(Example, {
290
+ title: "Basic Example",
291
+ children: /*#__PURE__*/_jsx(PeriodSelectorExample, {})
292
+ })
293
+ });
294
+ };
@@ -0,0 +1,85 @@
1
+ import React, { memo, useMemo } from 'react';
2
+ import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
3
+ import { useCartesianChartContext } from '../ChartProvider';
4
+ import { getAreaPath } from '../utils';
5
+ import { DottedArea } from './DottedArea';
6
+ import { GradientArea } from './GradientArea';
7
+ import { SolidArea } from './SolidArea';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ export const Area = /*#__PURE__*/memo(_ref => {
10
+ var _ref2;
11
+ let {
12
+ seriesId,
13
+ curve = 'linear',
14
+ type = 'solid',
15
+ AreaComponent: SelectedAreaComponent,
16
+ fill: specifiedFill,
17
+ fillOpacity = 1,
18
+ stroke,
19
+ strokeWidth,
20
+ baseline
21
+ } = _ref;
22
+ const theme = useTheme();
23
+ const {
24
+ getSeries,
25
+ getSeriesData,
26
+ getXScale,
27
+ getYScale,
28
+ getXAxis,
29
+ drawingArea
30
+ } = useCartesianChartContext();
31
+
32
+ // Get sourceData from series (using stacked data if available)
33
+ const matchedSeries = useMemo(() => getSeries(seriesId), [seriesId, getSeries]);
34
+
35
+ // Check for stacked data first, then fall back to raw data
36
+ const sourceData = useMemo(() => {
37
+ return getSeriesData(seriesId) || null;
38
+ }, [seriesId, getSeriesData]);
39
+
40
+ // Get scales and axes for this series
41
+ const xAxis = getXAxis();
42
+ const xScale = getXScale();
43
+ const yScale = getYScale(matchedSeries == null ? void 0 : matchedSeries.yAxisId);
44
+ const area = useMemo(() => {
45
+ if (!sourceData || sourceData.length === 0 || !xScale || !yScale) return '';
46
+
47
+ // Get numeric x-axis data if available
48
+ const xData = xAxis != null && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
49
+ return getAreaPath({
50
+ data: sourceData,
51
+ xScale,
52
+ yScale,
53
+ curve,
54
+ xData
55
+ });
56
+ }, [sourceData, xScale, yScale, curve, xAxis == null ? void 0 : xAxis.data]);
57
+ const AreaComponent = useMemo(() => {
58
+ if (SelectedAreaComponent) {
59
+ return SelectedAreaComponent;
60
+ }
61
+ switch (type) {
62
+ case 'solid':
63
+ return SolidArea;
64
+ case 'dotted':
65
+ return DottedArea;
66
+ case 'gradient':
67
+ default:
68
+ return GradientArea;
69
+ }
70
+ }, [SelectedAreaComponent, type]);
71
+ if (!xScale || !yScale || !sourceData || !area) {
72
+ return null;
73
+ }
74
+ const fill = (_ref2 = specifiedFill != null ? specifiedFill : matchedSeries == null ? void 0 : matchedSeries.color) != null ? _ref2 : theme.color.fgPrimary;
75
+ return /*#__PURE__*/_jsx(AreaComponent, {
76
+ baseline: baseline,
77
+ clipRect: drawingArea,
78
+ d: area,
79
+ fill: fill,
80
+ fillOpacity: fillOpacity,
81
+ stroke: stroke,
82
+ strokeWidth: strokeWidth,
83
+ yAxisId: matchedSeries == null ? void 0 : matchedSeries.yAxisId
84
+ });
85
+ });
@@ -0,0 +1,146 @@
1
+ const _excluded = ["series", "stacked", "AreaComponent", "curve", "fillOpacity", "type", "LineComponent", "strokeWidth", "showXAxis", "showYAxis", "showLines", "lineType", "xAxis", "yAxis", "inset", "children"],
2
+ _excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range"],
3
+ _excluded3 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"],
4
+ _excluded4 = ["id", "data", "label", "color", "yAxisId", "opacity", "LineComponent", "stackId"],
5
+ _excluded5 = ["id", "data", "label", "color", "yAxisId", "fill", "fillOpacity", "stackId"];
6
+ 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); }
7
+ 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; }
8
+ import { forwardRef, memo, useMemo } from 'react';
9
+ import { XAxis, YAxis } from '../axis';
10
+ import { CartesianChart } from '../CartesianChart';
11
+ import { Line } from '../line/Line';
12
+ import { defaultChartInset, defaultStackId, getChartInset } from '../utils';
13
+ import { Area } from './Area';
14
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
+ export const AreaChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
16
+ let {
17
+ series,
18
+ stacked,
19
+ AreaComponent,
20
+ curve,
21
+ fillOpacity,
22
+ type,
23
+ LineComponent,
24
+ strokeWidth,
25
+ showXAxis,
26
+ showYAxis,
27
+ showLines,
28
+ lineType = 'solid',
29
+ xAxis,
30
+ yAxis,
31
+ inset: userInset,
32
+ children
33
+ } = _ref,
34
+ chartProps = _objectWithoutPropertiesLoose(_ref, _excluded);
35
+ const calculatedInset = useMemo(() => getChartInset(userInset, defaultChartInset), [userInset]);
36
+
37
+ // Convert AreaSeries to Series for Chart context
38
+ const chartSeries = useMemo(() => {
39
+ return series == null ? void 0 : series.map(s => ({
40
+ id: s.id,
41
+ data: s.data,
42
+ label: s.label,
43
+ color: s.color,
44
+ yAxisId: s.yAxisId,
45
+ stackId: s.stackId
46
+ }));
47
+ }, [series]);
48
+ const transformedSeries = useMemo(() => {
49
+ if (!stacked || !chartSeries) return chartSeries;
50
+ return chartSeries.map(s => {
51
+ var _s$stackId;
52
+ return _extends({}, s, {
53
+ stackId: (_s$stackId = s.stackId) != null ? _s$stackId : defaultStackId
54
+ });
55
+ });
56
+ }, [chartSeries, stacked]);
57
+ const seriesToRender = transformedSeries != null ? transformedSeries : chartSeries;
58
+
59
+ // Split axis props into config props for Chart and visual props for axis components
60
+ const _ref2 = xAxis || {},
61
+ {
62
+ scaleType: xScaleType,
63
+ data: xData,
64
+ categoryPadding: xCategoryPadding,
65
+ domain: xDomain,
66
+ domainLimit: xDomainLimit,
67
+ range: xRange
68
+ } = _ref2,
69
+ xAxisVisualProps = _objectWithoutPropertiesLoose(_ref2, _excluded2);
70
+ const _ref3 = yAxis || {},
71
+ {
72
+ scaleType: yScaleType,
73
+ data: yData,
74
+ categoryPadding: yCategoryPadding,
75
+ domain: yDomain,
76
+ domainLimit: yDomainLimit,
77
+ range: yRange,
78
+ id: yAxisId
79
+ } = _ref3,
80
+ yAxisVisualProps = _objectWithoutPropertiesLoose(_ref3, _excluded3);
81
+ const xAxisConfig = {
82
+ scaleType: xScaleType,
83
+ data: xData,
84
+ categoryPadding: xCategoryPadding,
85
+ domain: xDomain,
86
+ domainLimit: xDomainLimit,
87
+ range: xRange
88
+ };
89
+ const hasNegativeValues = useMemo(() => {
90
+ if (!series) return false;
91
+ return series.some(s => {
92
+ var _s$data;
93
+ 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));
94
+ });
95
+ }, [series]);
96
+
97
+ // Set default min domain to 0 for area chart, but only if there are no negative values
98
+ const yAxisConfig = {
99
+ scaleType: yScaleType,
100
+ data: yData,
101
+ categoryPadding: yCategoryPadding,
102
+ domain: hasNegativeValues ? yDomain : _extends({
103
+ min: 0
104
+ }, yDomain),
105
+ domainLimit: yDomainLimit,
106
+ range: yRange
107
+ };
108
+ return /*#__PURE__*/_jsxs(CartesianChart, _extends({}, chartProps, {
109
+ ref: ref,
110
+ inset: calculatedInset,
111
+ series: seriesToRender,
112
+ xAxis: xAxisConfig,
113
+ yAxis: yAxisConfig,
114
+ children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _extends({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _extends({
115
+ axisId: yAxisId
116
+ }, yAxisVisualProps)), series == null ? void 0 : series.map(_ref4 => {
117
+ let {
118
+ id
119
+ } = _ref4,
120
+ areaPropsFromSeries = _objectWithoutPropertiesLoose(_ref4, _excluded4);
121
+ return /*#__PURE__*/_jsx(Area, _extends({
122
+ AreaComponent: AreaComponent,
123
+ curve: curve,
124
+ fillOpacity: fillOpacity,
125
+ seriesId: id,
126
+ type: type
127
+ }, areaPropsFromSeries), id);
128
+ }), showLines && (series == null ? void 0 : series.map(_ref5 => {
129
+ let {
130
+ id,
131
+ color
132
+ } = _ref5,
133
+ linePropsFromSeries = _objectWithoutPropertiesLoose(_ref5, _excluded5);
134
+ return /*#__PURE__*/_jsx(Line, _extends({
135
+ LineComponent: LineComponent,
136
+ curve: curve,
137
+ seriesId: id // Line component now handles stacked data automatically
138
+ ,
139
+ stroke: color // Default to series color
140
+ ,
141
+ strokeWidth: strokeWidth,
142
+ type: lineType
143
+ }, linePropsFromSeries), id + "-line");
144
+ })), children]
145
+ }));
146
+ }));
@@ -0,0 +1,128 @@
1
+ const _excluded = ["d", "fill", "fillOpacity", "patternSize", "dotSize", "peakOpacity", "baselineOpacity", "baseline", "yAxisId", "clipRect"];
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 { memo, useId } from 'react';
5
+ import { Circle, Defs, G, LinearGradient, Mask, Pattern, Stop } from 'react-native-svg';
6
+ import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
7
+ import { useCartesianChartContext } from '../ChartProvider';
8
+ import { Path } from '../Path';
9
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
+ export const DottedArea = /*#__PURE__*/memo(_ref => {
11
+ let {
12
+ d,
13
+ fill,
14
+ fillOpacity = 1,
15
+ patternSize = 4,
16
+ dotSize = 1,
17
+ peakOpacity = 1,
18
+ baselineOpacity = 0,
19
+ baseline,
20
+ yAxisId,
21
+ clipRect
22
+ } = _ref,
23
+ pathProps = _objectWithoutPropertiesLoose(_ref, _excluded);
24
+ const theme = useTheme();
25
+ const context = useCartesianChartContext();
26
+ const patternId = useId();
27
+ const gradientId = useId();
28
+ const maskId = useId();
29
+ const dotCenterPosition = patternSize / 2;
30
+
31
+ // Get the y-scale for the specified axis (or default)
32
+ const yScale = context.getYScale(yAxisId);
33
+ const yRange = yScale == null ? void 0 : yScale.range();
34
+ const yDomain = yScale == null ? void 0 : yScale.domain();
35
+
36
+ // Use chart range if available, otherwise fall back to percentage
37
+ const useUserSpaceUnits = yRange !== undefined;
38
+
39
+ // Auto-calculate baseline position based on domain
40
+ let baselinePosition;
41
+ let baselinePercentage;
42
+ if (yScale && yDomain) {
43
+ const [minValue, maxValue] = yDomain;
44
+ let dataBaseline;
45
+ if (minValue >= 0) {
46
+ // All positive: baseline at min
47
+ dataBaseline = minValue;
48
+ } else if (maxValue <= 0) {
49
+ // All negative: baseline at max
50
+ dataBaseline = maxValue;
51
+ } else {
52
+ // Crosses zero: baseline at 0
53
+ dataBaseline = 0;
54
+ }
55
+ if (useUserSpaceUnits && yRange) {
56
+ // Get the actual y coordinate for the baseline
57
+ const scaledValue = yScale(baseline != null ? baseline : dataBaseline);
58
+ if (typeof scaledValue === 'number') {
59
+ baselinePosition = scaledValue;
60
+ }
61
+ } else {
62
+ // Calculate percentage position
63
+ baselinePercentage = (maxValue - (baseline != null ? baseline : dataBaseline)) / (maxValue - minValue) * 100 + "%";
64
+ }
65
+ }
66
+ const gradientY1 = useUserSpaceUnits && yRange ? String(yRange[1]) : '0%';
67
+ const gradientY2 = useUserSpaceUnits && yRange ? String(yRange[0]) : '100%';
68
+ const effectiveFill = fill != null ? fill : theme.color.fgPrimary;
69
+ return /*#__PURE__*/_jsxs(G, {
70
+ children: [/*#__PURE__*/_jsxs(Defs, {
71
+ children: [/*#__PURE__*/_jsx(Pattern, {
72
+ height: patternSize,
73
+ id: patternId,
74
+ patternUnits: "userSpaceOnUse",
75
+ width: patternSize,
76
+ x: "0",
77
+ y: "0",
78
+ children: /*#__PURE__*/_jsx(Circle, {
79
+ cx: dotCenterPosition,
80
+ cy: dotCenterPosition,
81
+ fill: effectiveFill,
82
+ r: dotSize
83
+ })
84
+ }), /*#__PURE__*/_jsx(LinearGradient, {
85
+ gradientUnits: useUserSpaceUnits ? 'userSpaceOnUse' : 'objectBoundingBox',
86
+ id: gradientId,
87
+ x1: useUserSpaceUnits ? '0' : '0%',
88
+ x2: useUserSpaceUnits ? '0' : '0%',
89
+ y1: gradientY1,
90
+ y2: gradientY2,
91
+ children: baselinePosition !== undefined || baselinePercentage !== undefined ? /* Diverging gradient: high opacity at extremes, low at baseline */
92
+ [/*#__PURE__*/_jsx(Stop, {
93
+ offset: "0%",
94
+ stopColor: "white",
95
+ stopOpacity: peakOpacity
96
+ }, "0"), /*#__PURE__*/_jsx(Stop, {
97
+ offset: baselinePercentage != null ? baselinePercentage : (baselinePosition - yRange[1]) / (yRange[0] - yRange[1]) * 100 + "%",
98
+ stopColor: "white",
99
+ stopOpacity: baselineOpacity
100
+ }, "1"), /*#__PURE__*/_jsx(Stop, {
101
+ offset: "100%",
102
+ stopColor: "white",
103
+ stopOpacity: peakOpacity
104
+ }, "2")] : /* Simple gradient from top to bottom */
105
+ [/*#__PURE__*/_jsx(Stop, {
106
+ offset: "0%",
107
+ stopColor: "white",
108
+ stopOpacity: peakOpacity
109
+ }, "0"), /*#__PURE__*/_jsx(Stop, {
110
+ offset: "100%",
111
+ stopColor: "white",
112
+ stopOpacity: baselineOpacity
113
+ }, "1")]
114
+ }), /*#__PURE__*/_jsx(Mask, {
115
+ id: maskId,
116
+ children: /*#__PURE__*/_jsx(Path, {
117
+ d: d,
118
+ fill: "url(#" + gradientId + ")"
119
+ })
120
+ })]
121
+ }), /*#__PURE__*/_jsx(Path, _extends({
122
+ clipRect: clipRect,
123
+ d: d,
124
+ fill: "url(#" + patternId + ")",
125
+ mask: "url(#" + maskId + ")"
126
+ }, pathProps))]
127
+ });
128
+ });