@coinbase/cds-mobile-visualization 3.3.0 → 3.4.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/CHANGELOG.md +26 -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,476 @@
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 { Image, ScrollView, StyleSheet } from 'react-native';
4
+ import { Circle, G } from 'react-native-svg';
5
+ import { assets } from '@coinbase/cds-common/internal/data/assets';
6
+ import { candles as btcCandles } from '@coinbase/cds-common/internal/data/candles';
7
+ import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
8
+ import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
9
+ import { Box, HStack, VStack } from '@coinbase/cds-mobile/layout';
10
+ import { TextLabel1, TextLabel2, TextTitle1, TextTitle2 } from '@coinbase/cds-mobile/typography';
11
+ import { Area } from '../area/Area';
12
+ import { XAxis, YAxis } from '../axis';
13
+ import { BarPlot } from '../bar/BarPlot';
14
+ import { useCartesianChartContext } from '../ChartProvider';
15
+ import { Line } from '../line/Line';
16
+ import { Scrubber } from '../scrubber/Scrubber';
17
+ import { isCategoricalScale } from '../utils';
18
+ import { CartesianChart, DottedArea, GradientLine, ReferenceLine, SolidLine } from '../';
19
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
+ const defaultChartHeight = 250;
21
+ const LineStyles = () => {
22
+ const topChartData = [15, 28, 32, 44, 46, 36, 40, 45, 48, 38];
23
+ const upperMiddleChartData = [12, 23, 21, 29, 34, 28, 31, 38, 42, 35];
24
+ const lowerMiddleChartData = [8, 15, 14, 25, 20, 18, 22, 28, 24, 30];
25
+ const bottomChartData = [4, 8, 11, 15, 16, 14, 16, 10, 12, 14];
26
+ return /*#__PURE__*/_jsxs(CartesianChart, {
27
+ height: defaultChartHeight,
28
+ series: [{
29
+ id: 'top',
30
+ data: topChartData
31
+ }, {
32
+ id: 'upperMiddle',
33
+ data: upperMiddleChartData,
34
+ color: '#ef4444'
35
+ }, {
36
+ id: 'lowerMiddle',
37
+ data: lowerMiddleChartData,
38
+ color: '#f59e0b'
39
+ }, {
40
+ id: 'bottom',
41
+ data: bottomChartData,
42
+ color: '#800080'
43
+ }],
44
+ children: [/*#__PURE__*/_jsx(Line, {
45
+ seriesId: "top"
46
+ }), /*#__PURE__*/_jsx(Line, {
47
+ seriesId: "upperMiddle",
48
+ type: "dotted"
49
+ }), /*#__PURE__*/_jsx(Line, {
50
+ LineComponent: lineProps => /*#__PURE__*/_jsx(GradientLine, {
51
+ d: lineProps.d,
52
+ endColor: "#F7931A",
53
+ startColor: "#E3D74D",
54
+ stroke: lineProps.stroke,
55
+ strokeOpacity: lineProps.strokeOpacity,
56
+ strokeWidth: 4
57
+ }),
58
+ curve: "natural",
59
+ seriesId: "lowerMiddle"
60
+ }), /*#__PURE__*/_jsx(Line, {
61
+ showArea: true,
62
+ AreaComponent: DottedArea,
63
+ curve: "step",
64
+ seriesId: "bottom"
65
+ })]
66
+ });
67
+ };
68
+ const MultipleChart = () => {
69
+ const barData = [1, 2, 3, 2, 1];
70
+ const lineData = [4, 3, 1, 3, 4];
71
+ return /*#__PURE__*/_jsxs(CartesianChart, {
72
+ height: defaultChartHeight,
73
+ series: [{
74
+ id: 'bar',
75
+ data: barData
76
+ }, {
77
+ id: 'line',
78
+ data: lineData
79
+ }],
80
+ children: [/*#__PURE__*/_jsx(Area, {
81
+ seriesId: "bar",
82
+ type: "dotted"
83
+ }), /*#__PURE__*/_jsx(Line, {
84
+ curve: "natural",
85
+ seriesId: "line"
86
+ })]
87
+ });
88
+ };
89
+ const EarningsHistory = () => {
90
+ const theme = useTheme();
91
+ const CirclePlot = /*#__PURE__*/memo(_ref => {
92
+ let {
93
+ seriesId,
94
+ opacity = 1
95
+ } = _ref;
96
+ const {
97
+ getSeries,
98
+ getSeriesData,
99
+ getXScale,
100
+ getYScale
101
+ } = useCartesianChartContext();
102
+ const series = getSeries(seriesId);
103
+ const data = getSeriesData(seriesId);
104
+ const xScale = getXScale();
105
+ const yScale = getYScale(series == null ? void 0 : series.yAxisId);
106
+ if (!xScale || !yScale || !data || !isCategoricalScale(xScale)) return null;
107
+ const yScaleSize = Math.abs(yScale.range()[1] - yScale.range()[0]);
108
+
109
+ // Have circle diameter be the smaller of the x scale bandwidth or 10% of the y space available
110
+ const diameter = Math.min(xScale.bandwidth(), yScaleSize / 10);
111
+ return /*#__PURE__*/_jsx(G, {
112
+ children: data.map((value, index) => {
113
+ if (value === null || value === undefined) return null;
114
+
115
+ // Get x position from band scale - center of the band
116
+ const xPos = xScale(index);
117
+ if (xPos === undefined) return null;
118
+ const centerX = xPos + xScale.bandwidth() / 2;
119
+
120
+ // Get y position from value
121
+ const yValue = Array.isArray(value) ? value[1] : value;
122
+ const centerY = yScale(yValue);
123
+ if (centerY === undefined) return null;
124
+ return /*#__PURE__*/_jsx(Circle, {
125
+ cx: centerX,
126
+ cy: centerY,
127
+ fill: (series == null ? void 0 : series.color) || theme.color.fgPrimary,
128
+ opacity: opacity,
129
+ r: diameter / 2
130
+ }, seriesId + "-" + index);
131
+ })
132
+ });
133
+ });
134
+ const quarters = useMemo(() => ['Q1', 'Q2', 'Q3', 'Q4'], []);
135
+ const estimatedEPS = useMemo(() => [1.71, 1.82, 1.93, 2.34], []);
136
+ const actualEPS = useMemo(() => [1.68, 1.83, 2.01, 2.24], []);
137
+ const formatEarningAmount = useCallback(value => {
138
+ return "$" + value.toLocaleString('en-US', {
139
+ minimumFractionDigits: 2,
140
+ maximumFractionDigits: 2
141
+ });
142
+ }, []);
143
+ const surprisePercentage = useCallback(index => {
144
+ const percentage = (actualEPS[index] - estimatedEPS[index]) / estimatedEPS[index];
145
+ const percentageString = percentage.toLocaleString('en-US', {
146
+ style: 'percent',
147
+ minimumFractionDigits: 2,
148
+ maximumFractionDigits: 2
149
+ });
150
+ const prefix = percentage > 0 ? '+' : '';
151
+ return "" + prefix + percentageString;
152
+ }, [actualEPS, estimatedEPS]);
153
+ const styles = StyleSheet.create({
154
+ legendDot: {
155
+ width: 10,
156
+ height: 10,
157
+ borderRadius: 1000,
158
+ backgroundColor: theme.color.bgPositive
159
+ }
160
+ });
161
+ const LegendItem = /*#__PURE__*/memo(_ref2 => {
162
+ let {
163
+ opacity = 1,
164
+ label
165
+ } = _ref2;
166
+ return /*#__PURE__*/_jsxs(Box, {
167
+ alignItems: "center",
168
+ flexDirection: "row",
169
+ gap: 0.5,
170
+ children: [/*#__PURE__*/_jsx(Box, {
171
+ style: [styles.legendDot, {
172
+ opacity
173
+ }]
174
+ }), /*#__PURE__*/_jsx(TextLabel2, {
175
+ children: label
176
+ })]
177
+ });
178
+ });
179
+ return /*#__PURE__*/_jsxs(VStack, {
180
+ gap: 0.5,
181
+ children: [/*#__PURE__*/_jsxs(CartesianChart, {
182
+ height: defaultChartHeight,
183
+ inset: {
184
+ top: 32,
185
+ bottom: 0,
186
+ left: 0,
187
+ right: 0
188
+ },
189
+ overflow: "visible",
190
+ series: [{
191
+ id: 'estimatedEPS',
192
+ data: estimatedEPS,
193
+ color: theme.color.bgPositive
194
+ }, {
195
+ id: 'actualEPS',
196
+ data: actualEPS,
197
+ color: theme.color.bgPositive
198
+ }],
199
+ xAxis: {
200
+ scaleType: 'band',
201
+ categoryPadding: 0.25
202
+ },
203
+ children: [/*#__PURE__*/_jsx(YAxis, {
204
+ showGrid: true,
205
+ position: "left",
206
+ requestedTickCount: 3,
207
+ tickLabelFormatter: formatEarningAmount
208
+ }), /*#__PURE__*/_jsx(XAxis, {
209
+ height: 20,
210
+ tickLabelFormatter: index => quarters[index]
211
+ }), /*#__PURE__*/_jsx(XAxis, {
212
+ height: 20,
213
+ tickLabelFormatter: surprisePercentage
214
+ }), /*#__PURE__*/_jsx(CirclePlot, {
215
+ opacity: 0.5,
216
+ seriesId: "estimatedEPS"
217
+ }), /*#__PURE__*/_jsx(CirclePlot, {
218
+ seriesId: "actualEPS"
219
+ })]
220
+ }), /*#__PURE__*/_jsxs(HStack, {
221
+ gap: 2,
222
+ justifyContent: "flex-end",
223
+ children: [/*#__PURE__*/_jsx(LegendItem, {
224
+ label: "Estimated EPS",
225
+ opacity: 0.5
226
+ }), /*#__PURE__*/_jsx(LegendItem, {
227
+ label: "Actual EPS"
228
+ })]
229
+ })]
230
+ });
231
+ };
232
+ const PriceWithVolume = () => {
233
+ const theme = useTheme();
234
+ const btcData = btcCandles.slice(0, 180).reverse();
235
+ const btcPrices = btcData.map(candle => parseFloat(candle.close));
236
+ const btcVolumes = btcData.map(candle => parseFloat(candle.volume));
237
+ const btcDates = btcData.map(candle => new Date(parseInt(candle.start) * 1000));
238
+ const formatPrice = useCallback(price => {
239
+ return "$" + price.toLocaleString('en-US', {
240
+ minimumFractionDigits: 2,
241
+ maximumFractionDigits: 2
242
+ });
243
+ }, []);
244
+ const formatPriceInThousands = useCallback(price => {
245
+ return "$" + (price / 1000).toLocaleString('en-US', {
246
+ minimumFractionDigits: 0,
247
+ maximumFractionDigits: 2
248
+ }) + "k";
249
+ }, []);
250
+ const formatVolume = useCallback(volume => {
251
+ return (volume / 1000).toFixed(2) + "K";
252
+ }, []);
253
+ const formatDate = useCallback(date => {
254
+ return date.toLocaleDateString('en-US', {
255
+ month: 'short',
256
+ day: 'numeric'
257
+ });
258
+ }, []);
259
+ const scrubberLabel = useCallback(dataIndex => {
260
+ return formatDate(btcDates[dataIndex]);
261
+ }, [btcDates, formatDate]);
262
+
263
+ // Display the last values in the header
264
+ const displayIndex = btcPrices.length - 1;
265
+ const currentPrice = btcPrices[displayIndex];
266
+ const currentVolume = btcVolumes[displayIndex];
267
+ const currentDate = btcDates[displayIndex];
268
+ return /*#__PURE__*/_jsxs(VStack, {
269
+ gap: 2,
270
+ children: [/*#__PURE__*/_jsxs(HStack, {
271
+ gap: 2,
272
+ justifyContent: "space-between",
273
+ paddingX: 0,
274
+ children: [/*#__PURE__*/_jsxs(VStack, {
275
+ gap: 0,
276
+ children: [/*#__PURE__*/_jsx(TextTitle1, {
277
+ children: "Bitcoin"
278
+ }), /*#__PURE__*/_jsx(TextTitle2, {
279
+ children: formatPrice(currentPrice)
280
+ })]
281
+ }), /*#__PURE__*/_jsxs(HStack, {
282
+ gap: 2,
283
+ children: [/*#__PURE__*/_jsxs(VStack, {
284
+ alignItems: "flex-end",
285
+ justifyContent: "center",
286
+ children: [/*#__PURE__*/_jsx(TextLabel1, {
287
+ children: formatDate(currentDate)
288
+ }), /*#__PURE__*/_jsx(TextLabel2, {
289
+ children: formatVolume(currentVolume)
290
+ })]
291
+ }), /*#__PURE__*/_jsx(VStack, {
292
+ justifyContent: "center",
293
+ children: /*#__PURE__*/_jsx(Image, {
294
+ source: {
295
+ uri: assets.btc.imageUrl
296
+ },
297
+ style: {
298
+ width: theme.iconSize.l,
299
+ height: theme.iconSize.l,
300
+ borderRadius: 1000
301
+ }
302
+ })
303
+ })]
304
+ })]
305
+ }), /*#__PURE__*/_jsxs(CartesianChart, {
306
+ enableScrubbing: true,
307
+ height: defaultChartHeight,
308
+ series: [{
309
+ id: 'prices',
310
+ data: btcPrices,
311
+ color: assets.btc.color,
312
+ yAxisId: 'price'
313
+ }, {
314
+ id: 'volume',
315
+ data: btcVolumes,
316
+ color: theme.color.fgMuted,
317
+ yAxisId: 'volume'
318
+ }],
319
+ xAxis: {
320
+ scaleType: 'band'
321
+ },
322
+ yAxis: [{
323
+ id: 'price',
324
+ domain: _ref3 => {
325
+ let {
326
+ min,
327
+ max
328
+ } = _ref3;
329
+ return {
330
+ min: min * 0.9,
331
+ max
332
+ };
333
+ }
334
+ }, {
335
+ id: 'volume',
336
+ range: _ref4 => {
337
+ let {
338
+ min,
339
+ max
340
+ } = _ref4;
341
+ return {
342
+ min: max - 32,
343
+ max
344
+ };
345
+ }
346
+ }],
347
+ children: [/*#__PURE__*/_jsx(YAxis, {
348
+ showGrid: true,
349
+ axisId: "price",
350
+ tickLabelFormatter: formatPriceInThousands,
351
+ width: 20
352
+ }), /*#__PURE__*/_jsx(BarPlot, {
353
+ seriesIds: ['volume']
354
+ }), /*#__PURE__*/_jsx(Line, {
355
+ showArea: true,
356
+ curve: "monotone",
357
+ seriesId: "prices"
358
+ }), /*#__PURE__*/_jsx(Scrubber, {
359
+ label: scrubberLabel,
360
+ seriesIds: ['prices']
361
+ })]
362
+ })]
363
+ });
364
+ };
365
+ function TradingTrends() {
366
+ const theme = useTheme();
367
+ const profitData = [34, 24, 28, -4, 8, -16, -3, 12, 24, 18, 20, 28];
368
+ const gains = profitData.map(value => value > 0 ? value : 0);
369
+ const losses = profitData.map(value => value < 0 ? value : 0);
370
+ const renderProfit = useCallback(value => {
371
+ return "$" + value + "M";
372
+ }, []);
373
+ const ThinSolidLine = /*#__PURE__*/memo(props => /*#__PURE__*/_jsx(SolidLine, _extends({}, props, {
374
+ strokeWidth: 1
375
+ })));
376
+ const ThickSolidLine = /*#__PURE__*/memo(props => /*#__PURE__*/_jsx(SolidLine, _extends({}, props, {
377
+ strokeWidth: 2
378
+ })));
379
+ return /*#__PURE__*/_jsxs(CartesianChart, {
380
+ height: 250,
381
+ series: [{
382
+ id: 'gains',
383
+ data: gains,
384
+ yAxisId: 'profit',
385
+ color: theme.color.bgPositive,
386
+ stackId: 'bars'
387
+ }, {
388
+ id: 'losses',
389
+ data: losses,
390
+ yAxisId: 'profit',
391
+ color: theme.color.bgNegative,
392
+ stackId: 'bars'
393
+ }, {
394
+ id: 'revenue',
395
+ data: [128, 118, 122, 116, 120, 114, 118, 122, 126, 130, 134, 138],
396
+ yAxisId: 'revenue',
397
+ color: theme.color.fgMuted
398
+ }],
399
+ xAxis: {
400
+ scaleType: 'band',
401
+ data: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
402
+ },
403
+ yAxis: [{
404
+ id: 'profit',
405
+ range: _ref5 => {
406
+ let {
407
+ min,
408
+ max
409
+ } = _ref5;
410
+ return {
411
+ min: min,
412
+ max: max - 64
413
+ };
414
+ },
415
+ domain: {
416
+ min: -40,
417
+ max: 40
418
+ }
419
+ }, {
420
+ id: 'revenue',
421
+ range: _ref6 => {
422
+ let {
423
+ min,
424
+ max
425
+ } = _ref6;
426
+ return {
427
+ min: max - 64,
428
+ max
429
+ };
430
+ },
431
+ domain: {
432
+ min: 100
433
+ }
434
+ }],
435
+ children: [/*#__PURE__*/_jsx(YAxis, {
436
+ showGrid: true,
437
+ GridLineComponent: ThinSolidLine,
438
+ axisId: "profit",
439
+ position: "left",
440
+ tickLabelFormatter: renderProfit
441
+ }), /*#__PURE__*/_jsx(XAxis, {}), /*#__PURE__*/_jsx(ReferenceLine, {
442
+ LineComponent: ThickSolidLine,
443
+ dataY: 0,
444
+ yAxisId: "profit"
445
+ }), /*#__PURE__*/_jsx(BarPlot, {
446
+ seriesIds: ['gains', 'losses']
447
+ }), /*#__PURE__*/_jsx(Line, {
448
+ showArea: true,
449
+ curve: "monotone",
450
+ seriesId: "revenue"
451
+ })]
452
+ });
453
+ }
454
+ const ChartStories = () => {
455
+ return /*#__PURE__*/_jsx(ScrollView, {
456
+ children: /*#__PURE__*/_jsxs(ExampleScreen, {
457
+ children: [/*#__PURE__*/_jsx(Example, {
458
+ title: "Line Styles",
459
+ children: /*#__PURE__*/_jsx(LineStyles, {})
460
+ }), /*#__PURE__*/_jsx(Example, {
461
+ title: "Multiple Types",
462
+ children: /*#__PURE__*/_jsx(MultipleChart, {})
463
+ }), /*#__PURE__*/_jsx(Example, {
464
+ title: "Earnings History",
465
+ children: /*#__PURE__*/_jsx(EarningsHistory, {})
466
+ }), /*#__PURE__*/_jsx(Example, {
467
+ title: "Price With Volume",
468
+ children: /*#__PURE__*/_jsx(PriceWithVolume, {})
469
+ }), /*#__PURE__*/_jsx(Example, {
470
+ title: "Trading Trends",
471
+ children: /*#__PURE__*/_jsx(TradingTrends, {})
472
+ })]
473
+ })
474
+ });
475
+ };
476
+ export default ChartStories;
@@ -0,0 +1,79 @@
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 { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
3
+ import { CartesianChart, DottedArea, GradientLine, Line, LineChart } from '../';
4
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
+ const defaultChartHeight = 250;
6
+ const BasicLineChart = () => {
7
+ const chartData = [65, 78, 45, 88, 92, 73, 69];
8
+ return /*#__PURE__*/_jsx(LineChart, {
9
+ showYAxis: true,
10
+ height: defaultChartHeight,
11
+ series: [{
12
+ id: 'monthly-growth',
13
+ data: chartData,
14
+ label: 'Monthly Growth',
15
+ color: '#2ca02c'
16
+ }],
17
+ yAxis: {
18
+ requestedTickCount: 2,
19
+ tickLabelFormatter: value => "$" + value,
20
+ showGrid: true
21
+ }
22
+ });
23
+ };
24
+ const LineStyles = () => {
25
+ const topChartData = [15, 28, 32, 44, 46, 36, 40, 45, 48, 38];
26
+ const upperMiddleChartData = [12, 23, 21, 29, 34, 28, 31, 38, 42, 35];
27
+ const lowerMiddleChartData = [8, 15, 14, 25, 20, 18, 22, 28, 24, 30];
28
+ const bottomChartData = [4, 8, 11, 15, 16, 14, 16, 10, 12, 14];
29
+ return /*#__PURE__*/_jsxs(CartesianChart, {
30
+ height: defaultChartHeight,
31
+ series: [{
32
+ id: 'top',
33
+ data: topChartData
34
+ }, {
35
+ id: 'upperMiddle',
36
+ data: upperMiddleChartData,
37
+ color: '#ef4444'
38
+ }, {
39
+ id: 'lowerMiddle',
40
+ data: lowerMiddleChartData,
41
+ color: '#f59e0b'
42
+ }, {
43
+ id: 'bottom',
44
+ data: bottomChartData,
45
+ color: '#800080'
46
+ }],
47
+ children: [/*#__PURE__*/_jsx(Line, {
48
+ seriesId: "top"
49
+ }), /*#__PURE__*/_jsx(Line, {
50
+ seriesId: "upperMiddle",
51
+ type: "dotted"
52
+ }), /*#__PURE__*/_jsx(Line, {
53
+ LineComponent: props => /*#__PURE__*/_jsx(GradientLine, _extends({}, props, {
54
+ endColor: "#F7931A",
55
+ startColor: "#E3D74D",
56
+ strokeWidth: 4
57
+ })),
58
+ curve: "natural",
59
+ seriesId: "lowerMiddle"
60
+ }), /*#__PURE__*/_jsx(Line, {
61
+ showArea: true,
62
+ AreaComponent: DottedArea,
63
+ curve: "step",
64
+ seriesId: "bottom"
65
+ })]
66
+ });
67
+ };
68
+ const ChartStories = () => {
69
+ return /*#__PURE__*/_jsxs(ExampleScreen, {
70
+ children: [/*#__PURE__*/_jsx(Example, {
71
+ title: "Basic Line Chart",
72
+ children: /*#__PURE__*/_jsx(BasicLineChart, {})
73
+ }), /*#__PURE__*/_jsx(Example, {
74
+ title: "Line Styles",
75
+ children: /*#__PURE__*/_jsx(LineStyles, {})
76
+ })]
77
+ });
78
+ };
79
+ export default ChartStories;