@react-native-ohos/victory-native-xl 41.17.5-rc.1 → 41.17.5

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/src/index.ts CHANGED
@@ -1,52 +1,52 @@
1
- /**
2
- * Cartesian chart exports (including useful types)
3
- */
4
- export { CartesianChart } from "./cartesian/CartesianChart";
5
- export { PolarChart } from "./polar/PolarChart";
6
-
7
-
8
- export { type CurveType } from "victory-native";
9
- export { type RoundedCorners } from "victory-native";
10
-
11
- export { useAnimatedPath } from "victory-native";
12
- export { AnimatedPath } from "victory-native";
13
- export { usePrevious } from "victory-native";
14
- export {
15
- useChartPressState,
16
- type ChartPressState,
17
- } from "victory-native";
18
-
19
- // Line
20
- export { useLinePath } from "victory-native";
21
- export { Line } from "victory-native";
22
-
23
- // Bar
24
- export { useBarPath } from "victory-native";
25
- export { Bar } from "victory-native";
26
-
27
- // Bar group
28
- export { useBarGroupPaths } from "victory-native";
29
- export { BarGroup } from "victory-native";
30
-
31
- // Area
32
- export { useAreaPath } from "victory-native";
33
- export { Area } from "victory-native";
34
-
35
- // Scatter
36
- export { Scatter, type ScatterShape } from "victory-native";
37
-
38
- // Grid and Axis
39
- export { CartesianAxis } from "victory-native";
40
-
41
- /**
42
- * Polar chart exports
43
- */
44
-
45
- /**
46
- * Pie chart exports (including useful types)
47
- */
48
- export { Pie, type PieSliceData } from "victory-native";
49
-
50
- export { useSlicePath } from "victory-native";
51
- export { useSliceAngularInsetPath } from "victory-native";
52
- export { useChartTransformState } from "victory-native";
1
+ /**
2
+ * Cartesian chart exports (including useful types)
3
+ */
4
+ export { CartesianChart } from "./cartesian/CartesianChart";
5
+ export { PolarChart } from "./polar/PolarChart";
6
+
7
+
8
+ export { type CurveType } from "victory-native";
9
+ export { type RoundedCorners } from "victory-native";
10
+
11
+ export { useAnimatedPath } from "victory-native";
12
+ export { AnimatedPath } from "victory-native";
13
+ export { usePrevious } from "victory-native";
14
+ export {
15
+ useChartPressState,
16
+ type ChartPressState,
17
+ } from "victory-native";
18
+
19
+ // Line
20
+ export { useLinePath } from "victory-native";
21
+ export { Line } from "victory-native";
22
+
23
+ // Bar
24
+ export { useBarPath } from "victory-native";
25
+ export { Bar } from "victory-native";
26
+
27
+ // Bar group
28
+ export { useBarGroupPaths } from "victory-native";
29
+ export { BarGroup } from "victory-native";
30
+
31
+ // Area
32
+ export { useAreaPath } from "victory-native";
33
+ export { Area } from "victory-native";
34
+
35
+ // Scatter
36
+ export { Scatter, type ScatterShape } from "victory-native";
37
+
38
+ // Grid and Axis
39
+ export { CartesianAxis } from "victory-native";
40
+
41
+ /**
42
+ * Polar chart exports
43
+ */
44
+
45
+ /**
46
+ * Pie chart exports (including useful types)
47
+ */
48
+ export { Pie, type PieSliceData } from "victory-native";
49
+
50
+ export { useSlicePath } from "victory-native";
51
+ export { useSliceAngularInsetPath } from "victory-native";
52
+ export { useChartTransformState } from "victory-native";
@@ -1,144 +1,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 style={[styles.baseContainer, containerStyle]}>
56
- <Canvas
57
- onLayout={onLayout}
58
- style={StyleSheet.flatten([
59
- styles.canvasContainer,
60
- hasMeasuredLayoutSize ? { width, height } : null,
61
- canvasStyle,
62
- ])}
63
- >
64
- {/* https://shopify.github.io/react-native-skia/docs/canvas/contexts/
65
- we have to re-inject our context to make it available in the skia renderer
66
- */}
67
- <ContextBridge {...ctx}>
68
- {children}
69
- </ContextBridge>
70
- {/* <PolarChartProvider {...ctx} canvasSize={canvasSize}>
71
- {children}
72
- </PolarChartProvider> */}
73
- </Canvas>
74
- </View>
75
- );
76
- };
77
-
78
- type PolarChartProps<
79
- RawData extends Record<string, unknown>,
80
- LabelKey extends StringKeyOf<InputFields<RawData>>,
81
- ValueKey extends StringKeyOf<NumericalFields<RawData>>,
82
- ColorKey extends StringKeyOf<ColorFields<RawData>>,
83
- > = {
84
- data: RawData[];
85
- colorKey: ColorKey;
86
- labelKey: LabelKey;
87
- valueKey: ValueKey;
88
- } & Omit<
89
- PolarChartBaseProps,
90
- "canvasSize" | "onLayout" | "hasMeasuredLayoutSize" // omit exposing internal props for calculating canvas layout/size
91
- >;
92
- export const PolarChart = <
93
- RawData extends Record<string, unknown>,
94
- LabelKey extends StringKeyOf<InputFields<RawData>>,
95
- ValueKey extends StringKeyOf<NumericalFields<RawData>>,
96
- ColorKey extends StringKeyOf<ColorFields<RawData>>,
97
- >(
98
- props: React.PropsWithChildren<
99
- PolarChartProps<RawData, LabelKey, ValueKey, ColorKey>
100
- >,
101
- ) => {
102
- const { data, labelKey, colorKey, valueKey } = props;
103
-
104
- const [canvasSize, setCanvasSize] = React.useState({ width: 0, height: 0 });
105
-
106
- const [hasMeasuredLayoutSize, setHasMeasuredLayoutSize] =
107
- React.useState(false);
108
-
109
- const onLayout = React.useCallback(
110
- ({ nativeEvent: { layout } }: LayoutChangeEvent) => {
111
- setHasMeasuredLayoutSize(true);
112
- setCanvasSize(layout);
113
- },
114
- [],
115
- );
116
-
117
- return (
118
- <FiberProvider>
119
- <PolarChartProvider
120
- data={data}
121
- labelKey={labelKey.toString()}
122
- colorKey={colorKey.toString()}
123
- valueKey={valueKey.toString()}
124
- canvasSize={canvasSize}
125
- >
126
- <PolarChartBase
127
- {...props}
128
- onLayout={onLayout}
129
- hasMeasuredLayoutSize={hasMeasuredLayoutSize}
130
- canvasSize={canvasSize}
131
- />
132
- </PolarChartProvider>
133
- </FiberProvider>
134
- );
135
- };
136
-
137
- const styles = StyleSheet.create({
138
- baseContainer: {
139
- flex: 1,
140
- },
141
- canvasContainer: {
142
- flex: 1,
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 style={[styles.baseContainer, containerStyle]}>
56
+ <Canvas
57
+ onLayout={onLayout}
58
+ style={StyleSheet.flatten([
59
+ styles.canvasContainer,
60
+ hasMeasuredLayoutSize ? { width, height } : null,
61
+ canvasStyle,
62
+ ])}
63
+ >
64
+ {/* https://shopify.github.io/react-native-skia/docs/canvas/contexts/
65
+ we have to re-inject our context to make it available in the skia renderer
66
+ */}
67
+ <ContextBridge {...ctx}>
68
+ {children}
69
+ </ContextBridge>
70
+ {/* <PolarChartProvider {...ctx} canvasSize={canvasSize}>
71
+ {children}
72
+ </PolarChartProvider> */}
73
+ </Canvas>
74
+ </View>
75
+ );
76
+ };
77
+
78
+ type PolarChartProps<
79
+ RawData extends Record<string, unknown>,
80
+ LabelKey extends StringKeyOf<InputFields<RawData>>,
81
+ ValueKey extends StringKeyOf<NumericalFields<RawData>>,
82
+ ColorKey extends StringKeyOf<ColorFields<RawData>>,
83
+ > = {
84
+ data: RawData[];
85
+ colorKey: ColorKey;
86
+ labelKey: LabelKey;
87
+ valueKey: ValueKey;
88
+ } & Omit<
89
+ PolarChartBaseProps,
90
+ "canvasSize" | "onLayout" | "hasMeasuredLayoutSize" // omit exposing internal props for calculating canvas layout/size
91
+ >;
92
+ export const PolarChart = <
93
+ RawData extends Record<string, unknown>,
94
+ LabelKey extends StringKeyOf<InputFields<RawData>>,
95
+ ValueKey extends StringKeyOf<NumericalFields<RawData>>,
96
+ ColorKey extends StringKeyOf<ColorFields<RawData>>,
97
+ >(
98
+ props: React.PropsWithChildren<
99
+ PolarChartProps<RawData, LabelKey, ValueKey, ColorKey>
100
+ >,
101
+ ) => {
102
+ const { data, labelKey, colorKey, valueKey } = props;
103
+
104
+ const [canvasSize, setCanvasSize] = React.useState({ width: 0, height: 0 });
105
+
106
+ const [hasMeasuredLayoutSize, setHasMeasuredLayoutSize] =
107
+ React.useState(false);
108
+
109
+ const onLayout = React.useCallback(
110
+ ({ nativeEvent: { layout } }: LayoutChangeEvent) => {
111
+ setHasMeasuredLayoutSize(true);
112
+ setCanvasSize(layout);
113
+ },
114
+ [],
115
+ );
116
+
117
+ return (
118
+ <FiberProvider>
119
+ <PolarChartProvider
120
+ data={data}
121
+ labelKey={labelKey.toString()}
122
+ colorKey={colorKey.toString()}
123
+ valueKey={valueKey.toString()}
124
+ canvasSize={canvasSize}
125
+ >
126
+ <PolarChartBase
127
+ {...props}
128
+ onLayout={onLayout}
129
+ hasMeasuredLayoutSize={hasMeasuredLayoutSize}
130
+ canvasSize={canvasSize}
131
+ />
132
+ </PolarChartProvider>
133
+ </FiberProvider>
134
+ );
135
+ };
136
+
137
+ const styles = StyleSheet.create({
138
+ baseContainer: {
139
+ flex: 1,
140
+ },
141
+ canvasContainer: {
142
+ flex: 1,
143
+ },
144
+ });