react-native-gifted-charts 1.4.3 → 1.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gifted-charts",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
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,7 +24,7 @@
24
24
  "registry": "https://registry.npmjs.org/"
25
25
  },
26
26
  "dependencies": {
27
- "gifted-charts-core": "^0.0.13"
27
+ "gifted-charts-core": "^0.0.15"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.22.5",
@@ -48,6 +48,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
48
48
  topLabelContainerStyle,
49
49
  topLabelTextStyle,
50
50
  pointerConfig,
51
+ noOfSectionsBelowXAxis,
51
52
  } = props;
52
53
 
53
54
  const barHeight = Math.max(
@@ -112,7 +113,11 @@ const RenderBars = (props: RenderBarsPropsType) => {
112
113
  ? {
113
114
  transform: [
114
115
  {rotate: '180deg'},
115
- {translateY: autoShiftLabels ? 0 : 32},
116
+ {
117
+ translateY: autoShiftLabels
118
+ ? 0
119
+ : 16.5 * xAxisTextNumberOfLines + 14,
120
+ },
116
121
  ],
117
122
  }
118
123
  : {},
@@ -166,7 +171,18 @@ const RenderBars = (props: RenderBarsPropsType) => {
166
171
  : {transform: [{rotate: '60deg'}]}
167
172
  : horizontal
168
173
  ? {transform: [{rotate: '-90deg'}]}
169
- : {},
174
+ : value < 0
175
+ ? {
176
+ transform: [
177
+ {rotate: '180deg'},
178
+ {
179
+ translateY: autoShiftLabels
180
+ ? 0
181
+ : 16.5 * xAxisTextNumberOfLines + 14,
182
+ },
183
+ ],
184
+ }
185
+ : {},
170
186
  ]}>
171
187
  {item.labelComponent ? (
172
188
  item.labelComponent()
@@ -300,6 +316,8 @@ const RenderBars = (props: RenderBarsPropsType) => {
300
316
  (pointerConfig && pointerConfig.barTouchable !== true);
301
317
 
302
318
  const barContent = () => {
319
+ const isBarBelowXaxisAndInvisible =
320
+ item.value < 0 && !noOfSectionsBelowXAxis;
303
321
  const animated2DWithGradient = (noGradient, noAnimation) => (
304
322
  <Animated2DWithGradient
305
323
  {...commonPropsFor2Dand3Dbars}
@@ -341,7 +359,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
341
359
  }}
342
360
  />
343
361
  )}
344
- {isThreeD ? (
362
+ {isBarBelowXaxisAndInvisible ? null : isThreeD ? (
345
363
  <AnimatedThreeDBar
346
364
  {...commonPropsFor2Dand3Dbars}
347
365
  sideWidth={
@@ -401,6 +419,13 @@ const RenderBars = (props: RenderBarsPropsType) => {
401
419
  ? props.onLongPress(item, index)
402
420
  : null;
403
421
  }}
422
+ onPressOut={() => {
423
+ item.onPressOut
424
+ ? item.onPressOut()
425
+ : props.onPressOut
426
+ ? props.onPressOut(item, index)
427
+ : null;
428
+ }}
404
429
  style={barWrapperStyle}>
405
430
  {barContent()}
406
431
  </TouchableOpacity>
@@ -9,7 +9,11 @@ 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 { useRenderStackBars, BarDefaults, StackedBarChartPropsType } from 'gifted-charts-core';
12
+ import {
13
+ useRenderStackBars,
14
+ BarDefaults,
15
+ StackedBarChartPropsType,
16
+ } from 'gifted-charts-core';
13
17
 
14
18
  if (Platform.OS === 'android') {
15
19
  UIManager.setLayoutAnimationEnabledExperimental &&
@@ -121,7 +125,6 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
121
125
  };
122
126
 
123
127
  const static2DSimple = () => {
124
-
125
128
  return (
126
129
  <>
127
130
  <TouchableOpacity
@@ -135,13 +138,20 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
135
138
  props.onPress(item, index);
136
139
  }
137
140
  }}
138
- onLongPress={()=>{
141
+ onLongPress={() => {
139
142
  if (item.onLongPress) {
140
143
  item.onLongPress();
141
144
  } else if (props.onLongPress) {
142
145
  props.onLongPress(item, index);
143
146
  }
144
147
  }}
148
+ onPressOut={() => {
149
+ if (item.onPressOut) {
150
+ item.onPressOut();
151
+ } else if (props.onPressOut) {
152
+ props.onPressOut(item, index);
153
+ }
154
+ }}
145
155
  style={[
146
156
  {
147
157
  position: 'absolute',
@@ -14,6 +14,7 @@ export const BarChart = (props: BarChartPropsType) => {
14
14
 
15
15
  const scrollRef = props.scrollRef ?? useRef(null);
16
16
  const remainingScrollViewProps = {
17
+ onScroll: (ev: any) => props.onScroll?.(ev),
17
18
  onTouchStart: evt => {
18
19
  if (props.renderTooltip) {
19
20
  setSelectedIndex(-1);
@@ -732,6 +732,7 @@ export const LineChartBicolor = (props: LineChartBicolorPropsType) => {
732
732
  scrollRef={scrollRef}
733
733
  animatedWidth={animatedWidth}
734
734
  renderChartContent={renderChartContent}
735
+ remainingScrollViewProps={{onScroll: (ev: any) => props.onScroll?.(ev)}}
735
736
  />
736
737
  );
737
738
  };
@@ -1790,6 +1790,7 @@ export const LineChart = (props: LineChartPropsType) => {
1790
1790
 
1791
1791
  const remainingScrollViewProps = {
1792
1792
  onScroll: (ev: any) => {
1793
+ props.onScroll?.(ev);
1793
1794
  if (
1794
1795
  pointerConfig &&
1795
1796
  pointerConfig.activatePointersOnLongPress &&
@@ -25,6 +25,8 @@ export const PieChart = (props: PieChartPropsType) => {
25
25
  shiftInnerCenterY,
26
26
  tiltAngle,
27
27
  isDataShifted,
28
+ paddingHorizontal,
29
+ paddingVertical,
28
30
  } = usePieChart(props);
29
31
 
30
32
  const renderInnerCircle = (innerRadius, innerCircleBorderWidth) => {
@@ -40,8 +42,18 @@ export const PieChart = (props: PieChartPropsType) => {
40
42
  // zIndex: 100,
41
43
  alignSelf: 'center',
42
44
  backgroundColor: innerCircleColor,
43
- left: canvasWidth / 2 - innerRadius + shiftInnerCenterX,
44
- top: canvasHeight / 2 - innerRadius + shiftInnerCenterY,
45
+ left:
46
+ canvasWidth / 2 -
47
+ innerRadius +
48
+ shiftInnerCenterX +
49
+ extraRadiusForFocused +
50
+ paddingHorizontal / 2,
51
+ top:
52
+ canvasHeight / 2 -
53
+ innerRadius +
54
+ shiftInnerCenterY +
55
+ extraRadiusForFocused +
56
+ paddingVertical / 2,
45
57
  borderWidth: innerCircleBorderWidth,
46
58
  borderColor: innerCircleBorderColor,
47
59
  justifyContent: 'center',
@@ -80,16 +92,20 @@ export const PieChart = (props: PieChartPropsType) => {
80
92
  return (
81
93
  <View
82
94
  style={{
83
- height: (radius + extraRadiusForFocused) * (props.semiCircle ? 1 : 2),
84
- width: (radius + extraRadiusForFocused) * 2,
85
- marginLeft: extraRadiusForFocused * 2,
86
- marginTop: extraRadiusForFocused * 2,
95
+ height:
96
+ (radius + extraRadiusForFocused + paddingVertical / 2) *
97
+ (props.semiCircle ? 1 : 2),
98
+ width: (radius + extraRadiusForFocused + paddingHorizontal / 2) * 2,
99
+ overflow: 'hidden',
87
100
  }}>
88
101
  <View style={{position: 'absolute'}}>
89
102
  <PieChartMain
90
103
  {...props}
91
104
  selectedIndex={selectedIndex}
92
105
  setSelectedIndex={setSelectedIndex}
106
+ paddingHorizontal={paddingHorizontal}
107
+ paddingVertical={paddingVertical}
108
+ extraRadiusForFocused={extraRadiusForFocused}
93
109
  />
94
110
  </View>
95
111
  {renderInnerCircle(innerRadius, innerCircleBorderWidth)}
@@ -132,6 +148,9 @@ export const PieChart = (props: PieChartPropsType) => {
132
148
  innerRadius={props.innerRadius || radius / 2.5}
133
149
  isBiggerPie
134
150
  setSelectedIndex={setSelectedIndex}
151
+ paddingHorizontal={paddingHorizontal}
152
+ paddingVertical={paddingVertical}
153
+ extraRadiusForFocused={extraRadiusForFocused}
135
154
  />
136
155
  </View>
137
156
  )}
@@ -56,6 +56,9 @@ export const PieChartMain = (props: PieChartMainProps) => {
56
56
  cy,
57
57
  pData,
58
58
  mData,
59
+ paddingHorizontal,
60
+ paddingVertical,
61
+ extraRadiusForFocused,
59
62
  } = getPieChartMainProps(props);
60
63
 
61
64
  return (
@@ -64,27 +67,38 @@ export const PieChartMain = (props: PieChartMainProps) => {
64
67
  style={[
65
68
  {
66
69
  backgroundColor: backgroundColor,
67
- height: semiCircle ? canvasHeight / 2 : canvasHeight,
68
- width: canvasWidth,
70
+ height: semiCircle
71
+ ? (canvasHeight + paddingVertical) / 2 + extraRadiusForFocused
72
+ : canvasHeight + paddingVertical + extraRadiusForFocused * 2,
73
+ width: canvasWidth + paddingHorizontal + extraRadiusForFocused * 2,
69
74
  overflow: 'hidden',
70
75
  },
71
76
  isThreeD && {transform: [{rotateX: tiltAngle}]},
72
77
  ]}>
73
78
  <Svg
74
79
  pointerEvents={rnVersion >= 720000 ? 'box-none' : 'auto'} // use 'box-none' react-native version 0.72 onwards
75
- viewBox={`${strokeWidth / -2 + minShiftX} ${
76
- strokeWidth / -2 + minShiftY
80
+ viewBox={`${strokeWidth / -2 + minShiftX - extraRadiusForFocused - paddingHorizontal / 2} ${
81
+ strokeWidth / -2 +
82
+ minShiftY -
83
+ extraRadiusForFocused -
84
+ paddingVertical / 2
77
85
  } ${
78
- (radius + strokeWidth) * 2 +
86
+ (radius + extraRadiusForFocused + strokeWidth) * 2 +
87
+ paddingHorizontal +
79
88
  horizAdjustment +
80
89
  (horizAdjustment ? strokeWidth : 0)
81
90
  } ${
82
- (radius + strokeWidth) * 2 +
83
- +vertAdjustment +
91
+ (radius + extraRadiusForFocused + strokeWidth) * 2 +
92
+ paddingVertical +
93
+ vertAdjustment +
84
94
  (vertAdjustment ? strokeWidth : 0)
85
95
  }`}
86
- height={radius * 2 + strokeWidth}
87
- width={radius * 2 + strokeWidth}>
96
+ height={
97
+ (radius + extraRadiusForFocused) * 2 + strokeWidth + paddingVertical
98
+ }
99
+ width={
100
+ (radius + extraRadiusForFocused) * 2 + strokeWidth + paddingHorizontal
101
+ }>
88
102
  <Defs>
89
103
  {data.map((item, index) => {
90
104
  return (
@@ -334,7 +348,8 @@ export const PieChartMain = (props: PieChartMainProps) => {
334
348
  backgroundColor: shadowColor,
335
349
  borderRadius: radius,
336
350
  position: 'absolute',
337
- top: shadowWidth,
351
+ top: shadowWidth + paddingVertical / 2,
352
+ left: paddingHorizontal / 2,
338
353
  zIndex: -1,
339
354
  }}
340
355
  />