react-native-gifted-charts 1.3.33 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/package.json +2 -1
- package/src/BarChart/Animated2DWithGradient.tsx +13 -154
- package/src/BarChart/RenderBars.tsx +29 -179
- package/src/BarChart/RenderStackBars.tsx +22 -104
- package/src/BarChart/index.tsx +87 -686
- package/src/Components/AnimatedThreeDBar/index.tsx +16 -48
- package/src/Components/BarAndLineChartsWrapper/index.tsx +38 -283
- package/src/Components/BarAndLineChartsWrapper/renderHorizSections.tsx +17 -339
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.tsx +147 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.tsx +157 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.tsx +86 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.tsx +42 -0
- package/src/Components/BarAndLineChartsWrapper/renderVerticalLines.tsx +1 -1
- package/src/Components/BarSpecificComponents/cap.tsx +1 -1
- package/src/Components/common/StripAndLabel.tsx +3 -56
- package/src/Components/lineSvg.tsx +1 -1
- package/src/LineChart/LineChartBicolor.tsx +80 -516
- package/src/LineChart/index.tsx +266 -1778
- package/src/PieChart/index.tsx +20 -84
- package/src/PieChart/main.tsx +47 -119
- package/src/PopulationPyramid/index.tsx +90 -203
- package/src/index.tsx +2 -14
- package/src/BarChart/types.ts +0 -394
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart.tsx +0 -402
- package/src/LineChart/types.ts +0 -575
- package/src/PieChart/types.ts +0 -77
- package/src/PopulationPyramid/types.ts +0 -200
- package/src/utils/constants.ts +0 -333
- package/src/utils/index.tsx +0 -1137
- package/src/utils/types.ts +0 -360
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {useEffect
|
|
1
|
+
import React, {useEffect} from 'react';
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
4
|
TouchableOpacity,
|
|
@@ -9,8 +9,7 @@ import {
|
|
|
9
9
|
} from 'react-native';
|
|
10
10
|
import LinearGradient from 'react-native-linear-gradient';
|
|
11
11
|
import Svg, {Defs, Rect} from 'react-native-svg';
|
|
12
|
-
import {BarDefaults} from '
|
|
13
|
-
import {StackedBarChartPropsType, stackDataItem} from './types';
|
|
12
|
+
import { useRenderStackBars, BarDefaults, StackedBarChartPropsType } from 'gifted-charts-core';
|
|
14
13
|
|
|
15
14
|
if (Platform.OS === 'android') {
|
|
16
15
|
UIManager.setLayoutAnimationEnabledExperimental &&
|
|
@@ -24,11 +23,8 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
24
23
|
item,
|
|
25
24
|
index,
|
|
26
25
|
containerHeight,
|
|
27
|
-
maxValue,
|
|
28
26
|
spacing,
|
|
29
|
-
propSpacing,
|
|
30
27
|
rotateLabel,
|
|
31
|
-
xAxisThickness,
|
|
32
28
|
label,
|
|
33
29
|
labelTextStyle,
|
|
34
30
|
xAxisTextNumberOfLines,
|
|
@@ -36,12 +32,10 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
36
32
|
renderTooltip,
|
|
37
33
|
leftShiftForTooltip,
|
|
38
34
|
leftShiftForLastIndexTooltip,
|
|
39
|
-
initialSpacing,
|
|
40
35
|
selectedIndex,
|
|
41
36
|
setSelectedIndex,
|
|
42
37
|
activeOpacity,
|
|
43
38
|
stackData,
|
|
44
|
-
isAnimated,
|
|
45
39
|
animationDuration = BarDefaults.animationDuration,
|
|
46
40
|
barBorderWidth,
|
|
47
41
|
barBorderColor,
|
|
@@ -52,69 +46,25 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
52
46
|
stackBorderBottomRightRadius,
|
|
53
47
|
showValuesAsTopLabel,
|
|
54
48
|
} = props;
|
|
55
|
-
const cotainsNegative = item.stacks.some(item => item.value < 0);
|
|
56
|
-
const noAnimation = cotainsNegative || !isAnimated;
|
|
57
|
-
|
|
58
|
-
const localBarInnerComponent =
|
|
59
|
-
item.barInnerComponent ?? props.barInnerComponent;
|
|
60
|
-
|
|
61
49
|
const {
|
|
50
|
+
cotainsNegative,
|
|
51
|
+
noAnimation,
|
|
52
|
+
localBarInnerComponent,
|
|
62
53
|
borderRadius,
|
|
63
54
|
borderTopLeftRadius,
|
|
64
55
|
borderTopRightRadius,
|
|
65
56
|
borderBottomLeftRadius,
|
|
66
57
|
borderBottomRightRadius,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const getBarHeight = (value: number, marginBottom?: number) => {
|
|
78
|
-
return (
|
|
79
|
-
(Math.abs(value) * (containerHeight || 200)) / (maxValue || 200) -
|
|
80
|
-
(marginBottom || 0)
|
|
81
|
-
);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const getPosition = (index: number) => {
|
|
85
|
-
/* Returns bottom position for stack item
|
|
86
|
-
negative values are below origin (-> negative position) */
|
|
87
|
-
const height = getBarHeight(
|
|
88
|
-
item.stacks[index].value,
|
|
89
|
-
item.stacks[index].marginBottom,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const itemValue = item.stacks[index].value;
|
|
93
|
-
const isNegative = itemValue <= 0;
|
|
94
|
-
let position = isNegative ? -(height || 0) : 0;
|
|
95
|
-
|
|
96
|
-
for (let i = 0; i < index; i++) {
|
|
97
|
-
const valueOnIndex = item.stacks[i].value;
|
|
98
|
-
if (isNegative && valueOnIndex <= 0) {
|
|
99
|
-
position +=
|
|
100
|
-
(valueOnIndex * (containerHeight || 200)) / (maxValue || 200);
|
|
101
|
-
} else if (!isNegative && valueOnIndex >= 0) {
|
|
102
|
-
position +=
|
|
103
|
-
(valueOnIndex * (containerHeight || 200)) / (maxValue || 200);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return position;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const getLowestPosition = () => {
|
|
110
|
-
return (
|
|
111
|
-
item.stacks
|
|
112
|
-
.map((_, index) => getPosition(index))
|
|
113
|
-
.sort((a, b) => a - b)?.[0] || 0
|
|
114
|
-
);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const lowestBarPosition = getLowestPosition();
|
|
58
|
+
leftSpacing,
|
|
59
|
+
disablePress,
|
|
60
|
+
totalHeight,
|
|
61
|
+
height,
|
|
62
|
+
setHeight,
|
|
63
|
+
getBarHeight,
|
|
64
|
+
getPosition,
|
|
65
|
+
lowestBarPosition,
|
|
66
|
+
getStackBorderRadii,
|
|
67
|
+
} = useRenderStackBars(props);
|
|
118
68
|
|
|
119
69
|
const renderLabel = (label: String, labelTextStyle: any) => {
|
|
120
70
|
return (
|
|
@@ -147,15 +97,6 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
147
97
|
);
|
|
148
98
|
};
|
|
149
99
|
|
|
150
|
-
const totalHeight = props.item.stacks.reduce(
|
|
151
|
-
(acc, stack) =>
|
|
152
|
-
acc +
|
|
153
|
-
(Math.abs(stack.value) * (containerHeight || 200)) / (maxValue || 200),
|
|
154
|
-
0,
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
const [height, setHeight] = useState(noAnimation ? totalHeight : 1);
|
|
158
|
-
|
|
159
100
|
useEffect(() => {
|
|
160
101
|
if (!noAnimation) {
|
|
161
102
|
layoutAppear();
|
|
@@ -180,36 +121,6 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
180
121
|
};
|
|
181
122
|
|
|
182
123
|
const static2DSimple = () => {
|
|
183
|
-
const getStackBorderRadii = (item: stackDataItem, index: number) => {
|
|
184
|
-
const stackItem = item.stacks[index];
|
|
185
|
-
const borderRadii = {
|
|
186
|
-
borderTopLeftRadius:
|
|
187
|
-
stackItem.borderTopLeftRadius ??
|
|
188
|
-
stackItem.borderRadius ??
|
|
189
|
-
props.barBorderTopLeftRadius ??
|
|
190
|
-
props.barBorderRadius ??
|
|
191
|
-
0,
|
|
192
|
-
borderTopRightRadius:
|
|
193
|
-
stackItem.borderTopRightRadius ??
|
|
194
|
-
stackItem.borderRadius ??
|
|
195
|
-
props.barBorderTopRightRadius ??
|
|
196
|
-
props.barBorderRadius ??
|
|
197
|
-
0,
|
|
198
|
-
borderBottomLeftRadius:
|
|
199
|
-
stackItem.borderBottomLeftRadius ??
|
|
200
|
-
stackItem.borderRadius ??
|
|
201
|
-
props.barBorderBottomLeftRadius ??
|
|
202
|
-
props.barBorderRadius ??
|
|
203
|
-
0,
|
|
204
|
-
borderBottomRightRadius:
|
|
205
|
-
stackItem.borderBottomRightRadius ??
|
|
206
|
-
stackItem.borderRadius ??
|
|
207
|
-
props.barBorderBottomRightRadius ??
|
|
208
|
-
props.barBorderRadius ??
|
|
209
|
-
0,
|
|
210
|
-
};
|
|
211
|
-
return borderRadii;
|
|
212
|
-
};
|
|
213
124
|
|
|
214
125
|
return (
|
|
215
126
|
<>
|
|
@@ -224,6 +135,13 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
224
135
|
props.onPress(item, index);
|
|
225
136
|
}
|
|
226
137
|
}}
|
|
138
|
+
onLongPress={()=>{
|
|
139
|
+
if (item.onLongPress) {
|
|
140
|
+
item.onLongPress();
|
|
141
|
+
} else if (props.onLongPress) {
|
|
142
|
+
props.onLongPress(item, index);
|
|
143
|
+
}
|
|
144
|
+
}}
|
|
227
145
|
style={[
|
|
228
146
|
{
|
|
229
147
|
position: 'absolute',
|