@coinbase/cds-mobile-visualization 3.4.0-beta.2 → 3.4.0-beta.21

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 (211) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/dts/chart/CartesianChart.d.ts +92 -34
  3. package/dts/chart/CartesianChart.d.ts.map +1 -1
  4. package/dts/chart/ChartContextBridge.d.ts +28 -0
  5. package/dts/chart/ChartContextBridge.d.ts.map +1 -0
  6. package/dts/chart/ChartProvider.d.ts +3 -0
  7. package/dts/chart/ChartProvider.d.ts.map +1 -1
  8. package/dts/chart/Path.d.ts +97 -32
  9. package/dts/chart/Path.d.ts.map +1 -1
  10. package/dts/chart/PeriodSelector.d.ts +6 -13
  11. package/dts/chart/PeriodSelector.d.ts.map +1 -1
  12. package/dts/chart/area/Area.d.ts +39 -28
  13. package/dts/chart/area/Area.d.ts.map +1 -1
  14. package/dts/chart/area/AreaChart.d.ts +51 -10
  15. package/dts/chart/area/AreaChart.d.ts.map +1 -1
  16. package/dts/chart/area/DottedArea.d.ts +21 -2
  17. package/dts/chart/area/DottedArea.d.ts.map +1 -1
  18. package/dts/chart/area/GradientArea.d.ts +19 -13
  19. package/dts/chart/area/GradientArea.d.ts.map +1 -1
  20. package/dts/chart/area/SolidArea.d.ts +17 -2
  21. package/dts/chart/area/SolidArea.d.ts.map +1 -1
  22. package/dts/chart/axis/Axis.d.ts +86 -118
  23. package/dts/chart/axis/Axis.d.ts.map +1 -1
  24. package/dts/chart/axis/DefaultAxisTickLabel.d.ts +8 -0
  25. package/dts/chart/axis/DefaultAxisTickLabel.d.ts.map +1 -0
  26. package/dts/chart/axis/XAxis.d.ts +1 -1
  27. package/dts/chart/axis/XAxis.d.ts.map +1 -1
  28. package/dts/chart/axis/YAxis.d.ts +2 -2
  29. package/dts/chart/axis/YAxis.d.ts.map +1 -1
  30. package/dts/chart/axis/index.d.ts +1 -0
  31. package/dts/chart/axis/index.d.ts.map +1 -1
  32. package/dts/chart/bar/Bar.d.ts +49 -12
  33. package/dts/chart/bar/Bar.d.ts.map +1 -1
  34. package/dts/chart/bar/BarChart.d.ts +40 -19
  35. package/dts/chart/bar/BarChart.d.ts.map +1 -1
  36. package/dts/chart/bar/BarPlot.d.ts +3 -1
  37. package/dts/chart/bar/BarPlot.d.ts.map +1 -1
  38. package/dts/chart/bar/BarStack.d.ts +41 -46
  39. package/dts/chart/bar/BarStack.d.ts.map +1 -1
  40. package/dts/chart/bar/BarStackGroup.d.ts +2 -0
  41. package/dts/chart/bar/BarStackGroup.d.ts.map +1 -1
  42. package/dts/chart/bar/DefaultBar.d.ts +1 -1
  43. package/dts/chart/bar/DefaultBar.d.ts.map +1 -1
  44. package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -1
  45. package/dts/chart/gradient/Gradient.d.ts +25 -0
  46. package/dts/chart/gradient/Gradient.d.ts.map +1 -0
  47. package/dts/chart/gradient/index.d.ts +2 -0
  48. package/dts/chart/gradient/index.d.ts.map +1 -0
  49. package/dts/chart/index.d.ts +4 -1
  50. package/dts/chart/index.d.ts.map +1 -1
  51. package/dts/chart/legend/DefaultLegendEntry.d.ts +5 -0
  52. package/dts/chart/legend/DefaultLegendEntry.d.ts.map +1 -0
  53. package/dts/chart/legend/DefaultLegendShape.d.ts +5 -0
  54. package/dts/chart/legend/DefaultLegendShape.d.ts.map +1 -0
  55. package/dts/chart/legend/Legend.d.ts +168 -0
  56. package/dts/chart/legend/Legend.d.ts.map +1 -0
  57. package/dts/chart/legend/index.d.ts +4 -0
  58. package/dts/chart/legend/index.d.ts.map +1 -0
  59. package/dts/chart/line/DefaultReferenceLineLabel.d.ts +9 -0
  60. package/dts/chart/line/DefaultReferenceLineLabel.d.ts.map +1 -0
  61. package/dts/chart/line/DottedLine.d.ts +13 -5
  62. package/dts/chart/line/DottedLine.d.ts.map +1 -1
  63. package/dts/chart/line/Line.d.ts +61 -27
  64. package/dts/chart/line/Line.d.ts.map +1 -1
  65. package/dts/chart/line/LineChart.d.ts +43 -9
  66. package/dts/chart/line/LineChart.d.ts.map +1 -1
  67. package/dts/chart/line/ReferenceLine.d.ts +68 -20
  68. package/dts/chart/line/ReferenceLine.d.ts.map +1 -1
  69. package/dts/chart/line/SolidLine.d.ts +8 -5
  70. package/dts/chart/line/SolidLine.d.ts.map +1 -1
  71. package/dts/chart/line/index.d.ts +1 -1
  72. package/dts/chart/line/index.d.ts.map +1 -1
  73. package/dts/chart/point/DefaultPointLabel.d.ts +10 -0
  74. package/dts/chart/point/DefaultPointLabel.d.ts.map +1 -0
  75. package/dts/chart/point/Point.d.ts +136 -0
  76. package/dts/chart/point/Point.d.ts.map +1 -0
  77. package/dts/chart/point/index.d.ts +3 -0
  78. package/dts/chart/point/index.d.ts.map +1 -0
  79. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +38 -0
  80. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -0
  81. package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts +12 -0
  82. package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts.map +1 -0
  83. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +11 -0
  84. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -0
  85. package/dts/chart/scrubber/Scrubber.d.ts +230 -42
  86. package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
  87. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +54 -0
  88. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -0
  89. package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +46 -0
  90. package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +1 -0
  91. package/dts/chart/scrubber/ScrubberProvider.d.ts +6 -3
  92. package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -1
  93. package/dts/chart/scrubber/index.d.ts +3 -0
  94. package/dts/chart/scrubber/index.d.ts.map +1 -1
  95. package/dts/chart/text/ChartText.d.ts +151 -77
  96. package/dts/chart/text/ChartText.d.ts.map +1 -1
  97. package/dts/chart/text/{SmartChartTextGroup.d.ts → ChartTextGroup.d.ts} +9 -3
  98. package/dts/chart/text/ChartTextGroup.d.ts.map +1 -0
  99. package/dts/chart/text/index.d.ts +1 -1
  100. package/dts/chart/text/index.d.ts.map +1 -1
  101. package/dts/chart/utils/axis.d.ts +25 -1
  102. package/dts/chart/utils/axis.d.ts.map +1 -1
  103. package/dts/chart/utils/bar.d.ts +34 -0
  104. package/dts/chart/utils/bar.d.ts.map +1 -1
  105. package/dts/chart/utils/chart.d.ts +52 -7
  106. package/dts/chart/utils/chart.d.ts.map +1 -1
  107. package/dts/chart/utils/context.d.ts +28 -7
  108. package/dts/chart/utils/context.d.ts.map +1 -1
  109. package/dts/chart/utils/gradient.d.ts +117 -0
  110. package/dts/chart/utils/gradient.d.ts.map +1 -0
  111. package/dts/chart/utils/index.d.ts +3 -0
  112. package/dts/chart/utils/index.d.ts.map +1 -1
  113. package/dts/chart/utils/path.d.ts +59 -0
  114. package/dts/chart/utils/path.d.ts.map +1 -1
  115. package/dts/chart/utils/point.d.ts +71 -7
  116. package/dts/chart/utils/point.d.ts.map +1 -1
  117. package/dts/chart/utils/scale.d.ts +102 -0
  118. package/dts/chart/utils/scale.d.ts.map +1 -1
  119. package/dts/chart/utils/scrubber.d.ts +40 -0
  120. package/dts/chart/utils/scrubber.d.ts.map +1 -0
  121. package/dts/chart/utils/transition.d.ts +178 -0
  122. package/dts/chart/utils/transition.d.ts.map +1 -0
  123. package/esm/chart/CartesianChart.js +199 -75
  124. package/esm/chart/ChartContextBridge.js +159 -0
  125. package/esm/chart/ChartProvider.js +2 -2
  126. package/esm/chart/Path.js +200 -114
  127. package/esm/chart/PeriodSelector.js +7 -3
  128. package/esm/chart/__stories__/CartesianChart.stories.js +307 -134
  129. package/esm/chart/__stories__/ChartTransitions.stories.js +629 -0
  130. package/esm/chart/__stories__/PeriodSelector.stories.js +201 -75
  131. package/esm/chart/area/Area.js +27 -35
  132. package/esm/chart/area/AreaChart.js +17 -12
  133. package/esm/chart/area/DottedArea.js +64 -108
  134. package/esm/chart/area/GradientArea.js +37 -91
  135. package/esm/chart/area/SolidArea.js +24 -8
  136. package/esm/chart/area/__stories__/AreaChart.stories.js +1 -1
  137. package/esm/chart/axis/Axis.js +5 -39
  138. package/esm/chart/axis/DefaultAxisTickLabel.js +11 -0
  139. package/esm/chart/axis/XAxis.js +148 -66
  140. package/esm/chart/axis/YAxis.js +149 -65
  141. package/esm/chart/axis/__stories__/Axis.stories.js +259 -1
  142. package/esm/chart/axis/index.js +1 -0
  143. package/esm/chart/bar/Bar.js +7 -1
  144. package/esm/chart/bar/BarChart.js +17 -37
  145. package/esm/chart/bar/BarPlot.js +43 -35
  146. package/esm/chart/bar/BarStack.js +84 -37
  147. package/esm/chart/bar/BarStackGroup.js +7 -17
  148. package/esm/chart/bar/DefaultBar.js +29 -51
  149. package/esm/chart/bar/DefaultBarStack.js +34 -58
  150. package/esm/chart/bar/__stories__/BarChart.stories.js +948 -88
  151. package/esm/chart/gradient/Gradient.js +53 -0
  152. package/esm/chart/gradient/index.js +1 -0
  153. package/esm/chart/index.js +4 -1
  154. package/esm/chart/legend/DefaultLegendEntry.js +42 -0
  155. package/esm/chart/legend/DefaultLegendShape.js +64 -0
  156. package/esm/chart/legend/Legend.js +59 -0
  157. package/esm/chart/legend/__stories__/Legend.stories.js +574 -0
  158. package/esm/chart/legend/index.js +3 -0
  159. package/esm/chart/line/DefaultReferenceLineLabel.js +66 -0
  160. package/esm/chart/line/DottedLine.js +31 -14
  161. package/esm/chart/line/Line.js +96 -68
  162. package/esm/chart/line/LineChart.js +21 -14
  163. package/esm/chart/line/ReferenceLine.js +80 -63
  164. package/esm/chart/line/SolidLine.js +27 -10
  165. package/esm/chart/line/__stories__/LineChart.stories.js +1748 -2048
  166. package/esm/chart/line/__stories__/ReferenceLine.stories.js +177 -28
  167. package/esm/chart/line/index.js +1 -1
  168. package/esm/chart/point/DefaultPointLabel.js +39 -0
  169. package/esm/chart/point/Point.js +186 -0
  170. package/esm/chart/point/index.js +2 -0
  171. package/esm/chart/scrubber/DefaultScrubberBeacon.js +180 -0
  172. package/esm/chart/scrubber/DefaultScrubberBeaconLabel.js +43 -0
  173. package/esm/chart/scrubber/DefaultScrubberLabel.js +28 -0
  174. package/esm/chart/scrubber/Scrubber.js +130 -144
  175. package/esm/chart/scrubber/ScrubberBeaconGroup.js +165 -0
  176. package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +208 -0
  177. package/esm/chart/scrubber/ScrubberProvider.js +46 -54
  178. package/esm/chart/scrubber/__stories__/Scrubber.stories.js +760 -0
  179. package/esm/chart/scrubber/index.js +3 -1
  180. package/esm/chart/text/ChartText.js +242 -174
  181. package/esm/chart/text/{SmartChartTextGroup.js → ChartTextGroup.js} +6 -5
  182. package/esm/chart/text/index.js +1 -1
  183. package/esm/chart/utils/axis.js +47 -31
  184. package/esm/chart/utils/bar.js +43 -0
  185. package/esm/chart/utils/chart.js +57 -3
  186. package/esm/chart/utils/gradient.js +305 -0
  187. package/esm/chart/utils/index.js +3 -0
  188. package/esm/chart/utils/path.js +84 -8
  189. package/esm/chart/utils/point.js +171 -17
  190. package/esm/chart/utils/scale.js +242 -2
  191. package/esm/chart/utils/scrubber.js +146 -0
  192. package/esm/chart/utils/transition.js +215 -0
  193. package/esm/sparkline/__figma__/Sparkline.figma.js +1 -1
  194. package/esm/sparkline/__stories__/Sparkline.stories.js +11 -7
  195. package/esm/sparkline/__stories__/SparklineGradient.stories.js +7 -4
  196. package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +1 -1
  197. package/esm/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.js +51 -26
  198. package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +1 -1
  199. package/esm/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.js +17 -9
  200. package/package.json +15 -10
  201. package/dts/chart/Point.d.ts +0 -103
  202. package/dts/chart/Point.d.ts.map +0 -1
  203. package/dts/chart/line/GradientLine.d.ts +0 -45
  204. package/dts/chart/line/GradientLine.d.ts.map +0 -1
  205. package/dts/chart/scrubber/ScrubberBeacon.d.ts +0 -75
  206. package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +0 -1
  207. package/dts/chart/text/SmartChartTextGroup.d.ts.map +0 -1
  208. package/esm/chart/Point.js +0 -111
  209. package/esm/chart/__stories__/Chart.stories.js +0 -79
  210. package/esm/chart/line/GradientLine.js +0 -62
  211. package/esm/chart/scrubber/ScrubberBeacon.js +0 -199
