react-native-gifted-charts 1.4.1 → 1.4.3

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.1",
3
+ "version": "1.4.3",
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.13"
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, { useEffect, useState} from '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 {getPropsForAnimated2DWithGradient,Animated2DWithGradientPropsType} from 'gifted-charts-core';
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}
@@ -184,35 +173,35 @@ const Animated2DWithGradient = (props: Animated2DWithGradientPropsType) => {
184
173
  </View>
185
174
  ) : null}
186
175
  </View>
187
- {(item.topLabelComponent || showValuesAsTopLabel) && (
188
- <View
189
- style={[
190
- {
191
- position: 'absolute',
192
- top: (item.barWidth || barWidth || 30) * -1,
193
- height: item.barWidth || barWidth || 30,
194
- width: item.barWidth || barWidth || 30,
195
- justifyContent:
196
- (props.horizontal && !intactTopLabel) || item.value < 0
197
- ? 'center'
198
- : 'flex-end',
199
- alignItems: 'center',
200
- opacity: opacity,
201
- },
202
- item.value < 0 && {transform: [{rotate: '180deg'}]},
203
- props.horizontal &&
204
- !intactTopLabel && {transform: [{rotate: '270deg'}]},
205
- topLabelContainerStyle ?? item.topLabelContainerStyle,
206
- ]}>
207
- {showValuesAsTopLabel ? (
208
- <Text style={topLabelTextStyle}>{item.value}</Text>
209
- ) : (
210
- item.topLabelComponent?.()
211
- )}
212
- </View>
213
- )}
214
176
  </View>
215
177
  )}
178
+ {item.topLabelComponent || showValuesAsTopLabel ? (
179
+ <View
180
+ style={[
181
+ {
182
+ position: 'absolute',
183
+ top: (item.barWidth || barWidth || 30) * -1,
184
+ height: item.barWidth || barWidth || 30,
185
+ width: item.barWidth || barWidth || 30,
186
+ justifyContent:
187
+ (props.horizontal && !intactTopLabel) || item.value < 0
188
+ ? 'center'
189
+ : 'flex-end',
190
+ alignItems: 'center',
191
+ opacity: opacity,
192
+ },
193
+ item.value < 0 && {transform: [{rotate: '180deg'}]},
194
+ props.horizontal &&
195
+ !intactTopLabel && {transform: [{rotate: '270deg'}]},
196
+ topLabelContainerStyle ?? item.topLabelContainerStyle,
197
+ ]}>
198
+ {showValuesAsTopLabel ? (
199
+ <Text style={topLabelTextStyle}>{item.value}</Text>
200
+ ) : (
201
+ item.topLabelComponent?.()
202
+ )}
203
+ </View>
204
+ ) : null}
216
205
  </>
217
206
  );
218
207
  };
@@ -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 { getPropsForAnimated2DWithGradient,RenderBarsPropsType, barDataItem } from 'gifted-charts-core';
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 localBarInnerComponent = item.barInnerComponent ?? props.barInnerComponent;
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
- item.gradientColor || props.gradientColor || 'white',
196
- item.frontColor || props.frontColor || 'black',
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: item.barWidth || props.barWidth || 30,
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
- barBorderRadius={props.barBorderRadius || 0}
315
- barBorderTopLeftRadius={barBorderTopLeftRadius}
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
@@ -3,11 +3,7 @@ import {Animated, Easing, View} from 'react-native';
3
3
  import RenderBars from './RenderBars';
4
4
  import RenderStackBars from './RenderStackBars';
5
5
  import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
6
- import {
7
- BarChartPropsType,
8
- useBarChart,
9
- screenWidth,
10
- } from 'gifted-charts-core';
6
+ import {BarChartPropsType, useBarChart, screenWidth} from 'gifted-charts-core';
11
7
  import {StripAndLabel} from '../Components/common/StripAndLabel';
12
8
  import {Pointer} from '../Components/common/Pointer';
13
9
 
@@ -338,7 +334,7 @@ export const BarChart = (props: BarChartPropsType) => {
338
334
  <RenderBars
339
335
  data={data}
340
336
  side={side}
341
- minHeight={props.minHeight || 0}
337
+ minHeight={props.minHeight ?? (isAnimated && !isThreeD ? 0.1 : 0)}
342
338
  sideWidth={props.sideWidth}
343
339
  labelWidth={labelWidth}
344
340
  isThreeD={isThreeD}
@@ -10,7 +10,11 @@ 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, BarDefaults } from 'gifted-charts-core';
13
+ import {
14
+ useAnimatedThreeDBar,
15
+ animatedBarPropTypes,
16
+ trianglePropTypes,
17
+ } from 'gifted-charts-core';
14
18
 
