@react-native-ohos/victory-native-xl 41.17.5-rc.1 → 41.18.0-beta.1
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/LICENSE +7 -7
- package/README.OpenSource +10 -10
- package/README.md +12 -12
- package/package.json +52 -44
- package/src/cartesian/CartesianChart.tsx +795 -709
- package/src/index.ts +56 -52
- package/src/polar/PolarChart.tsx +146 -144
- package/src/shared/GestureHandler.tsx +45 -0
package/src/index.ts
CHANGED
|
@@ -1,52 +1,56 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cartesian chart exports (including useful types)
|
|
3
|
-
*/
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from "victory-native";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
|
|
27
|
-
// Bar
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
|
|
31
|
-
//
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
|
|
35
|
-
//
|
|
36
|
-
export {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export {
|
|
1
|
+
/**
|
|
2
|
+
* Cartesian chart exports (including useful types)
|
|
3
|
+
*/
|
|
4
|
+
export {
|
|
5
|
+
CartesianChart,
|
|
6
|
+
type CartesianActionsHandle,
|
|
7
|
+
type CartesianChartRef,
|
|
8
|
+
} from "./cartesian/CartesianChart";
|
|
9
|
+
export { PolarChart } from "./polar/PolarChart";
|
|
10
|
+
|
|
11
|
+
export { type CurveType } from "victory-native";
|
|
12
|
+
export { type RoundedCorners } from "victory-native";
|
|
13
|
+
export { type AxisScaleType, type AxisScales } from "victory-native/src/types";
|
|
14
|
+
|
|
15
|
+
export { useAnimatedPath } from "victory-native";
|
|
16
|
+
export { AnimatedPath } from "victory-native";
|
|
17
|
+
export { usePrevious } from "victory-native";
|
|
18
|
+
export {
|
|
19
|
+
useChartPressState,
|
|
20
|
+
type ChartPressState,
|
|
21
|
+
} from "victory-native";
|
|
22
|
+
|
|
23
|
+
// Line
|
|
24
|
+
export { useLinePath } from "victory-native";
|
|
25
|
+
export { Line } from "victory-native";
|
|
26
|
+
|
|
27
|
+
// Bar
|
|
28
|
+
export { useBarPath } from "victory-native";
|
|
29
|
+
export { Bar } from "victory-native";
|
|
30
|
+
|
|
31
|
+
// Bar group
|
|
32
|
+
export { useBarGroupPaths } from "victory-native";
|
|
33
|
+
export { BarGroup } from "victory-native";
|
|
34
|
+
|
|
35
|
+
// Area
|
|
36
|
+
export { useAreaPath } from "victory-native";
|
|
37
|
+
export { Area } from "victory-native";
|
|
38
|
+
|
|
39
|
+
// Scatter
|
|
40
|
+
export { Scatter, type ScatterShape } from "victory-native";
|
|
41
|
+
|
|
42
|
+
// Grid and Axis
|
|
43
|
+
export { CartesianAxis } from "victory-native";
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Polar chart exports
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Pie chart exports (including useful types)
|
|
51
|
+
*/
|
|
52
|
+
export { Pie, type PieSliceData } from "victory-native";
|
|
53
|
+
|
|
54
|
+
export { useSlicePath } from "victory-native";
|
|
55
|
+
export { useSliceAngularInsetPath } from "victory-native";
|
|
56
|
+
export { useChartTransformState } from "victory-native";
|
package/src/polar/PolarChart.tsx
CHANGED
|
@@ -1,144 +1,146 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
import { Canvas } from "@shopify/react-native-skia";
|
|
4
|
-
import { useContextBridge, FiberProvider } from "its-fine";
|
|
5
|
-
import {
|
|
6
|
-
StyleSheet,
|
|
7
|
-
View,
|
|
8
|
-
type ViewStyle,
|
|
9
|
-
type LayoutChangeEvent,
|
|
10
|
-
type StyleProp,
|
|
11
|
-
} from "react-native";
|
|
12
|
-
import {
|
|
13
|
-
PolarChartProvider,
|
|
14
|
-
usePolarChartContext,
|
|
15
|
-
} from "victory-native/src/polar/contexts/PolarChartContext";
|
|
16
|
-
import type {
|
|
17
|
-
ColorFields,
|
|
18
|
-
InputFields,
|
|
19
|
-
NumericalFields,
|
|
20
|
-
StringKeyOf,
|
|
21
|
-
} from "victory-native/src/types";
|
|
22
|
-
|
|
23
|
-
type PolarChartBaseProps = {
|
|
24
|
-
onLayout: ({ nativeEvent: { layout } }: LayoutChangeEvent) => void;
|
|
25
|
-
hasMeasuredLayoutSize: boolean;
|
|
26
|
-
canvasSize: { width: number; height: number };
|
|
27
|
-
containerStyle?: StyleProp<ViewStyle>;
|
|
28
|
-
canvasStyle?: StyleProp<ViewStyle>;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
interface PolarChartContext {
|
|
32
|
-
data: Record<string, unknown>[];
|
|
33
|
-
canvasSize: { width: number; height: number };
|
|
34
|
-
labelKey: string;
|
|
35
|
-
valueKey: string;
|
|
36
|
-
colorKey: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const PolarChartBase = (
|
|
40
|
-
props: React.PropsWithChildren<PolarChartBaseProps>,
|
|
41
|
-
) => {
|
|
42
|
-
const {
|
|
43
|
-
containerStyle,
|
|
44
|
-
canvasStyle,
|
|
45
|
-
children,
|
|
46
|
-
onLayout,
|
|
47
|
-
hasMeasuredLayoutSize,
|
|
48
|
-
canvasSize,
|
|
49
|
-
} = props;
|
|
50
|
-
const { width, height } = canvasSize;
|
|
51
|
-
|
|
52
|
-
const ctx = usePolarChartContext();
|
|
53
|
-
const ContextBridge = useContextBridge();
|
|
54
|
-
return (
|
|
55
|
-
<View
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
{
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
const [
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { Canvas } from "@shopify/react-native-skia";
|
|
4
|
+
import { useContextBridge, FiberProvider } from "its-fine";
|
|
5
|
+
import {
|
|
6
|
+
StyleSheet,
|
|
7
|
+
View,
|
|
8
|
+
type ViewStyle,
|
|
9
|
+
type LayoutChangeEvent,
|
|
10
|
+
type StyleProp,
|
|
11
|
+
} from "react-native";
|
|
12
|
+
import {
|
|
13
|
+
PolarChartProvider,
|
|
14
|
+
usePolarChartContext,
|
|
15
|
+
} from "victory-native/src/polar/contexts/PolarChartContext";
|
|
16
|
+
import type {
|
|
17
|
+
ColorFields,
|
|
18
|
+
InputFields,
|
|
19
|
+
NumericalFields,
|
|
20
|
+
StringKeyOf,
|
|
21
|
+
} from "victory-native/src/types";
|
|
22
|
+
|
|
23
|
+
type PolarChartBaseProps = {
|
|
24
|
+
onLayout: ({ nativeEvent: { layout } }: LayoutChangeEvent) => void;
|
|
25
|
+
hasMeasuredLayoutSize: boolean;
|
|
26
|
+
canvasSize: { width: number; height: number };
|
|
27
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
28
|
+
canvasStyle?: StyleProp<ViewStyle>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
interface PolarChartContext {
|
|
32
|
+
data: Record<string, unknown>[];
|
|
33
|
+
canvasSize: { width: number; height: number };
|
|
34
|
+
labelKey: string;
|
|
35
|
+
valueKey: string;
|
|
36
|
+
colorKey: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const PolarChartBase = (
|
|
40
|
+
props: React.PropsWithChildren<PolarChartBaseProps>,
|
|
41
|
+
) => {
|
|
42
|
+
const {
|
|
43
|
+
containerStyle,
|
|
44
|
+
canvasStyle,
|
|
45
|
+
children,
|
|
46
|
+
onLayout,
|
|
47
|
+
hasMeasuredLayoutSize,
|
|
48
|
+
canvasSize,
|
|
49
|
+
} = props;
|
|
50
|
+
const { width, height } = canvasSize;
|
|
51
|
+
|
|
52
|
+
const ctx = usePolarChartContext();
|
|
53
|
+
const ContextBridge = useContextBridge();
|
|
54
|
+
return (
|
|
55
|
+
<View
|
|
56
|
+
style={[styles.baseContainer, containerStyle]}
|
|
57
|
+
onLayout={onLayout}
|
|
58
|
+
>
|
|
59
|
+
<Canvas
|
|
60
|
+
style={StyleSheet.flatten([
|
|
61
|
+
styles.canvasContainer,
|
|
62
|
+
hasMeasuredLayoutSize ? { width, height } : null,
|
|
63
|
+
canvasStyle,
|
|
64
|
+
])}
|
|
65
|
+
>
|
|
66
|
+
{/* https://shopify.github.io/react-native-skia/docs/canvas/contexts/
|
|
67
|
+
we have to re-inject our context to make it available in the skia renderer
|
|
68
|
+
*/}
|
|
69
|
+
<ContextBridge {...ctx}>
|
|
70
|
+
{children}
|
|
71
|
+
</ContextBridge>
|
|
72
|
+
{/* <PolarChartProvider {...ctx} canvasSize={canvasSize}>
|
|
73
|
+
{children}
|
|
74
|
+
</PolarChartProvider> */}
|
|
75
|
+
</Canvas>
|
|
76
|
+
</View>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
type PolarChartProps<
|
|
81
|
+
RawData extends Record<string, unknown>,
|
|
82
|
+
LabelKey extends StringKeyOf<InputFields<RawData>>,
|
|
83
|
+
ValueKey extends StringKeyOf<NumericalFields<RawData>>,
|
|
84
|
+
ColorKey extends StringKeyOf<ColorFields<RawData>>,
|
|
85
|
+
> = {
|
|
86
|
+
data: RawData[];
|
|
87
|
+
colorKey: ColorKey;
|
|
88
|
+
labelKey: LabelKey;
|
|
89
|
+
valueKey: ValueKey;
|
|
90
|
+
} & Omit<
|
|
91
|
+
PolarChartBaseProps,
|
|
92
|
+
"canvasSize" | "onLayout" | "hasMeasuredLayoutSize" // omit exposing internal props for calculating canvas layout/size
|
|
93
|
+
>;
|
|
94
|
+
export const PolarChart = <
|
|
95
|
+
RawData extends Record<string, unknown>,
|
|
96
|
+
LabelKey extends StringKeyOf<InputFields<RawData>>,
|
|
97
|
+
ValueKey extends StringKeyOf<NumericalFields<RawData>>,
|
|
98
|
+
ColorKey extends StringKeyOf<ColorFields<RawData>>,
|
|
99
|
+
>(
|
|
100
|
+
props: React.PropsWithChildren<
|
|
101
|
+
PolarChartProps<RawData, LabelKey, ValueKey, ColorKey>
|
|
102
|
+
>,
|
|
103
|
+
) => {
|
|
104
|
+
const { data, labelKey, colorKey, valueKey } = props;
|
|
105
|
+
|
|
106
|
+
const [canvasSize, setCanvasSize] = React.useState({ width: 0, height: 0 });
|
|
107
|
+
|
|
108
|
+
const [hasMeasuredLayoutSize, setHasMeasuredLayoutSize] =
|
|
109
|
+
React.useState(false);
|
|
110
|
+
|
|
111
|
+
const onLayout = React.useCallback(
|
|
112
|
+
({ nativeEvent: { layout } }: LayoutChangeEvent) => {
|
|
113
|
+
setHasMeasuredLayoutSize(true);
|
|
114
|
+
setCanvasSize(layout);
|
|
115
|
+
},
|
|
116
|
+
[],
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<FiberProvider>
|
|
121
|
+
<PolarChartProvider
|
|
122
|
+
data={data}
|
|
123
|
+
labelKey={labelKey.toString()}
|
|
124
|
+
colorKey={colorKey.toString()}
|
|
125
|
+
valueKey={valueKey.toString()}
|
|
126
|
+
canvasSize={canvasSize}
|
|
127
|
+
>
|
|
128
|
+
<PolarChartBase
|
|
129
|
+
{...props}
|
|
130
|
+
onLayout={onLayout}
|
|
131
|
+
hasMeasuredLayoutSize={hasMeasuredLayoutSize}
|
|
132
|
+
canvasSize={canvasSize}
|
|
133
|
+
/>
|
|
134
|
+
</PolarChartProvider>
|
|
135
|
+
</FiberProvider>
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const styles = StyleSheet.create({
|
|
140
|
+
baseContainer: {
|
|
141
|
+
flex: 1,
|
|
142
|
+
},
|
|
143
|
+
canvasContainer: {
|
|
144
|
+
flex: 1,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ComposedGesture,
|
|
3
|
+
GestureDetector,
|
|
4
|
+
type GestureType,
|
|
5
|
+
} from "react-native-gesture-handler";
|
|
6
|
+
import { type SkRect } from "@shopify/react-native-skia";
|
|
7
|
+
import Animated, { useAnimatedStyle } from "react-native-reanimated";
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { type ChartTransformState } from "victory-native/src/cartesian/hooks/useChartTransformState";
|
|
10
|
+
import type { GestureHandlerConfig } from "victory-native/src/types";
|
|
11
|
+
|
|
12
|
+
type GestureHandlerProps = {
|
|
13
|
+
gesture: ComposedGesture | GestureType;
|
|
14
|
+
dimensions?: SkRect;
|
|
15
|
+
transformState?: ChartTransformState;
|
|
16
|
+
debug?: boolean;
|
|
17
|
+
config?: GestureHandlerConfig;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* OHOS: Keep the gesture overlay fixed to the chart container instead of
|
|
22
|
+
* following transformState.matrix. Upstream 41.20.2 moves the overlay with
|
|
23
|
+
* matrix transforms, which breaks pan/pinch on HarmonyOS RNGH (e.g. Y pan
|
|
24
|
+
* requires a horizontal move first). Aligns with upstream main PR #664.
|
|
25
|
+
*/
|
|
26
|
+
export const GestureHandler = ({
|
|
27
|
+
gesture,
|
|
28
|
+
debug = false,
|
|
29
|
+
config,
|
|
30
|
+
}: GestureHandlerProps) => {
|
|
31
|
+
const style = useAnimatedStyle(() => ({
|
|
32
|
+
position: "absolute",
|
|
33
|
+
top: 0,
|
|
34
|
+
left: 0,
|
|
35
|
+
right: 0,
|
|
36
|
+
bottom: 0,
|
|
37
|
+
backgroundColor: debug ? "rgba(100, 200, 255, 0.4)" : "transparent",
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<GestureDetector {...config} gesture={gesture}>
|
|
42
|
+
<Animated.View style={style} />
|
|
43
|
+
</GestureDetector>
|
|
44
|
+
);
|
|
45
|
+
};
|