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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import Animated from 'react-native-reanimated';
|
|
3
|
+
import { Path, PathProps } from 'react-native-svg';
|
|
4
|
+
|
|
5
|
+
import { LineChartDimensionsContext } from './Chart';
|
|
6
|
+
import { LineChartPathContext } from './ChartPath';
|
|
7
|
+
import useAnimatedPath from './useAnimatedPath';
|
|
8
|
+
import { useLineChart } from './useLineChart';
|
|
9
|
+
import { getPath } from './utils';
|
|
10
|
+
|
|
11
|
+
const AnimatedPath = Animated.createAnimatedComponent(Path);
|
|
12
|
+
|
|
13
|
+
export type LineChartColorProps = Animated.AnimateProps<PathProps> & {
|
|
14
|
+
color?: string;
|
|
15
|
+
from: number;
|
|
16
|
+
to: number;
|
|
17
|
+
showInactiveColor?: boolean;
|
|
18
|
+
inactiveColor?: string;
|
|
19
|
+
width?: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
LineChartHighlight.displayName = 'LineChartHighlight';
|
|
23
|
+
|
|
24
|
+
export function LineChartHighlight({
|
|
25
|
+
color = 'black',
|
|
26
|
+
inactiveColor,
|
|
27
|
+
showInactiveColor = true,
|
|
28
|
+
from,
|
|
29
|
+
to,
|
|
30
|
+
width: strokeWidth = 3,
|
|
31
|
+
...props
|
|
32
|
+
}: LineChartColorProps) {
|
|
33
|
+
const { data, yDomain } = useLineChart();
|
|
34
|
+
const { pathWidth, height, gutter, shape } = React.useContext(
|
|
35
|
+
LineChartDimensionsContext
|
|
36
|
+
);
|
|
37
|
+
const { isTransitionEnabled, isInactive: _isInactive } =
|
|
38
|
+
React.useContext(LineChartPathContext);
|
|
39
|
+
const isInactive = showInactiveColor && _isInactive;
|
|
40
|
+
|
|
41
|
+
////////////////////////////////////////////////
|
|
42
|
+
|
|
43
|
+
const path = React.useMemo(() => {
|
|
44
|
+
if (data && data.length > 0) {
|
|
45
|
+
return getPath({
|
|
46
|
+
data,
|
|
47
|
+
from,
|
|
48
|
+
to,
|
|
49
|
+
width: pathWidth,
|
|
50
|
+
height,
|
|
51
|
+
gutter,
|
|
52
|
+
shape,
|
|
53
|
+
yDomain,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return '';
|
|
57
|
+
}, [data, from, to, pathWidth, height, gutter, shape, yDomain]);
|
|
58
|
+
|
|
59
|
+
const { animatedProps } = useAnimatedPath({
|
|
60
|
+
enabled: isTransitionEnabled,
|
|
61
|
+
path,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
////////////////////////////////////////////////
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
<AnimatedPath
|
|
69
|
+
animatedProps={animatedProps}
|
|
70
|
+
fill="transparent"
|
|
71
|
+
stroke={isInactive ? inactiveColor || color : color}
|
|
72
|
+
strokeWidth={strokeWidth}
|
|
73
|
+
strokeOpacity={isInactive && !inactiveColor ? 0.5 : 1}
|
|
74
|
+
{...props}
|
|
75
|
+
/>
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -45,12 +45,14 @@ type HorizontalLineProps = {
|
|
|
45
45
|
| number;
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
LineChartHorizontalLine.displayName = 'LineChartHorizontalLine';
|
|
49
|
+
|
|
50
|
+
export function LineChartHorizontalLine({
|
|
49
51
|
color = 'gray',
|
|
50
52
|
lineProps = {},
|
|
51
53
|
at = { index: 0 },
|
|
52
54
|
offsetY = 0,
|
|
53
|
-
}: HorizontalLineProps)
|
|
55
|
+
}: HorizontalLineProps) {
|
|
54
56
|
const { width, path, height, gutter } = React.useContext(
|
|
55
57
|
LineChartDimensionsContext
|
|
56
58
|
);
|
|
@@ -104,4 +106,4 @@ export const LineChartHorizontalLine = ({
|
|
|
104
106
|
{...lineProps}
|
|
105
107
|
/>
|
|
106
108
|
);
|
|
107
|
-
}
|
|
109
|
+
}
|
package/src/charts/line/Path.tsx
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import Animated
|
|
3
|
-
useAnimatedProps,
|
|
4
|
-
useAnimatedReaction,
|
|
5
|
-
useSharedValue,
|
|
6
|
-
withTiming,
|
|
7
|
-
} from 'react-native-reanimated';
|
|
2
|
+
import Animated from 'react-native-reanimated';
|
|
8
3
|
import { Path, PathProps } from 'react-native-svg';
|
|
9
4
|
|
|
10
5
|
import { LineChartDimensionsContext } from './Chart';
|
|
11
|
-
import
|
|
12
|
-
import
|
|
6
|
+
import { LineChartPathContext } from './ChartPath';
|
|
7
|
+
import useAnimatedPath from './useAnimatedPath';
|
|
13
8
|
|
|
14
9
|
const AnimatedPath = Animated.createAnimatedComponent(Path);
|
|
15
10
|
|
|
16
11
|
export type LineChartPathProps = Animated.AnimateProps<PathProps> & {
|
|
17
12
|
color?: string;
|
|
13
|
+
inactiveColor?: string;
|
|
18
14
|
width?: number;
|
|
19
15
|
isInactive?: boolean;
|
|
20
16
|
/**
|
|
@@ -35,43 +31,23 @@ export type LineChartPathProps = Animated.AnimateProps<PathProps> & {
|
|
|
35
31
|
isTransitionEnabled?: boolean;
|
|
36
32
|
};
|
|
37
33
|
|
|
34
|
+
LineChartPath.displayName = 'LineChartPath';
|
|
35
|
+
|
|
38
36
|
export function LineChartPath({
|
|
39
37
|
color = 'black',
|
|
38
|
+
inactiveColor,
|
|
40
39
|
width: strokeWidth = 3,
|
|
41
|
-
isInactive,
|
|
42
|
-
isTransitionEnabled = true,
|
|
43
40
|
...props
|
|
44
41
|
}: LineChartPathProps) {
|
|
45
42
|
const { path } = React.useContext(LineChartDimensionsContext);
|
|
43
|
+
const { isTransitionEnabled, isInactive } =
|
|
44
|
+
React.useContext(LineChartPathContext);
|
|
46
45
|
|
|
47
46
|
////////////////////////////////////////////////
|
|
48
47
|
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
useAnimatedReaction(
|
|
54
|
-
() => {
|
|
55
|
-
return path;
|
|
56
|
-
},
|
|
57
|
-
(_, previous) => {
|
|
58
|
-
if (previous) {
|
|
59
|
-
transition.value = 0;
|
|
60
|
-
transition.value = withTiming(1);
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
[path]
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const animatedProps = useAnimatedProps(() => {
|
|
67
|
-
let d = path || '';
|
|
68
|
-
if (previousPath && isTransitionEnabled) {
|
|
69
|
-
const pathInterpolator = interpolatePath(previousPath, path, null);
|
|
70
|
-
d = pathInterpolator(transition.value);
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
d,
|
|
74
|
-
};
|
|
48
|
+
const { animatedProps } = useAnimatedPath({
|
|
49
|
+
enabled: isTransitionEnabled,
|
|
50
|
+
path,
|
|
75
51
|
});
|
|
76
52
|
|
|
77
53
|
////////////////////////////////////////////////
|
|
@@ -81,8 +57,8 @@ export function LineChartPath({
|
|
|
81
57
|
<AnimatedPath
|
|
82
58
|
animatedProps={animatedProps}
|
|
83
59
|
fill="transparent"
|
|
84
|
-
stroke={color}
|
|
85
|
-
strokeOpacity={isInactive ? 0.2 : 1}
|
|
60
|
+
stroke={isInactive ? inactiveColor || color : color}
|
|
61
|
+
strokeOpacity={isInactive && !inactiveColor ? 0.2 : 1}
|
|
86
62
|
strokeWidth={strokeWidth}
|
|
87
63
|
{...props}
|
|
88
64
|
/>
|
package/src/charts/line/index.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { LineChartGradient } from './Gradient';
|
|
2
1
|
import { LineChart as _LineChart } from './Chart';
|
|
3
2
|
import { LineChartPathWrapper } from './ChartPath';
|
|
3
|
+
import { LineChartHighlight } from './Highlight';
|
|
4
4
|
import { LineChartProvider } from './Context';
|
|
5
5
|
import { LineChartCursor } from './Cursor';
|
|
6
6
|
import { LineChartCursorCrosshair } from './CursorCrosshair';
|
|
7
7
|
import { LineChartCursorLine } from './CursorLine';
|
|
8
|
+
import { LineChartDot } from './Dot';
|
|
9
|
+
import { LineChartGradient } from './Gradient';
|
|
10
|
+
import { LineChartGroup } from './Group';
|
|
8
11
|
import { LineChartHorizontalLine } from './HorizontalLine';
|
|
9
12
|
import { LineChartTooltip } from './Tooltip';
|
|
10
13
|
import { LineChartPriceText } from './PriceText';
|
|
@@ -12,16 +15,16 @@ import { LineChartDatetimeText } from './DatetimeText';
|
|
|
12
15
|
import { useLineChartDatetime } from './useDatetime';
|
|
13
16
|
import { useLineChartPrice } from './usePrice';
|
|
14
17
|
import { useLineChart } from './useLineChart';
|
|
15
|
-
import { LineChartGroup } from './Group';
|
|
16
|
-
import { LineChartDot } from './Dot';
|
|
17
18
|
|
|
18
|
-
export * from './Gradient';
|
|
19
19
|
export * from './Chart';
|
|
20
20
|
export * from './ChartPath';
|
|
21
|
+
export * from './Highlight';
|
|
21
22
|
export * from './Context';
|
|
22
23
|
export * from './Cursor';
|
|
23
24
|
export * from './CursorCrosshair';
|
|
24
25
|
export * from './CursorLine';
|
|
26
|
+
export * from './Dot';
|
|
27
|
+
export * from './Gradient';
|
|
25
28
|
export * from './Tooltip';
|
|
26
29
|
export * from './DatetimeText';
|
|
27
30
|
export * from './Path';
|
|
@@ -32,12 +35,15 @@ export * from './usePrice';
|
|
|
32
35
|
export * from './types';
|
|
33
36
|
|
|
34
37
|
export const LineChart = Object.assign(_LineChart, {
|
|
35
|
-
Gradient: LineChartGradient,
|
|
36
38
|
Chart: _LineChart,
|
|
39
|
+
Dot: LineChartDot,
|
|
37
40
|
Path: LineChartPathWrapper,
|
|
38
41
|
Cursor: LineChartCursor,
|
|
39
42
|
CursorCrosshair: LineChartCursorCrosshair,
|
|
40
43
|
CursorLine: LineChartCursorLine,
|
|
44
|
+
Gradient: LineChartGradient,
|
|
45
|
+
Group: LineChartGroup,
|
|
46
|
+
Highlight: LineChartHighlight,
|
|
41
47
|
HorizontalLine: LineChartHorizontalLine,
|
|
42
48
|
Tooltip: LineChartTooltip,
|
|
43
49
|
Provider: LineChartProvider,
|
|
@@ -46,6 +52,4 @@ export const LineChart = Object.assign(_LineChart, {
|
|
|
46
52
|
useDatetime: useLineChartDatetime,
|
|
47
53
|
usePrice: useLineChartPrice,
|
|
48
54
|
useChart: useLineChart,
|
|
49
|
-
Group: LineChartGroup,
|
|
50
|
-
Dot: LineChartDot,
|
|
51
55
|
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useAnimatedProps,
|
|
3
|
+
useAnimatedReaction,
|
|
4
|
+
useSharedValue,
|
|
5
|
+
withTiming,
|
|
6
|
+
} from 'react-native-reanimated';
|
|
7
|
+
|
|
8
|
+
import { usePrevious } from '../../utils';
|
|
9
|
+
import { interpolatePath } from './utils';
|
|
10
|
+
|
|
11
|
+
export default function useAnimatedPath({
|
|
12
|
+
enabled = true,
|
|
13
|
+
path,
|
|
14
|
+
}: {
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
path: string;
|
|
17
|
+
}) {
|
|
18
|
+
const transition = useSharedValue(0);
|
|
19
|
+
|
|
20
|
+
const previousPath = usePrevious(path);
|
|
21
|
+
|
|
22
|
+
useAnimatedReaction(
|
|
23
|
+
() => {
|
|
24
|
+
return path;
|
|
25
|
+
},
|
|
26
|
+
(_, previous) => {
|
|
27
|
+
if (previous) {
|
|
28
|
+
transition.value = 0;
|
|
29
|
+
transition.value = withTiming(1);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
[path]
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const animatedProps = useAnimatedProps(() => {
|
|
36
|
+
let d = path || '';
|
|
37
|
+
if (previousPath && enabled) {
|
|
38
|
+
const pathInterpolator = interpolatePath(previousPath, path, null);
|
|
39
|
+
d = pathInterpolator(transition.value);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
d,
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return { animatedProps };
|
|
47
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import * as shape from 'd3-shape';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import { scaleLinear } from 'd3-scale';
|
|
5
|
+
|
|
6
|
+
import type { TLineChartData, YDomain } from '../types';
|
|
7
|
+
|
|
8
|
+
export function getArea({
|
|
9
|
+
data,
|
|
10
|
+
width,
|
|
11
|
+
height,
|
|
12
|
+
gutter,
|
|
13
|
+
shape: _shape,
|
|
14
|
+
yDomain,
|
|
15
|
+
}: {
|
|
16
|
+
data: TLineChartData;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
gutter: number;
|
|
20
|
+
shape?: unknown;
|
|
21
|
+
yDomain: YDomain;
|
|
22
|
+
}): string {
|
|
23
|
+
const timestamps = data.map((_, i) => i);
|
|
24
|
+
|
|
25
|
+
const scaleX = scaleLinear()
|
|
26
|
+
.domain([Math.min(...timestamps), Math.max(...timestamps)])
|
|
27
|
+
.range([0, width]);
|
|
28
|
+
const scaleY = scaleLinear()
|
|
29
|
+
.domain([yDomain.min, yDomain.max])
|
|
30
|
+
.range([height - gutter, gutter]);
|
|
31
|
+
const area = shape
|
|
32
|
+
.area()
|
|
33
|
+
.x((_: unknown, i: number) => scaleX(i))
|
|
34
|
+
.y0((d: { value: unknown }) => scaleY(d.value))
|
|
35
|
+
.y1(() => height)
|
|
36
|
+
.curve(_shape)(data);
|
|
37
|
+
return area;
|
|
38
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import * as shape from 'd3-shape';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import { scaleLinear } from 'd3-scale';
|
|
5
|
+
|
|
6
|
+
import type { TLineChartData, YDomain } from '../types';
|
|
7
|
+
|
|
8
|
+
export function getPath({
|
|
9
|
+
data,
|
|
10
|
+
from,
|
|
11
|
+
to,
|
|
12
|
+
width,
|
|
13
|
+
height,
|
|
14
|
+
gutter,
|
|
15
|
+
shape: _shape,
|
|
16
|
+
yDomain,
|
|
17
|
+
}: {
|
|
18
|
+
data: TLineChartData;
|
|
19
|
+
from?: number;
|
|
20
|
+
to?: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
gutter: number;
|
|
24
|
+
shape?: unknown;
|
|
25
|
+
yDomain: YDomain;
|
|
26
|
+
}): string {
|
|
27
|
+
const timestamps = data.map((_, i) => i);
|
|
28
|
+
|
|
29
|
+
const scaleX = scaleLinear()
|
|
30
|
+
.domain([Math.min(...timestamps), Math.max(...timestamps)])
|
|
31
|
+
.range([0, width]);
|
|
32
|
+
const scaleY = scaleLinear()
|
|
33
|
+
.domain([yDomain.min, yDomain.max])
|
|
34
|
+
.range([height - gutter, gutter]);
|
|
35
|
+
const path = shape
|
|
36
|
+
.line()
|
|
37
|
+
.defined((d: { timestamp: number }) =>
|
|
38
|
+
from || to
|
|
39
|
+
? data
|
|
40
|
+
.slice(from, to ? to + 1 : undefined)
|
|
41
|
+
.find((item) => item.timestamp === d.timestamp)
|
|
42
|
+
: true
|
|
43
|
+
)
|
|
44
|
+
.x((_: unknown, i: number) => scaleX(i))
|
|
45
|
+
.y((d: { value: number }) => scaleY(d.value))
|
|
46
|
+
.curve(_shape)(data);
|
|
47
|
+
return path;
|
|
48
|
+
}
|
|
@@ -608,7 +608,7 @@ export function interpolatePathCommands(
|
|
|
608
608
|
* end command object and returns true if the segment should be excluded from splitting.
|
|
609
609
|
* @returns {Function} Interpolation function that maps t ([0, 1]) to a path `d` string.
|
|
610
610
|
*/
|
|
611
|
-
export
|
|
611
|
+
export function interpolatePath(a, b, excludeSegment) {
|
|
612
612
|
'worklet';
|
|
613
613
|
|
|
614
614
|
let aCommands = pathCommandsFromString(a);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { TLineChartData, TLineChartDataProp } from '../types';
|
|
2
|
+
|
|
3
|
+
export function lineChartDataPropToArray(
|
|
4
|
+
dataProp: TLineChartDataProp
|
|
5
|
+
): TLineChartData {
|
|
6
|
+
'worklet';
|
|
7
|
+
|
|
8
|
+
if (!dataProp) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (Array.isArray(dataProp)) {
|
|
13
|
+
return dataProp;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const data: TLineChartData = [];
|
|
17
|
+
|
|
18
|
+
Object.values(dataProp).forEach((dataSet) => {
|
|
19
|
+
if (dataSet) {
|
|
20
|
+
data.push(...dataSet);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return data;
|
|
25
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @worklet
|
|
3
|
+
*/
|
|
4
|
+
export function formatDatetime({
|
|
5
|
+
value,
|
|
6
|
+
locale = 'en-US',
|
|
7
|
+
options = {},
|
|
8
|
+
}: {
|
|
9
|
+
value: number;
|
|
10
|
+
locale?: string;
|
|
11
|
+
options?: Intl.DateTimeFormatOptions;
|
|
12
|
+
}) {
|
|
13
|
+
'worklet';
|
|
14
|
+
const d = new Date(value);
|
|
15
|
+
return d.toLocaleString(locale, options);
|
|
16
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @worklet
|
|
5
3
|
*/
|
|
@@ -40,32 +38,3 @@ export function formatPrice({
|
|
|
40
38
|
}
|
|
41
39
|
return res;
|
|
42
40
|
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @worklet
|
|
46
|
-
*/
|
|
47
|
-
export function formatDatetime({
|
|
48
|
-
value,
|
|
49
|
-
locale = 'en-US',
|
|
50
|
-
options = {},
|
|
51
|
-
}: {
|
|
52
|
-
value: number;
|
|
53
|
-
locale?: string;
|
|
54
|
-
options?: Intl.DateTimeFormatOptions;
|
|
55
|
-
}) {
|
|
56
|
-
'worklet';
|
|
57
|
-
const d = new Date(value);
|
|
58
|
-
return d.toLocaleString(locale, options);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function usePrevious<T>(value: T) {
|
|
62
|
-
// The ref object is a generic container whose current property is mutable ...
|
|
63
|
-
// ... and can hold any value, similar to an instance property on a class
|
|
64
|
-
const ref = React.useRef<T>();
|
|
65
|
-
// Store current value in ref
|
|
66
|
-
React.useEffect(() => {
|
|
67
|
-
ref.current = value;
|
|
68
|
-
}, [value]); // Only re-run if value changes
|
|
69
|
-
// Return previous value (happens before update in useEffect above)
|
|
70
|
-
return ref.current;
|
|
71
|
-
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
export function usePrevious<T>(value: T) {
|
|
4
|
+
// The ref object is a generic container whose current property is mutable ...
|
|
5
|
+
// ... and can hold any value, similar to an instance property on a class
|
|
6
|
+
const ref = React.useRef<T>();
|
|
7
|
+
// Store current value in ref
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
ref.current = value;
|
|
10
|
+
}, [value]); // Only re-run if value changes
|
|
11
|
+
// Return previous value (happens before update in useEffect above)
|
|
12
|
+
return ref.current;
|
|
13
|
+
}
|
package/yarn.lock
CHANGED
|
@@ -6158,7 +6158,7 @@ react-devtools-core@^4.6.0:
|
|
|
6158
6158
|
shell-quote "^1.6.1"
|
|
6159
6159
|
ws "^7"
|
|
6160
6160
|
|
|
6161
|
-
react-is@^16.7.0, react-is@^16.8.1:
|
|
6161
|
+
react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.6:
|
|
6162
6162
|
version "16.13.1"
|
|
6163
6163
|
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
|
|
6164
6164
|
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
|
|
@@ -6168,6 +6168,13 @@ react-is@^17.0.1:
|
|
|
6168
6168
|
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
|
|
6169
6169
|
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
|
|
6170
6170
|
|
|
6171
|
+
react-keyed-flatten-children@^1.3.0:
|
|
6172
|
+
version "1.3.0"
|
|
6173
|
+
resolved "https://registry.yarnpkg.com/react-keyed-flatten-children/-/react-keyed-flatten-children-1.3.0.tgz#38d171582c6358909f430648a7a7d094aebae42a"
|
|
6174
|
+
integrity sha512-qB7A6n+NHU0x88qTZGAJw6dsqwI941jcRPBB640c/CyWqjPQQ+YUmXOuzPziuHb7iqplM3xksWAbGYwkQT0tXA==
|
|
6175
|
+
dependencies:
|
|
6176
|
+
react-is "^16.8.6"
|
|
6177
|
+
|
|
6171
6178
|
react-native-builder-bob@^0.18.1:
|
|
6172
6179
|
version "0.18.1"
|
|
6173
6180
|
resolved "https://registry.yarnpkg.com/react-native-builder-bob/-/react-native-builder-bob-0.18.1.tgz#43f238e6cb6efffa6e3d23ac449eb7392650c2c3"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["utils.ts"],"names":["getDomain","rows","values","map","value","Math","min","max","lineChartDataPropToArray","dataProp","Array","isArray","data","Object","forEach","dataSet","push","getPath","width","height","gutter","shape","_shape","curveBumpX","yDomain","timestamps","_","i","scaleX","domain","range","scaleY","path","line","x","y","d","curve","getArea","area","y0","y1"],"mappings":";;;;;;;;;;AACA;;AAEA;;;;;;AAHA;AAEA;AAMO,SAASA,SAAT,CAAmBC,IAAnB,EAA8D;AACnE;;AACA,QAAMC,MAAM,GAAGD,IAAI,CAACE,GAAL,CAAS,CAAC;AAAEC,IAAAA;AAAF,GAAD,KAAeA,KAAxB,CAAf;AACA,SAAO,CAACC,IAAI,CAACC,GAAL,CAAS,GAA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Content":["// @ts-ignore\nimport * as shape from 'd3-shape';\n// @ts-ignore\nimport { scaleLinear } from 'd3-scale';\n\nimport type { TLineChartData, TLineChartPoint, YDomain } from './types';\nimport type { TLineChartDataProp } from './types';\n\nexport function getDomain(rows: TLineChartPoint[]): [number, number] {\n 'worklet';\n const values = rows.map(({ value }) => value);\n return [Math.min(...values), Math.max(...values)];\n}\n\nexport function lineChartDataPropToArray(\n dataProp: TLineChartDataProp\n): TLineChartData {\n 'worklet';\n\n if (!dataProp) {\n return [];\n }\n\n if (Array.isArray(dataProp)) {\n return dataProp;\n }\n\n const data: TLineChartData = [];\n\n Object.values(dataProp).forEach((dataSet) => {\n if (dataSet) {\n data.push(...dataSet);\n }\n });\n\n return data;\n}\n\nexport function getPath({\n data,\n width,\n height,\n gutter,\n shape: _shape = shape.curveBumpX,\n yDomain,\n}: {\n data: TLineChartData;\n width: number;\n height: number;\n gutter: number;\n shape?: string;\n yDomain: YDomain;\n}): string {\n const timestamps = data.map((_, i) => i);\n\n const scaleX = scaleLinear()\n .domain([Math.min(...timestamps), Math.max(...timestamps)])\n .range([0, width]);\n const scaleY = scaleLinear()\n .domain([yDomain.min, yDomain.max])\n .range([height - gutter, gutter]);\n const path = shape\n .line()\n .x((_: unknown, i: number) => scaleX(i))\n .y((d: { value: unknown }) => scaleY(d.value))\n .curve(_shape)(data);\n return path;\n}\n\nexport function getArea({\n data,\n width,\n height,\n gutter,\n shape: _shape = shape.curveBumpX,\n yDomain,\n}: {\n data: TLineChartData;\n width: number;\n height: number;\n gutter: number;\n shape?: string;\n yDomain: YDomain;\n}): string {\n const timestamps = data.map((_, i) => i);\n\n const scaleX = scaleLinear()\n .domain([Math.min(...timestamps), Math.max(...timestamps)])\n .range([0, width]);\n const scaleY = scaleLinear()\n .domain([yDomain.min, yDomain.max])\n .range([height - gutter, gutter]);\n const area = shape\n .area()\n .x((_: unknown, i: number) => scaleX(i))\n .y0((d: { value: unknown }) => scaleY(d.value))\n .y1(() => height)\n .curve(_shape)(data);\n return area;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["utils.ts"],"names":["formatPrice","value","_value","defaultPrice","_defaultPrice","precision","toString","replace","decimals","Number","Math","min","slice","search","res","toFixed","vals","split","length","formatDatetime","locale","options","d","Date","toLocaleString","usePrevious","ref","React","useRef","useEffect","current"],"mappings":";;;;;;;;;AAAA;;;;;;AAEA;AACA;AACA;AACO,SAASA,WAAT,CAAqB;AAC1BC,EAAAA,KAAK,EAAEC,MADmB;AAE1BC,EAAAA,YAAY,EAAEC,aAAa,GAAG,EAFJ;AAG1BC,EAAAA;AAH0B,CAArB,EAQJ;AACD;;AADC;;AAGD,MAAIF,YAAY,GAAGC,aAAnB;;AACA,MAAI,OAAOD,YAAP,KAAwB,QAA5B,EAAsC;AACpCA,IAAAA,YAAY,GAAIA,YAAD,CAAyBG,QAAzB,EAAf;AACD;;AAED,MAAIL,KAAK,GAAGC,MAAM,uBAAIC,YAAJ,4EAAI,eAAcI,OAAlB,0DAAI,2CAAwB,GAAxB,EAA6B,EAA7B,CAAJ,CAAlB;;AACA,MAAI,CAACN,KAAL,EAAY;AACV,WAAQ,MAAR;AACD;;AAED,MAAIO,QAAQ,GACVH,SADU,aACVA,SADU,cACVA,SADU,GAETI,MAAM,CAACR,KAAD,CAAN,GAAgB,CAAhB,GACGS,IAAI,CAACC,GAAL,CAAS,CAAT,EAAYV,KAAK,CAACK,QAAN,GAAiBM,KAAjB,CAAuB,CAAvB,EAA0BC,MAA1B,CAAiC,OAAjC,IAA4C,CAAxD,CADH,GAEG,CAJN;AAMA,MAAIC,GAAG,GAAI,GAAEL,MAAM,CAACR,KAAD,CAAN,CAAcc,OAAd,CAAsBP,QAAtB,CAAgC,EAA7C;AACA,QAAMQ,IAAI,GAAGF,GAAG,CAACG,KAAJ,CAAU,GAAV,CAAb;;AACA,MAAID,IAAI,CAACE,MAAL,GAAc,CAAlB,EAAqB;AACnBJ,IAAAA,GAAG,GAAGE,IAAI,CAAC,CAAD,CAAJ,CAAQT,OAAR,CAAgB,uBAAhB,EAAyC,GAAzC,CAAN;;AACA,QAAIS,IAAI,CAACE,MAAL,KAAgB,CAApB,EAAuB;AACrB,aAAOJ,GAAG,GAAG,GAAN,GAAYE,IAAI,CAAC,CAAD,CAAvB;AACD;AACF;;AACD,SAAOF,GAAP;AACD;AAED;AACA;AACA;;;AACO,SAASK,cAAT,CAAwB;AAC7BlB,EAAAA,KAD6B;AAE7BmB,EAAAA,MAAM,GAAG,OAFoB;AAG7BC,EAAAA,OAAO,GAAG;AAHmB,CAAxB,EAQJ;AACD;;AACA,QAAMC,CAAC,GAAG,IAAIC,IAAJ,CAAStB,KAAT,CAAV;AACA,SAAOqB,CAAC,CAACE,cAAF,CAAiBJ,MAAjB,EAAyBC,OAAzB,CAAP;AACD;;AAEM,SAASI,WAAT,CAAwBxB,KAAxB,EAAkC;AACvC;AACA;AACA,QAAMyB,GAAG,GAAGC,KAAK,CAACC,MAAN,EAAZ,CAHuC,CAIvC;;AACAD,EAAAA,KAAK,CAACE,SAAN,CAAgB,MAAM;AACpBH,IAAAA,GAAG,CAACI,OAAJ,GAAc7B,KAAd;AACD,GAFD,EAEG,CAACA,KAAD,CAFH,EALuC,CAO1B;AACb;;AACA,SAAOyB,GAAG,CAACI,OAAX;AACD","sourcesContent":["import * as React from 'react';\n\n/**\n * @worklet\n */\nexport function formatPrice({\n value: _value,\n defaultPrice: _defaultPrice = '',\n precision,\n}: {\n value: string;\n defaultPrice?: string;\n precision?: number;\n}) {\n 'worklet';\n\n let defaultPrice = _defaultPrice;\n if (typeof defaultPrice === 'number') {\n defaultPrice = (defaultPrice as number).toString();\n }\n\n let value = _value || defaultPrice?.replace?.(',', '');\n if (!value) {\n return `0.00`;\n }\n\n let decimals =\n precision ??\n (Number(value) < 1\n ? Math.min(8, value.toString().slice(2).search(/[^0]/g) + 3)\n : 2);\n\n let res = `${Number(value).toFixed(decimals)}`;\n const vals = res.split('.');\n if (vals.length > 0) {\n res = vals[0].replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',');\n if (vals.length === 2) {\n return res + '.' + vals[1];\n }\n }\n return res;\n}\n\n/**\n * @worklet\n */\nexport function formatDatetime({\n value,\n locale = 'en-US',\n options = {},\n}: {\n value: number;\n locale?: string;\n options?: Intl.DateTimeFormatOptions;\n}) {\n 'worklet';\n const d = new Date(value);\n return d.toLocaleString(locale, options);\n}\n\nexport function usePrevious<T>(value: T) {\n // The ref object is a generic container whose current property is mutable ...\n // ... and can hold any value, similar to an instance property on a class\n const ref = React.useRef<T>();\n // Store current value in ref\n React.useEffect(() => {\n ref.current = value;\n }, [value]); // Only re-run if value changes\n // Return previous value (happens before update in useEffect above)\n return ref.current;\n}\n"]}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import * as shape from 'd3-shape'; // @ts-ignore
|
|
3
|
-
|
|
4
|
-
import { scaleLinear } from 'd3-scale';
|
|
5
|
-
export function getDomain(rows) {
|
|
6
|
-
'worklet';
|
|
7
|
-
|
|
8
|
-
const values = rows.map(({
|
|
9
|
-
value
|
|
10
|
-
}) => value);
|
|
11
|
-
return [Math.min(...values), Math.max(...values)];
|
|
12
|
-
}
|
|
13
|
-
export function lineChartDataPropToArray(dataProp) {
|
|
14
|
-
'worklet';
|
|
15
|
-
|
|
16
|
-
if (!dataProp) {
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (Array.isArray(dataProp)) {
|
|
21
|
-
return dataProp;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const data = [];
|
|
25
|
-
Object.values(dataProp).forEach(dataSet => {
|
|
26
|
-
if (dataSet) {
|
|
27
|
-
data.push(...dataSet);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
return data;
|
|
31
|
-
}
|
|
32
|
-
export function getPath({
|
|
33
|
-
data,
|
|
34
|
-
width,
|
|
35
|
-
height,
|
|
36
|
-
gutter,
|
|
37
|
-
shape: _shape = shape.curveBumpX,
|
|
38
|
-
yDomain
|
|
39
|
-
}) {
|
|
40
|
-
const timestamps = data.map((_, i) => i);
|
|
41
|
-
const scaleX = scaleLinear().domain([Math.min(...timestamps), Math.max(...timestamps)]).range([0, width]);
|
|
42
|
-
const scaleY = scaleLinear().domain([yDomain.min, yDomain.max]).range([height - gutter, gutter]);
|
|
43
|
-
const path = shape.line().x((_, i) => scaleX(i)).y(d => scaleY(d.value)).curve(_shape)(data);
|
|
44
|
-
return path;
|
|
45
|
-
}
|
|
46
|
-
export function getArea({
|
|
47
|
-
data,
|
|
48
|
-
width,
|
|
49
|
-
height,
|
|
50
|
-
gutter,
|
|
51
|
-
shape: _shape = shape.curveBumpX,
|
|
52
|
-
yDomain
|
|
53
|
-
}) {
|
|
54
|
-
const timestamps = data.map((_, i) => i);
|
|
55
|
-
const scaleX = scaleLinear().domain([Math.min(...timestamps), Math.max(...timestamps)]).range([0, width]);
|
|
56
|
-
const scaleY = scaleLinear().domain([yDomain.min, yDomain.max]).range([height - gutter, gutter]);
|
|
57
|
-
const area = shape.area().x((_, i) => scaleX(i)).y0(d => scaleY(d.value)).y1(() => height).curve(_shape)(data);
|
|
58
|
-
return area;
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["utils.ts"],"names":["shape","scaleLinear","getDomain","rows","values","map","value","Math","min","max","lineChartDataPropToArray","dataProp","Array","isArray","data","Object","forEach","dataSet","push","getPath","width","height","gutter","_shape","curveBumpX","yDomain","timestamps","_","i","scaleX","domain","range","scaleY","path","line","x","y","d","curve","getArea","area","y0","y1"],"mappings":"AAAA;AACA,OAAO,KAAKA,KAAZ,MAAuB,UAAvB,C,CACA;;AACA,SAASC,WAAT,QAA4B,UAA5B;AAKA,OAAO,SAASC,SAAT,CAAmBC,IAAnB,EAA8D;AACnE;;AACA,QAAMC,MAAM,GAAGD,IAAI,CAACE,G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,CAGNJ,CAAD,IAA2BL,MAAM,CAACK,CAAC,CAAC/B,KAAH,CAH1B,EAIVoC,EAJU,CAIP,MAAMrB,MAJC,EAKViB,KALU,CAKJf,MALI,EAKIT,IALJ,CAAb;AAMA,SAAO0B,IAAP;AACD","sourcesContent":["// @ts-ignore\nimport * as shape from 'd3-shape';\n// @ts-ignore\nimport { scaleLinear } from 'd3-scale';\n\nimport type { TLineChartData, TLineChartPoint, YDomain } from './types';\nimport type { TLineChartDataProp } from './types';\n\nexport function getDomain(rows: TLineChartPoint[]): [number, number] {\n 'worklet';\n const values = rows.map(({ value }) => value);\n return [Math.min(...values), Math.max(...values)];\n}\n\nexport function lineChartDataPropToArray(\n dataProp: TLineChartDataProp\n): TLineChartData {\n 'worklet';\n\n if (!dataProp) {\n return [];\n }\n\n if (Array.isArray(dataProp)) {\n return dataProp;\n }\n\n const data: TLineChartData = [];\n\n Object.values(dataProp).forEach((dataSet) => {\n if (dataSet) {\n data.push(...dataSet);\n }\n });\n\n return data;\n}\n\nexport function getPath({\n data,\n width,\n height,\n gutter,\n shape: _shape = shape.curveBumpX,\n yDomain,\n}: {\n data: TLineChartData;\n width: number;\n height: number;\n gutter: number;\n shape?: string;\n yDomain: YDomain;\n}): string {\n const timestamps = data.map((_, i) => i);\n\n const scaleX = scaleLinear()\n .domain([Math.min(...timestamps), Math.max(...timestamps)])\n .range([0, width]);\n const scaleY = scaleLinear()\n .domain([yDomain.min, yDomain.max])\n .range([height - gutter, gutter]);\n const path = shape\n .line()\n .x((_: unknown, i: number) => scaleX(i))\n .y((d: { value: unknown }) => scaleY(d.value))\n .curve(_shape)(data);\n return path;\n}\n\nexport function getArea({\n data,\n width,\n height,\n gutter,\n shape: _shape = shape.curveBumpX,\n yDomain,\n}: {\n data: TLineChartData;\n width: number;\n height: number;\n gutter: number;\n shape?: string;\n yDomain: YDomain;\n}): string {\n const timestamps = data.map((_, i) => i);\n\n const scaleX = scaleLinear()\n .domain([Math.min(...timestamps), Math.max(...timestamps)])\n .range([0, width]);\n const scaleY = scaleLinear()\n .domain([yDomain.min, yDomain.max])\n .range([height - gutter, gutter]);\n const area = shape\n .area()\n .x((_: unknown, i: number) => scaleX(i))\n .y0((d: { value: unknown }) => scaleY(d.value))\n .y1(() => height)\n .curve(_shape)(data);\n return area;\n}\n"]}
|