react-native-wagmi-charts 1.8.0 → 2.0.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 (213) hide show
  1. package/.DS_Store +0 -0
  2. package/README.md +331 -196
  3. package/example/.DS_Store +0 -0
  4. package/example/src/LineChart.tsx +10 -4
  5. package/example/src/data/line-data.json +20 -20
  6. package/lib/commonjs/charts/candle/utils/getDomain.js +19 -0
  7. package/lib/commonjs/charts/candle/utils/getDomain.js.map +1 -0
  8. package/lib/commonjs/charts/candle/utils/getHeight.js +19 -0
  9. package/lib/commonjs/charts/candle/utils/getHeight.js.map +1 -0
  10. package/lib/commonjs/charts/candle/utils/getPrice.js +20 -0
  11. package/lib/commonjs/charts/candle/utils/getPrice.js.map +1 -0
  12. package/lib/commonjs/charts/candle/utils/getY.js +19 -0
  13. package/lib/commonjs/charts/candle/utils/getY.js.map +1 -0
  14. package/lib/commonjs/charts/candle/utils/index.js +58 -0
  15. package/lib/commonjs/charts/candle/utils/index.js.map +1 -0
  16. package/lib/commonjs/charts/line/Chart.js +9 -3
  17. package/lib/commonjs/charts/line/Chart.js.map +1 -1
  18. package/lib/commonjs/charts/line/ChartPath.js +73 -17
  19. package/lib/commonjs/charts/line/ChartPath.js.map +1 -1
  20. package/lib/commonjs/charts/line/Context.js +1 -0
  21. package/lib/commonjs/charts/line/Context.js.map +1 -1
  22. package/lib/commonjs/charts/line/Cursor.js +1 -0
  23. package/lib/commonjs/charts/line/Cursor.js.map +1 -1
  24. package/lib/commonjs/charts/line/CursorCrosshair.js +10 -3
  25. package/lib/commonjs/charts/line/CursorCrosshair.js.map +1 -1
  26. package/lib/commonjs/charts/line/CursorLine.js +6 -6
  27. package/lib/commonjs/charts/line/CursorLine.js.map +1 -1
  28. package/lib/commonjs/charts/line/DatetimeText.js +2 -0
  29. package/lib/commonjs/charts/line/DatetimeText.js.map +1 -1
  30. package/lib/commonjs/charts/line/Dot.js +67 -62
  31. package/lib/commonjs/charts/line/Dot.js.map +1 -1
  32. package/lib/commonjs/charts/line/Gradient.js +8 -25
  33. package/lib/commonjs/charts/line/Gradient.js.map +1 -1
  34. package/lib/commonjs/charts/line/Group.js +5 -25
  35. package/lib/commonjs/charts/line/Group.js.map +1 -1
  36. package/lib/commonjs/charts/line/Highlight.js +92 -0
  37. package/lib/commonjs/charts/line/Highlight.js.map +1 -0
  38. package/lib/commonjs/charts/line/HorizontalLine.js +6 -6
  39. package/lib/commonjs/charts/line/HorizontalLine.js.map +1 -1
  40. package/lib/commonjs/charts/line/Path.js +19 -30
  41. package/lib/commonjs/charts/line/Path.js.map +1 -1
  42. package/lib/commonjs/charts/line/PriceText.js +2 -0
  43. package/lib/commonjs/charts/line/PriceText.js.map +1 -1
  44. package/lib/commonjs/charts/line/Tooltip.js +2 -0
  45. package/lib/commonjs/charts/line/Tooltip.js.map +1 -1
  46. package/lib/commonjs/charts/line/index.js +47 -20
  47. package/lib/commonjs/charts/line/index.js.map +1 -1
  48. package/lib/commonjs/charts/line/useAnimatedPath.js +44 -0
  49. package/lib/commonjs/charts/line/useAnimatedPath.js.map +1 -0
  50. package/lib/commonjs/charts/line/{utils.js → utils/getArea.js} +2 -49
  51. package/lib/commonjs/charts/line/utils/getArea.js.map +1 -0
  52. package/lib/commonjs/charts/line/utils/getDomain.js +16 -0
  53. package/lib/commonjs/charts/line/utils/getDomain.js.map +1 -0
  54. package/lib/commonjs/charts/line/utils/getPath.js +34 -0
  55. package/lib/commonjs/charts/line/utils/getPath.js.map +1 -0
  56. package/lib/commonjs/charts/line/utils/index.js +71 -0
  57. package/lib/commonjs/charts/line/utils/index.js.map +1 -0
  58. package/lib/commonjs/charts/line/{interpolatePath.js → utils/interpolatePath.js} +1 -1
  59. package/lib/commonjs/charts/line/{interpolatePath.js.map → utils/interpolatePath.js.map} +1 -1
  60. package/lib/commonjs/charts/line/utils/lineChartDataPropToArray.js +27 -0
  61. package/lib/commonjs/charts/line/utils/lineChartDataPropToArray.js.map +1 -0
  62. package/lib/commonjs/index.js +8 -8
  63. package/lib/commonjs/index.js.map +1 -1
  64. package/lib/commonjs/utils/formatDatetime.js +21 -0
  65. package/lib/commonjs/utils/formatDatetime.js.map +1 -0
  66. package/lib/commonjs/utils/formatPrice.js +46 -0
  67. package/lib/commonjs/utils/formatPrice.js.map +1 -0
  68. package/lib/commonjs/utils/index.js +45 -0
  69. package/lib/commonjs/utils/index.js.map +1 -0
  70. package/lib/commonjs/{utils.js → utils/usePrevious.js} +1 -57
  71. package/lib/commonjs/utils/usePrevious.js.map +1 -0
  72. package/lib/module/charts/candle/utils/getDomain.js +12 -0
  73. package/lib/module/charts/candle/utils/getDomain.js.map +1 -0
  74. package/lib/module/charts/candle/utils/getHeight.js +11 -0
  75. package/lib/module/charts/candle/utils/getHeight.js.map +1 -0
  76. package/lib/module/charts/candle/utils/getPrice.js +12 -0
  77. package/lib/module/charts/candle/utils/getPrice.js.map +1 -0
  78. package/lib/module/charts/candle/utils/getY.js +11 -0
  79. package/lib/module/charts/candle/utils/getY.js.map +1 -0
  80. package/lib/module/charts/candle/utils/index.js +5 -0
  81. package/lib/module/charts/candle/utils/index.js.map +1 -0
  82. package/lib/module/charts/line/Chart.js +9 -4
  83. package/lib/module/charts/line/Chart.js.map +1 -1
  84. package/lib/module/charts/line/ChartPath.js +69 -17
  85. package/lib/module/charts/line/ChartPath.js.map +1 -1
  86. package/lib/module/charts/line/Context.js +1 -0
  87. package/lib/module/charts/line/Context.js.map +1 -1
  88. package/lib/module/charts/line/Cursor.js +1 -0
  89. package/lib/module/charts/line/Cursor.js.map +1 -1
  90. package/lib/module/charts/line/CursorCrosshair.js +10 -4
  91. package/lib/module/charts/line/CursorCrosshair.js.map +1 -1
  92. package/lib/module/charts/line/CursorLine.js +4 -3
  93. package/lib/module/charts/line/CursorLine.js.map +1 -1
  94. package/lib/module/charts/line/DatetimeText.js +1 -0
  95. package/lib/module/charts/line/DatetimeText.js.map +1 -1
  96. package/lib/module/charts/line/Dot.js +66 -63
  97. package/lib/module/charts/line/Dot.js.map +1 -1
  98. package/lib/module/charts/line/Gradient.js +8 -24
  99. package/lib/module/charts/line/Gradient.js.map +1 -1
  100. package/lib/module/charts/line/Group.js +2 -24
  101. package/lib/module/charts/line/Group.js.map +1 -1
  102. package/lib/module/charts/line/Highlight.js +69 -0
  103. package/lib/module/charts/line/Highlight.js.map +1 -0
  104. package/lib/module/charts/line/HorizontalLine.js +4 -3
  105. package/lib/module/charts/line/HorizontalLine.js.map +1 -1
  106. package/lib/module/charts/line/Path.js +17 -29
  107. package/lib/module/charts/line/Path.js.map +1 -1
  108. package/lib/module/charts/line/PriceText.js +1 -0
  109. package/lib/module/charts/line/PriceText.js.map +1 -1
  110. package/lib/module/charts/line/Tooltip.js +1 -0
  111. package/lib/module/charts/line/Tooltip.js.map +1 -1
  112. package/lib/module/charts/line/index.js +12 -8
  113. package/lib/module/charts/line/index.js.map +1 -1
  114. package/lib/module/charts/line/useAnimatedPath.js +34 -0
  115. package/lib/module/charts/line/useAnimatedPath.js.map +1 -0
  116. package/lib/module/charts/line/utils/getArea.js +19 -0
  117. package/lib/module/charts/line/utils/getArea.js.map +1 -0
  118. package/lib/module/charts/line/utils/getDomain.js +9 -0
  119. package/lib/module/charts/line/utils/getDomain.js.map +1 -0
  120. package/lib/module/charts/line/utils/getPath.js +21 -0
  121. package/lib/module/charts/line/utils/getPath.js.map +1 -0
  122. package/lib/module/charts/line/utils/index.js +6 -0
  123. package/lib/module/charts/line/utils/index.js.map +1 -0
  124. package/lib/module/charts/line/{interpolatePath.js → utils/interpolatePath.js} +1 -1
  125. package/lib/module/charts/line/{interpolatePath.js.map → utils/interpolatePath.js.map} +1 -1
  126. package/lib/module/charts/line/utils/lineChartDataPropToArray.js +20 -0
  127. package/lib/module/charts/line/utils/lineChartDataPropToArray.js.map +1 -0
  128. package/lib/module/index.js +1 -1
  129. package/lib/module/index.js.map +1 -1
  130. package/lib/module/utils/formatDatetime.js +14 -0
  131. package/lib/module/utils/formatDatetime.js.map +1 -0
  132. package/lib/module/{utils.js → utils/formatPrice.js} +1 -29
  133. package/lib/module/utils/formatPrice.js.map +1 -0
  134. package/lib/module/utils/index.js +4 -0
  135. package/lib/module/utils/index.js.map +1 -0
  136. package/lib/module/utils/usePrevious.js +14 -0
  137. package/lib/module/utils/usePrevious.js.map +1 -0
  138. package/lib/typescript/src/charts/candle/utils/getDomain.d.ts +2 -0
  139. package/lib/typescript/src/charts/candle/utils/getHeight.d.ts +6 -0
  140. package/lib/typescript/src/charts/candle/utils/getPrice.d.ts +6 -0
  141. package/lib/typescript/src/charts/candle/utils/getY.d.ts +6 -0
  142. package/lib/typescript/src/charts/candle/utils/index.d.ts +4 -0
  143. package/lib/typescript/src/charts/line/Chart.d.ts +5 -1
  144. package/lib/typescript/src/charts/line/ChartPath.d.ts +10 -1
  145. package/lib/typescript/src/charts/line/Context.d.ts +3 -0
  146. package/lib/typescript/src/charts/line/Cursor.d.ts +3 -0
  147. package/lib/typescript/src/charts/line/CursorCrosshair.d.ts +4 -1
  148. package/lib/typescript/src/charts/line/CursorLine.d.ts +4 -1
  149. package/lib/typescript/src/charts/line/DatetimeText.d.ts +3 -0
  150. package/lib/typescript/src/charts/line/Dot.d.ts +10 -7
  151. package/lib/typescript/src/charts/line/Gradient.d.ts +3 -0
  152. package/lib/typescript/src/charts/line/Group.d.ts +1 -2
  153. package/lib/typescript/src/charts/line/Highlight.d.ts +15 -0
  154. package/lib/typescript/src/charts/line/HorizontalLine.d.ts +4 -1
  155. package/lib/typescript/src/charts/line/Path.d.ts +5 -1
  156. package/lib/typescript/src/charts/line/PriceText.d.ts +3 -0
  157. package/lib/typescript/src/charts/line/Tooltip.d.ts +3 -0
  158. package/lib/typescript/src/charts/line/index.d.ts +15 -25
  159. package/lib/typescript/src/charts/line/useAnimatedPath.d.ts +8 -0
  160. package/lib/typescript/src/charts/line/utils/getArea.d.ts +9 -0
  161. package/lib/typescript/src/charts/line/utils/getDomain.d.ts +2 -0
  162. package/lib/typescript/src/charts/line/utils/getPath.d.ts +11 -0
  163. package/lib/typescript/src/charts/line/utils/index.d.ts +5 -0
  164. package/lib/typescript/src/charts/line/{interpolatePath.d.ts → utils/interpolatePath.d.ts} +1 -1
  165. package/lib/typescript/src/charts/line/utils/lineChartDataPropToArray.d.ts +2 -0
  166. package/lib/typescript/src/index.d.ts +1 -1
  167. package/lib/typescript/src/utils/formatDatetime.d.ts +8 -0
  168. package/lib/typescript/src/utils/formatPrice.d.ts +8 -0
  169. package/lib/typescript/src/utils/index.d.ts +3 -0
  170. package/lib/typescript/src/utils/usePrevious.d.ts +1 -0
  171. package/package.json +4 -2
  172. package/src/charts/candle/utils/getDomain.ts +9 -0
  173. package/src/charts/candle/utils/getHeight.ts +21 -0
  174. package/src/charts/candle/utils/getPrice.ts +17 -0
  175. package/src/charts/candle/utils/getY.ts +16 -0
  176. package/src/charts/candle/utils/index.ts +4 -0
  177. package/src/charts/line/Chart.tsx +9 -3
  178. package/src/charts/line/ChartPath.tsx +109 -33
  179. package/src/charts/line/Context.tsx +2 -0
  180. package/src/charts/line/Cursor.tsx +2 -0
  181. package/src/charts/line/CursorCrosshair.tsx +20 -5
  182. package/src/charts/line/CursorLine.tsx +5 -3
  183. package/src/charts/line/DatetimeText.tsx +2 -0
  184. package/src/charts/line/Dot.tsx +83 -86
  185. package/src/charts/line/Gradient.tsx +7 -34
  186. package/src/charts/line/Group.tsx +4 -47
  187. package/src/charts/line/Highlight.tsx +78 -0
  188. package/src/charts/line/HorizontalLine.tsx +5 -3
  189. package/src/charts/line/Path.tsx +14 -38
  190. package/src/charts/line/PriceText.tsx +2 -0
  191. package/src/charts/line/Tooltip.tsx +2 -0
  192. package/src/charts/line/index.ts +11 -7
  193. package/src/charts/line/useAnimatedPath.ts +47 -0
  194. package/src/charts/line/utils/getArea.ts +38 -0
  195. package/src/charts/line/utils/getDomain.ts +7 -0
  196. package/src/charts/line/utils/getPath.ts +48 -0
  197. package/src/charts/line/utils/index.ts +5 -0
  198. package/src/charts/line/{interpolatePath.ts → utils/interpolatePath.ts} +1 -1
  199. package/src/charts/line/utils/lineChartDataPropToArray.ts +25 -0
  200. package/src/index.ts +1 -1
  201. package/src/utils/formatDatetime.ts +16 -0
  202. package/src/{utils.ts → utils/formatPrice.ts} +0 -31
  203. package/src/utils/index.ts +3 -0
  204. package/src/utils/usePrevious.ts +13 -0
  205. package/yarn.lock +8 -1
  206. package/lib/commonjs/charts/line/utils.js.map +0 -1
  207. package/lib/commonjs/utils.js.map +0 -1
  208. package/lib/module/charts/line/utils.js +0 -60
  209. package/lib/module/charts/line/utils.js.map +0 -1
  210. package/lib/module/utils.js.map +0 -1
  211. package/lib/typescript/src/charts/line/utils.d.ts +0 -20
  212. package/lib/typescript/src/utils.d.ts +0 -17
  213. package/src/charts/line/utils.ts +0 -100