15
19
  if (Platform.OS === 'android') {
16
20
  UIManager.setLayoutAnimationEnabledExperimental &&
@@ -54,7 +58,7 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
54
58
  animationDuration,
55
59
  item,
56
60
  index,
57
- width,
61
+ barWidth,
58
62
  sideWidth,
59
63
  barStyle,
60
64
  barBackgroundPattern,
@@ -129,8 +133,8 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
129
133
  <View style={{position: 'absolute', top: sideWidth / -2}}>
130
134
  <View
131
135
  style={{
132
- width: width,
133
- height: width * 0.4,
136
+ width: barWidth,
137
+ height: barWidth * 0.4,
134
138
  // left: width / 2,
135
139
  backgroundColor: topColor,
136
140
  opacity: opacity,
@@ -141,7 +145,7 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
141
145
  style={{
142
146
  position: 'absolute',
143
147
  top: sideWidth / -2,
144
- left: width,
148
+ left: barWidth,
145
149
  }}>
146
150
  <TriangleCorner
147
151
  color={topColor}
@@ -154,33 +158,31 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
154
158
 
155
159
  {/*******************************************************************/}
156
160
 
157
- {props.height ? (
158
- <View style={{marginTop: sideWidth / -2}}>
159
- <TriangleCorner
160
- color={sideColor}
161
- width={sideWidth}
162
- style={{transform: [{rotate: '-90deg'}], opacity: opacity}}
163
- />
164
- <View
165
- style={{
166
- width: sideWidth / 2,
167
- height: height - sideWidth / 2, //animatedSideHeight
168
- backgroundColor: sideColor,
169
- opacity: opacity,
170
- }}
171
- />
172
- <TriangleCorner
173
- color={sideColor}
174
- width={sideWidth}
175
- style={{transform: [{rotate: '90deg'}], opacity: opacity}}
176
- />
177
- </View>
178
- ) : null}
161
+ <View style={{marginTop: sideWidth / -2}}>
162
+ <TriangleCorner
163
+ color={height ? sideColor : 'transparent'}
164
+ width={sideWidth}
165
+ style={{transform: [{rotate: '-90deg'}], opacity: opacity}}
166
+ />
167
+ <View
168
+ style={{
169
+ width: sideWidth / 2,
170
+ height: height - sideWidth / 2, //animatedSideHeight
171
+ backgroundColor: sideColor,
172
+ opacity: opacity,
173
+ }}
174
+ />
175
+ <TriangleCorner
176
+ color={height ? sideColor : 'transparent'}
177
+ width={sideWidth}
178
+ style={{transform: [{rotate: '90deg'}], opacity: opacity}}
179
+ />
180
+ </View>
179
181
 
180
182
  <View
181
183
  style={[
182
184
  {
183
- width: width,
185
+ width: barWidth,
184
186
  height: height, //animatedHeight
185
187
  backgroundColor: frontColor,
186
188
  borderLeftWidth: StyleSheet.hairlineWidth,
@@ -205,7 +207,7 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
205
207
  stroke="transparent"
206
208
  x="1"
207
209
  y="1"
208
- width={width || 30}
210
+ width={barWidth || 30}
209
211
  height={height}
210
212
  fill={`url(#${patternId})`}
211
213
  />
@@ -225,9 +227,9 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
225
227
  style={[
226
228
  {
227
229
  position: 'absolute',
228
- top: width * -2,
229
- height: (width * 3) / 2,
230
- width: (width * 3) / 2,
230
+ top: barWidth * -2,
231
+ height: (barWidth * 3) / 2,
232
+ width: (barWidth * 3) / 2,
231
233
  justifyContent: 'flex-end',
232
234
  alignItems: 'center',
233
235
  opacity: opacity,
@@ -104,7 +104,6 @@ export const LineChart = (props: LineChartPropsType) => {
104
104
  arrowPointsFromSet,
105
105
  selectedIndex,
106
106
  setSelectedIndex,
107
- noOfSections,
108
107
  containerHeight,
109
108
  data,
110
109
  data2,
@@ -298,7 +297,7 @@ export const LineChart = (props: LineChartPropsType) => {
298
297
 
299
298
  if (!initialData) {
300
299
  initialData = data0 ?? [...data];
301
- animations = initialData.map(item => new Animated.Value(item.value));
300
+ animations = initialData?.map(item => new Animated.Value(item.value));
302
301
  }
303
302
 
304
303
  const widthValuesFromSet = useMemo(