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.
- package/README.md +143 -66
- package/lib/commonjs/charts/candle/Candle.js +92 -177
- package/lib/commonjs/charts/candle/Candles.js +39 -66
- package/lib/commonjs/charts/candle/Chart.js +26 -37
- package/lib/commonjs/charts/candle/Context.js +49 -69
- package/lib/commonjs/charts/candle/Crosshair.js +82 -183
- package/lib/commonjs/charts/candle/Crosshair.js.map +1 -1
- package/lib/commonjs/charts/candle/CrosshairTooltip.js +61 -140
- package/lib/commonjs/charts/candle/DatetimeText.js +14 -19
- package/lib/commonjs/charts/candle/Line.js +27 -73
- package/lib/commonjs/charts/candle/PriceText.js +14 -19
- package/lib/commonjs/charts/candle/index.js +64 -67
- package/lib/commonjs/charts/candle/types.js +4 -4
- package/lib/commonjs/charts/candle/useCandleData.js +12 -9
- package/lib/commonjs/charts/candle/useCandlestickChart.js +7 -9
- package/lib/commonjs/charts/candle/useDatetime.js +18 -16
- package/lib/commonjs/charts/candle/usePrice.js +22 -21
- package/lib/commonjs/charts/candle/utils/getDomain.js +9 -5
- package/lib/commonjs/charts/candle/utils/getDomain.js.map +1 -1
- package/lib/commonjs/charts/candle/utils/getHeight.js +11 -12
- package/lib/commonjs/charts/candle/utils/getHeight.js.map +1 -1
- package/lib/commonjs/charts/candle/utils/getPrice.js +11 -12
- package/lib/commonjs/charts/candle/utils/getPrice.js.map +1 -1
- package/lib/commonjs/charts/candle/utils/getY.js +11 -12
- package/lib/commonjs/charts/candle/utils/getY.js.map +1 -1
- package/lib/commonjs/charts/candle/utils/index.js +16 -16
- package/lib/commonjs/charts/line/Axis.js +148 -268
- package/lib/commonjs/charts/line/Chart.js +62 -129
- package/lib/commonjs/charts/line/Chart.js.map +1 -1
- package/lib/commonjs/charts/line/ChartPath.js +105 -285
- package/lib/commonjs/charts/line/Context.js +37 -95
- package/lib/commonjs/charts/line/Cursor.js +74 -125
- package/lib/commonjs/charts/line/Cursor.js.map +1 -1
- package/lib/commonjs/charts/line/CursorCrosshair.js +56 -134
- package/lib/commonjs/charts/line/CursorCrosshair.js.map +1 -1
- package/lib/commonjs/charts/line/CursorLine.js +67 -152
- package/lib/commonjs/charts/line/CursorLine.js.map +1 -1
- package/lib/commonjs/charts/line/Data.js +34 -73
- package/lib/commonjs/charts/line/DatetimeText.js +15 -20
- package/lib/commonjs/charts/line/Dot.js +56 -149
- package/lib/commonjs/charts/line/Gradient.js +53 -124
- package/lib/commonjs/charts/line/Group.js +23 -54
- package/lib/commonjs/charts/line/Group.js.map +1 -1
- package/lib/commonjs/charts/line/Highlight.js +47 -115
- package/lib/commonjs/charts/line/HorizontalLine.js +39 -92
- package/lib/commonjs/charts/line/HoverTrap/index.js +7 -10
- package/lib/commonjs/charts/line/HoverTrap/index.web.js +43 -48
- package/lib/commonjs/charts/line/LineChartPathContext.js +11 -14
- package/lib/commonjs/charts/line/Path.js +32 -78
- package/lib/commonjs/charts/line/PriceText.js +36 -78
- package/lib/commonjs/charts/line/Tooltip.js +102 -188
- package/lib/commonjs/charts/line/Tooltip.js.map +1 -1
- package/lib/commonjs/charts/line/index.js +65 -65
- package/lib/commonjs/charts/line/types.js +4 -4
- package/lib/commonjs/charts/line/useAnimatedPath.js +22 -27
- package/lib/commonjs/charts/line/useCurrentY.js +17 -17
- package/lib/commonjs/charts/line/useDatetime.js +28 -32
- package/lib/commonjs/charts/line/useLineChart.js +15 -20
- package/lib/commonjs/charts/line/usePrice.js +26 -28
- package/lib/commonjs/charts/line/utils/getArea.js +14 -47
- package/lib/commonjs/charts/line/utils/getDomain.js +8 -5
- package/lib/commonjs/charts/line/utils/getDomain.js.map +1 -1
- package/lib/commonjs/charts/line/utils/getPath.js +14 -53
- package/lib/commonjs/charts/line/utils/getXPositionForCurve.js +5 -8
- package/lib/commonjs/charts/line/utils/index.js +19 -19
- package/lib/commonjs/charts/line/utils/interpolatePath.js +60 -100
- package/lib/commonjs/charts/line/utils/lineChartDataPropToArray.js +5 -5
- package/lib/commonjs/components/AnimatedText.js +29 -67
- package/lib/commonjs/index.js +19 -19
- package/lib/commonjs/types.js +2 -2
- package/lib/commonjs/utils/formatDatetime.js +9 -5
- package/lib/commonjs/utils/formatPrice.js +6 -10
- package/lib/commonjs/utils/index.js +13 -13
- package/lib/commonjs/utils/usePrevious.js +6 -8
- package/lib/module/charts/candle/Candle.js +76 -126
- package/lib/module/charts/candle/Candles.js +30 -52
- package/lib/module/charts/candle/Chart.js +19 -22
- package/lib/module/charts/candle/Context.js +29 -47
- package/lib/module/charts/candle/Crosshair.js +69 -142
- package/lib/module/charts/candle/Crosshair.js.map +1 -1
- package/lib/module/charts/candle/CrosshairTooltip.js +51 -101
- package/lib/module/charts/candle/DatetimeText.js +5 -5
- package/lib/module/charts/candle/Line.js +19 -37
- package/lib/module/charts/candle/PriceText.js +5 -5
- package/lib/module/charts/candle/index.js +2 -2
- package/lib/module/charts/candle/types.js +1 -1
- package/lib/module/charts/candle/useCandleData.js +7 -3
- package/lib/module/charts/candle/useCandlestickChart.js +1 -1
- package/lib/module/charts/candle/useDatetime.js +12 -10
- package/lib/module/charts/candle/usePrice.js +14 -12
- package/lib/module/charts/candle/utils/getDomain.js +6 -2
- package/lib/module/charts/candle/utils/getDomain.js.map +1 -1
- package/lib/module/charts/candle/utils/getHeight.js +8 -9
- package/lib/module/charts/candle/utils/getHeight.js.map +1 -1
- package/lib/module/charts/candle/utils/getPrice.js +8 -4
- package/lib/module/charts/candle/utils/getPrice.js.map +1 -1
- package/lib/module/charts/candle/utils/getY.js +8 -4
- package/lib/module/charts/candle/utils/getY.js.map +1 -1
- package/lib/module/charts/candle/utils/index.js +1 -1
- package/lib/module/charts/line/Axis.js +113 -189
- package/lib/module/charts/line/Chart.js +40 -73
- package/lib/module/charts/line/Chart.js.map +1 -1
- package/lib/module/charts/line/ChartPath.js +90 -238
- package/lib/module/charts/line/Context.js +29 -61
- package/lib/module/charts/line/Cursor.js +61 -82
- package/lib/module/charts/line/Cursor.js.map +1 -1
- package/lib/module/charts/line/CursorCrosshair.js +47 -99
- package/lib/module/charts/line/CursorCrosshair.js.map +1 -1
- package/lib/module/charts/line/CursorLine.js +52 -107
- package/lib/module/charts/line/CursorLine.js.map +1 -1
- package/lib/module/charts/line/Data.js +28 -41
- package/lib/module/charts/line/DatetimeText.js +5 -5
- package/lib/module/charts/line/Dot.js +39 -93
- package/lib/module/charts/line/Gradient.js +41 -79
- package/lib/module/charts/line/Group.js +14 -15
- package/lib/module/charts/line/Group.js.map +1 -1
- package/lib/module/charts/line/Highlight.js +32 -61
- package/lib/module/charts/line/HorizontalLine.js +27 -49
- package/lib/module/charts/line/HoverTrap/index.js +2 -3
- package/lib/module/charts/line/HoverTrap/index.web.js +34 -34
- package/lib/module/charts/line/LineChartPathContext.js +3 -3
- package/lib/module/charts/line/Path.js +20 -33
- package/lib/module/charts/line/PriceText.js +25 -42
- package/lib/module/charts/line/Tooltip.js +89 -151
- package/lib/module/charts/line/Tooltip.js.map +1 -1
- package/lib/module/charts/line/index.js +2 -2
- package/lib/module/charts/line/types.js +1 -1
- package/lib/module/charts/line/useAnimatedPath.js +16 -22
- package/lib/module/charts/line/useCurrentY.js +9 -4
- package/lib/module/charts/line/useDatetime.js +22 -26
- package/lib/module/charts/line/useLineChart.js +7 -10
- package/lib/module/charts/line/usePrice.js +20 -22
- package/lib/module/charts/line/utils/getArea.js +8 -15
- package/lib/module/charts/line/utils/getDomain.js +5 -2
- package/lib/module/charts/line/utils/getDomain.js.map +1 -1
- package/lib/module/charts/line/utils/getPath.js +8 -21
- package/lib/module/charts/line/utils/getXPositionForCurve.js +2 -5
- package/lib/module/charts/line/utils/index.js +1 -1
- package/lib/module/charts/line/utils/interpolatePath.js +57 -97
- package/lib/module/charts/line/utils/lineChartDataPropToArray.js +2 -2
- package/lib/module/components/AnimatedText.js +21 -25
- package/lib/module/index.js +1 -1
- package/lib/module/types.js +2 -1
- package/lib/module/utils/formatDatetime.js +6 -2
- package/lib/module/utils/formatPrice.js +3 -7
- package/lib/module/utils/index.js +1 -1
- package/lib/module/utils/usePrevious.js +1 -1
- package/lib/typescript/src/charts/candle/Candle.d.ts +31 -45
- package/lib/typescript/src/charts/candle/Candles.d.ts +13 -24
- package/lib/typescript/src/charts/candle/Chart.d.ts +7 -12
- package/lib/typescript/src/charts/candle/Context.d.ts +7 -12
- package/lib/typescript/src/charts/candle/Crosshair.d.ts +9 -17
- package/lib/typescript/src/charts/candle/CrosshairTooltip.d.ts +8 -15
- package/lib/typescript/src/charts/candle/DatetimeText.d.ts +9 -15
- package/lib/typescript/src/charts/candle/Line.d.ts +5 -10
- package/lib/typescript/src/charts/candle/PriceText.d.ts +7 -13
- package/lib/typescript/src/charts/candle/index.d.ts +13 -32
- package/lib/typescript/src/charts/candle/types.d.ts +16 -16
- package/lib/typescript/src/charts/candle/useCandleData.d.ts +1 -1
- package/lib/typescript/src/charts/candle/useCandlestickChart.d.ts +1 -1
- package/lib/typescript/src/charts/candle/useDatetime.d.ts +9 -13
- package/lib/typescript/src/charts/candle/usePrice.d.ts +7 -11
- package/lib/typescript/src/charts/candle/utils/getDomain.d.ts +1 -1
- package/lib/typescript/src/charts/candle/utils/getDomain.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/utils/getHeight.d.ts +5 -9
- package/lib/typescript/src/charts/candle/utils/getPrice.d.ts +5 -9
- package/lib/typescript/src/charts/candle/utils/getY.d.ts +5 -9
- package/lib/typescript/src/charts/candle/utils/index.d.ts +1 -1
- package/lib/typescript/src/charts/line/Axis.d.ts +14 -27
- package/lib/typescript/src/charts/line/Chart.d.ts +23 -33
- package/lib/typescript/src/charts/line/Chart.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/ChartPath.d.ts +15 -28
- package/lib/typescript/src/charts/line/Context.d.ts +9 -16
- package/lib/typescript/src/charts/line/Cursor.d.ts +14 -22
- package/lib/typescript/src/charts/line/Cursor.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/CursorCrosshair.d.ts +11 -23
- package/lib/typescript/src/charts/line/CursorCrosshair.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/CursorLine.d.ts +9 -15
- package/lib/typescript/src/charts/line/CursorLine.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Data.d.ts +13 -17
- package/lib/typescript/src/charts/line/DatetimeText.d.ts +8 -14
- package/lib/typescript/src/charts/line/Dot.d.ts +25 -38
- package/lib/typescript/src/charts/line/Gradient.d.ts +5 -9
- package/lib/typescript/src/charts/line/Group.d.ts +3 -6
- package/lib/typescript/src/charts/line/Group.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Highlight.d.ts +9 -17
- package/lib/typescript/src/charts/line/HorizontalLine.d.ts +22 -30
- package/lib/typescript/src/charts/line/HoverTrap/index.d.ts +1 -1
- package/lib/typescript/src/charts/line/HoverTrap/index.web.d.ts +1 -1
- package/lib/typescript/src/charts/line/LineChartPathContext.d.ts +4 -4
- package/lib/typescript/src/charts/line/Path.d.ts +23 -28
- package/lib/typescript/src/charts/line/PriceText.d.ts +20 -28
- package/lib/typescript/src/charts/line/Tooltip.d.ts +20 -32
- package/lib/typescript/src/charts/line/index.d.ts +20 -33
- package/lib/typescript/src/charts/line/types.d.ts +17 -19
- package/lib/typescript/src/charts/line/useAnimatedPath.d.ts +7 -10
- package/lib/typescript/src/charts/line/useCurrentY.d.ts +2 -2
- package/lib/typescript/src/charts/line/useDatetime.d.ts +7 -11
- package/lib/typescript/src/charts/line/useLineChart.d.ts +10 -10
- package/lib/typescript/src/charts/line/usePrice.d.ts +7 -11
- package/lib/typescript/src/charts/line/utils/getArea.d.ts +9 -17
- package/lib/typescript/src/charts/line/utils/getDomain.d.ts +1 -1
- package/lib/typescript/src/charts/line/utils/getDomain.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/utils/getPath.d.ts +11 -21
- package/lib/typescript/src/charts/line/utils/getXPositionForCurve.d.ts +1 -1
- package/lib/typescript/src/charts/line/utils/index.d.ts +1 -1
- package/lib/typescript/src/charts/line/utils/interpolatePath.d.ts +5 -17
- package/lib/typescript/src/charts/line/utils/lineChartDataPropToArray.d.ts +2 -4
- package/lib/typescript/src/components/AnimatedText.d.ts +4 -7
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/types.d.ts +4 -7
- package/lib/typescript/src/utils/formatDatetime.d.ts +5 -9
- package/lib/typescript/src/utils/formatPrice.d.ts +5 -9
- package/lib/typescript/src/utils/index.d.ts +1 -1
- package/lib/typescript/src/utils/usePrevious.d.ts +1 -1
- package/package.json +1 -1
- package/src/charts/line/CursorLine.tsx +6 -2
- 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 {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
76
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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__*/
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
);
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|