react-native-wagmi-charts 2.9.0 → 2.10.0

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 (218) hide show
  1. package/README.md +143 -66
  2. package/lib/commonjs/charts/candle/Candle.js +92 -177
  3. package/lib/commonjs/charts/candle/Candles.js +39 -66
  4. package/lib/commonjs/charts/candle/Chart.js +26 -37
  5. package/lib/commonjs/charts/candle/Context.js +49 -69
  6. package/lib/commonjs/charts/candle/Crosshair.js +82 -183
  7. package/lib/commonjs/charts/candle/Crosshair.js.map +1 -1
  8. package/lib/commonjs/charts/candle/CrosshairTooltip.js +61 -140
  9. package/lib/commonjs/charts/candle/DatetimeText.js +14 -19
  10. package/lib/commonjs/charts/candle/Line.js +27 -73
  11. package/lib/commonjs/charts/candle/PriceText.js +14 -19
  12. package/lib/commonjs/charts/candle/index.js +64 -67
  13. package/lib/commonjs/charts/candle/types.js +4 -4
  14. package/lib/commonjs/charts/candle/useCandleData.js +12 -9
  15. package/lib/commonjs/charts/candle/useCandlestickChart.js +7 -9
  16. package/lib/commonjs/charts/candle/useDatetime.js +18 -16
  17. package/lib/commonjs/charts/candle/usePrice.js +22 -21
  18. package/lib/commonjs/charts/candle/utils/getDomain.js +9 -5
  19. package/lib/commonjs/charts/candle/utils/getDomain.js.map +1 -1
  20. package/lib/commonjs/charts/candle/utils/getHeight.js +11 -12
  21. package/lib/commonjs/charts/candle/utils/getHeight.js.map +1 -1
  22. package/lib/commonjs/charts/candle/utils/getPrice.js +11 -12
  23. package/lib/commonjs/charts/candle/utils/getPrice.js.map +1 -1
  24. package/lib/commonjs/charts/candle/utils/getY.js +11 -12
  25. package/lib/commonjs/charts/candle/utils/getY.js.map +1 -1
  26. package/lib/commonjs/charts/candle/utils/index.js +16 -16
  27. package/lib/commonjs/charts/line/Axis.js +148 -268
  28. package/lib/commonjs/charts/line/Chart.js +62 -129
  29. package/lib/commonjs/charts/line/Chart.js.map +1 -1
  30. package/lib/commonjs/charts/line/ChartPath.js +105 -285
  31. package/lib/commonjs/charts/line/Context.js +37 -95
  32. package/lib/commonjs/charts/line/Cursor.js +74 -125
  33. package/lib/commonjs/charts/line/Cursor.js.map +1 -1
  34. package/lib/commonjs/charts/line/CursorCrosshair.js +56 -134
  35. package/lib/commonjs/charts/line/CursorCrosshair.js.map +1 -1
  36. package/lib/commonjs/charts/line/CursorLine.js +67 -152
  37. package/lib/commonjs/charts/line/CursorLine.js.map +1 -1
  38. package/lib/commonjs/charts/line/Data.js +34 -73
  39. package/lib/commonjs/charts/line/DatetimeText.js +15 -20
  40. package/lib/commonjs/charts/line/Dot.js +56 -149
  41. package/lib/commonjs/charts/line/Gradient.js +53 -124
  42. package/lib/commonjs/charts/line/Group.js +23 -54
  43. package/lib/commonjs/charts/line/Group.js.map +1 -1
  44. package/lib/commonjs/charts/line/Highlight.js +47 -115
  45. package/lib/commonjs/charts/line/HorizontalLine.js +39 -92
  46. package/lib/commonjs/charts/line/HoverTrap/index.js +7 -10
  47. package/lib/commonjs/charts/line/HoverTrap/index.web.js +43 -48
  48. package/lib/commonjs/charts/line/LineChartPathContext.js +11 -14
  49. package/lib/commonjs/charts/line/Path.js +32 -78
  50. package/lib/commonjs/charts/line/PriceText.js +36 -78
  51. package/lib/commonjs/charts/line/Tooltip.js +102 -188
  52. package/lib/commonjs/charts/line/Tooltip.js.map +1 -1
  53. package/lib/commonjs/charts/line/index.js +65 -65
  54. package/lib/commonjs/charts/line/types.js +4 -4
  55. package/lib/commonjs/charts/line/useAnimatedPath.js +22 -27
  56. package/lib/commonjs/charts/line/useCurrentY.js +17 -17
  57. package/lib/commonjs/charts/line/useDatetime.js +28 -32
  58. package/lib/commonjs/charts/line/useLineChart.js +15 -20
  59. package/lib/commonjs/charts/line/usePrice.js +26 -28
  60. package/lib/commonjs/charts/line/utils/getArea.js +14 -47
  61. package/lib/commonjs/charts/line/utils/getDomain.js +8 -5
  62. package/lib/commonjs/charts/line/utils/getDomain.js.map +1 -1
  63. package/lib/commonjs/charts/line/utils/getPath.js +14 -53
  64. package/lib/commonjs/charts/line/utils/getXPositionForCurve.js +5 -8
  65. package/lib/commonjs/charts/line/utils/index.js +19 -19
  66. package/lib/commonjs/charts/line/utils/interpolatePath.js +60 -100
  67. package/lib/commonjs/charts/line/utils/lineChartDataPropToArray.js +5 -5
  68. package/lib/commonjs/components/AnimatedText.js +29 -67
  69. package/lib/commonjs/index.js +19 -19
  70. package/lib/commonjs/types.js +2 -2
  71. package/lib/commonjs/utils/formatDatetime.js +9 -5
  72. package/lib/commonjs/utils/formatPrice.js +6 -10
  73. package/lib/commonjs/utils/index.js +13 -13
  74. package/lib/commonjs/utils/usePrevious.js +6 -8
  75. package/lib/module/charts/candle/Candle.js +76 -126
  76. package/lib/module/charts/candle/Candles.js +30 -52
  77. package/lib/module/charts/candle/Chart.js +19 -22
  78. package/lib/module/charts/candle/Context.js +29 -47
  79. package/lib/module/charts/candle/Crosshair.js +69 -142
  80. package/lib/module/charts/candle/Crosshair.js.map +1 -1
  81. package/lib/module/charts/candle/CrosshairTooltip.js +51 -101
  82. package/lib/module/charts/candle/DatetimeText.js +5 -5
  83. package/lib/module/charts/candle/Line.js +19 -37
  84. package/lib/module/charts/candle/PriceText.js +5 -5
  85. package/lib/module/charts/candle/index.js +2 -2
  86. package/lib/module/charts/candle/types.js +1 -1
  87. package/lib/module/charts/candle/useCandleData.js +7 -3
  88. package/lib/module/charts/candle/useCandlestickChart.js +1 -1
  89. package/lib/module/charts/candle/useDatetime.js +12 -10
  90. package/lib/module/charts/candle/usePrice.js +14 -12
  91. package/lib/module/charts/candle/utils/getDomain.js +6 -2
  92. package/lib/module/charts/candle/utils/getDomain.js.map +1 -1
  93. package/lib/module/charts/candle/utils/getHeight.js +8 -9
  94. package/lib/module/charts/candle/utils/getHeight.js.map +1 -1
  95. package/lib/module/charts/candle/utils/getPrice.js +8 -4
  96. package/lib/module/charts/candle/utils/getPrice.js.map +1 -1
  97. package/lib/module/charts/candle/utils/getY.js +8 -4
  98. package/lib/module/charts/candle/utils/getY.js.map +1 -1
  99. package/lib/module/charts/candle/utils/index.js +1 -1
  100. package/lib/module/charts/line/Axis.js +113 -189
  101. package/lib/module/charts/line/Chart.js +40 -73
  102. package/lib/module/charts/line/Chart.js.map +1 -1
  103. package/lib/module/charts/line/ChartPath.js +90 -238
  104. package/lib/module/charts/line/Context.js +29 -61
  105. package/lib/module/charts/line/Cursor.js +61 -82
  106. package/lib/module/charts/line/Cursor.js.map +1 -1
  107. package/lib/module/charts/line/CursorCrosshair.js +47 -99
  108. package/lib/module/charts/line/CursorCrosshair.js.map +1 -1
  109. package/lib/module/charts/line/CursorLine.js +52 -107
  110. package/lib/module/charts/line/CursorLine.js.map +1 -1
  111. package/lib/module/charts/line/Data.js +28 -41
  112. package/lib/module/charts/line/DatetimeText.js +5 -5
  113. package/lib/module/charts/line/Dot.js +39 -93
  114. package/lib/module/charts/line/Gradient.js +41 -79
  115. package/lib/module/charts/line/Group.js +14 -15
  116. package/lib/module/charts/line/Group.js.map +1 -1
  117. package/lib/module/charts/line/Highlight.js +32 -61
  118. package/lib/module/charts/line/HorizontalLine.js +27 -49
  119. package/lib/module/charts/line/HoverTrap/index.js +2 -3
  120. package/lib/module/charts/line/HoverTrap/index.web.js +34 -34
  121. package/lib/module/charts/line/LineChartPathContext.js +3 -3
  122. package/lib/module/charts/line/Path.js +20 -33
  123. package/lib/module/charts/line/PriceText.js +25 -42
  124. package/lib/module/charts/line/Tooltip.js +89 -151
  125. package/lib/module/charts/line/Tooltip.js.map +1 -1
  126. package/lib/module/charts/line/index.js +2 -2
  127. package/lib/module/charts/line/types.js +1 -1
  128. package/lib/module/charts/line/useAnimatedPath.js +16 -22
  129. package/lib/module/charts/line/useCurrentY.js +9 -4
  130. package/lib/module/charts/line/useDatetime.js +22 -26
  131. package/lib/module/charts/line/useLineChart.js +7 -10
  132. package/lib/module/charts/line/usePrice.js +20 -22
  133. package/lib/module/charts/line/utils/getArea.js +8 -15
  134. package/lib/module/charts/line/utils/getDomain.js +5 -2
  135. package/lib/module/charts/line/utils/getDomain.js.map +1 -1
  136. package/lib/module/charts/line/utils/getPath.js +8 -21
  137. package/lib/module/charts/line/utils/getXPositionForCurve.js +2 -5
  138. package/lib/module/charts/line/utils/index.js +1 -1
  139. package/lib/module/charts/line/utils/interpolatePath.js +57 -97
  140. package/lib/module/charts/line/utils/lineChartDataPropToArray.js +2 -2
  141. package/lib/module/components/AnimatedText.js +21 -25
  142. package/lib/module/index.js +1 -1
  143. package/lib/module/types.js +2 -1
  144. package/lib/module/utils/formatDatetime.js +6 -2
  145. package/lib/module/utils/formatPrice.js +3 -7
  146. package/lib/module/utils/index.js +1 -1
  147. package/lib/module/utils/usePrevious.js +1 -1
  148. package/lib/typescript/src/charts/candle/Candle.d.ts +31 -45
  149. package/lib/typescript/src/charts/candle/Candles.d.ts +13 -24
  150. package/lib/typescript/src/charts/candle/Chart.d.ts +7 -12
  151. package/lib/typescript/src/charts/candle/Context.d.ts +7 -12
  152. package/lib/typescript/src/charts/candle/Crosshair.d.ts +9 -17
  153. package/lib/typescript/src/charts/candle/CrosshairTooltip.d.ts +8 -15
  154. package/lib/typescript/src/charts/candle/DatetimeText.d.ts +9 -15
  155. package/lib/typescript/src/charts/candle/Line.d.ts +5 -10
  156. package/lib/typescript/src/charts/candle/PriceText.d.ts +7 -13
  157. package/lib/typescript/src/charts/candle/index.d.ts +13 -32
  158. package/lib/typescript/src/charts/candle/types.d.ts +16 -16
  159. package/lib/typescript/src/charts/candle/useCandleData.d.ts +1 -1
  160. package/lib/typescript/src/charts/candle/useCandlestickChart.d.ts +1 -1
  161. package/lib/typescript/src/charts/candle/useDatetime.d.ts +9 -13
  162. package/lib/typescript/src/charts/candle/usePrice.d.ts +7 -11
  163. package/lib/typescript/src/charts/candle/utils/getDomain.d.ts +1 -1
  164. package/lib/typescript/src/charts/candle/utils/getDomain.d.ts.map +1 -1
  165. package/lib/typescript/src/charts/candle/utils/getHeight.d.ts +5 -9
  166. package/lib/typescript/src/charts/candle/utils/getPrice.d.ts +5 -9
  167. package/lib/typescript/src/charts/candle/utils/getY.d.ts +5 -9
  168. package/lib/typescript/src/charts/candle/utils/index.d.ts +1 -1
  169. package/lib/typescript/src/charts/line/Axis.d.ts +14 -27
  170. package/lib/typescript/src/charts/line/Chart.d.ts +23 -33
  171. package/lib/typescript/src/charts/line/Chart.d.ts.map +1 -1
  172. package/lib/typescript/src/charts/line/ChartPath.d.ts +15 -28
  173. package/lib/typescript/src/charts/line/Context.d.ts +9 -16
  174. package/lib/typescript/src/charts/line/Cursor.d.ts +14 -22
  175. package/lib/typescript/src/charts/line/Cursor.d.ts.map +1 -1
  176. package/lib/typescript/src/charts/line/CursorCrosshair.d.ts +11 -23
  177. package/lib/typescript/src/charts/line/CursorCrosshair.d.ts.map +1 -1
  178. package/lib/typescript/src/charts/line/CursorLine.d.ts +9 -15
  179. package/lib/typescript/src/charts/line/CursorLine.d.ts.map +1 -1
  180. package/lib/typescript/src/charts/line/Data.d.ts +13 -17
  181. package/lib/typescript/src/charts/line/DatetimeText.d.ts +8 -14
  182. package/lib/typescript/src/charts/line/Dot.d.ts +25 -38
  183. package/lib/typescript/src/charts/line/Gradient.d.ts +5 -9
  184. package/lib/typescript/src/charts/line/Group.d.ts +3 -6
  185. package/lib/typescript/src/charts/line/Group.d.ts.map +1 -1
  186. package/lib/typescript/src/charts/line/Highlight.d.ts +9 -17
  187. package/lib/typescript/src/charts/line/HorizontalLine.d.ts +22 -30
  188. package/lib/typescript/src/charts/line/HoverTrap/index.d.ts +1 -1
  189. package/lib/typescript/src/charts/line/HoverTrap/index.web.d.ts +1 -1
  190. package/lib/typescript/src/charts/line/LineChartPathContext.d.ts +4 -4
  191. package/lib/typescript/src/charts/line/Path.d.ts +23 -28
  192. package/lib/typescript/src/charts/line/PriceText.d.ts +20 -28
  193. package/lib/typescript/src/charts/line/Tooltip.d.ts +20 -32
  194. package/lib/typescript/src/charts/line/index.d.ts +20 -33
  195. package/lib/typescript/src/charts/line/types.d.ts +17 -19
  196. package/lib/typescript/src/charts/line/useAnimatedPath.d.ts +7 -10
  197. package/lib/typescript/src/charts/line/useCurrentY.d.ts +2 -2
  198. package/lib/typescript/src/charts/line/useDatetime.d.ts +7 -11
  199. package/lib/typescript/src/charts/line/useLineChart.d.ts +10 -10
  200. package/lib/typescript/src/charts/line/usePrice.d.ts +7 -11
  201. package/lib/typescript/src/charts/line/utils/getArea.d.ts +9 -17
  202. package/lib/typescript/src/charts/line/utils/getDomain.d.ts +1 -1
  203. package/lib/typescript/src/charts/line/utils/getDomain.d.ts.map +1 -1
  204. package/lib/typescript/src/charts/line/utils/getPath.d.ts +11 -21
  205. package/lib/typescript/src/charts/line/utils/getXPositionForCurve.d.ts +1 -1
  206. package/lib/typescript/src/charts/line/utils/index.d.ts +1 -1
  207. package/lib/typescript/src/charts/line/utils/interpolatePath.d.ts +5 -17
  208. package/lib/typescript/src/charts/line/utils/lineChartDataPropToArray.d.ts +2 -4
  209. package/lib/typescript/src/components/AnimatedText.d.ts +4 -7
  210. package/lib/typescript/src/index.d.ts +1 -1
  211. package/lib/typescript/src/types.d.ts +4 -7
  212. package/lib/typescript/src/utils/formatDatetime.d.ts +5 -9
  213. package/lib/typescript/src/utils/formatPrice.d.ts +5 -9
  214. package/lib/typescript/src/utils/index.d.ts +1 -1
  215. package/lib/typescript/src/utils/usePrevious.d.ts +1 -1
  216. package/package.json +1 -1
  217. package/src/charts/line/CursorLine.tsx +6 -2
  218. package/src/charts/line/HorizontalLine.tsx +5 -1
