react-native-gifted-charts 1.4.9 → 1.4.11

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 CHANGED
@@ -1,4 +1,4 @@
1
- # react-native-gifted-charts [![Rate on Openbase](https://badges.openbase.com/js/rating/react-native-gifted-charts.svg)](https://openbase.com/js/react-native-gifted-charts?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge)
1
+ # react-native-gifted-charts
2
2
 
3
3
  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.
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gifted-charts",
3
- "version": "1.4.9",
3
+ "version": "1.4.11",
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.1.3"
27
+ "gifted-charts-core": "^0.1.7"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.22.5",
@@ -4,7 +4,7 @@ import AnimatedThreeDBar from '../Components/AnimatedThreeDBar';
4
4
  import Animated2DWithGradient from './Animated2DWithGradient';
5
5
  import Cap from '../Components/BarSpecificComponents/cap';
6
6
  import BarBackgroundPattern from '../Components/BarSpecificComponents/barBackgroundPattern';
7
- import LinearGradient from "../Components/common/LinearGradient";
7
+ import LinearGradient from '../Components/common/LinearGradient';
8
8
  import {
9
9
  getPropsForAnimated2DWithGradient,
10
10
  RenderBarsPropsType,
@@ -51,6 +51,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
51
51
  pointerConfig,
52
52
  noOfSectionsBelowXAxis,
53
53
  yAxisOffset,
54
+ barWidth,
54
55
  } = props;
55
56
 
56
57
  const barHeight = Math.max(
@@ -88,8 +89,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
88
89
  (item.labelWidth ||
89
90
  props.labelWidth ||
90
91
  item.barWidth ||
91
- props.barWidth ||
92
- 30) + spacing,
92
+ barWidth) + spacing,
93
93
  left: spacing / -2,
94
94
  position: 'absolute',
95
95
  height: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
@@ -154,8 +154,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
154
154
  (item.labelWidth ||
155
155
  props.labelWidth ||
156
156
  item.barWidth ||
157
- props.barWidth ||
158
- 30) + spacing,
157
+ barWidth) + spacing,
159
158
  left: spacing / -2,
160
159
  position: 'absolute',
161
160
  height: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
@@ -206,8 +205,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
206
205
  let leftSpacing = initialSpacing;
207
206
  for (let i = 0; i < index; i++) {
208
207
  leftSpacing +=
209
- (data[i].spacing ?? propSpacing) +
210
- (data[i].barWidth || props.barWidth || 30);
208
+ (data[i].spacing ?? propSpacing) + (data[i].barWidth || barWidth);
211
209
  }
212
210
 