@@ -0,0 +1,760 @@
1
+ const _excluded = ["seriesId", "color", "label"],
2
+ _excluded2 = ["seriesId", "color", "label"];
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
+ 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
+ import { memo, useCallback, useMemo, useRef, useState } from 'react';
6
+ import { useDerivedValue } from 'react-native-reanimated';
7
+ import { assets } from '@coinbase/cds-common/internal/data/assets';
8
+ import { useTheme } from '@coinbase/cds-mobile';
9
+ import { Button, IconButton } from '@coinbase/cds-mobile/buttons';
10
+ import { ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
11
+ import { Box, HStack, VStack } from '@coinbase/cds-mobile/layout';
12
+ import { Text } from '@coinbase/cds-mobile/typography';
13
+ import { FontWeight, Skia, TextAlign } from '@shopify/react-native-skia';
14
+ import { useCartesianChartContext } from '../../ChartProvider';
15
+ import { LineChart, SolidLine } from '../../line';
16
+ import { getLineData, unwrapAnimatedValue, useScrubberContext } from '../../utils';
17
+ import { DefaultScrubberBeacon, DefaultScrubberBeaconLabel, DefaultScrubberLabel, Scrubber } from '..';
18
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
+ const sampleData = [10, 22, 29, 45, 98, 45, 22, 52, 21, 4, 68, 20, 21, 58];
20
+ const BasicScrubber = () => {
21
+ return /*#__PURE__*/_jsx(LineChart, {
22
+ enableScrubbing: true,
23
+ showArea: true,
24
+ showYAxis: true,
25
+ height: 150,
26
+ series: [{
27
+ id: 'prices',
28
+ data: sampleData
29
+ }],
30
+ xAxis: {
31
+ range: _ref => {
32
+ let {
33
+ min,
34
+ max
35
+ } = _ref;
36
+ return {
37
+ min,
38
+ max: max - 8
39
+ };
40
+ }
41
+ },
42
+ yAxis: {
43
+ showGrid: true
44
+ },
45
+ children: /*#__PURE__*/_jsx(Scrubber, {
46
+ idlePulse: true
47
+ })
48
+ });
49
+ };
50
+ const SeriesFilter = () => {
51
+ return /*#__PURE__*/_jsx(LineChart, {
52
+ enableScrubbing: true,
53
+ height: 150,
54
+ series: [{
55
+ id: 'top',
56
+ data: [15, 28, 32, 44, 46, 36, 40, 45, 48, 38]
57
+ }, {
58
+ id: 'upperMiddle',
59
+ data: [12, 23, 21, 29, 34, 28, 31, 38, 42, 35],
60
+ color: '#ef4444',
61
+ type: 'dotted'
62
+ }, {
63
+ id: 'lowerMiddle',
64
+ data: [8, 15, 14, 25, 20, 18, 22, 28, 24, 30],
65
+ color: '#f59e0b',
66
+ curve: 'natural'
67
+ }, {
68
+ id: 'bottom',
69
+ data: [4, 8, 11, 15, 16, 14, 16, 10, 12, 14],
70
+ color: '#800080',
71
+ curve: 'step',
72
+ showArea: true
73
+ }],
74
+ children: /*#__PURE__*/_jsx(Scrubber, {
75
+ seriesIds: ['top', 'lowerMiddle']
76
+ })
77
+ });
78
+ };
79
+ const WithLabels = () => {
80
+ return /*#__PURE__*/_jsx(LineChart, {
81
+ enableScrubbing: true,
82
+ showArea: true,
83
+ height: 150,
84
+ series: [{
85
+ id: 'prices',
86
+ data: sampleData,
87
+ label: 'Price'
88
+ }],
89
+ children: /*#__PURE__*/_jsx(Scrubber, {
90
+ label: dataIndex => "Day " + (dataIndex + 1)
91
+ })
92
+ });
93
+ };
94
+ const IdlePulse = () => {
95
+ const theme = useTheme();
96
+ return /*#__PURE__*/_jsx(LineChart, {
97
+ enableScrubbing: true,
98
+ showArea: true,
99
+ height: 150,
100
+ series: [{
101
+ id: 'prices',
102
+ data: sampleData,
103
+ color: theme.color.fgPositive
104
+ }],
105
+ children: /*#__PURE__*/_jsx(Scrubber, {
106
+ idlePulse: true
107
+ })
108
+ });
109
+ };
110
+ const ImperativePulse = () => {
111
+ const scrubberRef = useRef(null);
112
+ return /*#__PURE__*/_jsxs(VStack, {
113
+ gap: 2,
114
+ children: [/*#__PURE__*/_jsx(LineChart, {
115
+ enableScrubbing: true,
116
+ showArea: true,
117
+ height: 150,
118
+ series: [{
119
+ id: 'prices',
120
+ data: sampleData
121
+ }],
122
+ children: /*#__PURE__*/_jsx(Scrubber, {
123
+ ref: scrubberRef
124
+ })
125
+ }), /*#__PURE__*/_jsx(Button, {
126
+ onPress: () => {
127
+ var _scrubberRef$current;
128
+ return (_scrubberRef$current = scrubberRef.current) == null ? void 0 : _scrubberRef$current.pulse();
129
+ },
130
+ children: "Pulse"
131
+ })]
132
+ });
133
+ };
134
+ const BeaconStroke = () => {
135
+ const theme = useTheme();
136
+ const backgroundColor = "rgb(" + theme.spectrum.red40 + ")";
137
+ const foregroundColor = "rgb(" + theme.spectrum.gray0 + ")";
138
+ return /*#__PURE__*/_jsx(Box, {
139
+ borderRadius: 300,
140
+ padding: 2,
141
+ style: {
142
+ backgroundColor
143
+ },
144
+ children: /*#__PURE__*/_jsx(LineChart, {
145
+ enableScrubbing: true,
146
+ showArea: true,
147
+ height: 150,
148
+ series: [{
149
+ id: 'prices',
150
+ data: sampleData,
151
+ color: foregroundColor
152
+ }],
153
+ children: /*#__PURE__*/_jsx(Scrubber, {
154
+ hideOverlay: true,
155
+ idlePulse: true,
156
+ beaconStroke: backgroundColor,
157
+ lineStroke: foregroundColor
158
+ })
159
+ })
160
+ });
161
+ };
162
+ const CustomBeacon = () => {
163
+ const theme = useTheme();
164
+ const InvertedBeacon = /*#__PURE__*/memo(props => /*#__PURE__*/_jsx(DefaultScrubberBeacon, _extends({}, props, {
165
+ color: theme.color.bg,
166
+ radius: 5,
167
+ stroke: theme.color.fg,
168
+ strokeWidth: 3
169
+ })));
170
+ return /*#__PURE__*/_jsx(LineChart, {
171
+ enableScrubbing: true,
172
+ showArea: true,
173
+ showYAxis: true,
174
+ height: 150,
175
+ series: [{
176
+ id: 'prices',
177
+ data: sampleData,
178
+ color: theme.color.fg
179
+ }],
180
+ xAxis: {
181
+ range: _ref2 => {
182
+ let {
183
+ min,
184
+ max
185
+ } = _ref2;
186
+ return {
187
+ min,
188
+ max: max - 16
189
+ };
190
+ }
191
+ },
192
+ yAxis: {
193
+ showGrid: true,
194
+ domain: {
195
+ min: 0,
196
+ max: 100
197
+ }
198
+ },
199
+ children: /*#__PURE__*/_jsx(Scrubber, {
200
+ BeaconComponent: InvertedBeacon
201
+ })
202
+ });
203
+ };
204
+ const CustomBeaconLabel = () => {
205
+ const theme = useTheme();
206
+ const MyScrubberBeaconLabel = /*#__PURE__*/memo(_ref3 => {
207
+ let {
208
+ seriesId,
209
+ color,
210
+ label
211
+ } = _ref3,
212
+ props = _objectWithoutPropertiesLoose(_ref3, _excluded);
213
+ const {
214
+ getSeriesData,
215
+ series
216
+ } = useCartesianChartContext();
217
+ const {
218
+ scrubberPosition
219
+ } = useScrubberContext();
220
+ const seriesData = useMemo(() => getLineData(getSeriesData(seriesId)), [getSeriesData, seriesId]);
221
+ const dataLength = useMemo(() => {
222
+ var _series$reduce;
223
+ return (_series$reduce = series == null ? void 0 : series.reduce((max, s) => {
224
+ var _data$length;
225
+ const data = getSeriesData(s.id);
226
+ return Math.max(max, (_data$length = data == null ? void 0 : data.length) != null ? _data$length : 0);
227
+ }, 0)) != null ? _series$reduce : 0;
228
+ }, [series, getSeriesData]);
229
+ const dataIndex = useDerivedValue(() => {
230
+ var _scrubberPosition$val;
231
+ return (_scrubberPosition$val = scrubberPosition.value) != null ? _scrubberPosition$val : Math.max(0, dataLength - 1);
232
+ }, [scrubberPosition, dataLength]);
233
+ const percentageLabel = useDerivedValue(() => {
234
+ if (seriesData !== undefined) {
235
+ const dataAtPosition = seriesData[dataIndex.value];
236
+ return unwrapAnimatedValue(label) + " \xB7 " + dataAtPosition + "%";
237
+ }
238
+ return unwrapAnimatedValue(label);
239
+ }, [label, seriesData, dataIndex]);
240
+ return /*#__PURE__*/_jsx(DefaultScrubberBeaconLabel, _extends({}, props, {
241
+ background: color,
242
+ color: theme.color.bg,
243
+ label: percentageLabel,
244
+ seriesId: seriesId
245
+ }));
246
+ });
247
+ return /*#__PURE__*/_jsx(LineChart, {
248
+ enableScrubbing: true,
249
+ showArea: true,
250
+ showYAxis: true,
251
+ areaType: "dotted",
252
+ height: 150,
253
+ series: [{
254
+ id: 'Boston',
255
+ data: [25, 30, 35, 45, 60, 100],
256
+ color: "rgb(" + theme.spectrum.green40 + ")",
257
+ label: 'Boston'
258
+ }, {
259
+ id: 'Miami',
260
+ data: [20, 25, 30, 35, 20, 0],
261
+ color: "rgb(" + theme.spectrum.blue40 + ")",
262
+ label: 'Miami'
263
+ }, {
264
+ id: 'Denver',
265
+ data: [10, 15, 20, 25, 40, 0],
266
+ color: "rgb(" + theme.spectrum.orange40 + ")",
267
+ label: 'Denver'
268
+ }, {
269
+ id: 'Phoenix',
270
+ data: [15, 10, 5, 0, 0, 0],
271
+ color: "rgb(" + theme.spectrum.red40 + ")",
272
+ label: 'Phoenix'
273
+ }],
274
+ yAxis: {
275
+ showGrid: true
276
+ },
277
+ children: /*#__PURE__*/_jsx(Scrubber, {
278
+ BeaconLabelComponent: MyScrubberBeaconLabel
279
+ })
280
+ });
281
+ };
282
+ const PercentageBeaconLabels = () => {
283
+ const theme = useTheme();
284
+ const PercentageScrubberBeaconLabel = /*#__PURE__*/memo(_ref4 => {
285
+ let {
286
+ seriesId,
287
+ color,
288
+ label
289
+ } = _ref4,
290
+ props = _objectWithoutPropertiesLoose(_ref4, _excluded2);
291
+ const {
292
+ getSeriesData,
293
+ series,
294
+ fontProvider
295
+ } = useCartesianChartContext();
296
+ const {
297
+ scrubberPosition
298
+ } = useScrubberContext();
299
+ const seriesData = useMemo(() => getLineData(getSeriesData(seriesId)), [getSeriesData, seriesId]);
300
+ const dataLength = useMemo(() => {
301
+ var _series$reduce2;
302
+ return (_series$reduce2 = series == null ? void 0 : series.reduce((max, s) => {
303
+ var _data$length2;
304
+ const data = getSeriesData(s.id);
305
+ return Math.max(max, (_data$length2 = data == null ? void 0 : data.length) != null ? _data$length2 : 0);
306
+ }, 0)) != null ? _series$reduce2 : 0;
307
+ }, [series, getSeriesData]);
308
+ const dataIndex = useDerivedValue(() => {
309
+ var _scrubberPosition$val2;
310
+ return (_scrubberPosition$val2 = scrubberPosition.value) != null ? _scrubberPosition$val2 : Math.max(0, dataLength - 1);
311
+ }, [scrubberPosition, dataLength]);
312
+ const labelColor = "rgb(" + theme.spectrum.gray0 + ")";
313
+ const regularStyle = useMemo(() => ({
314
+ fontFamilies: ['Inter'],
315
+ fontSize: 14,
316
+ fontStyle: {
317
+ weight: FontWeight.Normal
318
+ },
319
+ color: Skia.Color(labelColor)
320
+ }), [labelColor]);
321
+ const boldStyle = useMemo(() => _extends({}, regularStyle, {
322
+ fontStyle: {
323
+ weight: FontWeight.Bold
324
+ }
325
+ }), [regularStyle]);
326
+ const percentageLabel = useDerivedValue(() => {
327
+ const labelValue = unwrapAnimatedValue(label);
328
+ if (seriesData !== undefined) {
329
+ const dataAtPosition = seriesData[dataIndex.value];
330
+ const builder = Skia.ParagraphBuilder.Make({
331
+ textAlign: TextAlign.Left
332
+ }, fontProvider);
333
+ builder.pushStyle(boldStyle);
334
+ builder.addText(dataAtPosition + "%");
335
+ builder.pushStyle(regularStyle);
336
+ builder.addText(" " + labelValue);
337
+ const para = builder.build();
338
+ para.layout(512);
339
+ return para;
340
+ }
341
+ return labelValue;
342
+ }, [label, seriesData, dataIndex, fontProvider, boldStyle, regularStyle]);
343
+ return /*#__PURE__*/_jsx(DefaultScrubberBeaconLabel, _extends({}, props, {
344
+ background: color,
345
+ label: percentageLabel,
346
+ seriesId: seriesId
347
+ }));
348
+ });
349
+ const isLightTheme = theme.activeColorScheme === 'light';
350
+ const background = isLightTheme ? "rgb(" + theme.spectrum.gray90 + ")" : "rgb(" + theme.spectrum.gray0 + ")";
351
+ const scrubberLineStroke = isLightTheme ? "rgb(" + theme.spectrum.gray0 + ")" : "rgb(" + theme.spectrum.gray90 + ")";
352
+ const seriesData = [{
353
+ id: 'prices2',
354
+ data: [90, 78, 71, 55, 2, 55, 78, 48, 79, 96, 32, 80, 79, 42],
355
+ color: "rgb(" + theme.spectrum.blue40 + ")",
356
+ label: 'ATL'
357
+ }, {
358
+ id: 'prices',
359
+ data: [10, 22, 29, 45, 98, 45, 22, 52, 21, 4, 68, 20, 21, 58],
360
+ color: "rgb(" + theme.spectrum.chartreuse40 + ")",
361
+ label: 'NYC'
362
+ }];
363
+ return /*#__PURE__*/_jsxs(VStack, {
364
+ gap: 4,
365
+ children: [/*#__PURE__*/_jsx(Box, {
366
+ borderRadius: 300,
367
+ padding: 2,
368
+ style: {
369
+ backgroundColor: background
370
+ },
371
+ children: /*#__PURE__*/_jsx(LineChart, {
372
+ enableScrubbing: true,
373
+ showArea: true,
374
+ areaType: "dotted",
375
+ height: 150,
376
+ inset: {
377
+ bottom: 8,
378
+ left: 8,
379
+ top: 8,
380
+ right: 0
381
+ },
382
+ series: seriesData,
383
+ xAxis: {
384
+ range: _ref5 => {
385
+ let {
386
+ min,
387
+ max
388
+ } = _ref5;
389
+ return {
390
+ min,
391
+ max: max - 92
392
+ };
393
+ }
394
+ },
395
+ children: /*#__PURE__*/_jsx(Scrubber, {
396
+ hideOverlay: true,
397
+ idlePulse: true,
398
+ BeaconLabelComponent: PercentageScrubberBeaconLabel,
399
+ beaconStroke: background,
400
+ lineStroke: scrubberLineStroke
401
+ })
402
+ })
403
+ }), /*#__PURE__*/_jsx(Box, {
404
+ borderRadius: 300,
405
+ padding: 2,
406
+ style: {
407
+ backgroundColor: background
408
+ },
409
+ children: /*#__PURE__*/_jsx(LineChart, {
410
+ enableScrubbing: true,
411
+ showArea: true,
412
+ areaType: "dotted",
413
+ height: 150,
414
+ inset: {
415
+ bottom: 8,
416
+ left: 8,
417
+ top: 8,
418
+ right: 0
419
+ },
420
+ series: seriesData,
421
+ xAxis: {
422
+ range: _ref6 => {
423
+ let {
424
+ min,
425
+ max
426
+ } = _ref6;
427
+ return {
428
+ min,
429
+ max: max - 92
430
+ };
431
+ }
432
+ },
433
+ children: /*#__PURE__*/_jsx(Scrubber, {
434
+ hideOverlay: true,
435
+ idlePulse: true,
436
+ BeaconLabelComponent: PercentageScrubberBeaconLabel,
437
+ beaconLabelPreferredSide: "left",
438
+ beaconStroke: background,
439
+ lineStroke: scrubberLineStroke
440
+ })
441
+ })
442
+ })]
443
+ });
444
+ };
445
+ const HideBeaconLabels = () => {
446
+ const theme = useTheme();
447
+ return /*#__PURE__*/_jsx(LineChart, {
448
+ enableScrubbing: true,
449
+ legend: true,
450
+ showArea: true,
451
+ height: 200,
452
+ inset: {
453
+ top: 60
454
+ },
455
+ series: [{
456
+ id: 'pageViews',
457
+ data: [2400, 1398, 9800, 3908, 4800, 3800, 4300],
458
+ color: theme.color.accentBoldGreen,
459
+ label: 'Page Views'
460
+ }, {
461
+ id: 'uniqueVisitors',
462
+ data: [4000, 3000, 2000, 2780, 1890, 2390, 3490],
463
+ color: theme.color.accentBoldPurple,
464
+ label: 'Unique Visitors'
465
+ }],
466
+ children: /*#__PURE__*/_jsx(Scrubber, {
467
+ hideBeaconLabels: true,
468
+ labelElevated: true,
469
+ label: dataIndex => "Day " + (dataIndex + 1)
470
+ })
471
+ });
472
+ };
473
+ const LabelElevated = () => {
474
+ return /*#__PURE__*/_jsx(LineChart, {
475
+ enableScrubbing: true,
476
+ showArea: true,
477
+ height: 200,
478
+ inset: {
479
+ top: 60
480
+ },
481
+ series: [{
482
+ id: 'prices',
483
+ data: sampleData
484
+ }],
485
+ children: /*#__PURE__*/_jsx(Scrubber, {
486
+ labelElevated: true,
487
+ label: dataIndex => "Day " + (dataIndex + 1)
488
+ })
489
+ });
490
+ };
491
+ const CustomLabelComponent = () => {
492
+ const theme = useTheme();
493
+ const MyLabelComponent = /*#__PURE__*/memo(props => {
494
+ const {
495
+ drawingArea
496
+ } = useCartesianChartContext();
497
+ if (!drawingArea) return null;
498
+ return /*#__PURE__*/_jsx(DefaultScrubberLabel, _extends({}, props, {
499
+ elevated: true,
500
+ background: theme.color.bgPrimary,
501
+ color: theme.color.bgPrimaryWash,
502
+ dy: 32,
503
+ fontWeight: FontWeight.Bold,
504
+ y: drawingArea.y + drawingArea.height
505
+ }));
506
+ });
507
+ return /*#__PURE__*/_jsx(LineChart, {
508
+ enableScrubbing: true,
509
+ showArea: true,
510
+ height: 200,
511
+ inset: {
512
+ top: 16,
513
+ bottom: 64
514
+ },
515
+ series: [{
516
+ id: 'prices',
517
+ data: sampleData
518
+ }],
519
+ children: /*#__PURE__*/_jsx(Scrubber, {
520
+ LabelComponent: MyLabelComponent,
521
+ label: dataIndex => "Day " + (dataIndex + 1)
522
+ })
523
+ });
524
+ };
525
+ const LabelFonts = () => {
526
+ return /*#__PURE__*/_jsx(LineChart, {
527
+ enableScrubbing: true,
528
+ showArea: true,
529
+ showYAxis: true,
530
+ height: 150,
531
+ series: [{
532
+ id: 'btc',
533
+ data: sampleData,
534
+ label: 'BTC',
535
+ color: assets.btc.color
536
+ }, {
537
+ id: 'eth',
538
+ data: [5, 15, 18, 30, 65, 30, 15, 35, 15, 2, 45, 12, 15, 40],
539
+ label: 'ETH',
540
+ color: assets.eth.color
541
+ }],
542
+ yAxis: {
543
+ showGrid: true
544
+ },
545
+ children: /*#__PURE__*/_jsx(Scrubber, {
546
+ beaconLabelFont: "legal",
547
+ label: dataIndex => "Day " + (dataIndex + 1),
548
+ labelFont: "legal"
549
+ })
550
+ });
551
+ };
552
+ const LabelBoundsInset = () => {
553
+ return /*#__PURE__*/_jsxs(VStack, {
554
+ gap: 4,
555
+ children: [/*#__PURE__*/_jsx(LineChart, {
556
+ enableScrubbing: true,
557
+ showArea: true,
558
+ height: 150,
559
+ inset: {
560
+ left: 0,
561
+ right: 0
562
+ },
563
+ series: [{
564
+ id: 'prices',
565
+ data: sampleData
566
+ }],
567
+ children: /*#__PURE__*/_jsx(Scrubber, {
568
+ label: "Without bounds - text touches edge",
569
+ labelBoundsInset: 0
570
+ })
571
+ }), /*#__PURE__*/_jsx(LineChart, {
572
+ enableScrubbing: true,
573
+ showArea: true,
574
+ height: 150,
575
+ inset: {
576
+ left: 0,
577
+ right: 0
578
+ },
579
+ series: [{
580
+ id: 'prices',
581
+ data: sampleData
582
+ }],
583
+ children: /*#__PURE__*/_jsx(Scrubber, {
584
+ label: "With bounds inset - text has space",
585
+ labelBoundsInset: {
586
+ top: 0,
587
+ bottom: 0,
588
+ left: 12,
589
+ right: 12
590
+ }
591
+ })
592
+ })]
593
+ });
594
+ };
595
+ const CustomLine = () => {
596
+ return /*#__PURE__*/_jsx(LineChart, {
597
+ enableScrubbing: true,
598
+ showArea: true,
599
+ height: 150,
600
+ series: [{
601
+ id: 'prices',
602
+ data: sampleData
603
+ }],
604
+ children: /*#__PURE__*/_jsx(Scrubber, {
605
+ LineComponent: SolidLine
606
+ })
607
+ });
608
+ };
609
+ const HiddenScrubberWhenIdle = () => {
610
+ const MyScrubberBeacon = /*#__PURE__*/memo(props => {
611
+ const {
612
+ scrubberPosition
613
+ } = useScrubberContext();
614
+ const beaconOpacity = useDerivedValue(() => scrubberPosition.value !== undefined ? 1 : 0, [scrubberPosition]);
615
+ return /*#__PURE__*/_jsx(DefaultScrubberBeacon, _extends({}, props, {
616
+ opacity: beaconOpacity
617
+ }));
618
+ });
619
+ const MyScrubberBeaconLabel = /*#__PURE__*/memo(props => {
620
+ const {
621
+ scrubberPosition
622
+ } = useScrubberContext();
623
+ const labelOpacity = useDerivedValue(() => scrubberPosition.value !== undefined ? 1 : 0, [scrubberPosition]);
624
+ return /*#__PURE__*/_jsx(DefaultScrubberBeaconLabel, _extends({}, props, {
625
+ opacity: labelOpacity
626
+ }));
627
+ });
628
+ return /*#__PURE__*/_jsx(LineChart, {
629
+ enableScrubbing: true,
630
+ showArea: true,
631
+ height: 150,
632
+ series: [{
633
+ id: 'prices',
634
+ data: sampleData,
635
+ label: 'Price'
636
+ }],
637
+ children: /*#__PURE__*/_jsx(Scrubber, {
638
+ BeaconComponent: MyScrubberBeacon,
639
+ BeaconLabelComponent: MyScrubberBeaconLabel
640
+ })
641
+ });
642
+ };
643
+ const HideOverlay = () => {
644
+ return /*#__PURE__*/_jsx(LineChart, {
645
+ enableScrubbing: true,
646
+ showArea: true,
647
+ height: 150,
648
+ series: [{
649
+ id: 'prices',
650
+ data: sampleData
651
+ }],
652
+ children: /*#__PURE__*/_jsx(Scrubber, {
653
+ hideOverlay: true
654
+ })
655
+ });
656
+ };
657
+ const ExampleNavigator = () => {
658
+ const [currentIndex, setCurrentIndex] = useState(0);
659
+ const examples = useMemo(() => [{
660
+ title: 'Basic',
661
+ component: /*#__PURE__*/_jsx(BasicScrubber, {})
662
+ }, {
663
+ title: 'Series Filter',
664
+ component: /*#__PURE__*/_jsx(SeriesFilter, {})
665
+ }, {
666
+ title: 'With Labels',
667
+ component: /*#__PURE__*/_jsx(WithLabels, {})
668
+ }, {
669
+ title: 'Idle Pulse',
670
+ component: /*#__PURE__*/_jsx(IdlePulse, {})
671
+ }, {
672
+ title: 'Imperative Pulse',
673
+ component: /*#__PURE__*/_jsx(ImperativePulse, {})
674
+ }, {
675
+ title: 'Beacon Stroke',
676
+ component: /*#__PURE__*/_jsx(BeaconStroke, {})
677
+ }, {
678
+ title: 'Custom Beacon',
679
+ component: /*#__PURE__*/_jsx(CustomBeacon, {})
680
+ }, {
681
+ title: 'Custom Beacon Label',
682
+ component: /*#__PURE__*/_jsx(CustomBeaconLabel, {})
683
+ }, {
684
+ title: 'Percentage Beacon Labels',
685
+ component: /*#__PURE__*/_jsx(PercentageBeaconLabels, {})
686
+ }, {
687
+ title: 'Hide Beacon Labels',
688
+ component: /*#__PURE__*/_jsx(HideBeaconLabels, {})
689
+ }, {
690
+ title: 'Label Elevated',
691
+ component: /*#__PURE__*/_jsx(LabelElevated, {})
692
+ }, {
693
+ title: 'Custom Label Component',
694
+ component: /*#__PURE__*/_jsx(CustomLabelComponent, {})
695
+ }, {
696
+ title: 'Label Fonts',
697
+ component: /*#__PURE__*/_jsx(LabelFonts, {})
698
+ }, {
699
+ title: 'Label Bounds Inset',
700
+ component: /*#__PURE__*/_jsx(LabelBoundsInset, {})
701
+ }, {
702
+ title: 'Custom Line',
703
+ component: /*#__PURE__*/_jsx(CustomLine, {})
704
+ }, {
705
+ title: 'Hidden Scrubber When Idle',
706
+ component: /*#__PURE__*/_jsx(HiddenScrubberWhenIdle, {})
707
+ }, {
708
+ title: 'Hide Overlay',
709
+ component: /*#__PURE__*/_jsx(HideOverlay, {})
710
+ }], []);
711
+ const currentExample = examples[currentIndex];
712
+ const isFirstExample = currentIndex === 0;
713
+ const isLastExample = currentIndex === examples.length - 1;
714
+ const handlePrevious = useCallback(() => {
715
+ setCurrentIndex(prev => Math.max(0, prev - 1));
716
+ }, []);
717
+ const handleNext = useCallback(() => {
718
+ setCurrentIndex(prev => Math.min(examples.length - 1, prev + 1));
719
+ }, [examples.length]);
720
+ return /*#__PURE__*/_jsx(ExampleScreen, {
721
+ children: /*#__PURE__*/_jsxs(VStack, {
722
+ gap: 4,
723
+ children: [/*#__PURE__*/_jsxs(HStack, {
724
+ alignItems: "center",
725
+ justifyContent: "space-between",
726
+ paddingY: 2,
727
+ children: [/*#__PURE__*/_jsx(IconButton, {
728
+ accessibilityHint: "Navigate to previous example",
729
+ accessibilityLabel: "Previous",
730
+ disabled: isFirstExample,
731
+ name: "arrowLeft",
732
+ onPress: handlePrevious,
733
+ variant: "secondary"
734
+ }), /*#__PURE__*/_jsxs(VStack, {
735
+ alignItems: "center",
736
+ gap: 1,
737
+ children: [/*#__PURE__*/_jsx(Text, {
738
+ font: "title3",
739
+ children: currentExample.title
740
+ }), /*#__PURE__*/_jsxs(Text, {
741
+ color: "fgMuted",
742
+ font: "label1",
743
+ children: [currentIndex + 1, " / ", examples.length]
744
+ })]
745
+ }), /*#__PURE__*/_jsx(IconButton, {
746
+ accessibilityHint: "Navigate to next example",
747
+ accessibilityLabel: "Next",
748
+ disabled: isLastExample,
749
+ name: "arrowRight",
750
+ onPress: handleNext,
751
+ variant: "secondary"
752
+ })]
753
+ }), /*#__PURE__*/_jsx(Box, {
754
+ padding: 1,
755
+ children: currentExample.component
756
+ })]
757
+ })
758
+ });
759
+ };
760
+ export default ExampleNavigator;