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.
- package/.DS_Store +0 -0
- package/README.md +331 -196
- package/example/.DS_Store +0 -0
- package/example/src/LineChart.tsx +10 -4
- package/example/src/data/line-data.json +20 -20
- package/lib/commonjs/charts/candle/utils/getDomain.js +19 -0
- package/lib/commonjs/charts/candle/utils/getDomain.js.map +1 -0
- package/lib/commonjs/charts/candle/utils/getHeight.js +19 -0
- package/lib/commonjs/charts/candle/utils/getHeight.js.map +1 -0
- package/lib/commonjs/charts/candle/utils/getPrice.js +20 -0
- package/lib/commonjs/charts/candle/utils/getPrice.js.map +1 -0
- package/lib/commonjs/charts/candle/utils/getY.js +19 -0
- package/lib/commonjs/charts/candle/utils/getY.js.map +1 -0
- package/lib/commonjs/charts/candle/utils/index.js +58 -0
- package/lib/commonjs/charts/candle/utils/index.js.map +1 -0
- package/lib/commonjs/charts/line/Chart.js +9 -3
- package/lib/commonjs/charts/line/Chart.js.map +1 -1
- package/lib/commonjs/charts/line/ChartPath.js +73 -17
- package/lib/commonjs/charts/line/ChartPath.js.map +1 -1
- package/lib/commonjs/charts/line/Context.js +1 -0
- package/lib/commonjs/charts/line/Context.js.map +1 -1
- package/lib/commonjs/charts/line/Cursor.js +1 -0
- package/lib/commonjs/charts/line/Cursor.js.map +1 -1
- package/lib/commonjs/charts/line/CursorCrosshair.js +10 -3
- package/lib/commonjs/charts/line/CursorCrosshair.js.map +1 -1
- package/lib/commonjs/charts/line/CursorLine.js +6 -6
- package/lib/commonjs/charts/line/CursorLine.js.map +1 -1
- package/lib/commonjs/charts/line/DatetimeText.js +2 -0
- package/lib/commonjs/charts/line/DatetimeText.js.map +1 -1
- package/lib/commonjs/charts/line/Dot.js +67 -62
- package/lib/commonjs/charts/line/Dot.js.map +1 -1
- package/lib/commonjs/charts/line/Gradient.js +8 -25
- package/lib/commonjs/charts/line/Gradient.js.map +1 -1
- package/lib/commonjs/charts/line/Group.js +5 -25
- package/lib/commonjs/charts/line/Group.js.map +1 -1
- package/lib/commonjs/charts/line/Highlight.js +92 -0
- package/lib/commonjs/charts/line/Highlight.js.map +1 -0
- package/lib/commonjs/charts/line/HorizontalLine.js +6 -6
- package/lib/commonjs/charts/line/HorizontalLine.js.map +1 -1
- package/lib/commonjs/charts/line/Path.js +19 -30
- package/lib/commonjs/charts/line/Path.js.map +1 -1
- package/lib/commonjs/charts/line/PriceText.js +2 -0
- package/lib/commonjs/charts/line/PriceText.js.map +1 -1
- package/lib/commonjs/charts/line/Tooltip.js +2 -0
- package/lib/commonjs/charts/line/Tooltip.js.map +1 -1
- package/lib/commonjs/charts/line/index.js +47 -20
- package/lib/commonjs/charts/line/index.js.map +1 -1
- package/lib/commonjs/charts/line/useAnimatedPath.js +44 -0
- package/lib/commonjs/charts/line/useAnimatedPath.js.map +1 -0
- package/lib/commonjs/charts/line/{utils.js → utils/getArea.js} +2 -49
- package/lib/commonjs/charts/line/utils/getArea.js.map +1 -0
- package/lib/commonjs/charts/line/utils/getDomain.js +16 -0
- package/lib/commonjs/charts/line/utils/getDomain.js.map +1 -0
- package/lib/commonjs/charts/line/utils/getPath.js +34 -0
- package/lib/commonjs/charts/line/utils/getPath.js.map +1 -0
- package/lib/commonjs/charts/line/utils/index.js +71 -0
- package/lib/commonjs/charts/line/utils/index.js.map +1 -0
- package/lib/commonjs/charts/line/{interpolatePath.js → utils/interpolatePath.js} +1 -1
- package/lib/commonjs/charts/line/{interpolatePath.js.map → utils/interpolatePath.js.map} +1 -1
- package/lib/commonjs/charts/line/utils/lineChartDataPropToArray.js +27 -0
- package/lib/commonjs/charts/line/utils/lineChartDataPropToArray.js.map +1 -0
- package/lib/commonjs/index.js +8 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/formatDatetime.js +21 -0
- package/lib/commonjs/utils/formatDatetime.js.map +1 -0
- package/lib/commonjs/utils/formatPrice.js +46 -0
- package/lib/commonjs/utils/formatPrice.js.map +1 -0
- package/lib/commonjs/utils/index.js +45 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/commonjs/{utils.js → utils/usePrevious.js} +1 -57
- package/lib/commonjs/utils/usePrevious.js.map +1 -0
- package/lib/module/charts/candle/utils/getDomain.js +12 -0
- package/lib/module/charts/candle/utils/getDomain.js.map +1 -0
- package/lib/module/charts/candle/utils/getHeight.js +11 -0
- package/lib/module/charts/candle/utils/getHeight.js.map +1 -0
- package/lib/module/charts/candle/utils/getPrice.js +12 -0
- package/lib/module/charts/candle/utils/getPrice.js.map +1 -0
- package/lib/module/charts/candle/utils/getY.js +11 -0
- package/lib/module/charts/candle/utils/getY.js.map +1 -0
- package/lib/module/charts/candle/utils/index.js +5 -0
- package/lib/module/charts/candle/utils/index.js.map +1 -0
- package/lib/module/charts/line/Chart.js +9 -4
- package/lib/module/charts/line/Chart.js.map +1 -1
- package/lib/module/charts/line/ChartPath.js +69 -17
- package/lib/module/charts/line/ChartPath.js.map +1 -1
- package/lib/module/charts/line/Context.js +1 -0
- package/lib/module/charts/line/Context.js.map +1 -1
- package/lib/module/charts/line/Cursor.js +1 -0
- package/lib/module/charts/line/Cursor.js.map +1 -1
- package/lib/module/charts/line/CursorCrosshair.js +10 -4
- package/lib/module/charts/line/CursorCrosshair.js.map +1 -1
- package/lib/module/charts/line/CursorLine.js +4 -3
- package/lib/module/charts/line/CursorLine.js.map +1 -1
- package/lib/module/charts/line/DatetimeText.js +1 -0
- package/lib/module/charts/line/DatetimeText.js.map +1 -1
- package/lib/module/charts/line/Dot.js +66 -63
- package/lib/module/charts/line/Dot.js.map +1 -1
- package/lib/module/charts/line/Gradient.js +8 -24
- package/lib/module/charts/line/Gradient.js.map +1 -1
- package/lib/module/charts/line/Group.js +2 -24
- package/lib/module/charts/line/Group.js.map +1 -1
- package/lib/module/charts/line/Highlight.js +69 -0
- package/lib/module/charts/line/Highlight.js.map +1 -0
- package/lib/module/charts/line/HorizontalLine.js +4 -3
- package/lib/module/charts/line/HorizontalLine.js.map +1 -1
- package/lib/module/charts/line/Path.js +17 -29
- package/lib/module/charts/line/Path.js.map +1 -1
- package/lib/module/charts/line/PriceText.js +1 -0
- package/lib/module/charts/line/PriceText.js.map +1 -1
- package/lib/module/charts/line/Tooltip.js +1 -0
- package/lib/module/charts/line/Tooltip.js.map +1 -1
- package/lib/module/charts/line/index.js +12 -8
- package/lib/module/charts/line/index.js.map +1 -1
- package/lib/module/charts/line/useAnimatedPath.js +34 -0
- package/lib/module/charts/line/useAnimatedPath.js.map +1 -0
- package/lib/module/charts/line/utils/getArea.js +19 -0
- package/lib/module/charts/line/utils/getArea.js.map +1 -0
- package/lib/module/charts/line/utils/getDomain.js +9 -0
- package/lib/module/charts/line/utils/getDomain.js.map +1 -0
- package/lib/module/charts/line/utils/getPath.js +21 -0
- package/lib/module/charts/line/utils/getPath.js.map +1 -0
- package/lib/module/charts/line/utils/index.js +6 -0
- package/lib/module/charts/line/utils/index.js.map +1 -0
- package/lib/module/charts/line/{interpolatePath.js → utils/interpolatePath.js} +1 -1
- package/lib/module/charts/line/{interpolatePath.js.map → utils/interpolatePath.js.map} +1 -1
- package/lib/module/charts/line/utils/lineChartDataPropToArray.js +20 -0
- package/lib/module/charts/line/utils/lineChartDataPropToArray.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/formatDatetime.js +14 -0
- package/lib/module/utils/formatDatetime.js.map +1 -0
- package/lib/module/{utils.js → utils/formatPrice.js} +1 -29
- package/lib/module/utils/formatPrice.js.map +1 -0
- package/lib/module/utils/index.js +4 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/module/utils/usePrevious.js +14 -0
- package/lib/module/utils/usePrevious.js.map +1 -0
- package/lib/typescript/src/charts/candle/utils/getDomain.d.ts +2 -0
- package/lib/typescript/src/charts/candle/utils/getHeight.d.ts +6 -0
- package/lib/typescript/src/charts/candle/utils/getPrice.d.ts +6 -0
- package/lib/typescript/src/charts/candle/utils/getY.d.ts +6 -0
- package/lib/typescript/src/charts/candle/utils/index.d.ts +4 -0
- package/lib/typescript/src/charts/line/Chart.d.ts +5 -1
- package/lib/typescript/src/charts/line/ChartPath.d.ts +10 -1
- package/lib/typescript/src/charts/line/Context.d.ts +3 -0
- package/lib/typescript/src/charts/line/Cursor.d.ts +3 -0
- package/lib/typescript/src/charts/line/CursorCrosshair.d.ts +4 -1
- package/lib/typescript/src/charts/line/CursorLine.d.ts +4 -1
- package/lib/typescript/src/charts/line/DatetimeText.d.ts +3 -0
- package/lib/typescript/src/charts/line/Dot.d.ts +10 -7
- package/lib/typescript/src/charts/line/Gradient.d.ts +3 -0
- package/lib/typescript/src/charts/line/Group.d.ts +1 -2
- package/lib/typescript/src/charts/line/Highlight.d.ts +15 -0
- package/lib/typescript/src/charts/line/HorizontalLine.d.ts +4 -1
- package/lib/typescript/src/charts/line/Path.d.ts +5 -1
- package/lib/typescript/src/charts/line/PriceText.d.ts +3 -0
- package/lib/typescript/src/charts/line/Tooltip.d.ts +3 -0
- package/lib/typescript/src/charts/line/index.d.ts +15 -25
- package/lib/typescript/src/charts/line/useAnimatedPath.d.ts +8 -0
- package/lib/typescript/src/charts/line/utils/getArea.d.ts +9 -0
- package/lib/typescript/src/charts/line/utils/getDomain.d.ts +2 -0
- package/lib/typescript/src/charts/line/utils/getPath.d.ts +11 -0
- package/lib/typescript/src/charts/line/utils/index.d.ts +5 -0
- package/lib/typescript/src/charts/line/{interpolatePath.d.ts → utils/interpolatePath.d.ts} +1 -1
- package/lib/typescript/src/charts/line/utils/lineChartDataPropToArray.d.ts +2 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/utils/formatDatetime.d.ts +8 -0
- package/lib/typescript/src/utils/formatPrice.d.ts +8 -0
- package/lib/typescript/src/utils/index.d.ts +3 -0
- package/lib/typescript/src/utils/usePrevious.d.ts +1 -0
- package/package.json +4 -2
- package/src/charts/candle/utils/getDomain.ts +9 -0
- package/src/charts/candle/utils/getHeight.ts +21 -0
- package/src/charts/candle/utils/getPrice.ts +17 -0
- package/src/charts/candle/utils/getY.ts +16 -0
- package/src/charts/candle/utils/index.ts +4 -0
- package/src/charts/line/Chart.tsx +9 -3
- package/src/charts/line/ChartPath.tsx +109 -33
- package/src/charts/line/Context.tsx +2 -0
- package/src/charts/line/Cursor.tsx +2 -0
- package/src/charts/line/CursorCrosshair.tsx +20 -5
- package/src/charts/line/CursorLine.tsx +5 -3
- package/src/charts/line/DatetimeText.tsx +2 -0
- package/src/charts/line/Dot.tsx +83 -86
- package/src/charts/line/Gradient.tsx +7 -34
- package/src/charts/line/Group.tsx +4 -47
- package/src/charts/line/Highlight.tsx +78 -0
- package/src/charts/line/HorizontalLine.tsx +5 -3
- package/src/charts/line/Path.tsx +14 -38
- package/src/charts/line/PriceText.tsx +2 -0
- package/src/charts/line/Tooltip.tsx +2 -0
- package/src/charts/line/index.ts +11 -7
- package/src/charts/line/useAnimatedPath.ts +47 -0
- package/src/charts/line/utils/getArea.ts +38 -0
- package/src/charts/line/utils/getDomain.ts +7 -0
- package/src/charts/line/utils/getPath.ts +48 -0
- package/src/charts/line/utils/index.ts +5 -0
- package/src/charts/line/{interpolatePath.ts → utils/interpolatePath.ts} +1 -1
- package/src/charts/line/utils/lineChartDataPropToArray.ts +25 -0
- package/src/index.ts +1 -1
- package/src/utils/formatDatetime.ts +16 -0
- package/src/{utils.ts → utils/formatPrice.ts} +0 -31
- package/src/utils/index.ts +3 -0
- package/src/utils/usePrevious.ts +13 -0
- package/yarn.lock +8 -1
- package/lib/commonjs/charts/line/utils.js.map +0 -1
- package/lib/commonjs/utils.js.map +0 -1
- package/lib/module/charts/line/utils.js +0 -60
- package/lib/module/charts/line/utils.js.map +0 -1
- package/lib/module/utils.js.map +0 -1
- package/lib/typescript/src/charts/line/utils.d.ts +0 -20
- package/lib/typescript/src/utils.d.ts +0 -17
- 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,
|
|
5
|
-
import {
|
|
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
|
-
|
|
15
|
-
pulsesOuter = 'while-inactive',
|
|
16
|
-
outerSize = size * 4,
|
|
14
|
+
color: defaultColor = 'black',
|
|
17
15
|
dotProps,
|
|
18
|
-
|
|
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
|
-
|
|
29
|
-
const
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 (
|
|
45
|
-
return
|
|
46
|
-
|
|
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:
|
|
74
|
+
duration: pulseDurationMs,
|
|
54
75
|
easing
|
|
55
76
|
})), -1, false);
|
|
56
|
-
const scale = withRepeat(withSequence(withTiming(0), withTiming(
|
|
57
|
-
duration:
|
|
77
|
+
const scale = withRepeat(withSequence(withTiming(0), withTiming(outerSize, {
|
|
78
|
+
duration: pulseDurationMs,
|
|
58
79
|
easing
|
|
59
80
|
})), -1, false);
|
|
60
81
|
|
|
61
|
-
if (
|
|
62
|
-
return {
|
|
82
|
+
if (pulseBehaviour === 'while-inactive') {
|
|
83
|
+
return { ...defaultProps,
|
|
63
84
|
opacity: isActive.value ? withTiming(0) : animatedOpacity,
|
|
64
|
-
|
|
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
|
-
|
|
73
|
-
scale
|
|
74
|
-
}]
|
|
91
|
+
r: scale
|
|
75
92
|
};
|
|
76
|
-
}, [
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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","
|
|
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","animat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CAvD2C,CAA9C,CAvCoB,CAgGpB;;AAEA,sBACE,uDACE,oBAAC,cAAD;AACE,IAAA,aAAa,EAAEiB,gBADjB;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
|
|
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
|
|
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
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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","
|
|
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,iBAAT,CAA2B;AAChCE,EAAAA,KAAK,EAAEC,aAAa,GAAGC,SADS;AAEhCC,EAAAA,QAFgC;AAGhC,KAAGC;AAH6B,CAA3B,EAIoB;AACzB,QAAM;AAAEC,IAAAA;AAAF,MAAWnB,KAAK,CAACoB,UAAN,CAAiBd,0BAAjB,CAAjB;AACA,QAAM;AAAEQ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AnD,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
|
-
|
|
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","
|
|
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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,CAAzC,CA3BsB,CAgCtB;;AAEA,sBACE,uDACE,oBAAC,YAAD;AACE,IAAA,aAAa,EAAEG,aADjB;AAEE,IAAA,IAAI,EAAC,aAFP;AAGE,IAAA,MAAM,EAAEL,UAAU,GAAGf,aAAa,IAAID,KAApB,GAA4BA,KAHhD;AAIE,IAAA,WAAW,EAAEM,WAJf;AAKE,IAAA,aAAa,EAAEU,UAAU,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
|
-
|
|
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;
|
|
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;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA,MAAMC,YAAY,GAAGV,QAAQ,CAACW,uBAAT,CAAiCN,OAAjC,CAArB;AAmCAO,uBAAuB,CAACC,WAAxB,GAAsC,yBAAtC;AAEA,OAAO,SAASD,uBAAT,CAAiC;AACtCE,EAAAA,KAAK,GAAG,MAD8B;AAEtCC,EAAAA,SAAS,GAAG,EAF0B;AAGtCC,EAAAA,EAAE,GAAG;AAAEC,IAAAA,KAAK,EAAE;AAAT,GAHiC;AAItCC,EAAAA,OAAO,GAAG;AAJ4B,CAAjC,EAKiB;AACtB,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA,IAAT;AAAeC,IAAAA,MAAf;AAAuBC,IAAAA;A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AGtC,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
|
|
4
|
+
import Animated from 'react-native-reanimated';
|
|
5
5
|
import { Path } from 'react-native-svg';
|
|
6
6
|
import { LineChartDimensionsContext } from './Chart';
|
|
7
|
-
import
|
|
8
|
-
import
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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","
|
|
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,
|