react-native-gifted-charts 1.2.19 → 1.2.22

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.2.19",
3
+ "version": "1.2.22",
4
4
  "description": "The most complete library for Bar, Line, Area, Pie, Donut and Stacked Bar charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
5
5
  "main": "src/index.tsx",
6
6
  "files": [
@@ -630,9 +630,12 @@ export const BarChart = (props: PropTypes) => {
630
630
  outputRange: [0, totalWidth],
631
631
  });
632
632
 
633
- const getLabel = val => {
633
+ const getLabel = (val, index) => {
634
634
  let label = '';
635
- if (showFractionalValues) {
635
+ if (
636
+ showFractionalValues ||
637
+ (props.yAxisLabelTexts && props.yAxisLabelTexts[index] !== undefined)
638
+ ) {
636
639
  if (val) {
637
640
  label = val;
638
641
  } else {
@@ -731,7 +734,7 @@ export const BarChart = (props: PropTypes) => {
731
734
  props.hideAxesAndRules !== true &&
732
735
  !hideYAxisText &&
733
736
  horizSections.map((sectionItems, index) => {
734
- let label = getLabel(sectionItems.value);
737
+ let label = getLabel(sectionItems.value, index);
735
738
  if (hideOrigin && index === horizSections.length - 1) {
736
739
  label = '';
737
740
  }
@@ -852,6 +855,7 @@ export const BarChart = (props: PropTypes) => {
852
855
  horizSectionsBelow.map((sectionItems, index) => {
853
856
  let label = getLabel(
854
857
  horizSectionsBelow[horizSectionsBelow.length - 1 - index].value,
858
+ index,
855
859
  );
856
860
  return (
857
861
  <View
@@ -906,7 +910,7 @@ export const BarChart = (props: PropTypes) => {
906
910
  props.hideAxesAndRules !== true &&
907
911
  !hideYAxisText &&
908
912
  horizSections.map((sectionItems, index) => {
909
- let label = getLabel(sectionItems.value);
913
+ let label = getLabel(sectionItems.value, index);
910
914
  if (hideOrigin && index === horizSections.length - 1) {
911
915
  label = '';
912
916
  }
@@ -267,6 +267,7 @@ type propTypes = {
267
267
  noOfSectionsBelowXAxis?: number;
268
268
  labelsExtraHeight?: number;
269
269
  adjustToWidth?: Boolean;
270
+ getPointerProps?: Function;
270
271
  };
271
272
  type referenceConfigType = {
272
273
  thickness: number;
@@ -346,6 +347,7 @@ type Pointer = {
346
347
  pointerStripColor?: ColorValue;
347
348
  pointerStripUptoDataPoint?: boolean;
348
349
  pointerLabelComponent?: Function;
350
+ stripOverPointer?: boolean;
349
351
  autoAdjustPointerLabelPosition?: boolean;
350
352
  shiftPointerLabelX?: number;
351
353
  shiftPointerLabelY?: number;
@@ -364,6 +366,7 @@ type Pointer = {
364
366
 
365
367
  export const LineChart = (props: propTypes) => {
366
368
  const scrollRef = useRef();
369
+ const [pointerIndex, setPointerIndex] = useState(-1);
367
370
  const [pointerX, setPointerX] = useState(0);
368
371
  const [pointerY, setPointerY] = useState(0);
369
372
  const [pointerItem, setPointerItem] = useState({
@@ -1410,6 +1413,7 @@ export const LineChart = (props: propTypes) => {
1410
1413
  pointerStripColor: 'black',
1411
1414
  pointerStripUptoDataPoint: false,
1412
1415
  pointerLabelComponent: null,
1416
+ stripOverPointer: false,
1413
1417
  shiftPointerLabelX: 0,
1414
1418
  shiftPointerLabelY: 0,
1415
1419
  pointerLabelWidth: 20,
@@ -1425,6 +1429,7 @@ export const LineChart = (props: propTypes) => {
1425
1429
  hidePointer5: false,
1426
1430
  };
1427
1431
  const pointerConfig = props.pointerConfig || null;
1432
+ const getPointerProps = props.getPointerProps || null;
1428
1433
  const pointerHeight =
1429
1434
  pointerConfig && pointerConfig.height
1430
1435
  ? pointerConfig.height
@@ -1447,8 +1452,8 @@ export const LineChart = (props: propTypes) => {
1447
1452
  : defaultPointerConfig.pointerComponent;
1448
1453
 
1449
1454
  const showPointerStrip =
1450
- pointerConfig && pointerConfig.showPointerStrip
1451
- ? pointerConfig.showPointerStrip
1455
+ pointerConfig && pointerConfig.showPointerStrip === false
1456
+ ? false
1452
1457
  : defaultPointerConfig.showPointerStrip;
1453
1458
  const pointerStripHeight =
1454
1459
  pointerConfig && pointerConfig.pointerStripHeight
@@ -1470,6 +1475,10 @@ export const LineChart = (props: propTypes) => {
1470
1475
  pointerConfig && pointerConfig.pointerLabelComponent
1471
1476
  ? pointerConfig.pointerLabelComponent
1472
1477
  : defaultPointerConfig.pointerLabelComponent;
1478
+ const stripOverPointer =
1479
+ pointerConfig && pointerConfig.stripOverPointer
1480
+ ? pointerConfig.stripOverPointer
1481
+ : defaultPointerConfig.stripOverPointer;
1473
1482
  const shiftPointerLabelX =
1474
1483
  pointerConfig && pointerConfig.shiftPointerLabelX
1475
1484
  ? pointerConfig.shiftPointerLabelX
@@ -1770,9 +1779,12 @@ export const LineChart = (props: propTypes) => {
1770
1779
  // )
1771
1780
  // }
1772
1781
 
1773
- const getLabel = val => {
1782
+ const getLabel = (val, index) => {
1774
1783
  let label = '';
1775
- if (showFractionalValues) {
1784
+ if (
1785
+ showFractionalValues ||
1786
+ (props.yAxisLabelTexts && props.yAxisLabelTexts[index] !== undefined)
1787
+ ) {
1776
1788
  if (val) {
1777
1789
  label = props.yAxisOffset
1778
1790
  ? (Number(val) + props.yAxisOffset).toString()
@@ -1873,7 +1885,7 @@ export const LineChart = (props: propTypes) => {
1873
1885
  props.hideAxesAndRules !== true &&
1874
1886
  !hideYAxisText &&
1875
1887
  horizSections.map((sectionItems, index) => {
1876
- let label = getLabel(sectionItems.value);
1888
+ let label = getLabel(sectionItems.value, index);
1877
1889
  if (hideOrigin && index === horizSections.length - 1) {
1878
1890
  label = '';
1879
1891
  }
@@ -1978,6 +1990,7 @@ export const LineChart = (props: propTypes) => {
1978
1990
  horizSectionsBelow.map((sectionItems, index) => {
1979
1991
  let label = getLabel(
1980
1992
  horizSectionsBelow[horizSectionsBelow.length - 1 - index].value,
1993
+ index,
1981
1994
  );
1982
1995
  return (
1983
1996
  <View
@@ -2032,7 +2045,7 @@ export const LineChart = (props: propTypes) => {
2032
2045
  props.hideAxesAndRules !== true &&
2033
2046
  !hideYAxisText &&
2034
2047
  horizSections.map((sectionItems, index) => {
2035
- let label = getLabel(sectionItems.value);
2048
+ let label = getLabel(sectionItems.value, index);
2036
2049
  if (hideOrigin && index === horizSections.length - 1) {
2037
2050
  label = '';
2038
2051
  }
@@ -2814,6 +2827,7 @@ export const LineChart = (props: propTypes) => {
2814
2827
  (pointerRadius || pointerWidth / 2) -
2815
2828
  2;
2816
2829
  setPointerX(z);
2830
+ setPointerIndex(factor);
2817
2831
  let item, y;
2818
2832
  item = data[factor];
2819
2833
  y =
@@ -2900,6 +2914,7 @@ export const LineChart = (props: propTypes) => {
2900
2914
  2;
2901
2915
  let item, y;
2902
2916
  setPointerX(z);
2917
+ setPointerIndex(factor);
2903
2918
  item = data[factor];
2904
2919
  y =
2905
2920
  containerHeight -
@@ -2963,6 +2978,7 @@ export const LineChart = (props: propTypes) => {
2963
2978
  onResponderEnd={evt => {
2964
2979
  // console.log('evt...end.......',evt);
2965
2980
  setResponderStartTime(0);
2981
+ setPointerIndex(-1);
2966
2982
  setResponderActive(false);
2967
2983
  setTimeout(() => setPointerX(0), pointerVanishDelay);
2968
2984
  }}
@@ -3037,6 +3053,7 @@ export const LineChart = (props: propTypes) => {
3037
3053
  (pointerRadius || pointerWidth / 2) -
3038
3054
  2;
3039
3055
  setPointerX(z);
3056
+ setPointerIndex(factor);
3040
3057
  let item, y;
3041
3058
  item = data[factor];
3042
3059
  y =
@@ -3122,6 +3139,7 @@ export const LineChart = (props: propTypes) => {
3122
3139
  2;
3123
3140
  let item, y;
3124
3141
  setPointerX(z);
3142
+ setPointerIndex(factor);
3125
3143
  item = data[factor];
3126
3144
  y =
3127
3145
  containerHeight -
@@ -3185,6 +3203,7 @@ export const LineChart = (props: propTypes) => {
3185
3203
  onResponderEnd={evt => {
3186
3204
  // console.log('evt...end.......',evt);
3187
3205
  setResponderStartTime(0);
3206
+ setPointerIndex(-1);
3188
3207
  setResponderActive(false);
3189
3208
  setTimeout(() => setPointerX(0), pointerVanishDelay);
3190
3209
  }}
@@ -3460,12 +3479,13 @@ export const LineChart = (props: propTypes) => {
3460
3479
  width: totalWidth,
3461
3480
  zIndex: 20,
3462
3481
  }}>
3482
+ {!stripOverPointer && renderStripAndLabel()}
3463
3483
  {renderPointer(1)}
3464
3484
  {points2 ? renderPointer(2) : null}
3465
3485
  {points3 ? renderPointer(3) : null}
3466
3486
  {points4 ? renderPointer(4) : null}
3467
3487
  {points5 ? renderPointer(5) : null}
3468
- {renderStripAndLabel()}
3488
+ {stripOverPointer && renderStripAndLabel()}
3469
3489
  </View>
3470
3490
  ) : null}
3471
3491
  {data.map((item: itemType, index: number) => {
@@ -3496,6 +3516,9 @@ export const LineChart = (props: propTypes) => {
3496
3516
  );
3497
3517
  })}
3498
3518
  </ScrollView>
3519
+ {pointerConfig &&
3520
+ getPointerProps &&
3521
+ getPointerProps({pointerIndex, pointerX, pointerY})}
3499
3522
  </View>
3500
3523
  );
3501
3524
  };