@@ -1,37 +1,14 @@
1
- function _extends() {
2
- return (
3
- (_extends = Object.assign
4
- ? Object.assign.bind()
5
- : function (n) {
6
- for (var e = 1; e < arguments.length; e++) {
7
- var t = arguments[e];
8
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
9
- }
10
- return n;
11
- }),
12
- _extends.apply(null, arguments)
13
- );
14
- }
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); }
15
2
  import React from 'react';
16
3
  import { StyleSheet, View, Platform } from 'react-native';
17
4
  import { Svg, Defs, ClipPath, Rect, G } from 'react-native-svg';
18
- import Animated, {
19
- useAnimatedProps,
20
- useSharedValue,
21
- withTiming,
22
- } from 'react-native-reanimated';
5
+ import Animated, { useAnimatedProps, useSharedValue, withTiming } from 'react-native-reanimated';
23
6
  import flattenChildren from 'react-keyed-flatten-children';
24
7
  import { LineChartDimensionsContext } from './Chart';
25
8
  import { LineChartPathContext } from './LineChartPathContext';
26
9
  import { LineChartPath } from './Path';
27
10
  import { useLineChart } from './useLineChart';
28
- const BACKGROUND_COMPONENTS = [
29
- 'LineChartHighlight',
30
- 'LineChartHorizontalLine',
31
- 'LineChartGradient',
32
- 'LineChartDot',
33
- 'LineChartTooltip',
34
- ];
11
+ const BACKGROUND_COMPONENTS = ['LineChartHighlight', 'LineChartHorizontalLine', 'LineChartGradient', 'LineChartDot', 'LineChartTooltip'];
35
12
  const FOREGROUND_COMPONENTS = ['LineChartHighlight', 'LineChartDot'];