213
211
  const static2DWithGradient = (item: barDataItem) => {
@@ -249,9 +247,9 @@ const RenderBars = (props: RenderBarsPropsType) => {
249
247
  style={[
250
248
  {
251
249
  position: 'absolute',
252
- top: (item.barWidth || props.barWidth || 30) * -1,
253
- height: item.barWidth || props.barWidth || 30,
254
- width: item.barWidth || props.barWidth || 30,
250
+ top: (item.barWidth || barWidth) * -1,
251
+ height: item.barWidth || barWidth,
252
+ width: item.barWidth || barWidth,
255
253
  justifyContent:
256
254
  (horizontal && !intactTopLabel) || item.value < 0
257
255
  ? 'center'
@@ -287,25 +285,30 @@ const RenderBars = (props: RenderBarsPropsType) => {
287
285
  height: barHeight,
288
286
  marginRight: spacing,
289
287
  },
290
- item.value < 0
288
+
289
+ pointerConfig
291
290
  ? {
292
291
  transform: [
293
292
  {
294
293
  translateY:
295
- (Math.abs(item.value) * (containerHeight || 200)) /
296
- (maxValue || 200),
294
+ (containerHeight || 200) -
295
+ (barHeight - 10 + xAxisLabelsVerticalShift) +
296
+ (item.value < 0
297
+ ? (Math.abs(item.value) * (containerHeight || 200)) /
298
+ (maxValue || 200)
299
+ : 0),
297
300
  },
298
- {rotateZ: '180deg'},
299
301
  ],
300
302
  }
301
- : pointerConfig
303
+ : item.value < 0
302
304
  ? {
303
305
  transform: [
304
306
  {
305
307
  translateY:
306
- (containerHeight || 200) -
307
- (barHeight - 10 + xAxisLabelsVerticalShift),
308
+ (Math.abs(item.value) * (containerHeight || 200)) /
309
+ (maxValue || 200),
308
310
  },
311
+ {rotateZ: '180deg'},
309
312
  ],
310
313
  }
311
314
  : null,
@@ -353,10 +356,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
353
356
  height: props.xAxisIndicesHeight,
354
357
  width: props.xAxisIndicesWidth,
355
358
  bottom: props.xAxisIndicesHeight / -2,
356
- left:
357
- ((item.barWidth || props.barWidth || 30) -
358
- props.xAxisIndicesWidth) /
359
- 2,
359
+ left: ((item.barWidth || barWidth) - props.xAxisIndicesWidth) / 2,
360
360
  backgroundColor: props.xAxisIndicesColor,
361
361
  }}
362
362
  />
@@ -367,7 +367,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
367
367
  sideWidth={
368
368
  item.sideWidth ||
369
369
  props.sideWidth ||
370
- (item.barWidth || props.barWidth || 30) / 2
370
+ (item.barWidth || barWidth) / 2
371
371
  }
372
372
  side={side || 'left'}
373
373
  sideColor={item.sideColor || props.sideColor || ''}
@@ -86,7 +86,7 @@ export const BarChart = (props: BarChartPropsType) => {
86
86
  autoShiftLabels,
87
87
  getPropsCommonForBarAndStack,
88
88
  barAndLineChartsWrapperProps,
89
- } = useBarChart({...props, heightValue, widthValue, opacValue});
89
+ } = useBarChart({...props, heightValue, widthValue, opacValue, parentWidth: props.parentWidth ?? screenWidth});
90
90
 
91
91
  const labelsAppear = useCallback(() => {
92
92
  opacValue.setValue(0);
@@ -52,6 +52,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
52
52
 
53
53
  onEndReached,
54
54
  onStartReached,
55
+ onMomentumScrollEnd,
55
56
  } = props;
56
57
 
57
58
  const {
@@ -77,7 +78,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
77
78
  verticalLinesProps,
78
79
  lineInBarChartProps,
79
80
  lineInBarChartProps2,
80
- } = useBarAndLineChartsWrapper({...props, isRTL:I18nManager.isRTL});
81
+ } = useBarAndLineChartsWrapper({...props, isRTL: I18nManager.isRTL});
81
82
 
82
83
  useEffect(() => {
83
84
  if (pointerConfig && getPointerProps) {
@@ -124,6 +125,9 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
124
125
  setCanMomentum(true);
125
126
  }}
126
127
  onMomentumScrollEnd={({nativeEvent}) => {
128
+ if (onMomentumScrollEnd) {
129
+ onMomentumScrollEnd();
130
+ }
127
131
  if (isCloseToEnd(nativeEvent) && canMomentum) {
128
132
  onEndReached ? onEndReached() : null;
129
133
  setCanMomentum(false);
@@ -15,6 +15,7 @@ import {
15
15
  bicolorLineDataItem,
16
16
  useLineChartBiColor,
17
17
  } from 'gifted-charts-core';
18
+ import { screenWidth } from '../utils';
18
19
 
19
20
  export const LineChartBicolor = (props: LineChartBicolorPropsType) => {
20
21
  const scrollRef = useRef();
@@ -81,7 +82,7 @@ export const LineChartBicolor = (props: LineChartBicolorPropsType) => {
81
82
  unFocusOnPressOut,
82
83
  delayBeforeUnFocus,
83
84
  barAndLineChartsWrapperProps,
84
- } = useLineChartBiColor(props);
85
+ } = useLineChartBiColor({...props, parentWidth: props.parentWidth ?? screenWidth});
85
86
 
86
87
  const labelsAppear = useCallback(() => {
87
88
  opacValue.setValue(0);
@@ -87,6 +87,8 @@ export const LineChart = (props: LineChartPropsType) => {
87
87
  setPointerItem4,
88
88
  pointerY5,
89
89
  setPointerY5,
90
+ pointerYsForDataSet,
91
+ setPointerYsForDataSet,
90
92
  pointerItem5,
91
93
  setPointerItem5,
92
94
  secondaryPointerY,
@@ -185,6 +187,7 @@ export const LineChart = (props: LineChartPropsType) => {
185
187
  getX,
186
188
  getY,
187
189
  getSecondaryY,
190
+ secondaryMaxValue,
188
191
  showValuesAsDataPointsText,
189
192
  thickness1,
190
193
  thickness2,
@@ -290,6 +293,7 @@ export const LineChart = (props: LineChartPropsType) => {
290
293
  showDataPointOnFocus,
291
294
  showStripOnFocus,
292
295
  showTextOnFocus,
296
+ showDataPointLabelOnFocus,
293
297
  stripHeight,
294
298
  stripWidth,
295
299
  stripColor,
@@ -302,7 +306,11 @@ export const LineChart = (props: LineChartPropsType) => {
302
306
  lineGradientStartColor,
303
307
  lineGradientEndColor,
304
308
  barAndLineChartsWrapperProps,
305
- } = useLineChart({...props, animations, screenWidth});
309
+ } = useLineChart({
310
+ ...props,
311
+ animations,
312
+ parentWidth: props.parentWidth ?? screenWidth,
313
+ });
306
314
 
307
315
  const widthValuesFromSet = useMemo(
308
316
  () => dataSet?.map(set => new Animated.Value(0)),
@@ -783,7 +791,11 @@ export const LineChart = (props: LineChartPropsType) => {
783
791
  spacing * index,
784
792
  },
785
793
  ]}>
786
- {dataPointLabelComponent()}
794
+ {showDataPointLabelOnFocus
795
+ ? index === selectedIndex
796
+ ? dataPointLabelComponent()
797
+ : null
798
+ : dataPointLabelComponent()}
787
799
  </View>
788
800
  ) : null
789
801
  ) : text || item.dataPointText ? (
@@ -847,7 +859,31 @@ export const LineChart = (props: LineChartPropsType) => {
847
859
  });
848
860
  };
849
861
 
850
- const renderPointer = (lineNumber: number) => {
862
+ const renderPointer = (lineNumber: number, isDataSet?: boolean) => {
863
+ if (isDataSet) {
864
+ let pointerItemLocal, pointerYLocal, pointerColorLocal;
865
+ return dataSet?.map((set, index) => {
866
+ const pIndex = barAndLineChartsWrapperProps.pointerIndex;
867
+ pointerItemLocal = set[pIndex];
868
+ pointerYLocal = pointerYsForDataSet[index];
869
+ pointerColorLocal =
870
+ pointerConfig?.pointerColorsForDataSet?.[index] ?? pointerColor;
871
+ return (
872
+ <Fragment key={'dSetPts' + index}>
873
+ {Pointer({
874
+ pointerX,
875
+ pointerYLocal: pointerYLocal + xAxisThickness,
876
+ pointerComponent,
877
+ pointerHeight,
878
+ pointerRadius,
879
+ pointerWidth,
880
+ pointerItemLocal,
881
+ pointerColorLocal,
882
+ })}
883
+ </Fragment>
884
+ );
885
+ });
886
+ }
851
887
  if (lineNumber === 1 && hidePointer1) return;
852
888
  if (lineNumber === 2 && hidePointer2) return;
853
889
  if (lineNumber === 3 && hidePointer3) return;
@@ -1144,7 +1180,7 @@ export const LineChart = (props: LineChartPropsType) => {
1144
1180
  );
1145
1181
  }) ?? null}
1146
1182
 
1147
- {/*** !!! Here it's done thrice intentionally, trying to make it to only 1 breaks things !!! ***/}
1183
+ {/*** !!! Here it's done 5 times intentionally, trying to make it to only 1 breaks things !!! ***/}
1148
1184
  {renderDataPoints(
1149
1185
  hideDataPoints1,
1150
1186
  data,
@@ -1329,13 +1365,27 @@ export const LineChart = (props: LineChartPropsType) => {
1329
1365
  if (item) {
1330
1366
  y =
1331
1367
  containerHeight -
1332
- (item.value * containerHeight) / maxValue -
1368
+ (item.value * containerHeight) / secondaryMaxValue -
1333
1369
  (pointerRadius || pointerHeight / 2) +
1334
1370
  10;
1335
1371
  setSecondaryPointerY(y);
1336
1372
  setSecondaryPointerItem(item);
1337
1373
  }
1338
1374
  }
1375
+ if (dataSet?.length) {
1376
+ if (dataSet[0].data[factor]) {
1377
+ const ysForDataSet = dataSet.map(set => {
1378
+ const item = set.data[factor];
1379
+ const y =
1380
+ containerHeight -
1381
+ (item.value * containerHeight) / maxValue -
1382
+ (pointerRadius || pointerHeight / 2) +
1383
+ 10;
1384
+ return y;
1385
+ });
1386
+ setPointerYsForDataSet(ysForDataSet);
1387
+ }
1388
+ }
1339
1389
  };
1340
1390
 
1341
1391
  const renderLine = (
@@ -1458,13 +1508,27 @@ export const LineChart = (props: LineChartPropsType) => {
1458
1508
  if (item) {
1459
1509
  y =
1460
1510
  containerHeight -
1461
- (item.value * containerHeight) / maxValue -
1511
+ (item.value * containerHeight) / secondaryMaxValue -
1462
1512
  (pointerRadius || pointerHeight / 2) +
1463
1513
  10;
1464
1514
  setSecondaryPointerY(y);
1465
1515
  setSecondaryPointerItem(item);
1466
1516
  }
1467
1517
  }
1518
+ if (dataSet?.length) {
1519
+ if (dataSet[0].data[factor]) {
1520
+ const ysForDataSet = dataSet.map(set => {
1521
+ const item = set.data[factor];
1522
+ const y =
1523
+ containerHeight -
1524
+ (item.value * containerHeight) / maxValue -
1525
+ (pointerRadius || pointerHeight / 2) +
1526
+ 10;
1527
+ return y;
1528
+ });
1529
+ setPointerYsForDataSet(ysForDataSet);
1530
+ }
1531
+ }
1468
1532
  }}
1469
1533
  // onResponderReject={evt => {
1470
1534
  // console.log('evt...reject.......',evt);
@@ -1644,13 +1708,27 @@ export const LineChart = (props: LineChartPropsType) => {
1644
1708
  if (item) {
1645
1709
  y =
1646
1710
  containerHeight -
1647
- (item.value * containerHeight) / maxValue -
1711
+ (item.value * containerHeight) / secondaryMaxValue -
1648
1712
  (pointerRadius || pointerHeight / 2) +
1649
1713
  10;
1650
1714
  setSecondaryPointerY(y);
1651
1715
  setSecondaryPointerItem(item);
1652
1716
  }
1653
1717
  }
1718
+ if (dataSet?.length) {
1719
+ if (dataSet[0].data[factor]) {
1720
+ const ysForDataSet = dataSet.map(set => {
1721
+ const item = set.data[factor];
1722
+ const y =
1723
+ containerHeight -
1724
+ (item.value * containerHeight) / maxValue -
1725
+ (pointerRadius || pointerHeight / 2) +
1726
+ 10;
1727
+ return y;
1728
+ });
1729
+ setPointerYsForDataSet(ysForDataSet);
1730
+ }
1731
+ }
1654
1732
  }}
1655
1733
  // onResponderReject={evt => {
1656
1734
  // console.log('evt...reject.......',evt);
@@ -2021,8 +2099,9 @@ export const LineChart = (props: LineChartPropsType) => {
2021
2099
  }}>
2022
2100
  {!stripOverPointer && renderStripAndLabel()}
2023
2101
  {dataSet ? (
2024
- renderPointer(1)
2102
+ renderPointer(0, true)
2025
2103
  ) : (
2104
+ // dataSet.map((set, index) => renderPointer(index))
2026
2105
  <>
2027
2106
  {renderPointer(1)}
2028
2107
  {points2 ? renderPointer(2) : null}
@@ -40,7 +40,7 @@ export const PieChartPro = (props: PieChartPropsType) => {
40
40
  edgesRadius = 0,
41
41
  showGradient,
42
42
  ring,
43
- pieInnerComponent,
43
+ centerLabelComponent,
44
44
  strokeDashArray,
45
45
  semiCircle,
46
46
  } = props;
@@ -103,7 +103,7 @@ export const PieChartPro = (props: PieChartPropsType) => {
103
103
  ? {position: 'absolute', bottom: 0}
104
104
  : {position: 'absolute'}
105
105
  }>
106
- {pieInnerComponent ? pieInnerComponent() : null}
106
+ {centerLabelComponent ? centerLabelComponent() : null}
107
107
  </View>
108
108
  <Svg
109
109
  {...rnSvgProps}