react-native-gifted-charts 1.2.29 → 1.2.32

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.29",
3
+ "version": "1.2.32",
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": [
@@ -40,10 +40,12 @@ type PropTypes = {
40
40
  // animationEasing?: any;
41
41
  opacity?: number;
42
42
  isThreeD?: Boolean;
43
+ xAxisLength?: number;
43
44
  xAxisThickness?: number;
44
45
  xAxisColor?: ColorValue;
45
46
  yAxisThickness?: number;
46
47
  yAxisColor?: ColorValue;
48
+ xAxisType?: String;
47
49
  yAxisLabelContainerStyle?: any;
48
50
  horizontalRulesStyle?: any;
49
51
  yAxisTextStyle?: any;
@@ -52,6 +54,7 @@ type PropTypes = {
52
54
  yAxisLabelWidth?: number;
53
55
  hideYAxisText?: Boolean;
54
56
  yAxisSide?: string;
57
+ yAxisOffset?: number;
55
58
  initialSpacing?: number;
56
59
  barWidth?: number;
57
60
  sideWidth?: number;
@@ -66,6 +69,7 @@ type PropTypes = {
66
69
 
67
70
  hideAxesAndRules?: Boolean;
68
71
  hideRules?: Boolean;
72
+ rulesLength?: number;
69
73
  rulesColor?: ColorValue;
70
74
  rulesThickness?: number;
71
75
  rulesType?: String;
@@ -103,6 +107,7 @@ type PropTypes = {
103
107
 
104
108
  disableScroll?: Boolean;
105
109
  showScrollIndicator?: Boolean;
110
+ indicatorColor?: 'black' | 'default' | 'white';
106
111
  roundedTop?: Boolean;
107
112
  roundedBottom?: Boolean;
108
113
  disablePress?: boolean;
@@ -200,7 +205,18 @@ export const BarChart = (props: PropTypes) => {
200
205
  const showLine = props.showLine || false;
201
206
  const initialSpacing =
202
207
  props.initialSpacing === 0 ? 0 : props.initialSpacing || 40;
203
- const data = useMemo(() => props.data || [], [props.data]);
208
+ const data = useMemo(() => {
209
+ if (!props.data) {
210
+ return [];
211
+ }
212
+ if (props.yAxisOffset) {
213
+ return props.data.map(item => {
214
+ item.value = item.value - props.yAxisOffset;
215
+ return item;
216
+ });
217
+ }
218
+ return props.data;
219
+ }, [props.yAxisOffset, props.data]);
204
220
  const lineData = props.lineData || data;
205
221
  const defaultLineConfig = {
206
222
  initialSpacing: initialSpacing,
@@ -346,6 +362,7 @@ export const BarChart = (props: PropTypes) => {
346
362
  const showVerticalLines = props.showVerticalLines || false;
347
363
  const rulesThickness =
348
364
  props.rulesThickness === 0 ? 0 : props.rulesThickness || 1;
365
+ const rulesLength = props.rulesLength;
349
366
  const rulesColor = props.rulesColor || 'lightgray';
350
367
  const verticalLinesThickness =
351
368
  props.verticalLinesThickness === 0 ? 0 : props.verticalLinesThickness || 1;
@@ -377,6 +394,7 @@ export const BarChart = (props: PropTypes) => {
377
394
  props.xAxisThickness === 0
378
395
  ? props.xAxisThickness
379
396
  : props.xAxisThickness || 1;
397
+ const xAxisLength = props.xAxisLength;
380
398
  const xAxisColor = props.xAxisColor || 'black';
381
399
 
382
400
  const hideRules = props.hideRules || false;
@@ -402,6 +420,7 @@ export const BarChart = (props: PropTypes) => {
402
420
  const hideOrigin = props.hideOrigin || false;
403
421
 
404
422
  const rulesType = props.rulesType || 'line';
423
+ const xAxisType = props.xAxisType || 'solid';
405
424
  const dashWidth = props.dashWidth === 0 ? 0 : props.dashWidth || 4;
406
425
  const dashGap = props.dashGap === 0 ? 0 : props.dashGap || 8;
407
426
 
@@ -650,15 +669,20 @@ export const BarChart = (props: PropTypes) => {
650
669
  (props.yAxisLabelTexts && props.yAxisLabelTexts[index] !== undefined)
651
670
  ) {
652
671
  if (val) {
653
- label = val;
672
+ label = props.yAxisOffset
673
+ ? (Number(val) + props.yAxisOffset).toString()
674
+ : val;
654
675
  } else {
655
- label = '0';
676
+ label = props.yAxisOffset ? props.yAxisOffset.toString() : '0';
656
677
  }
657
678
  } else {
658
679
  if (val) {
659
680
  label = val.toString().split('.')[0];
681
+ if (props.yAxisOffset) {
682
+ label = (Number(label) + props.yAxisOffset).toString();
683
+ }
660
684
  } else {
661
- label = '0';
685
+ label = props.yAxisOffset ? props.yAxisOffset.toString() : '0';
662
686
  }
663
687
  }
664
688
 
@@ -715,20 +739,30 @@ export const BarChart = (props: PropTypes) => {
715
739
  {backgroundColor: backgroundColor},
716
740
  ]}>
717
741
  {index === noOfSections ? (
718
- <View
719
- style={[
720
- styles.lastLine,
721
- {height: xAxisThickness, backgroundColor: xAxisColor},
722
- ]}
742
+ <Rule
743
+ config={{
744
+ thickness: xAxisThickness,
745
+ color: xAxisColor,
746
+ width:
747
+ xAxisLength ||
748
+ (horizontal
749
+ ? props.width || Math.min(300, totalWidth)
750
+ : (props.width || totalWidth) + 11),
751
+ dashWidth: dashWidth,
752
+ dashGap: dashGap,
753
+ type: xAxisType,
754
+ }}
723
755
  />
724
756
  ) : hideRules ? null : (
725
757
  <Rule
726
758
  config={{
727
759
  thickness: rulesThickness,
728
760
  color: rulesColor,
729
- width: horizontal
730
- ? props.width || Math.min(300, totalWidth)
731
- : (props.width || totalWidth) + 11,
761
+ width:
762
+ rulesLength ||
763
+ (horizontal
764
+ ? props.width || Math.min(300, totalWidth)
765
+ : (props.width || totalWidth) + 11),
732
766
  dashWidth: dashWidth,
733
767
  dashGap: dashGap,
734
768
  type: rulesType,
@@ -846,9 +880,11 @@ export const BarChart = (props: PropTypes) => {
846
880
  config={{
847
881
  thickness: rulesThickness,
848
882
  color: rulesColor,
849
- width: horizontal
850
- ? props.width || totalWidth
851
- : (props.width || totalWidth) + 11,
883
+ width:
884
+ rulesLength ||
885
+ (horizontal
886
+ ? props.width || totalWidth
887
+ : (props.width || totalWidth) + 11),
852
888
  dashWidth: dashWidth,
853
889
  dashGap: dashGap,
854
890
  type: rulesType,
@@ -1379,6 +1415,7 @@ export const BarChart = (props: PropTypes) => {
1379
1415
  !props.width && {width: totalWidth},
1380
1416
  ]}
1381
1417
  showsHorizontalScrollIndicator={showScrollIndicator}
1418
+ indicatorStyle={props.indicatorColor}
1382
1419
  horizontal
1383
1420
  // data={props.stackData || data}
1384
1421
  keyExtractor={(item, index) => index.toString()}>
@@ -69,9 +69,12 @@ type propTypes = {
69
69
  onDataChangeAnimationDuration?: number;
70
70
  animationEasing?: any;
71
71
  animateTogether?: boolean;
72
+ xAxisLength?: number;
72
73
  xAxisThickness?: number;
73
74
  xAxisColor?: ColorValue;
75
+ xAxisType?: String;
74
76
  hideRules?: Boolean;
77
+ rulesLength?: number;
75
78
  rulesColor?: ColorValue;
76
79
  rulesThickness?: number;
77
80
  pressEnabled?: Boolean;
@@ -119,6 +122,7 @@ type propTypes = {
119
122
  disableScroll?: Boolean;
120
123
  pointerConfig?: Pointer;
121
124
  showScrollIndicator?: Boolean;
125
+ indicatorColor?: 'black' | 'default' | 'white';
122
126
 
123
127
  //Indices
124
128
 
@@ -369,6 +373,7 @@ type Pointer = {
369
373
 
370
374
  export const LineChart = (props: propTypes) => {
371
375
  const scrollRef = useRef();
376
+ const [scrollX, setScrollX] = useState(0);
372
377
  const [pointerIndex, setPointerIndex] = useState(-1);
373
378
  const [pointerX, setPointerX] = useState(0);
374
379
  const [pointerY, setPointerY] = useState(0);
@@ -546,6 +551,7 @@ export const LineChart = (props: propTypes) => {
546
551
  ? ((props.width || 200) - initialSpacing) / data.length
547
552
  : 60);
548
553
 
554
+ const xAxisLength = props.xAxisLength;
549
555
  const xAxisThickness =
550
556
  props.xAxisThickness === 0 ? 0 : props.xAxisThickness || 1;
551
557
  const dataPointsHeight1 =
@@ -1367,6 +1373,7 @@ export const LineChart = (props: propTypes) => {
1367
1373
 
1368
1374
  const rulesThickness =
1369
1375
  props.rulesThickness === 0 ? 0 : props.rulesThickness || 1;
1376
+ const rulesLength = props.rulesLength;
1370
1377
  const rulesColor = props.rulesColor || 'lightgray';
1371
1378
  const verticalLinesThickness =
1372
1379
  props.verticalLinesThickness === 0 ? 0 : props.verticalLinesThickness || 1;
@@ -1554,6 +1561,7 @@ export const LineChart = (props: propTypes) => {
1554
1561
  const hideOrigin = props.hideOrigin || false;
1555
1562
 
1556
1563
  const rulesType = props.rulesType || 'line';
1564
+ const xAxisType = props.xAxisType || 'solid';
1557
1565
  const dashWidth = props.dashWidth === 0 ? 0 : props.dashWidth || 4;
1558
1566
  const dashGap = props.dashGap === 0 ? 0 : props.dashGap || 8;
1559
1567
 
@@ -1855,18 +1863,22 @@ export const LineChart = (props: propTypes) => {
1855
1863
  },
1856
1864
  ]}>
1857
1865
  {index === noOfSections ? (
1858
- <View
1859
- style={[
1860
- styles.lastLine,
1861
- {height: xAxisThickness, backgroundColor: xAxisColor},
1862
- ]}
1866
+ <Rule
1867
+ config={{
1868
+ thickness: xAxisThickness,
1869
+ color: xAxisColor,
1870
+ width: xAxisLength || (props.width || totalWidth) + 11,
1871
+ dashWidth: dashWidth,
1872
+ dashGap: dashGap,
1873
+ type: xAxisType,
1874
+ }}
1863
1875
  />
1864
1876
  ) : hideRules ? null : (
1865
1877
  <Rule
1866
1878
  config={{
1867
1879
  thickness: rulesThickness,
1868
1880
  color: rulesColor,
1869
- width: (props.width || totalWidth) + 11,
1881
+ width: rulesLength || (props.width || totalWidth) + 11,
1870
1882
  dashWidth: dashWidth,
1871
1883
  dashGap: dashGap,
1872
1884
  type: rulesType,
@@ -1979,7 +1991,7 @@ export const LineChart = (props: propTypes) => {
1979
1991
  config={{
1980
1992
  thickness: rulesThickness,
1981
1993
  color: rulesColor,
1982
- width: (props.width || totalWidth) + 11,
1994
+ width: rulesLength || (props.width || totalWidth) + 11,
1983
1995
  dashWidth: dashWidth,
1984
1996
  dashGap: dashGap,
1985
1997
  type: rulesType,
@@ -2550,6 +2562,11 @@ export const LineChart = (props: propTypes) => {
2550
2562
  if (autoAdjustPointerLabelPosition) {
2551
2563
  if (pointerX < pointerLabelWidth / 2) {
2552
2564
  left = 7;
2565
+ } else if (
2566
+ activatePointersOnLongPress &&
2567
+ pointerX - scrollX < pointerLabelWidth / 2 - 10
2568
+ ) {
2569
+ left = 7;
2553
2570
  } else {
2554
2571
  if (
2555
2572
  !activatePointersOnLongPress &&
@@ -2561,7 +2578,10 @@ export const LineChart = (props: propTypes) => {
2561
2578
  left = -pointerLabelWidth - 4;
2562
2579
  } else if (
2563
2580
  activatePointersOnLongPress &&
2564
- pointerX > totalWidth - yAxisLabelWidth - pointerLabelWidth / 2
2581
+ pointerX - scrollX >
2582
+ (props.width + 10 ||
2583
+ Dimensions.get('window').width - yAxisLabelWidth - 15) -
2584
+ pointerLabelWidth / 2
2565
2585
  ) {
2566
2586
  left = -pointerLabelWidth - 4;
2567
2587
  } else {
@@ -3286,7 +3306,17 @@ export const LineChart = (props: propTypes) => {
3286
3306
  scrollRef.current.scrollToEnd({animated: scrollAnimation});
3287
3307
  }
3288
3308
  }}
3309
+ onScroll={ev => {
3310
+ if (
3311
+ pointerConfig &&
3312
+ pointerConfig.activatePointersOnLongPress &&
3313
+ pointerConfig.autoAdjustPointerLabelPosition
3314
+ ) {
3315
+ setScrollX(ev.nativeEvent.contentOffset.x);
3316
+ }
3317
+ }}
3289
3318
  showsHorizontalScrollIndicator={showScrollIndicator}
3319
+ indicatorStyle={props.indicatorColor}
3290
3320
  style={[
3291
3321
  {
3292
3322
  marginLeft:
package/src/todos.md CHANGED
@@ -4,19 +4,16 @@
4
4
 
5
5
  ## To-dos in documentation-
6
6
 
7
- 1. Prepare a doc for Bar chart with negative values
8
- 2. Prepare a doc for Line chart with negative values
9
- 3. Prepare a doc for Bar chart with y axis on right side
10
- 4. Prepare a doc for Line chart with y axis on right side
11
- 5. Prepare a doc for Bar chart combined with Line chart having a separate data for the Line chart
12
- 6. Prepare a doc for Line chart with smoothly scrolling data pointer and strip (along with pointerShiftX)
13
- 7. Prepare a doc for Bar chart with barMarginBottom
14
- 8. Prepare a doc for reference lines
15
- 9. Prepare a doc for labelsPosition in Pie and Donut charts
16
- 8. Prepare a doc for adjustToWidth in Line and Area charts
17
- 9. Prepare a doc for xAxisLabelTexts and xAxisLabelTextStyle in Bar, Line And Area Charts
18
- 10. Prepare a doc for vertical lines to explain noOfVerticalLines and verticalLinesSpacing props. https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/205
19
- 11. Prepare a doc for negative marginBottom instead of marginTop for x axis labels. https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/190
7
+ 1. Prepare a doc for Line chart with negative values
8
+ 2. Prepare a doc for Line chart with y axis on right side
9
+ 3. Prepare a doc for Line chart with gaps in the line https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/100
10
+ 4. Prepare a doc for Bar chart combined with Line chart having a separate data for the Line chart
11
+ 5. Prepare a doc for Line chart with smoothly scrolling data pointer and strip (along with pointerShiftX)
12
+ 6. Prepare a doc for labelsPosition in Pie and Donut charts
13
+ 7. Prepare a doc for adjustToWidth in Line and Area charts
14
+ 8. Prepare a doc for xAxisLabelTexts and xAxisLabelTextStyle in Bar, Line And Area Charts
15
+ 9. Prepare a doc for vertical lines to explain noOfVerticalLines and verticalLinesSpacing props. https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/205
16
+ 10. Prepare a doc for negative marginBottom instead of marginTop for x axis labels. https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/190
20
17
 
21
18
 
22
19
  ## Architecture Enhancement