36
13
  const AnimatedSVG = Animated.createAnimatedComponent(Svg);
37
14
  const AnimatedRect = Animated.createAnimatedComponent(Rect);
@@ -48,12 +25,17 @@ export function LineChartPathWrapper({
48
25
  showInactivePath = true,
49
26
  animateOnMount,
50
27
  mountAnimationDuration = animationDuration,
51
- mountAnimationProps = animationProps,
28
+ mountAnimationProps = animationProps
52
29
  }) {
53
- const { height, pathWidth, width } = React.useContext(
54
- LineChartDimensionsContext
55
- );
56
- const { currentX, isActive } = useLineChart();
30
+ const {
31
+ height,
32
+ pathWidth,
33
+ width
34
+ } = React.useContext(LineChartDimensionsContext);
35
+ const {
36
+ currentX,
37
+ isActive
38
+ } = useLineChart();
57
39
  const isMounted = useSharedValue(false);
58
40
  const hasMountedAnimation = useSharedValue(false);
59
41
  React.useEffect(() => {
@@ -65,63 +47,30 @@ export function LineChartPathWrapper({
65
47
 
66
48
  ////////////////////////////////////////////////
67
49
 
68
- const clipId = React.useMemo(
69
- () => `clip-foreground-${Math.random().toString(36).substring(2, 11)}`,
70
- []
71
- );
50
+ const clipId = React.useMemo(() => `clip-foreground-${Math.random().toString(36).substring(2, 11)}`, []);
72
51
  const clipProps = useAnimatedProps(() => {
73
52
  const shouldAnimateOnMount = animateOnMount === 'foreground';
74
- const inactiveWidth =
75
- !isMounted.value && shouldAnimateOnMount ? 0 : pathWidth;
76
- let duration =
77
- shouldAnimateOnMount && !hasMountedAnimation.value
78
- ? mountAnimationDuration
79
- : animationDuration;
80
- const props =
81
- shouldAnimateOnMount && !hasMountedAnimation.value
82
- ? mountAnimationProps
83
- : animationProps;
53
+ const inactiveWidth = !isMounted.value && shouldAnimateOnMount ? 0 : pathWidth;
54
+ let duration = shouldAnimateOnMount && !hasMountedAnimation.value ? mountAnimationDuration : animationDuration;
55
+ const props = shouldAnimateOnMount && !hasMountedAnimation.value ? mountAnimationProps : animationProps;
84
56
  if (isActive.value) {
85
57
  duration = 0;
86
58
  }
87
59
  return {
88
- width: withTiming(
89
- isActive.value
90
- ? // on Web, <svg /> elements don't support negative widths
91
- // https://github.com/coinjar/react-native-wagmi-charts/issues/24#issuecomment-955789904
92
- Math.max(currentX.value, 0)
93
- : inactiveWidth + widthOffset,
94
- Object.assign(
95
- {
96
- duration,
97
- },
98
- props
99
- ),
100
- () => {
101
- hasMountedAnimation.value = true;
102
- }
103
- ),
60
+ width: withTiming(isActive.value ?
61
+ // on Web, <svg /> elements don't support negative widths
62
+ // https://github.com/coinjar/react-native-wagmi-charts/issues/24#issuecomment-955789904
63
+ Math.max(currentX.value, 0) : inactiveWidth + widthOffset, Object.assign({
64
+ duration
65
+ }, props), () => {
66
+ hasMountedAnimation.value = true;
67
+ })
104
68
  };
105
- }, [
106
- animateOnMount,
107
- animationDuration,
108
- animationProps,
109
- currentX,
110
- hasMountedAnimation,
111
- isActive,
112
- isMounted,
113
- mountAnimationDuration,
114
- mountAnimationProps,
115
- pathWidth,
116
- widthOffset,
117
- ]);
118
- const viewSize = React.useMemo(
119
- () => ({
120
- width,
121
- height,
122
- }),
123
- [width, height]
124
- );
69
+ }, [animateOnMount, animationDuration, animationProps, currentX, hasMountedAnimation, isActive, isMounted, mountAnimationDuration, mountAnimationProps, pathWidth, widthOffset]);
70
+ const viewSize = React.useMemo(() => ({
71
+ width,
72
+ height
73
+ }), [width, height]);
125
74
 
126
75
  ////////////////////////////////////////////////
127
76
 
@@ -129,165 +78,68 @@ export function LineChartPathWrapper({
129
78
  let foregroundChildren;
130
79
  if (children) {
131
80
  const iterableChildren = flattenChildren(children);
132
- backgroundChildren = iterableChildren.filter((child) =>
133
- BACKGROUND_COMPONENTS.includes(child?.type?.displayName || '')
134
- );
135
- foregroundChildren = iterableChildren.filter((child) =>
136
- FOREGROUND_COMPONENTS.includes(child?.type?.displayName || '')
137
- );
81
+ backgroundChildren = iterableChildren.filter(child => BACKGROUND_COMPONENTS.includes(child?.type?.displayName || ''));
82
+ foregroundChildren = iterableChildren.filter(child => FOREGROUND_COMPONENTS.includes(child?.type?.displayName || ''));
138
83
  }
139
84
 
140
85
  ////////////////////////////////////////////////
141
86
 
142
- return /*#__PURE__*/ React.createElement(
143
- React.Fragment,
144
- null,
145
- /*#__PURE__*/ React.createElement(
146
- LineChartPathContext.Provider,
147
- {
148
- value: {
149
- color,
150
- isInactive: showInactivePath,
151
- isTransitionEnabled: pathProps.isTransitionEnabled ?? true,
152
- },
153
- },
154
- /*#__PURE__*/ React.createElement(
155
- View,
156
- {
157
- style: viewSize,
158
- },
159
- /*#__PURE__*/ React.createElement(
160
- Svg,
161
- {
162
- width: width,
163
- height: height,
164
- },
165
- /*#__PURE__*/ React.createElement(
166
- LineChartPath,
167
- _extends(
168
- {
169
- color: color,
170
- inactiveColor: inactiveColor,
171
- width: strokeWidth,
172
- },
173
- pathProps
174
- )
175
- )
176
- ),
177
- /*#__PURE__*/ React.createElement(
178
- Svg,
179
- {
180
- style: StyleSheet.absoluteFill,
181
- },
182
- backgroundChildren
183
- )
184
- )
185
- ),
186
- /*#__PURE__*/ React.createElement(
187
- LineChartPathContext.Provider,
188
- {
189
- value: {
190
- color,
191
- isInactive: false,
192
- isTransitionEnabled: pathProps.isTransitionEnabled ?? true,
193
- },
194
- },
195
- /*#__PURE__*/ React.createElement(
196
- View,
197
- {
198
- style: StyleSheet.absoluteFill,
199
- },
200
- Platform.OS === 'web'
201
- ? /*#__PURE__*/ React.createElement(
202
- React.Fragment,
203
- null,
204
- /*#__PURE__*/ React.createElement(
205
- Svg,
206
- {
207
- width: width,
208
- height: height,
209
- },
210
- /*#__PURE__*/ React.createElement(
211
- Defs,
212
- null,
213
- /*#__PURE__*/ React.createElement(
214
- ClipPath,
215
- {
216
- id: clipId,
217
- },
218
- /*#__PURE__*/ React.createElement(AnimatedRect, {
219
- x: 0,
220
- y: 0,
221
- animatedProps: clipProps,
222
- height: height,
223
- })
224
- )
225
- ),
226
- /*#__PURE__*/ React.createElement(
227
- G,
228
- {
229
- clipPath: `url(#${clipId})`,
230
- },
231
- /*#__PURE__*/ React.createElement(
232
- LineChartPath,
233
- _extends(
234
- {
235
- color: color,
236
- width: strokeWidth,
237
- },
238
- pathProps
239
- )
240
- )
241
- )
242
- ),
243
- /*#__PURE__*/ React.createElement(
244
- Svg,
245
- {
246
- width: width,
247
- height: height,
248
- style: StyleSheet.absoluteFill,
249
- },
250
- /*#__PURE__*/ React.createElement(
251
- G,
252
- {
253
- clipPath: `url(#${clipId})`,
254
- },
255
- foregroundChildren
256
- )
257
- )
258
- )
259
- : /*#__PURE__*/ React.createElement(
260
- React.Fragment,
261
- null,
262
- /*#__PURE__*/ React.createElement(
263
- AnimatedSVG,
264
- {
265
- animatedProps: clipProps,
266
- height: height,
267
- },
268
- /*#__PURE__*/ React.createElement(
269
- LineChartPath,
270
- _extends(
271
- {
272
- color: color,
273
- width: strokeWidth,
274
- },
275
- pathProps
276
- )
277
- )
278
- ),
279
- /*#__PURE__*/ React.createElement(
280
- AnimatedSVG,
281
- {
282
- animatedProps: clipProps,
283
- height: height,
284
- style: StyleSheet.absoluteFill,
285
- },
286
- foregroundChildren
287
- )
288
- )
289
- )
290
- )
291
- );
87
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(LineChartPathContext.Provider, {
88
+ value: {
89
+ color,
90
+ isInactive: showInactivePath,
91
+ isTransitionEnabled: pathProps.isTransitionEnabled ?? true
92
+ }
93
+ }, /*#__PURE__*/React.createElement(View, {
94
+ style: viewSize
95
+ }, /*#__PURE__*/React.createElement(Svg, {
96
+ width: width,
97
+ height: height
98
+ }, /*#__PURE__*/React.createElement(LineChartPath, _extends({
99
+ color: color,
100
+ inactiveColor: inactiveColor,
101
+ width: strokeWidth
102
+ }, pathProps))), /*#__PURE__*/React.createElement(Svg, {
103
+ style: StyleSheet.absoluteFill
104
+ }, backgroundChildren))), /*#__PURE__*/React.createElement(LineChartPathContext.Provider, {
105
+ value: {
106
+ color,
107
+ isInactive: false,
108
+ isTransitionEnabled: pathProps.isTransitionEnabled ?? true
109
+ }
110
+ }, /*#__PURE__*/React.createElement(View, {
111
+ style: StyleSheet.absoluteFill
112
+ }, Platform.OS === 'web' ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Svg, {
113
+ width: width,
114
+ height: height
115
+ }, /*#__PURE__*/React.createElement(Defs, null, /*#__PURE__*/React.createElement(ClipPath, {
116
+ id: clipId
117
+ }, /*#__PURE__*/React.createElement(AnimatedRect, {
118
+ x: 0,
119
+ y: 0,
120
+ animatedProps: clipProps,
121
+ height: height
122
+ }))), /*#__PURE__*/React.createElement(G, {
123
+ clipPath: `url(#${clipId})`
124
+ }, /*#__PURE__*/React.createElement(LineChartPath, _extends({
125
+ color: color,
126
+ width: strokeWidth
127
+ }, pathProps)))), /*#__PURE__*/React.createElement(Svg, {
128
+ width: width,
129
+ height: height,
130
+ style: StyleSheet.absoluteFill
131
+ }, /*#__PURE__*/React.createElement(G, {
132
+ clipPath: `url(#${clipId})`
133
+ }, foregroundChildren))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(AnimatedSVG, {
134
+ animatedProps: clipProps,
135
+ height: height
136
+ }, /*#__PURE__*/React.createElement(LineChartPath, _extends({
137
+ color: color,
138
+ width: strokeWidth
139
+ }, pathProps))), /*#__PURE__*/React.createElement(AnimatedSVG, {
140
+ animatedProps: clipProps,
141
+ height: height,
142
+ style: StyleSheet.absoluteFill
143
+ }, foregroundChildren)))));
292
144
  }
293
- //# sourceMappingURL=ChartPath.js.map
145
+ //# sourceMappingURL=ChartPath.js.map
@@ -1,28 +1,24 @@
1
1
  import React, { createContext, useMemo } from 'react';
2
- import {
3
- runOnJS,
4
- useAnimatedReaction,
5
- useSharedValue,
6
- } from 'react-native-reanimated';
2
+ import { runOnJS, useAnimatedReaction, useSharedValue } from 'react-native-reanimated';
7
3
  import { LineChartDataProvider } from './Data';
8
4
  import { getDomain, lineChartDataPropToArray } from './utils';
9
- export const LineChartContext = /*#__PURE__*/ createContext({
5
+ export const LineChartContext = /*#__PURE__*/createContext({
10
6
  currentX: {
11
- value: -1,
7
+ value: -1
12
8
  },
13
9
  currentIndex: {
14
- value: -1,
10
+ value: -1
15
11
  },
16
12
  domain: [0, 0],
17
13
  isActive: {
18
- value: false,
14
+ value: false
19
15
  },
20
16
  yDomain: {
21
17
  min: 0,
22
- max: 0,
18
+ max: 0
23
19
  },
24
20
  xDomain: undefined,
25
- xLength: 0,
21
+ xLength: 0
26
22
  });
27
23
  export function LineChartProvider({
28
24
  children,
@@ -30,26 +26,19 @@ export function LineChartProvider({
30
26
  yRange,
31
27
  onCurrentIndexChange,
32
28
  xLength,
33
- xDomain,
29
+ xDomain
34
30
  }) {
35
31
  const currentX = useSharedValue(-1);
36
32
  const currentIndex = useSharedValue(-1);
37
33
  const isActive = useSharedValue(false);
38
- const domain = useMemo(
39
- () => getDomain(Array.isArray(data) ? data : Object.values(data)[0]),
40
- [data]
41
- );
42
- const values = useMemo(
43
- () => lineChartDataPropToArray(data).map(({ value }) => value),
44
- [data]
45
- );
46
- const yDomainValues = useMemo(
47
- () => ({
48
- min: yRange?.min ?? Math.min(...values),
49
- max: yRange?.max ?? Math.max(...values),
50
- }),
51
- [values, yRange?.min, yRange?.max]
52
- );
34
+ const domain = useMemo(() => getDomain(Array.isArray(data) ? data : Object.values(data)[0]), [data]);
35
+ const values = useMemo(() => lineChartDataPropToArray(data).map(({
36
+ value
37
+ }) => value), [data]);
38
+ const yDomainValues = useMemo(() => ({
39
+ min: yRange?.min ?? Math.min(...values),
40
+ max: yRange?.max ?? Math.max(...values)
41
+ }), [values, yRange?.min, yRange?.max]);
53
42
  const contextValue = useMemo(() => {
54
43
  const domainRows = Array.isArray(data) ? data : Object.values(data)[0];
55
44
  return {
@@ -59,40 +48,19 @@ export function LineChartProvider({
59
48
  domain,
60
49
  yDomain: yDomainValues,
61
50
  xDomain,
62
- xLength: xLength ?? domainRows.length,
51
+ xLength: xLength ?? domainRows.length
63
52
  };
64
- }, [
65
- currentIndex,
66
- currentX,
67
- data,
68
- domain,
69
- isActive,
70
- yDomainValues,
71
- xLength,
72
- xDomain,
73
- ]);
74
- useAnimatedReaction(
75
- () => currentIndex.value,
76
- (x, prevX) => {
77
- if (x !== prevX && onCurrentIndexChange) {
78
- runOnJS(onCurrentIndexChange)(x);
79
- }
80
- },
81
- [currentIndex]
82
- );
83
- return /*#__PURE__*/ React.createElement(
84
- LineChartDataProvider,
85
- {
86
- data: data,
87
- },
88
- /*#__PURE__*/ React.createElement(
89
- LineChartContext.Provider,
90
- {
91
- value: contextValue,
92
- },
93
- children
94
- )
95
- );
53
+ }, [currentIndex, currentX, data, domain, isActive, yDomainValues, xLength, xDomain]);
54
+ useAnimatedReaction(() => currentIndex.value, (x, prevX) => {
55
+ if (x !== prevX && onCurrentIndexChange) {
56
+ runOnJS(onCurrentIndexChange)(x);
57
+ }
58
+ }, [currentIndex]);
59
+ return /*#__PURE__*/React.createElement(LineChartDataProvider, {
60
+ data: data
61
+ }, /*#__PURE__*/React.createElement(LineChartContext.Provider, {
62
+ value: contextValue
63
+ }, children));
96
64
  }
97
65
  LineChartProvider.displayName = 'LineChartProvider';
98
- //# sourceMappingURL=Context.js.map
66
+ //# sourceMappingURL=Context.js.map