@@ -1,21 +1,27 @@
1
1
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import * as React from 'react';
4
- import Animated, { Easing, useAnimatedStyle, useDerivedValue, withRepeat, withSequence, withTiming } from 'react-native-reanimated';
5
- import { View } from 'react-native';
4
+ import Animated, { Easing, useAnimatedProps, useDerivedValue, withRepeat, withSequence, withTiming } from 'react-native-reanimated';
5
+ import { Circle } from 'react-native-svg';
6
6
  import { getYForX, parse } from 'react-native-redash';
7
- import { useMemo } from 'react';
8
7
  import { LineChartDimensionsContext } from './Chart';
8
+ import { LineChartPathContext } from './ChartPath';
9
9
  import { useLineChart } from './useLineChart';
10
+ const AnimatedCircle = Animated.createAnimatedComponent(Circle);
10
11
  LineChartDot.displayName = 'LineChartDot';
11
12
  export function LineChartDot({
12
- color = 'black',
13
13
  at,
14
- size = 8,
15
- pulsesOuter = 'while-inactive',
16
- outerSize = size * 4,
14
+ color: defaultColor = 'black',
17
15
  dotProps,
18
- outerDotProps
16
+ hasOuterDot: defaultHasOuterDot = false,
17
+ hasPulse = false,
18
+ inactiveColor,
19
+ outerDotProps,
20
+ pulseBehaviour = 'while-inactive',
21
+ pulseDurationMs = 800,
22
+ showInactiveColor = true,
23
+ size = 4,
24
+ outerSize = size * 4
19
25
  }) {
20
26
  const {
21
27
  data,
@@ -24,79 +30,76 @@ export function LineChartDot({
24
30
  const {
25
31
  path,
26
32
  pathWidth: width
27
- } = React.useContext(LineChartDimensionsContext);
28
- const parsedPath = React.useMemo(() => parse(path), [path]);
29
- const pointWidth = React.useMemo(() => width / (data.length - 1), [data.length, width]);
33
+ } = React.useContext(LineChartDimensionsContext); ////////////////////////////////////////////////////////////
34
+
35
+ const {
36
+ isInactive: _isInactive
37
+ } = React.useContext(LineChartPathContext);
38
+ const isInactive = showInactiveColor && _isInactive;
39
+ const color = isInactive ? inactiveColor || defaultColor : defaultColor;
40
+ const opacity = isInactive && !inactiveColor ? 0.5 : 1;
41
+ const hasOuterDot = defaultHasOuterDot || hasPulse; ////////////////////////////////////////////////////////////
42
+
43
+ const parsedPath = React.useMemo(() => parse(path), [path]); ////////////////////////////////////////////////////////////
44
+
45
+ const pointWidth = React.useMemo(() => width / (data.length - 1), [data.length, width]); ////////////////////////////////////////////////////////////
46
+
30
47
  const x = useDerivedValue(() => withTiming(pointWidth * at));
31
- const y = useDerivedValue(() => withTiming(getYForX(parsedPath, x.value) || 0));
32
- const containerStyle = useAnimatedStyle(() => {
33
- return {
34
- transform: [{
35
- translateX: x.value - outerSize / 2
36
- }, {
37
- translateY: y.value - outerSize / 2
38
- }]
48
+ const y = useDerivedValue(() => withTiming(getYForX(parsedPath, x.value) || 0)); ////////////////////////////////////////////////////////////
49
+
50
+ const animatedDotProps = useAnimatedProps(() => ({
51
+ cx: x.value,
52
+ cy: y.value
53
+ }));
54
+ const animatedOuterDotProps = useAnimatedProps(() => {
55
+ let defaultProps = {
56
+ cx: x.value,
57
+ cy: y.value,
58
+ opacity: 0.1,
59
+ r: outerSize
39
60
  };
40
- });
41
- const outerStyle = useAnimatedStyle(() => {
42
- let opacity = 0.1;
43
61
 
44
- if (pulsesOuter === 'never') {
45
- return {
46
- opacity
62
+ if (!hasPulse) {
63
+ return defaultProps;
64
+ }
65
+
66
+ if (isActive.value && pulseBehaviour === 'while-inactive') {
67
+ return { ...defaultProps,
68
+ r: 0
47
69
  };
48
70
  }
49
71
 
50
- const enterMs = 800;
51
72
  const easing = Easing.out(Easing.sin);
52
73
  const animatedOpacity = withRepeat(withSequence(withTiming(0.8), withTiming(0, {
53
- duration: enterMs,
74
+ duration: pulseDurationMs,
54
75
  easing
55
76
  })), -1, false);
56
- const scale = withRepeat(withSequence(withTiming(0), withTiming(1, {
57
- duration: enterMs,
77
+ const scale = withRepeat(withSequence(withTiming(0), withTiming(outerSize, {
78
+ duration: pulseDurationMs,
58
79
  easing
59
80
  })), -1, false);
60
81
 
61
- if (pulsesOuter === 'while-inactive') {
62
- return {
82
+ if (pulseBehaviour === 'while-inactive') {
83
+ return { ...defaultProps,
63
84
  opacity: isActive.value ? withTiming(0) : animatedOpacity,
64
- transform: [{
65
- scale: isActive.value ? withTiming(0) : scale
66
- }]
85
+ r: isActive.value ? withTiming(0) : scale
67
86
  };
68
87
  }
69
88
 
70
- return {
89
+ return { ...defaultProps,
71
90
  opacity: animatedOpacity,
72
- transform: [{
73
- scale
74
- }]
91
+ r: scale
75
92
  };
76
- }, [pulsesOuter]);
77
- return /*#__PURE__*/React.createElement(Animated.View, {
78
- pointerEvents: "none",
79
- style: useMemo(() => [{
80
- width: outerSize,
81
- height: outerSize,
82
- alignItems: 'center',
83
- justifyContent: 'center'
84
- }, containerStyle], [containerStyle, outerSize])
85
- }, /*#__PURE__*/React.createElement(Animated.View, _extends({}, outerDotProps, {
86
- style: useMemo(() => [{
87
- backgroundColor: color,
88
- width: outerSize,
89
- height: outerSize,
90
- borderRadius: outerSize,
91
- position: 'absolute'
92
- }, outerStyle, outerDotProps === null || outerDotProps === void 0 ? void 0 : outerDotProps.style], [color, outerSize, outerStyle, outerDotProps === null || outerDotProps === void 0 ? void 0 : outerDotProps.style])
93
- })), /*#__PURE__*/React.createElement(View, _extends({}, dotProps, {
94
- style: useMemo(() => [{
95
- backgroundColor: color,
96
- width: size,
97
- height: size,
98
- borderRadius: size
99
- }, dotProps === null || dotProps === void 0 ? void 0 : dotProps.style], [color, size, dotProps === null || dotProps === void 0 ? void 0 : dotProps.style])
100
- })));
93
+ }, [outerSize]); ////////////////////////////////////////////////////////////
94
+
95
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(AnimatedCircle, _extends({
96
+ animatedProps: animatedDotProps,
97
+ r: size,
98
+ fill: color,
99
+ opacity: opacity
100
+ }, dotProps)), hasOuterDot && /*#__PURE__*/React.createElement(AnimatedCircle, _extends({
101
+ animatedProps: animatedOuterDotProps,
102
+ fill: color
103
+ }, outerDotProps)));
101
104
  }
102
105
  //# sourceMappingURL=Dot.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["Dot.tsx"],"names":["React","Animated","Easing","useAnimatedStyle","useDerivedValue","withRepeat","withSequence","withTiming","View","getYForX","parse","useMemo","LineChartDimensionsContext","useLineChart","LineChartDot","displayName","color","at","size","pulsesOuter","outerSize","dotProps","outerDotProps","data","isActive","path","pathWidth","width","useContext","parsedPath","pointWidth","length","x","y","value","containerStyle","transform","translateX","translateY","outerStyle","opacity","enterMs","easing","out","sin","animatedOpacity","duration","scale","height","alignItems","justifyContent","backgroundColor","borderRadius","position","style"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,QAAP,IACEC,MADF,EAEEC,gBAFF,EAGEC,eAHF,EAIEC,UAJF,EAKEC,YALF,EAMEC,UANF,QAOO,yBAPP;AAQA,SAASC,IAAT,QAAqB,cAArB;AACA,SAASC,QAAT,EAAmBC,KAAnB,QAAgC,qBAAhC;AACA,SAASC,OAAT,QAAwB,OAAxB;AAEA,SAASC,0BAAT,QAA2C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AAxB,CAVY;AAFhB,KAhCF,CADF;AAkDD","sourcesContent":["import * as React from 'react';\nimport Animated, {\n Easing,\n useAnimatedStyle,\n useDerivedValue,\n withRepeat,\n withSequence,\n withTiming,\n} from 'react-native-reanimated';\nimport { View } from 'react-native';\nimport { getYForX, parse } from 'react-native-redash';\nimport { useMemo } from 'react';\n\nimport { LineChartDimensionsContext } from './Chart';\nimport { useLineChart } from './useLineChart';\nimport type { ViewProps } from 'react-native';\n\nexport type LineChartDotProps = {\n dotProps?: ViewProps;\n outerDotProps?: ViewProps;\n color?: string;\n at: number;\n size?: number;\n /**\n * If `always`, the outer dot will still animate when interaction is active.\n *\n * If `never`, the outer dot will never animate.\n *\n * If `while-inactive`, the outer dot will animate only when the interaction is inactive.\n *\n * Default: `while-inactive`\n */\n pulsesOuter?: 'always' | 'while-inactive' | 'never';\n /**\n * Defaults to `size * 4`\n */\n outerSize?: number;\n pulseDurationMs?: number;\n};\n\nLineChartDot.displayName = 'LineChartDot';\n\nexport function LineChartDot({\n color = 'black',\n at,\n size = 8,\n pulsesOuter = 'while-inactive',\n outerSize = size * 4,\n dotProps,\n outerDotProps,\n}: LineChartDotProps) {\n const { data, isActive } = useLineChart();\n const { path, pathWidth: width } = React.useContext(\n LineChartDimensionsContext\n );\n\n const parsedPath = React.useMemo(() => parse(path), [path]);\n const pointWidth = React.useMemo(\n () => width / (data.length - 1),\n [data.length, width]\n );\n\n const x = useDerivedValue(() => withTiming(pointWidth * at));\n const y = useDerivedValue(() =>\n withTiming(getYForX(parsedPath!, x.value) || 0)\n );\n\n const containerStyle = useAnimatedStyle(() => {\n return {\n transform: [\n { translateX: x.value - outerSize / 2 },\n { translateY: y.value - outerSize / 2 },\n ],\n };\n });\n const outerStyle = useAnimatedStyle(() => {\n let opacity = 0.1;\n if (pulsesOuter === 'never') {\n return {\n opacity,\n };\n }\n const enterMs = 800;\n const easing = Easing.out(Easing.sin);\n const animatedOpacity = withRepeat(\n withSequence(\n withTiming(0.8),\n withTiming(0, {\n duration: enterMs,\n easing,\n })\n ),\n -1,\n false\n );\n const scale = withRepeat(\n withSequence(\n withTiming(0),\n withTiming(1, {\n duration: enterMs,\n easing,\n })\n ),\n -1,\n false\n );\n\n if (pulsesOuter === 'while-inactive') {\n return {\n opacity: isActive.value ? withTiming(0) : animatedOpacity,\n transform: [\n {\n scale: isActive.value ? withTiming(0) : scale,\n },\n ],\n };\n }\n return {\n opacity: animatedOpacity,\n transform: [\n {\n scale,\n },\n ],\n };\n }, [pulsesOuter]);\n\n return (\n <Animated.View\n pointerEvents=\"none\"\n style={useMemo(\n () => [\n {\n width: outerSize,\n height: outerSize,\n alignItems: 'center',\n justifyContent: 'center',\n },\n containerStyle,\n ],\n [containerStyle, outerSize]\n )}\n >\n <Animated.View\n {...outerDotProps}\n style={useMemo(\n () => [\n {\n backgroundColor: color,\n width: outerSize,\n height: outerSize,\n borderRadius: outerSize,\n position: 'absolute',\n },\n outerStyle,\n outerDotProps?.style,\n ],\n [color, outerSize, outerStyle, outerDotProps?.style]\n )}\n />\n <View\n {...dotProps}\n style={useMemo(\n () => [\n {\n backgroundColor: color,\n width: size,\n height: size,\n borderRadius: size,\n },\n dotProps?.style,\n ],\n [color, size, dotProps?.style]\n )}\n />\n </Animated.View>\n );\n}\n"]}
1
+ {"version":3,"sources":["Dot.tsx"],"names":["React","Animated","Easing","useAnimatedProps","useDerivedValue","withRepeat","withSequence","withTiming","Circle","getYForX","parse","LineChartDimensionsContext","LineChartPathContext","useLineChart","AnimatedCircle","createAnimatedComponent","LineChartDot","displayName","at","color","defaultColor","dotProps","hasOuterDot","defaultHasOuterDot","hasPulse","inactiveColor","outerDotProps","pulseBehaviour","pulseDurationMs","showInactiveColor","size","outerSize","data","isActive","path","pathWidth","width","useContext","isInactive","_isInactive","opacity","parsedPath","useMemo","pointWidth","length","x","y","value","animatedDotProps","cx","cy","animatedOuterDotProps","defaultProps","r","easing","out","sin","animatedOpacity","duration","scale"],"mappings":";;AAAA,OAAO,KAAKA,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ADjB;AAEE,IAAA,CAAC,EAAElB,IAFL;AAGE,IAAA,IAAI,EAAEX,KAHR;AAIE,IAAA,OAAO,EAAEqB;AAJX,KAKMnB,QALN,EADF,EAQGC,WAAW,iBACV,oBAAC,cAAD;AACE,IAAA,aAAa,EAAE6B,qBADjB;AAEE,IAAA,IAAI,EAAEhC;AAFR,KAGMO,aAHN,EATJ,CADF;AAkBD","sourcesContent":["import * as React from 'react';\nimport Animated, {\n Easing,\n useAnimatedProps,\n useDerivedValue,\n withRepeat,\n withSequence,\n withTiming,\n} from 'react-native-reanimated';\nimport { Circle, CircleProps } from 'react-native-svg';\nimport { getYForX, parse } from 'react-native-redash';\n\nimport { LineChartDimensionsContext } from './Chart';\nimport { LineChartPathContext } from './ChartPath';\nimport { useLineChart } from './useLineChart';\n\nconst AnimatedCircle = Animated.createAnimatedComponent(Circle);\n\nexport type LineChartDotProps = {\n dotProps?: Animated.AnimateProps<CircleProps>;\n outerDotProps?: Animated.AnimateProps<CircleProps>;\n color?: string;\n inactiveColor?: string;\n showInactiveColor?: boolean;\n at: number;\n size?: number;\n hasPulse?: boolean;\n hasOuterDot?: boolean;\n /**\n * If `always`, the outer dot will still animate when interaction is active.\n *\n * If `while-inactive`, the outer dot will animate only when the interaction is inactive.\n *\n * Default: `while-inactive`\n */\n pulseBehaviour?: 'always' | 'while-inactive';\n /**\n * Defaults to `size * 4`\n */\n outerSize?: number;\n pulseDurationMs?: number;\n};\n\nLineChartDot.displayName = 'LineChartDot';\n\nexport function LineChartDot({\n at,\n color: defaultColor = 'black',\n dotProps,\n hasOuterDot: defaultHasOuterDot = false,\n hasPulse = false,\n inactiveColor,\n outerDotProps,\n pulseBehaviour = 'while-inactive',\n pulseDurationMs = 800,\n showInactiveColor = true,\n size = 4,\n outerSize = size * 4,\n}: LineChartDotProps) {\n const { data, isActive } = useLineChart();\n const { path, pathWidth: width } = React.useContext(\n LineChartDimensionsContext\n );\n\n ////////////////////////////////////////////////////////////\n\n const { isInactive: _isInactive } = React.useContext(LineChartPathContext);\n const isInactive = showInactiveColor && _isInactive;\n const color = isInactive ? inactiveColor || defaultColor : defaultColor;\n const opacity = isInactive && !inactiveColor ? 0.5 : 1;\n const hasOuterDot = defaultHasOuterDot || hasPulse;\n\n ////////////////////////////////////////////////////////////\n\n const parsedPath = React.useMemo(() => parse(path), [path]);\n\n ////////////////////////////////////////////////////////////\n\n const pointWidth = React.useMemo(\n () => width / (data.length - 1),\n [data.length, width]\n );\n\n ////////////////////////////////////////////////////////////\n\n const x = useDerivedValue(() => withTiming(pointWidth * at));\n const y = useDerivedValue(() =>\n withTiming(getYForX(parsedPath!, x.value) || 0)\n );\n\n ////////////////////////////////////////////////////////////\n\n const animatedDotProps = useAnimatedProps(() => ({\n cx: x.value,\n cy: y.value,\n }));\n\n const animatedOuterDotProps = useAnimatedProps(() => {\n let defaultProps = {\n cx: x.value,\n cy: y.value,\n opacity: 0.1,\n r: outerSize,\n };\n\n if (!hasPulse) {\n return defaultProps;\n }\n\n if (isActive.value && pulseBehaviour === 'while-inactive') {\n return {\n ...defaultProps,\n r: 0,\n };\n }\n\n const easing = Easing.out(Easing.sin);\n const animatedOpacity = withRepeat(\n withSequence(\n withTiming(0.8),\n withTiming(0, {\n duration: pulseDurationMs,\n easing,\n })\n ),\n -1,\n false\n );\n const scale = withRepeat(\n withSequence(\n withTiming(0),\n withTiming(outerSize, {\n duration: pulseDurationMs,\n easing,\n })\n ),\n -1,\n false\n );\n\n if (pulseBehaviour === 'while-inactive') {\n return {\n ...defaultProps,\n opacity: isActive.value ? withTiming(0) : animatedOpacity,\n r: isActive.value ? withTiming(0) : scale,\n };\n }\n return {\n ...defaultProps,\n opacity: animatedOpacity,\n r: scale,\n };\n }, [outerSize]);\n\n ////////////////////////////////////////////////////////////\n\n return (\n <>\n <AnimatedCircle\n animatedProps={animatedDotProps}\n r={size}\n fill={color}\n opacity={opacity}\n {...dotProps}\n />\n {hasOuterDot && (\n <AnimatedCircle\n animatedProps={animatedOuterDotProps}\n fill={color}\n {...outerDotProps}\n />\n )}\n </>\n );\n}\n"]}
@@ -1,14 +1,14 @@
1
1
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import * as React from 'react';
4
- import Animated, { useAnimatedProps, useAnimatedReaction, useSharedValue, withTiming } from 'react-native-reanimated';
4
+ import Animated from 'react-native-reanimated';
5
5
  import { Defs, LinearGradient, Stop, Path } from 'react-native-svg';
6
6
  import { LineChartDimensionsContext } from './Chart';
7
7
  import { LineChartPathContext } from './ChartPath';
8
- import interpolatePath from './interpolatePath';
9
- import { usePrevious } from '../../utils';
8
+ import useAnimatedPath from './useAnimatedPath';
10
9
  const AnimatedPath = Animated.createAnimatedComponent(Path);
11
10
  let id = 0;
11
+ LineChartGradient.displayName = 'LineChartGradient';
12
12
  export function LineChartGradient({
13
13
  color: overrideColor = undefined,
14
14
  children,
@@ -23,27 +23,11 @@ export function LineChartGradient({
23
23
  } = React.useContext(LineChartPathContext);
24
24
  const color = overrideColor || contextColor; ////////////////////////////////////////////////
25
25
 
26
- const transition = useSharedValue(0);
27
- const previousPath = usePrevious(area);
28
- useAnimatedReaction(() => {
29
- return area;
30
- }, (_, previous) => {
31
- if (previous) {
32
- transition.value = 0;
33
- transition.value = withTiming(1);
34
- }
35
- }, [area]);
36
- const animatedProps = useAnimatedProps(() => {
37
- let d = area || '';
38
-
39
- if (previousPath && isTransitionEnabled) {
40
- const pathInterpolator = interpolatePath(previousPath, area, null);
41
- d = pathInterpolator(transition.value);
42
- }
43
-
44
- return {
45
- d
46
- };
26
+ const {
27
+ animatedProps
28
+ } = useAnimatedPath({
29
+ enabled: isTransitionEnabled,
30
+ path: area
47
31
  }); ////////////////////////////////////////////////
48
32
 
49
33
  const localId = React.useRef(++id); ////////////////////////////////////////////////
@@ -1 +1 @@
1
- {"version":3,"sources":["Gradient.tsx"],"names":["React","Animated","useAnimatedProps","useAnimatedReaction","useSharedValue","withTiming","Defs","LinearGradient","Stop","Path","LineChartDimensionsContext","LineChartPathContext","interpolatePath","usePrevious","AnimatedPath","createAnimatedComponent","id","LineChartGradient","color","overrideColor","undefined","children","props","area","useContext","contextColor","isTransitionEnabled","transition","previousPath","_","previous","value","animatedProps","d","pathInterpolator","localId","useRef","current"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,QAAP,IACEC,gBADF,EAEEC,mBAFF,EAGEC,cAHF,EAIEC,UAJF,QAKO,yBALP;AAMA,SAASC,IAAT,EAAeC,cAAf,EAA+BC,IAA/B,EAAqCC,IAArC,QAA4D,kBAA5D;AAEA,SAASC,0BAAT,QAA2C,SAA3C;AACA,SAASC,oBAAT,QAAqC,aAArC;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,SAASC,WAAT,QAA4B,aAA5B;AAEA,MAAMC,YAAY,GAAGb,QAAQ,CAACc,uBAAT,CAAiCN,IAAjC,CAArB;AAOA,IAAIO,EAAE,GAAG,CAAT;AAEA,OAAO,SAASC,iBAAT,CAA2B;AAChCC,EAAAA,KAAK,EAAEC,aAAa,GAAGC,SADS;AAEhCC,EAAAA,QAFgC;AAGhC,KAAGC;AAH6B,CAA3B,EAIoB;AACzB,QAAM;AAAEC,IAAAA;AAAF,MAAWvB,KAAK,CAACwB,UAAN,CAAiBd,0BAAjB,CAAjB;AACA,QAAM;AAAEQ,IAAAA,KAAK,EAAEO,YAAT;AAAuBC,IAAAA;AAAvB,MACJ1B,KAAK,CAACwB,UAAN,CAAiBb,oBAAjB,CADF;AAGA,QAAMO,KAAK,GAAGC,aAAa,IAAIM,YAA/B,CALyB,CAOzB;;AAEA,QAAME,UAAU,GAAGvB,cAAc,CAAC,CAAD,CAAjC;AAEA,QAAMwB,YAAY,GAAGf,WAAW,CAACU,IAAD,CAAhC;AAEApB,EAAAA,mBAAmB,C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,IAAA,MAAM,EAAC,KAAb;AAAmB,IAAA,SAAS,EAAEnB,KAA9B;AAAqC,IAAA,WAAW,EAAE;AAAlD,IAPF,eAQE,oBAAC,IAAD;AAAM,IAAA,MAAM,EAAC,KAAb;AAAmB,IAAA,SAAS,EAAEA,KAA9B;AAAqC,IAAA,WAAW,EAAE;AAAlD,IARF,eASE,oBAAC,IAAD;AAAM,IAAA,MAAM,EAAC,MAAb;AAAoB,IAAA,SAAS,EAAEA,KAA/B;AAAsC,IAAA,WAAW,EAAE;AAAnD,IATF,CADF,CAdJ,eA4BE,oBAAC,YAAD;AACE,IAAA,aAAa,EAAEc,aADjB;AAEE,IAAA,IAAI,EAAG,QAAOG,OAAO,CAACE,OAAQ;AAFhC,KAGMf,KAHN,EA5BF,CADF;AAoCD","sourcesContent":["import * as React from 'react';\nimport Animated, {\n useAnimatedProps,\n useAnimatedReaction,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { Defs, LinearGradient, Stop, Path, PathProps } from 'react-native-svg';\n\nimport { LineChartDimensionsContext } from './Chart';\nimport { LineChartPathContext } from './ChartPath';\nimport interpolatePath from './interpolatePath';\nimport { usePrevious } from '../../utils';\n\nconst AnimatedPath = Animated.createAnimatedComponent(Path);\n\nexport type LineChartGradientProps = Animated.AnimateProps<PathProps> & {\n color?: string;\n children?: React.ReactNode;\n};\n\nlet id = 0;\n\nexport function LineChartGradient({\n color: overrideColor = undefined,\n children,\n ...props\n}: LineChartGradientProps) {\n const { area } = React.useContext(LineChartDimensionsContext);\n const { color: contextColor, isTransitionEnabled } =\n React.useContext(LineChartPathContext);\n\n const color = overrideColor || contextColor;\n\n ////////////////////////////////////////////////\n\n const transition = useSharedValue(0);\n\n const previousPath = usePrevious(area);\n\n useAnimatedReaction(\n () => {\n return area;\n },\n (_, previous) => {\n if (previous) {\n transition.value = 0;\n transition.value = withTiming(1);\n }\n },\n [area]\n );\n\n const animatedProps = useAnimatedProps(() => {\n let d = area || '';\n if (previousPath && isTransitionEnabled) {\n const pathInterpolator = interpolatePath(previousPath, area, null);\n d = pathInterpolator(transition.value);\n }\n return {\n d,\n };\n });\n\n ////////////////////////////////////////////////\n\n const localId = React.useRef(++id);\n\n ////////////////////////////////////////////////\n\n return (\n <>\n {children ? (\n <Defs>\n <LinearGradient\n id={`${localId.current}`}\n x1=\"0\"\n x2=\"0\"\n y1=\"0\"\n y2=\"100%\"\n >\n {children}\n </LinearGradient>\n </Defs>\n ) : (\n <Defs>\n <LinearGradient\n id={`${localId.current}`}\n x1=\"0\"\n x2=\"0\"\n y1=\"0\"\n y2=\"100%\"\n >\n <Stop offset=\"20%\" stopColor={color} stopOpacity={0.15} />\n <Stop offset=\"40%\" stopColor={color} stopOpacity={0.05} />\n <Stop offset=\"100%\" stopColor={color} stopOpacity={0} />\n </LinearGradient>\n </Defs>\n )}\n <AnimatedPath\n animatedProps={animatedProps}\n fill={`url(#${localId.current})`}\n {...props}\n />\n </>\n );\n}\n"]}
1
+ {"version":3,"sources":["Gradient.tsx"],"names":["React","Animated","Defs","LinearGradient","Stop","Path","LineChartDimensionsContext","LineChartPathContext","useAnimatedPath","AnimatedPath","createAnimatedComponent","id","LineChartGradient","displayName","color","overrideColor","undefined","children","props","area","useContext","contextColor","isTransitionEnabled","animatedProps","enabled","path","localId","useRef","current"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,QAAP,MAAqB,yBAArB;AACA,SAASC,IAAT,EAAeC,cAAf,EAA+BC,IAA/B,EAAqCC,IAArC,QAA4D,kBAA5D;AAEA,SAASC,0BAAT,QAA2C,SAA3C;AACA,SAASC,oBAAT,QAAqC,aAArC;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AAEA,MAAMC,YAAY,GAAGR,QAAQ,CAACS,uBAAT,CAAiCL,IAAjC,CAArB;AAOA,IAAIM,EAAE,GAAG,CAAT;AAEAC,iBAAiB,CAACC,WAAlB,GAAgC,mBAAhC;AAEA,OAAO,SAASD,iBAA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AAD;AAAM,IAAA,MAAM,EAAC,KAAb;AAAmB,IAAA,SAAS,EAAEA,KAA9B;AAAqC,IAAA,WAAW,EAAE;AAAlD,IARF,eASE,oBAAC,IAAD;AAAM,IAAA,MAAM,EAAC,MAAb;AAAoB,IAAA,SAAS,EAAEA,KAA/B;AAAsC,IAAA,WAAW,EAAE;AAAnD,IATF,CADF,CAdJ,eA4BE,oBAAC,YAAD;AACE,IAAA,aAAa,EAAES,aADjB;AAEE,IAAA,IAAI,EAAG,QAAOG,OAAO,CAACE,OAAQ;AAFhC,KAGMV,KAHN,EA5BF,CADF;AAoCD","sourcesContent":["import * as React from 'react';\nimport Animated from 'react-native-reanimated';\nimport { Defs, LinearGradient, Stop, Path, PathProps } from 'react-native-svg';\n\nimport { LineChartDimensionsContext } from './Chart';\nimport { LineChartPathContext } from './ChartPath';\nimport useAnimatedPath from './useAnimatedPath';\n\nconst AnimatedPath = Animated.createAnimatedComponent(Path);\n\nexport type LineChartGradientProps = Animated.AnimateProps<PathProps> & {\n color?: string;\n children?: React.ReactNode;\n};\n\nlet id = 0;\n\nLineChartGradient.displayName = 'LineChartGradient';\n\nexport function LineChartGradient({\n color: overrideColor = undefined,\n children,\n ...props\n}: LineChartGradientProps) {\n const { area } = React.useContext(LineChartDimensionsContext);\n const { color: contextColor, isTransitionEnabled } =\n React.useContext(LineChartPathContext);\n\n const color = overrideColor || contextColor;\n\n ////////////////////////////////////////////////\n\n const { animatedProps } = useAnimatedPath({\n enabled: isTransitionEnabled,\n path: area,\n });\n\n ////////////////////////////////////////////////\n\n const localId = React.useRef(++id);\n\n ////////////////////////////////////////////////\n\n return (\n <>\n {children ? (\n <Defs>\n <LinearGradient\n id={`${localId.current}`}\n x1=\"0\"\n x2=\"0\"\n y1=\"0\"\n y2=\"100%\"\n >\n {children}\n </LinearGradient>\n </Defs>\n ) : (\n <Defs>\n <LinearGradient\n id={`${localId.current}`}\n x1=\"0\"\n x2=\"0\"\n y1=\"0\"\n y2=\"100%\"\n >\n <Stop offset=\"20%\" stopColor={color} stopOpacity={0.15} />\n <Stop offset=\"40%\" stopColor={color} stopOpacity={0.05} />\n <Stop offset=\"100%\" stopColor={color} stopOpacity={0} />\n </LinearGradient>\n </Defs>\n )}\n <AnimatedPath\n animatedProps={animatedProps}\n fill={`url(#${localId.current})`}\n {...props}\n />\n </>\n );\n}\n"]}
@@ -1,30 +1,8 @@
1
1
  import React from 'react';
2
- /* Returns React children into an array, flattening fragments.
3
-
4
- Forked from https://github.com/grrowl/react-keyed-flatten-children/blob/master/index.ts
5
- */
6
-
7
- import { Children, isValidElement, cloneElement } from 'react';
2
+ import { Children, cloneElement } from 'react';
8
3
  import { View } from 'react-native';
4
+ import flattenChildren from 'react-keyed-flatten-children';
9
5
  import { LineChart } from './Chart';
10
- export default function flattenChildren(children, depth = 0, keys = []) {
11
- return Children.toArray(children).reduce( // eslint-disable-next-line
12
- (acc, node, nodeIndex) => {
13
- if (node.type === React.Fragment) {
14
- acc.push.apply(acc, flattenChildren(node.props.children, depth + 1, keys.concat(node.key || nodeIndex)));
15
- } else {
16
- if ( /*#__PURE__*/isValidElement(node)) {
17
- acc.push( /*#__PURE__*/cloneElement(node, {
18
- key: keys.concat(String(node.key)).join('.')
19
- }));
20
- } else if (typeof node === 'string' || typeof node === 'number') {
21
- acc.push(node);
22
- }
23
- }
24
-
25
- return acc;
26
- }, []);
27
- }
28
6
  export function LineChartGroup({
29
7
  children,
30
8
  ...props
@@ -1 +1 @@
1
- {"version":3,"sources":["Group.tsx"],"names":["React","Children","isValidElement","cloneElement","View","LineChart","flattenChildren","children","depth","keys","toArray","reduce","acc","node","nodeIndex","type","Fragment","push","apply","props","concat","key","String","join","LineChartGroup","flatChildren","flatChildrenCount","count","map","child","index","isLast","absolute"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAEA;AACA;AACA;AACA;;AACA,SAGEC,QAHF,EAIEC,cAJF,EAKEC,YALF,QAMO,OANP;AAOA,SAAoBC,IAApB,QAAgC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BAAC,IAAD,EAAUN,KAAV,EAEGlB,QAAQ,CAAC2B,GAAT,CAAaH,YAAb,EAA2B,CAACI,KAAD,EAAaC,KAAb,KAAuB;AACjD,UAAMC,MAAM,GAAGD,KAAK,KAAKJ,iBAAiB,GAAG,CAA7C;;AACA,QAAI,CAACK,MAAD,IAAWF,KAAK,CAACd,IAAN,KAAeV,SAA9B,EAAyC;AACvC,0BAAOF,YAAY,CAAC0B,KAAD,EAAQ;AACzBG,QAAAA,QAAQ,EAAE;AADe,OAAR,CAAnB;AAGD;;AACD,WAAOH,KAAP;AACD,GARA,CAFH,CADF;AAcD","sourcesContent":["import React from 'react';\n\n/* Returns React children into an array, flattening fragments.\n\nForked from https://github.com/grrowl/react-keyed-flatten-children/blob/master/index.ts\n*/\nimport {\n ReactNode,\n ReactChild,\n Children,\n isValidElement,\n cloneElement,\n} from 'react';\nimport { ViewProps, View } from 'react-native';\nimport { LineChart } from './Chart';\n\nexport default function flattenChildren(\n children: ReactNode,\n depth: number = 0,\n keys: (string | number)[] = []\n): ReactChild[] {\n return Children.toArray(children).reduce(\n // eslint-disable-next-line\n (acc: ReactChild[], node: any, nodeIndex) => {\n if (node.type === React.Fragment) {\n acc.push.apply(\n acc,\n flattenChildren(\n node.props.children,\n depth + 1,\n keys.concat(node.key || nodeIndex)\n )\n );\n } else {\n if (isValidElement(node)) {\n acc.push(\n cloneElement(node, {\n key: keys.concat(String(node.key)).join('.'),\n })\n );\n } else if (typeof node === 'string' || typeof node === 'number') {\n acc.push(node);\n }\n }\n return acc;\n },\n []\n );\n}\n\ntype Props = {\n children: ReactNode;\n} & ViewProps;\n\nexport function LineChartGroup({ children, ...props }: Props) {\n const flatChildren = flattenChildren(children);\n const flatChildrenCount = Children.count(flatChildren);\n return (\n <View {...props}>\n {/* eslint-disable-next-line */}\n {Children.map(flatChildren, (child: any, index) => {\n const isLast = index === flatChildrenCount - 1;\n if (!isLast && child.type === LineChart) {\n return cloneElement(child, {\n absolute: true,\n });\n }\n return child;\n })}\n </View>\n );\n}\n"]}
1
+ {"version":3,"sources":["Group.tsx"],"names":["React","Children","cloneElement","View","flattenChildren","LineChart","LineChartGroup","children","props","flatChildren","flatChildrenCount","count","map","child","index","isLast","type","absolute"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAAoBC,QAApB,EAA8BC,YAA9B,QAAkD,OAAlD;AACA,SAAoBC,IAApB,QAAgC,cAAhC;AACA,OAAOC,eAAP,MAA4B,8BAA5B;AAEA,SAASC,SAAT,QAA0B,SAA1B;AAMA,OAAO,SAASC,cAAT,CAAwB;AAAEC,EAAAA,QAAF;AAAY,KAAGC;AAAf,CAAxB,EAAuD;AAC5D,QAAMC,YAAY,GAAGL,eAAe,CAACG,QAAD,CAApC;AACA,QAAMG,iBAAiB,GAAGT,QAAQ,CAACU,KAAT,CAAeF,YAAf,CAA1B;AACA,sBACE,oBAAC,IAAD,EAAUD,KAAV,EAEGP,QAAQ,CAACW,GAAT,CAAaH,YAAb,EAA2B,CAACI,KAAD,EAAaC,KAAb,KAAuB;AACjD,UAAMC,MAAM,GAAGD,KAAK,KAAKJ,iBAAiB,GAAG,CAA7C;;AACA,QAAI,CAACK,MAAD,IAAWF,KAAK,CAACG,IAAN,KAAeX,SAA9B,EAAyC;AACvC,0BAAOH,YAAY,CAACW,KAAD,EAAQ;AACzBI,QAAAA,QAAQ,EAAE;AADe,OAAR,CAAnB;AAGD;;AACD,WAAOJ,KAAP;AACD,GARA,CAFH,CADF;AAcD","sourcesContent":["import React from 'react';\nimport { ReactNode, Children, cloneElement } from 'react';\nimport { ViewProps, View } from 'react-native';\nimport flattenChildren from 'react-keyed-flatten-children';\n\nimport { LineChart } from './Chart';\n\ntype Props = {\n children: ReactNode;\n} & ViewProps;\n\nexport function LineChartGroup({ children, ...props }: Props) {\n const flatChildren = flattenChildren(children);\n const flatChildrenCount = Children.count(flatChildren);\n return (\n <View {...props}>\n {/* eslint-disable-next-line @typescript-eslint/no-explicit-any */}\n {Children.map(flatChildren, (child: any, index) => {\n const isLast = index === flatChildrenCount - 1;\n if (!isLast && child.type === LineChart) {\n return cloneElement(child, {\n absolute: true,\n });\n }\n return child;\n })}\n </View>\n );\n}\n"]}
@@ -0,0 +1,69 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import * as React from 'react';
4
+ import Animated from 'react-native-reanimated';
5
+ import { Path } from 'react-native-svg';
6
+ import { LineChartDimensionsContext } from './Chart';
7
+ import { LineChartPathContext } from './ChartPath';
8
+ import useAnimatedPath from './useAnimatedPath';
9
+ import { useLineChart } from './useLineChart';
10
+ import { getPath } from './utils';
11
+ const AnimatedPath = Animated.createAnimatedComponent(Path);
12
+ LineChartHighlight.displayName = 'LineChartHighlight';
13
+ export function LineChartHighlight({
14
+ color = 'black',
15
+ inactiveColor,
16
+ showInactiveColor = true,
17
+ from,
18
+ to,
19
+ width: strokeWidth = 3,
20
+ ...props
21
+ }) {
22
+ const {
23
+ data,
24
+ yDomain
25
+ } = useLineChart();
26
+ const {
27
+ pathWidth,
28
+ height,
29
+ gutter,
30
+ shape
31
+ } = React.useContext(LineChartDimensionsContext);
32
+ const {
33
+ isTransitionEnabled,
34
+ isInactive: _isInactive
35
+ } = React.useContext(LineChartPathContext);
36
+ const isInactive = showInactiveColor && _isInactive; ////////////////////////////////////////////////
37
+
38
+ const path = React.useMemo(() => {
39
+ if (data && data.length > 0) {
40
+ return getPath({
41
+ data,
42
+ from,
43
+ to,
44
+ width: pathWidth,
45
+ height,
46
+ gutter,
47
+ shape,
48
+ yDomain
49
+ });
50
+ }
51
+
52
+ return '';
53
+ }, [data, from, to, pathWidth, height, gutter, shape, yDomain]);
54
+ const {
55
+ animatedProps
56
+ } = useAnimatedPath({
57
+ enabled: isTransitionEnabled,
58
+ path
59
+ }); ////////////////////////////////////////////////
60
+
61
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(AnimatedPath, _extends({
62
+ animatedProps: animatedProps,
63
+ fill: "transparent",
64
+ stroke: isInactive ? inactiveColor || color : color,
65
+ strokeWidth: strokeWidth,
66
+ strokeOpacity: isInactive && !inactiveColor ? 0.5 : 1
67
+ }, props)));
68
+ }
69
+ //# sourceMappingURL=Highlight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["Highlight.tsx"],"names":["React","Animated","Path","LineChartDimensionsContext","LineChartPathContext","useAnimatedPath","useLineChart","getPath","AnimatedPath","createAnimatedComponent","LineChartHighlight","displayName","color","inactiveColor","showInactiveColor","from","to","width","strokeWidth","props","data","yDomain","pathWidth","height","gutter","shape","useContext","isTransitionEnabled","isInactive","_isInactive","path","useMemo","length","animatedProps","enabled"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,QAAP,MAAqB,yBAArB;AACA,SAASC,IAAT,QAAgC,kBAAhC;AAEA,SAASC,0BAAT,QAA2C,SAA3C;AACA,SAASC,oBAAT,QAAqC,aAArC;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,OAAT,QAAwB,SAAxB;AAEA,MAAMC,YAAY,GAAGP,QAAQ,CAACQ,uBAAT,CAAiCP,IAAjC,CAArB;AAWAQ,kBAAkB,CAACC,WAAnB,GAAiC,oBAAjC;AAEA,OAAO,SAASD,kBAAT,CAA4B;AACjCE,EAAAA,KAAK,GAAG,OADyB;AAEjCC,EAAAA,aAFiC;AAGjCC,EAAAA,iBAAiB,GAAG,IAHa;AAIjCC,EAAAA,IAJiC;AAKjCC,EAAAA,EALiC;AAMjCC,EAAAA,KAAK,EAAEC,WAAW,GAAG,CANY;AAOjC,KAAGC;AAP8B,CAA5B,EAQiB;AACtB,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAo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U,IAAI,CAACf,aAAf,GAA+B,GAA/B,GAAqC;AALtD,KAMMM,KANN,EADF,CADF;AAYD","sourcesContent":["import * as React from 'react';\nimport Animated from 'react-native-reanimated';\nimport { Path, PathProps } from 'react-native-svg';\n\nimport { LineChartDimensionsContext } from './Chart';\nimport { LineChartPathContext } from './ChartPath';\nimport useAnimatedPath from './useAnimatedPath';\nimport { useLineChart } from './useLineChart';\nimport { getPath } from './utils';\n\nconst AnimatedPath = Animated.createAnimatedComponent(Path);\n\nexport type LineChartColorProps = Animated.AnimateProps<PathProps> & {\n color?: string;\n from: number;\n to: number;\n showInactiveColor?: boolean;\n inactiveColor?: string;\n width?: number;\n};\n\nLineChartHighlight.displayName = 'LineChartHighlight';\n\nexport function LineChartHighlight({\n color = 'black',\n inactiveColor,\n showInactiveColor = true,\n from,\n to,\n width: strokeWidth = 3,\n ...props\n}: LineChartColorProps) {\n const { data, yDomain } = useLineChart();\n const { pathWidth, height, gutter, shape } = React.useContext(\n LineChartDimensionsContext\n );\n const { isTransitionEnabled, isInactive: _isInactive } =\n React.useContext(LineChartPathContext);\n const isInactive = showInactiveColor && _isInactive;\n\n ////////////////////////////////////////////////\n\n const path = React.useMemo(() => {\n if (data && data.length > 0) {\n return getPath({\n data,\n from,\n to,\n width: pathWidth,\n height,\n gutter,\n shape,\n yDomain,\n });\n }\n return '';\n }, [data, from, to, pathWidth, height, gutter, shape, yDomain]);\n\n const { animatedProps } = useAnimatedPath({\n enabled: isTransitionEnabled,\n path,\n });\n\n ////////////////////////////////////////////////\n\n return (\n <>\n <AnimatedPath\n animatedProps={animatedProps}\n fill=\"transparent\"\n stroke={isInactive ? inactiveColor || color : color}\n strokeWidth={strokeWidth}\n strokeOpacity={isInactive && !inactiveColor ? 0.5 : 1}\n {...props}\n />\n </>\n );\n}\n"]}
@@ -7,14 +7,15 @@ import { getYForX, parse } from 'react-native-redash';
7
7
  import { LineChartDimensionsContext } from './Chart';
8
8
  import { useLineChart } from './useLineChart';
9
9
  const AnimatedLine = Animated.createAnimatedComponent(SVGLine);
10
- export const LineChartHorizontalLine = ({
10
+ LineChartHorizontalLine.displayName = 'LineChartHorizontalLine';
11
+ export function LineChartHorizontalLine({
11
12
  color = 'gray',
12
13
  lineProps = {},
13
14
  at = {
14
15
  index: 0
15
16
  },
16
17
  offsetY = 0
17
- }) => {
18
+ }) {
18
19
  const {
19
20
  width,
20
21
  path,
@@ -62,5 +63,5 @@ export const LineChartHorizontalLine = ({
62
63
  stroke: color,
63
64
  strokeDasharray: "3 3"
64
65
  }, lineProps));
65
- };
66
+ }
66
67
  //# sourceMappingURL=HorizontalLine.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["HorizontalLine.tsx"],"names":["React","Animated","useAnimatedProps","useDerivedValue","withTiming","Line","SVGLine","getYForX","parse","LineChartDimensionsContext","useLineChart","AnimatedLine","createAnimatedComponent","LineChartHorizontalLine","color","lineProps","at","index","offsetY","width","path","height","gutter","useContext","data","yDomain","parsedPath","useMemo","pointWidth","length","y","yForX","offsetTop","max","value","percentageOffsetTop","min","heightBetweenGutters","offsetTopPixels","lineAnimatedProps","x1","x2","y1","y2"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,QAAP,IACEC,gBADF,EAEEC,eAFF,EAGEC,UAHF,QAIO,yBAJP;AAKA,SAASC,IAAI,IAAIC,OAAjB,QAA2C,kBAA3C;AACA,SAASC,QAAT,EAAmBC,KAAnB,QAAgC,qBAAhC;AAEA,SAASC,0BAAT,QAA2C,SAA3C;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA,MAAMC,YAAY,GAAGV,QAAQ,CAACW,uBAAT,CAAiCN,OAAjC,CAArB;AAmCA,OAAO,MAAMO,uBAAuB,GAAG,CAAC;AACtCC,EAAAA,KAAK,GAAG,MAD8B;AAEtCC,EAAAA,SAAS,GAAG,EAF0B;AAGtCC,EAAAA,EAAE,GAAG;AAAEC,IAAAA,KAAK,EAAE;AAAT,GAHiC;AAItCC,E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BAAmB,GAAGE,oBAAvD;AAEA,WAAOjC,UAAU,CAACkC,eAAe,GAAGpB,OAAnB,CAAjB;AACD,GAxBwB,CAAzB;AA0BA,QAAMqB,iBAAiB,GAAGrC,gBAAgB,CAAC,OAAO;AAChDsC,IAAAA,EAAE,EAAE,CAD4C;AAEhDC,IAAAA,EAAE,EAAEtB,KAF4C;AAGhDuB,IAAAA,EAAE,EAAEZ,CAAC,CAACI,KAH0C;AAIhDS,IAAAA,EAAE,EAAEb,CAAC,CAACI;AAJ0C,GAAP,CAAD,CAA1C;AAOA,sBACE,oBAAC,YAAD;AACE,IAAA,aAAa,EAAEK,iBADjB;AAEE,IAAA,WAAW,EAAE,CAFf;AAGE,IAAA,MAAM,EAAEzB,KAHV;AAIE,IAAA,eAAe,EAAC;AAJlB,KAKMC,SALN,EADF;AASD,CA3DM","sourcesContent":["import React from 'react';\nimport Animated, {\n useAnimatedProps,\n useDerivedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { Line as SVGLine, LineProps } from 'react-native-svg';\nimport { getYForX, parse } from 'react-native-redash';\n\nimport { LineChartDimensionsContext } from './Chart';\nimport { useLineChart } from './useLineChart';\n\nconst AnimatedLine = Animated.createAnimatedComponent(SVGLine);\n\ntype HorizontalLineProps = {\n color?: string;\n lineProps?: Partial<LineProps>;\n offsetY?: number;\n /**\n * (Optional) A pixel value to nudge the line up or down.\n *\n * This may be useful to customize the line's position based on the thickness of your cursor or chart path.\n *\n * ```tsx\n * <LineChart.HorizontalLine\n * at={{ index: 3 }}\n * />\n *\n * // or\n *\n * <LineChart.HorizontalLine\n * at={{ value: 320.32}}\n * />\n * ```\n */\n at?:\n | {\n index: number;\n value?: never;\n }\n | {\n index?: never;\n value: number;\n }\n | number;\n};\n\nexport const LineChartHorizontalLine = ({\n color = 'gray',\n lineProps = {},\n at = { index: 0 },\n offsetY = 0,\n}: HorizontalLineProps) => {\n const { width, path, height, gutter } = React.useContext(\n LineChartDimensionsContext\n );\n const { data, yDomain } = useLineChart();\n\n const parsedPath = React.useMemo(() => parse(path), [path]);\n const pointWidth = React.useMemo(\n () => width / data.length,\n [data.length, width]\n );\n\n const y = useDerivedValue(() => {\n if (typeof at === 'number' || at.index != null) {\n const index = typeof at === 'number' ? at : at.index;\n const yForX = getYForX(parsedPath!, pointWidth * index) || 0;\n return withTiming(yForX + offsetY);\n }\n /**\n * <gutter>\n * | ---------- | <- yDomain.max |\n * | | | offsetTop\n * | | <- value |\n * | |\n * | | <- yDomain.min\n * <gutter>\n */\n\n const offsetTop = yDomain.max - at.value;\n const percentageOffsetTop = offsetTop / (yDomain.max - yDomain.min);\n\n const heightBetweenGutters = height - gutter * 2;\n\n const offsetTopPixels = gutter + percentageOffsetTop * heightBetweenGutters;\n\n return withTiming(offsetTopPixels + offsetY);\n });\n\n const lineAnimatedProps = useAnimatedProps(() => ({\n x1: 0,\n x2: width,\n y1: y.value,\n y2: y.value,\n }));\n\n return (\n <AnimatedLine\n animatedProps={lineAnimatedProps}\n strokeWidth={2}\n stroke={color}\n strokeDasharray=\"3 3\"\n {...lineProps}\n />\n );\n};\n"]}
1
+ {"version":3,"sources":["HorizontalLine.tsx"],"names":["React","Animated","useAnimatedProps","useDerivedValue","withTiming","Line","SVGLine","getYForX","parse","LineChartDimensionsContext","useLineChart","AnimatedLine","createAnimatedComponent","LineChartHorizontalLine","displayName","color","lineProps","at","index","offsetY","width","path","height","gutter","useContext","data","yDomain","parsedPath","useMemo","pointWidth","length","y","yForX","offsetTop","max","value","percentageOffsetTop","min","heightBetweenGutters","offsetTopPixels","lineAnimatedProps","x1","x2","y1","y2"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,QAAP,IACEC,gBADF,EAEEC,eAFF,EAGEC,UAHF,QAIO,yBAJP;AAKA,SAASC,IAAI,IAAIC,OAAjB,QAA2C,kBAA3C;AACA,SAASC,QAAT,EAAmBC,KAAnB,QAAgC,qBAAhC;AAEA,SAASC,0BAAT,QAA2C,SAA3C;AAC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AACD;AACD;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEI,UAAMc,SAAS,GAAGP,OAAO,CAACQ,GAAR,GAAcjB,EAAE,CAACkB,KAAnC;AACA,UAAMC,mBAAmB,GAAGH,SAAS,IAAIP,OAAO,CAACQ,GAAR,GAAcR,OAAO,CAACW,GAA1B,CAArC;AAEA,UAAMC,oBAAoB,GAAGhB,MAAM,GAAGC,MAAM,GAAG,CAA/C;AAEA,UAAMgB,eAAe,GAAGhB,MAAM,GAAGa,mBAAmB,GAAGE,oBAAvD;AAEA,WAAOlC,UAAU,CAACmC,eAAe,GAAGpB,OAAnB,CAAjB;AACD,GAxBwB,CAAzB;AA0BA,QAAMqB,iBAAiB,GAAGtC,gBAAgB,CAAC,OAAO;AAChDuC,IAAAA,EAAE,EAAE,CAD4C;AAEhDC,IAAAA,EAAE,EAAEtB,KAF4C;AAGhDuB,IAAAA,EAAE,EAAEZ,CAAC,CAACI,KAH0C;AAIhDS,IAAAA,EAAE,EAAEb,CAAC,CAACI;AAJ0C,GAAP,CAAD,CAA1C;AAOA,sBACE,oBAAC,YAAD;AACE,IAAA,aAAa,EAAEK,iBADjB;AAEE,IAAA,WAAW,EAAE,CAFf;AAGE,IAAA,MAAM,EAAEzB,KAHV;AAIE,IAAA,eAAe,EAAC;AAJlB,KAKMC,SALN,EADF;AASD","sourcesContent":["import React from 'react';\nimport Animated, {\n useAnimatedProps,\n useDerivedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { Line as SVGLine, LineProps } from 'react-native-svg';\nimport { getYForX, parse } from 'react-native-redash';\n\nimport { LineChartDimensionsContext } from './Chart';\nimport { useLineChart } from './useLineChart';\n\nconst AnimatedLine = Animated.createAnimatedComponent(SVGLine);\n\ntype HorizontalLineProps = {\n color?: string;\n lineProps?: Partial<LineProps>;\n offsetY?: number;\n /**\n * (Optional) A pixel value to nudge the line up or down.\n *\n * This may be useful to customize the line's position based on the thickness of your cursor or chart path.\n *\n * ```tsx\n * <LineChart.HorizontalLine\n * at={{ index: 3 }}\n * />\n *\n * // or\n *\n * <LineChart.HorizontalLine\n * at={{ value: 320.32}}\n * />\n * ```\n */\n at?:\n | {\n index: number;\n value?: never;\n }\n | {\n index?: never;\n value: number;\n }\n | number;\n};\n\nLineChartHorizontalLine.displayName = 'LineChartHorizontalLine';\n\nexport function LineChartHorizontalLine({\n color = 'gray',\n lineProps = {},\n at = { index: 0 },\n offsetY = 0,\n}: HorizontalLineProps) {\n const { width, path, height, gutter } = React.useContext(\n LineChartDimensionsContext\n );\n const { data, yDomain } = useLineChart();\n\n const parsedPath = React.useMemo(() => parse(path), [path]);\n const pointWidth = React.useMemo(\n () => width / data.length,\n [data.length, width]\n );\n\n const y = useDerivedValue(() => {\n if (typeof at === 'number' || at.index != null) {\n const index = typeof at === 'number' ? at : at.index;\n const yForX = getYForX(parsedPath!, pointWidth * index) || 0;\n return withTiming(yForX + offsetY);\n }\n /**\n * <gutter>\n * | ---------- | <- yDomain.max |\n * | | | offsetTop\n * | | <- value |\n * | |\n * | | <- yDomain.min\n * <gutter>\n */\n\n const offsetTop = yDomain.max - at.value;\n const percentageOffsetTop = offsetTop / (yDomain.max - yDomain.min);\n\n const heightBetweenGutters = height - gutter * 2;\n\n const offsetTopPixels = gutter + percentageOffsetTop * heightBetweenGutters;\n\n return withTiming(offsetTopPixels + offsetY);\n });\n\n const lineAnimatedProps = useAnimatedProps(() => ({\n x1: 0,\n x2: width,\n y1: y.value,\n y2: y.value,\n }));\n\n return (\n <AnimatedLine\n animatedProps={lineAnimatedProps}\n strokeWidth={2}\n stroke={color}\n strokeDasharray=\"3 3\"\n {...lineProps}\n />\n );\n}\n"]}
@@ -1,51 +1,39 @@
1
1
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import * as React from 'react';
4
- import Animated, { useAnimatedProps, useAnimatedReaction, useSharedValue, withTiming } from 'react-native-reanimated';
4
+ import Animated from 'react-native-reanimated';
5
5
  import { Path } from 'react-native-svg';
6
6
  import { LineChartDimensionsContext } from './Chart';
7
- import interpolatePath from './interpolatePath';
8
- import { usePrevious } from '../../utils';
7
+ import { LineChartPathContext } from './ChartPath';
8
+ import useAnimatedPath from './useAnimatedPath';
9
9
  const AnimatedPath = Animated.createAnimatedComponent(Path);
10
+ LineChartPath.displayName = 'LineChartPath';
10
11
  export function LineChartPath({
11
12
  color = 'black',
13
+ inactiveColor,
12
14
  width: strokeWidth = 3,
13
- isInactive,
14
- isTransitionEnabled = true,
15
15
  ...props
16
16
  }) {
17
17
  const {
18
18
  path
19
- } = React.useContext(LineChartDimensionsContext); ////////////////////////////////////////////////
20
-
21
- const transition = useSharedValue(0);
22
- const previousPath = usePrevious(path);
23
- useAnimatedReaction(() => {
24
- return path;
25
- }, (_, previous) => {
26
- if (previous) {
27
- transition.value = 0;
28
- transition.value = withTiming(1);
29
- }
30
- }, [path]);
31
- const animatedProps = useAnimatedProps(() => {
32
- let d = path || '';
33
-
34
- if (previousPath && isTransitionEnabled) {
35
- const pathInterpolator = interpolatePath(previousPath, path, null);
36
- d = pathInterpolator(transition.value);
37
- }
19
+ } = React.useContext(LineChartDimensionsContext);
20
+ const {
21
+ isTransitionEnabled,
22
+ isInactive
23
+ } = React.useContext(LineChartPathContext); ////////////////////////////////////////////////
38
24
 
39
- return {
40
- d
41
- };
25
+ const {
26
+ animatedProps
27
+ } = useAnimatedPath({
28
+ enabled: isTransitionEnabled,
29
+ path
42
30
  }); ////////////////////////////////////////////////
43
31
 
44
32
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(AnimatedPath, _extends({
45
33
  animatedProps: animatedProps,
46
34
  fill: "transparent",
47
- stroke: color,
48
- strokeOpacity: isInactive ? 0.2 : 1,
35
+ stroke: isInactive ? inactiveColor || color : color,
36
+ strokeOpacity: isInactive && !inactiveColor ? 0.2 : 1,
49
37
  strokeWidth: strokeWidth
50
38
  }, props)));
51
39
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["Path.tsx"],"names":["React","Animated","useAnimatedProps","useAnimatedReaction","useSharedValue","withTiming","Path","LineChartDimensionsContext","interpolatePath","usePrevious","AnimatedPath","createAnimatedComponent","LineChartPath","color","width","strokeWidth","isInactive","isTransitionEnabled","props","path","useContext","transition","previousPath","_","previous","value","animatedProps","d","pathInterpolator"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,QAAP,IACEC,gBADF,EAEEC,mBAFF,EAGEC,cAHF,EAIEC,UAJF,QAKO,yBALP;AAMA,SAASC,IAAT,QAAgC,kBAAhC;AAEA,SAASC,0BAAT,QAA2C,SAA3C;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,SAASC,WAAT,QAA4B,aAA5B;AAEA,MAAMC,YAAY,GAAGT,QAAQ,CAACU,uBAAT,CAAiCL,IAAjC,CAArB;AAwBA,OAAO,SAASM,aAAT,CAAuB;AAC5BC,EAAAA,KAAK,GAAG,OADoB;AAE5BC,EAAAA,KAAK,EAAEC,WAAW,GAAG,CAFO;AAG5BC,EAAAA,UAH4B;AAI5BC,EAAAA,mBAAmB,GAAG,IAJM;AAK5B,KAAGC;AALyB,CAAvB,EAMgB;AACrB,QAAM;AAAEC,IAAAA;AAAF,MAAWnB,KAAK,CAACoB,UAAN,CAAiBb,0BAAjB,CAAjB,CADqB,CAGrB;;AAEA,QAAMc,UAAU,GAAGjB,cAAc,CAAC,CAAD,CAAjC;AAEA,QAAMkB,YAAY,GAAGb,WAAW,CAACU,IAAD,CAAhC;AAEAhB,EAAAA,mBAAmB,CACjB,MAAM;AACJ,WAAOgB,IAAP;AACD,GAHgB,EAIjB,CAACI,CAAD,EAAIC,QAAJ,KAAiB;AACf,QAAIA,QAAJ,EAAc;AACZH,MAAAA,UAAU,CAACI,KAAX,GAAmB,CAAnB;AACAJ,MAAAA,UAAU,CAACI,KAAX,GAAmBpB,UAAU,CAAC,CAAD,CAA7B;AACD;AACF,GATgB,EAUjB,CAACc,IAAD,CAViB,CAAnB;AAaA,QAAMO,aAAa,GAAGxB,gBAAgB,CAAC,MAAM;AAC3C,QAAIyB,CAAC,GAAGR,IAAI,IAAI,EAAhB;;AACA,QAAIG,YAAY,IAAIL,mBAApB,EAAyC;AACvC,YAAMW,gBAAgB,GAAGpB,eAAe,CAACc,YAAD,EAAeH,IAAf,EAAqB,IAArB,CAAxC;AACAQ,MAAAA,CAAC,GAAGC,gBAAgB,CAACP,UAAU,CAACI,KAAZ,CAApB;AACD;;AACD,WAAO;AACLE,MAAAA;AADK,KAAP;AAGD,GATqC,CAAtC,CAtBqB,CAiCrB;;AAEA,sBACE,uDACE,oBAAC,YAAD;AACE,IAAA,aAAa,EAAED,aADjB;AAEE,IAAA,IAAI,EAAC,aAFP;AAGE,IAAA,MAAM,EAAEb,KAHV;AAIE,IAAA,aAAa,EAAEG,UAAU,GAAG,GAAH,GAAS,CAJpC;AAKE,IAAA,WAAW,EAAED;AALf,KAMMG,KANN,EADF,CADF;AAYD","sourcesContent":["import * as React from 'react';\nimport Animated, {\n useAnimatedProps,\n useAnimatedReaction,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { Path, PathProps } from 'react-native-svg';\n\nimport { LineChartDimensionsContext } from './Chart';\nimport interpolatePath from './interpolatePath';\nimport { usePrevious } from '../../utils';\n\nconst AnimatedPath = Animated.createAnimatedComponent(Path);\n\nexport type LineChartPathProps = Animated.AnimateProps<PathProps> & {\n color?: string;\n width?: number;\n isInactive?: boolean;\n /**\n * Default: `true`.\n *\n * If `false`, changes in the chart's path will not animate.\n *\n * While this use case is rare, it may be useful on web, where animations might not work as well.\n *\n * **Example**\n *\n * ```tsx\n * <LineChart.Path\n * pathProps={{ isTransitionEnabled: Platform.OS !== 'web' }}\n * />\n * ```\n */\n isTransitionEnabled?: boolean;\n};\n\nexport function LineChartPath({\n color = 'black',\n width: strokeWidth = 3,\n isInactive,\n isTransitionEnabled = true,\n ...props\n}: LineChartPathProps) {\n const { path } = React.useContext(LineChartDimensionsContext);\n\n ////////////////////////////////////////////////\n\n const transition = useSharedValue(0);\n\n const previousPath = usePrevious(path);\n\n useAnimatedReaction(\n () => {\n return path;\n },\n (_, previous) => {\n if (previous) {\n transition.value = 0;\n transition.value = withTiming(1);\n }\n },\n [path]\n );\n\n const animatedProps = useAnimatedProps(() => {\n let d = path || '';\n if (previousPath && isTransitionEnabled) {\n const pathInterpolator = interpolatePath(previousPath, path, null);\n d = pathInterpolator(transition.value);\n }\n return {\n d,\n };\n });\n\n ////////////////////////////////////////////////\n\n return (\n <>\n <AnimatedPath\n animatedProps={animatedProps}\n fill=\"transparent\"\n stroke={color}\n strokeOpacity={isInactive ? 0.2 : 1}\n strokeWidth={strokeWidth}\n {...props}\n />\n </>\n );\n}\n"]}
1
+ {"version":3,"sources":["Path.tsx"],"names":["React","Animated","Path","LineChartDimensionsContext","LineChartPathContext","useAnimatedPath","AnimatedPath","createAnimatedComponent","LineChartPath","displayName","color","inactiveColor","width","strokeWidth","props","path","useContext","isTransitionEnabled","isInactive","animatedProps","enabled"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,QAAP,MAAqB,yBAArB;AACA,SAASC,IAAT,QAAgC,kBAAhC;AAEA,SAASC,0BAAT,QAA2C,SAA3C;AACA,SAASC,oBAAT,QAAqC,aAArC;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AAEA,MAAMC,YAAY,GAAGL,QAAQ,CAACM,uBAAT,CAAiCL,IAAjC,CAArB;AAyBAM,aAAa,CAACC,WAAd,GAA4B,eAA5B;AAEA,OAAO,SAASD,aAAT,CAAuB;AAC5BE,EAAAA,KAAK,GAAG,OADoB;AAE5BC,EAAAA,aAF4B;AAG5BC,EAAAA,KAAK,EAAEC,WAAW,GAAG,CAHO;AAI5B,KAAGC;AAJyB,CAAvB,EAKgB;AACrB,QAAM;AAAEC,IAAAA;AAAF,MAAWf,KAAK,CAACgB,UAAN,CAAiBb,0BAAjB,CAAjB;AACA,QAAM;AAAEc,IAAAA,mBAAF;AAAuBC,IAAAA;AAAvB,MACJlB,KAAK,CAACgB,UAAN,CAAiBZ,oBAAjB,CADF,CAFqB,CAKrB;;AAEA,QAAM;AAAEe,IAAAA;AAAF,MAAoBd,eAAe,CAAC;AACxCe,IAAAA,OAAO,EAAEH,mBAD+B;AAExCF,IAAAA;AAFwC,GAAD,CAAzC,CAPqB,CAYrB;;AAEA,sBACE,uDACE,oBAAC,YAAD;AACE,IAAA,aAAa,EAAEI,aADjB;AAEE,IAAA,IAAI,EAAC,aAFP;AAGE,IAAA,MAAM,EAAED,UAAU,GAAGP,aAAa,IAAID,KAApB,GAA4BA,KAHhD;AAIE,IAAA,aAAa,EAAEQ,UAAU,IAAI,CAACP,aAAf,GAA+B,GAA/B,GAAqC,CAJtD;AAKE,IAAA,WAAW,EAAEE;AALf,KAMMC,KANN,EADF,CADF;AAYD","sourcesContent":["import * as React from 'react';\nimport Animated from 'react-native-reanimated';\nimport { Path, PathProps } from 'react-native-svg';\n\nimport { LineChartDimensionsContext } from './Chart';\nimport { LineChartPathContext } from './ChartPath';\nimport useAnimatedPath from './useAnimatedPath';\n\nconst AnimatedPath = Animated.createAnimatedComponent(Path);\n\nexport type LineChartPathProps = Animated.AnimateProps<PathProps> & {\n color?: string;\n inactiveColor?: string;\n width?: number;\n isInactive?: boolean;\n /**\n * Default: `true`.\n *\n * If `false`, changes in the chart's path will not animate.\n *\n * While this use case is rare, it may be useful on web, where animations might not work as well.\n *\n * **Example**\n *\n * ```tsx\n * <LineChart.Path\n * pathProps={{ isTransitionEnabled: Platform.OS !== 'web' }}\n * />\n * ```\n */\n isTransitionEnabled?: boolean;\n};\n\nLineChartPath.displayName = 'LineChartPath';\n\nexport function LineChartPath({\n color = 'black',\n inactiveColor,\n width: strokeWidth = 3,\n ...props\n}: LineChartPathProps) {\n const { path } = React.useContext(LineChartDimensionsContext);\n const { isTransitionEnabled, isInactive } =\n React.useContext(LineChartPathContext);\n\n ////////////////////////////////////////////////\n\n const { animatedProps } = useAnimatedPath({\n enabled: isTransitionEnabled,\n path,\n });\n\n ////////////////////////////////////////////////\n\n return (\n <>\n <AnimatedPath\n animatedProps={animatedProps}\n fill=\"transparent\"\n stroke={isInactive ? inactiveColor || color : color}\n strokeOpacity={isInactive && !inactiveColor ? 0.2 : 1}\n strokeWidth={strokeWidth}\n {...props}\n />\n </>\n );\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { useLineChartPrice } from './usePrice';
3
3
  import { AnimatedText } from '../../components/AnimatedText';
4
+ LineChartPriceText.displayName = 'LineChartPriceText';
4
5
  export function LineChartPriceText({
5
6
  format,
6
7
  precision = 2,