react-native-gifted-charts 1.4.0 → 1.4.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gifted-charts",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar and Population Pyramid charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
|
5
5
|
"main": "src/index.tsx",
|
|
6
6
|
"files": [
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"registry": "https://registry.npmjs.org/"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"gifted-charts-core": "^0.0.10"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@babel/core": "^7.22.5",
|
|
@@ -38,12 +39,15 @@
|
|
|
38
39
|
"eslint": "^8.44.0",
|
|
39
40
|
"jest": "^29.5.0",
|
|
40
41
|
"metro-react-native-babel-preset": "^0.76.7",
|
|
42
|
+
"react": "^18.2.0",
|
|
43
|
+
"react-native": "^0.73.2",
|
|
44
|
+
"react-native-linear-gradient": "^2.8.3",
|
|
45
|
+
"react-native-svg": "^14.1.0",
|
|
41
46
|
"react-test-renderer": "18.2.0",
|
|
42
47
|
"ts-jest": "^29.1.1",
|
|
43
48
|
"typescript": "^5.1.6"
|
|
44
49
|
},
|
|
45
50
|
"peerDependencies": {
|
|
46
|
-
"gifted-charts-core": "*",
|
|
47
51
|
"react": "*",
|
|
48
52
|
"react-native": "*",
|
|
49
53
|
"react-native-linear-gradient": "*",
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import {
|
|
3
|
-
View,
|
|
4
|
-
LayoutAnimation,
|
|
5
|
-
Platform,
|
|
6
|
-
UIManager,
|
|
7
|
-
Text,
|
|
8
|
-
ViewStyle,
|
|
9
|
-
} from 'react-native';
|
|
1
|
+
import React, {useEffect, useState} from 'react';
|
|
2
|
+
import {View, LayoutAnimation, Platform, UIManager, Text} from 'react-native';
|
|
10
3
|
import LinearGradient from 'react-native-linear-gradient';
|
|
11
4
|
import Svg, {Defs, Rect} from 'react-native-svg';
|
|
12
5
|
import Cap from '../Components/BarSpecificComponents/cap';
|
|
13
|
-
import {
|
|
6
|
+
import {Animated2DWithGradientPropsType} from 'gifted-charts-core';
|
|
14
7
|
|
|
15
8
|
if (Platform.OS === 'android') {
|
|
16
9
|
UIManager.setLayoutAnimationEnabledExperimental &&
|
|
@@ -37,6 +30,8 @@ const Animated2DWithGradient = (props: Animated2DWithGradientPropsType) => {
|
|
|
37
30
|
showValuesAsTopLabel,
|
|
38
31
|
topLabelContainerStyle,
|
|
39
32
|
topLabelTextStyle,
|
|
33
|
+
commonStyleForBar,
|
|
34
|
+
barStyleWithBackground,
|
|
40
35
|
} = props;
|
|
41
36
|
const [height, setHeight] = useState(noAnimation ? props.height : 0.2);
|
|
42
37
|
const [initialRender, setInitialRender] = useState(
|
|
@@ -71,11 +66,6 @@ const Animated2DWithGradient = (props: Animated2DWithGradientPropsType) => {
|
|
|
71
66
|
setTimeout(() => elevate(), Platform.OS == 'ios' ? 10 : 100);
|
|
72
67
|
};
|
|
73
68
|
|
|
74
|
-
const{
|
|
75
|
-
commonStyleForBar,
|
|
76
|
-
barStyleWithBackground,
|
|
77
|
-
} = getPropsForAnimated2DWithGradient(props);
|
|
78
|
-
|
|
79
69
|
return (
|
|
80
70
|
<>
|
|
81
71
|
{!initialRender && (
|
|
@@ -110,8 +100,7 @@ const Animated2DWithGradient = (props: Animated2DWithGradientPropsType) => {
|
|
|
110
100
|
item.barStyle || barStyle,
|
|
111
101
|
]}>
|
|
112
102
|
{noGradient ? (
|
|
113
|
-
<View
|
|
114
|
-
style={barStyleWithBackground}>
|
|
103
|
+
<View style={barStyleWithBackground}>
|
|
115
104
|
{props.cappedBars && item.value ? (
|
|
116
105
|
<Cap
|
|
117
106
|
capThicknessFromItem={item.capThickness}
|
|
@@ -5,8 +5,11 @@ import LinearGradient from 'react-native-linear-gradient';
|
|
|
5
5
|
import Animated2DWithGradient from './Animated2DWithGradient';
|
|
6
6
|
import Cap from '../Components/BarSpecificComponents/cap';
|
|
7
7
|
import BarBackgroundPattern from '../Components/BarSpecificComponents/barBackgroundPattern';
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import {
|
|
9
|
+
getPropsForAnimated2DWithGradient,
|
|
10
|
+
RenderBarsPropsType,
|
|
11
|
+
barDataItem,
|
|
12
|
+
} from 'gifted-charts-core';
|
|
10
13
|
|
|
11
14
|
const RenderBars = (props: RenderBarsPropsType) => {
|
|
12
15
|
const {
|
|
@@ -21,12 +24,6 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
21
24
|
data,
|
|
22
25
|
barBorderWidth,
|
|
23
26
|
barBorderColor,
|
|
24
|
-
barBorderTopLeftRadius,
|
|
25
|
-
barBorderTopRightRadius,
|
|
26
|
-
barBorderBottomLeftRadius,
|
|
27
|
-
barBorderBottomRightRadius,
|
|
28
|
-
// oldValue,
|
|
29
|
-
|
|
30
27
|
isThreeD,
|
|
31
28
|
isAnimated,
|
|
32
29
|
rotateLabel,
|
|
@@ -53,7 +50,26 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
53
50
|
pointerConfig,
|
|
54
51
|
} = props;
|
|
55
52
|
|
|
56
|
-
const
|
|
53
|
+
const barHeight = Math.max(
|
|
54
|
+
minHeight,
|
|
55
|
+
(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200) -
|
|
56
|
+
(xAxisThickness ?? 0),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const {
|
|
60
|
+
commonStyleForBar,
|
|
61
|
+
barStyleWithBackground,
|
|
62
|
+
commonPropsFor2Dand3Dbars,
|
|
63
|
+
isFocused,
|
|
64
|
+
focusedBarConfig,
|
|
65
|
+
localFrontColor,
|
|
66
|
+
} = getPropsForAnimated2DWithGradient({...props, barHeight});
|
|
67
|
+
|
|
68
|
+
const itemOrPropsBarInnerComponent =
|
|
69
|
+
item.barInnerComponent ?? props.barInnerComponent;
|
|
70
|
+
const localBarInnerComponent = isFocused
|
|
71
|
+
? focusedBarConfig?.barInnerComponent ?? itemOrPropsBarInnerComponent
|
|
72
|
+
: itemOrPropsBarInnerComponent;
|
|
57
73
|
|
|
58
74
|
const barMarginBottom =
|
|
59
75
|
item.barMarginBottom === 0
|
|
@@ -169,12 +185,6 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
169
185
|
);
|
|
170
186
|
};
|
|
171
187
|
|
|
172
|
-
const barHeight = Math.max(
|
|
173
|
-
minHeight,
|
|
174
|
-
(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200) -
|
|
175
|
-
(xAxisThickness ?? 0),
|
|
176
|
-
);
|
|
177
|
-
|
|
178
188
|
let leftSpacing = initialSpacing;
|
|
179
189
|
for (let i = 0; i < index; i++) {
|
|
180
190
|
leftSpacing +=
|
|
@@ -182,9 +192,9 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
182
192
|
(data[i].barWidth || props.barWidth || 30);
|
|
183
193
|
}
|
|
184
194
|
|
|
185
|
-
const {commonStyleForBar, commonPropsFor2Dand3Dbars} = getPropsForAnimated2DWithGradient({...props, barHeight});
|
|
186
|
-
|
|
187
195
|
const static2DWithGradient = (item: barDataItem) => {
|
|
196
|
+
const localGradientColor =
|
|
197
|
+
item.gradientColor || props.gradientColor || 'white';
|
|
188
198
|
return (
|
|
189
199
|
<>
|
|
190
200
|
<LinearGradient
|
|
@@ -192,8 +202,10 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
192
202
|
start={{x: 0, y: 0}}
|
|
193
203
|
end={{x: 0, y: 1}}
|
|
194
204
|
colors={[
|
|
195
|
-
|
|
196
|
-
|
|
205
|
+
isFocused
|
|
206
|
+
? focusedBarConfig?.gradientColor ?? localGradientColor
|
|
207
|
+
: localGradientColor,
|
|
208
|
+
localFrontColor,
|
|
197
209
|
]}>
|
|
198
210
|
{props.cappedBars && item.value ? (
|
|
199
211
|
<Cap
|
|
@@ -253,7 +265,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
253
265
|
{
|
|
254
266
|
// overflow: 'visible',
|
|
255
267
|
marginBottom: 60 + barMarginBottom + xAxisLabelsVerticalShift,
|
|
256
|
-
width:
|
|
268
|
+
width: commonPropsFor2Dand3Dbars.barWidth,
|
|
257
269
|
height: barHeight,
|
|
258
270
|
marginRight: spacing,
|
|
259
271
|
},
|
|
@@ -279,8 +291,6 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
279
291
|
],
|
|
280
292
|
}
|
|
281
293
|
: null,
|
|
282
|
-
// !isThreeD && !item.showGradient && !props.showGradient &&
|
|
283
|
-
// { backgroundColor: item.frontColor || props.frontColor || 'black' },
|
|
284
294
|
side !== 'right' && {zIndex: data.length - index},
|
|
285
295
|
];
|
|
286
296
|
|
|
@@ -293,13 +303,11 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
293
303
|
const animated2DWithGradient = (noGradient, noAnimation) => (
|
|
294
304
|
<Animated2DWithGradient
|
|
295
305
|
{...commonPropsFor2Dand3Dbars}
|
|
296
|
-
barWidth={props.barWidth || 30}
|
|
297
306
|
animationDuration={animationDuration || 800}
|
|
298
307
|
roundedBottom={props.roundedBottom || false}
|
|
299
308
|
roundedTop={props.roundedTop || false}
|
|
300
309
|
noGradient={noGradient}
|
|
301
310
|
noAnimation={noAnimation}
|
|
302
|
-
gradientColor={noGradient ? undefined : props.gradientColor}
|
|
303
311
|
containerHeight={containerHeight}
|
|
304
312
|
maxValue={maxValue}
|
|
305
313
|
minHeight={minHeight ?? 0}
|
|
@@ -311,11 +319,8 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
311
319
|
horizontal={horizontal}
|
|
312
320
|
barBorderWidth={barBorderWidth}
|
|
313
321
|
barBorderColor={barBorderColor}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
barBorderTopRightRadius={barBorderTopRightRadius}
|
|
317
|
-
barBorderBottomLeftRadius={barBorderBottomLeftRadius}
|
|
318
|
-
barBorderBottomRightRadius={barBorderBottomRightRadius}
|
|
322
|
+
commonStyleForBar={commonStyleForBar}
|
|
323
|
+
barStyleWithBackground={barStyleWithBackground}
|
|
319
324
|
/>
|
|
320
325
|
);
|
|
321
326
|
return (
|
|
@@ -350,6 +355,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
350
355
|
horizontal={horizontal}
|
|
351
356
|
isAnimated={isAnimated}
|
|
352
357
|
animationDuration={animationDuration || 800}
|
|
358
|
+
selectedIndex={selectedIndex}
|
|
353
359
|
/>
|
|
354
360
|
) : item.showGradient || props.showGradient ? (
|
|
355
361
|
isAnimated ? (
|
|
@@ -379,7 +385,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
379
385
|
<TouchableOpacity
|
|
380
386
|
activeOpacity={props.activeOpacity || 0.2}
|
|
381
387
|
onPress={() => {
|
|
382
|
-
if (renderTooltip) {
|
|
388
|
+
if (renderTooltip || props.focusBarOnPress) {
|
|
383
389
|
setSelectedIndex(index);
|
|
384
390
|
}
|
|
385
391
|
item.onPress
|
|
@@ -388,7 +394,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
388
394
|
? props.onPress(item, index)
|
|
389
395
|
: null;
|
|
390
396
|
}}
|
|
391
|
-
onLongPress={()=>{
|
|
397
|
+
onLongPress={() => {
|
|
392
398
|
item.onLongPress
|
|
393
399
|
? item.onLongPress()
|
|
394
400
|
: props.onLongPress
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import LinearGradient from 'react-native-linear-gradient';
|
|
11
11
|
import Svg, {Defs, Rect} from 'react-native-svg';
|
|
12
12
|
import {styles} from './styles';
|
|
13
|
-
import { useAnimatedThreeDBar, animatedBarPropTypes, trianglePropTypes
|
|
13
|
+
import { useAnimatedThreeDBar, animatedBarPropTypes, trianglePropTypes } from 'gifted-charts-core';
|
|
14
14
|
|
|
15
15
|
if (Platform.OS === 'android') {
|
|
16
16
|
UIManager.setLayoutAnimationEnabledExperimental &&
|
|
@@ -54,7 +54,7 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
|
|
|
54
54
|
animationDuration,
|
|
55
55
|
item,
|
|
56
56
|
index,
|
|
57
|
-
|
|
57
|
+
barWidth,
|
|
58
58
|
sideWidth,
|
|
59
59
|
barStyle,
|
|
60
60
|
barBackgroundPattern,
|
|
@@ -129,8 +129,8 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
|
|
|
129
129
|
<View style={{position: 'absolute', top: sideWidth / -2}}>
|
|
130
130
|
<View
|
|
131
131
|
style={{
|
|
132
|
-
width:
|
|
133
|
-
height:
|
|
132
|
+
width: barWidth,
|
|
133
|
+
height: barWidth * 0.4,
|
|
134
134
|
// left: width / 2,
|
|
135
135
|
backgroundColor: topColor,
|
|
136
136
|
opacity: opacity,
|
|
@@ -141,7 +141,7 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
|
|
|
141
141
|
style={{
|
|
142
142
|
position: 'absolute',
|
|
143
143
|
top: sideWidth / -2,
|
|
144
|
-
left:
|
|
144
|
+
left: barWidth,
|
|
145
145
|
}}>
|
|
146
146
|
<TriangleCorner
|
|
147
147
|
color={topColor}
|
|
@@ -180,7 +180,7 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
|
|
|
180
180
|
<View
|
|
181
181
|
style={[
|
|
182
182
|
{
|
|
183
|
-
width:
|
|
183
|
+
width: barWidth,
|
|
184
184
|
height: height, //animatedHeight
|
|
185
185
|
backgroundColor: frontColor,
|
|
186
186
|
borderLeftWidth: StyleSheet.hairlineWidth,
|
|
@@ -205,7 +205,7 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
|
|
|
205
205
|
stroke="transparent"
|
|
206
206
|
x="1"
|
|
207
207
|
y="1"
|
|
208
|
-
width={
|
|
208
|
+
width={barWidth || 30}
|
|
209
209
|
height={height}
|
|
210
210
|
fill={`url(#${patternId})`}
|
|
211
211
|
/>
|
|
@@ -225,9 +225,9 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
|
|
|
225
225
|
style={[
|
|
226
226
|
{
|
|
227
227
|
position: 'absolute',
|
|
228
|
-
top:
|
|
229
|
-
height: (
|
|
230
|
-
width: (
|
|
228
|
+
top: barWidth * -2,
|
|
229
|
+
height: (barWidth * 3) / 2,
|
|
230
|
+
width: (barWidth * 3) / 2,
|
|
231
231
|
justifyContent: 'flex-end',
|
|
232
232
|
alignItems: 'center',
|
|
233
233
|
opacity: opacity,
|
package/src/index.tsx
CHANGED
|
@@ -8,10 +8,17 @@ export {
|
|
|
8
8
|
barDataItem,
|
|
9
9
|
stackDataItem,
|
|
10
10
|
BarChartPropsType,
|
|
11
|
-
StackedBarChartPropsType,
|
|
11
|
+
StackedBarChartPropsType,
|
|
12
|
+
pieDataItem,
|
|
13
|
+
PieChartPropsType,
|
|
12
14
|
lineDataItem,
|
|
13
15
|
bicolorLineDataItem,
|
|
14
16
|
LineChartPropsType,
|
|
15
17
|
LineChartBicolorPropsType,
|
|
16
18
|
popnPyramidDataItem,
|
|
17
|
-
PopulationPyramidPropsType,
|
|
19
|
+
PopulationPyramidPropsType,
|
|
20
|
+
chartTypes,
|
|
21
|
+
ruleTypes,
|
|
22
|
+
yAxisSides,
|
|
23
|
+
EdgePosition,
|
|
24
|
+
} from 'gifted-charts-core';
|