react-native-gifted-charts 1.0.5 → 1.0.8

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
@@ -102,6 +102,10 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
102
102
  | **Invariant Violation: requireNativeComponent: "RNCWebView" was not found in the UIManager.** | install `react-native-webview` |
103
103
  | Setting `height`, `maxValue`, `stepValue`, `stepHeight`, or `noOfSections` breaks the chart | Please make sure that<br/> `maxValue = noOfSections * stepValue;` <br/>is followed. [See this](https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/71) |
104
104
 
105
+ ## To-dos
106
+
107
+ [To do list](./src/todos.md)
108
+
105
109
  ## License
106
110
 
107
111
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gifted-charts",
3
- "version": "1.0.5",
3
+ "version": "1.0.8",
4
4
  "description": "The most complete library for Bar, Line, Area, Pie and Donut charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
5
5
  "main": "src/index.tsx",
6
6
  "files": [
@@ -52,6 +52,7 @@ type PropTypes = {
52
52
  barWidth?: number;
53
53
  sideWidth?: number;
54
54
  showLine?: Boolean;
55
+ lineData?: any;
55
56
  lineConfig?: lineConfigType;
56
57
 
57
58
  cappedBars?: Boolean;
@@ -124,6 +125,7 @@ type PropTypes = {
124
125
  labelsExtraHeight?: number;
125
126
  };
126
127
  type lineConfigType = {
128
+ initialSpacing?: number;
127
129
  curved?: Boolean;
128
130
  isAnimated?: Boolean;
129
131
  delay?: number;
@@ -140,6 +142,8 @@ type lineConfigType = {
140
142
  textShiftX?: number;
141
143
  textShiftY?: number;
142
144
  shiftY?: number;
145
+ startIndex?: number;
146
+ endIndex?: number;
143
147
  };
144
148
  type referenceConfigType = {
145
149
  thickness: number;
@@ -175,7 +179,12 @@ export const BarChart = (props: PropTypes) => {
175
179
  const scrollRef = useRef();
176
180
  const [points, setPoints] = useState('');
177
181
  const showLine = props.showLine || false;
182
+ const initialSpacing =
183
+ props.initialSpacing === 0 ? 0 : props.initialSpacing || 40;
184
+ const data = useMemo(() => props.data || [], [props.data]);
185
+ const lineData = props.lineData || data;
178
186
  const defaultLineConfig = {
187
+ initialSpacing: initialSpacing,
179
188
  curved: false,
180
189
  isAnimated: false,
181
190
  thickness: 1,
@@ -192,9 +201,16 @@ export const BarChart = (props: PropTypes) => {
192
201
  textShiftY: 0,
193
202
  shiftY: 0,
194
203
  delay: 0,
204
+ startIndex: 0,
205
+ endIndex: lineData.length - 1,
195
206
  };
196
207
  const lineConfig = props.lineConfig
197
208
  ? {
209
+ initialSpacing:
210
+ props.lineConfig.initialSpacing === 0
211
+ ? 0
212
+ : props.lineConfig.initialSpacing ||
213
+ defaultLineConfig.initialSpacing,
198
214
  curved: props.lineConfig.curved || defaultLineConfig.curved,
199
215
  isAnimated: props.lineConfig.isAnimated || defaultLineConfig.isAnimated,
200
216
  thickness: props.lineConfig.thickness || defaultLineConfig.thickness,
@@ -220,6 +236,11 @@ export const BarChart = (props: PropTypes) => {
220
236
  textShiftY: props.lineConfig.textShiftY || defaultLineConfig.textShiftY,
221
237
  shiftY: props.lineConfig.shiftY || defaultLineConfig.shiftY,
222
238
  delay: props.lineConfig.delay || defaultLineConfig.delay,
239
+ startIndex: props.lineConfig.startIndex || defaultLineConfig.startIndex,
240
+ endIndex:
241
+ props.lineConfig.endIndex === 0
242
+ ? 0
243
+ : props.lineConfig.endIndex || defaultLineConfig.endIndex,
223
244
  }
224
245
  : defaultLineConfig;
225
246
  const containerHeight = props.height || 200;
@@ -227,7 +248,6 @@ export const BarChart = (props: PropTypes) => {
227
248
  const horizSections = [{value: '0'}];
228
249
  const horizSectionsBelow = [];
229
250
  const stepHeight = props.stepHeight || containerHeight / noOfSections;
230
- const data = useMemo(() => props.data || [], [props.data]);
231
251
  const spacing = props.spacing === 0 ? 0 : props.spacing ? props.spacing : 20;
232
252
  const labelWidth = props.labelWidth || 0;
233
253
  const scrollToEnd = props.scrollToEnd || false;
@@ -235,7 +255,8 @@ export const BarChart = (props: PropTypes) => {
235
255
  const labelsExtraHeight = props.labelsExtraHeight || 0;
236
256
 
237
257
  let totalWidth = spacing;
238
- let maxItem = 0, minItem = 0;
258
+ let maxItem = 0,
259
+ minItem = 0;
239
260
  if (props.stackData) {
240
261
  props.stackData.forEach(stackItem => {
241
262
  // console.log('stackItem', stackItem);
@@ -247,7 +268,7 @@ export const BarChart = (props: PropTypes) => {
247
268
  if (stackSum > maxItem) {
248
269
  maxItem = stackSum;
249
270
  }
250
- if(stackSum < minItem){
271
+ if (stackSum < minItem) {
251
272
  minItem = stackSum;
252
273
  }
253
274
  totalWidth +=
@@ -259,7 +280,7 @@ export const BarChart = (props: PropTypes) => {
259
280
  if (item.value > maxItem) {
260
281
  maxItem = item.value;
261
282
  }
262
- if(item.value < minItem){
283
+ if (item.value < minItem) {
263
284
  minItem = item.value;
264
285
  }
265
286
  totalWidth +=
@@ -273,7 +294,7 @@ export const BarChart = (props: PropTypes) => {
273
294
  maxItem = maxItem + (10 - (maxItem % 10));
274
295
  maxItem /= 10 * (props.roundToDigits || 1);
275
296
  maxItem = parseFloat(maxItem.toFixed(props.roundToDigits || 1));
276
- if(minItem !== 0){
297
+ if (minItem !== 0) {
277
298
  minItem *= 10 * (props.roundToDigits || 1);
278
299
  minItem = minItem - (10 + (minItem % 10));
279
300
  minItem /= 10 * (props.roundToDigits || 1);
@@ -281,8 +302,8 @@ export const BarChart = (props: PropTypes) => {
281
302
  }
282
303
  } else {
283
304
  maxItem = maxItem + (10 - (maxItem % 10));
284
- if(minItem !== 0){
285
- minItem = minItem - (10 + (minItem % 10))
305
+ if (minItem !== 0) {
306
+ minItem = minItem - (10 + (minItem % 10));
286
307
  }
287
308
  }
288
309
 
@@ -290,11 +311,10 @@ export const BarChart = (props: PropTypes) => {
290
311
  const minValue = props.minValue || minItem;
291
312
 
292
313
  const stepValue = props.stepValue || maxValue / noOfSections;
293
- const noOfSectionsBelowXAxis = props.noOfSectionsBelowXAxis || (-minValue / stepValue);
314
+ const noOfSectionsBelowXAxis =
315
+ props.noOfSectionsBelowXAxis || -minValue / stepValue;
294
316
  const disableScroll = props.disableScroll || false;
295
317
  const showScrollIndicator = props.showScrollIndicator || false;
296
- const initialSpacing =
297
- props.initialSpacing === 0 ? 0 : props.initialSpacing || 40;
298
318
  // const oldData = props.oldData || [];
299
319
  const side = props.side || '';
300
320
  const rotateLabel = props.rotateLabel || false;
@@ -393,39 +413,41 @@ export const BarChart = (props: PropTypes) => {
393
413
  if (showLine) {
394
414
  let pp = '';
395
415
  if (!lineConfig.curved) {
396
- for (let i = 0; i < data.length; i++) {
416
+ for (let i = 0; i < lineData.length; i++) {
417
+ if (i < lineConfig.startIndex || i > lineConfig.endIndex) continue;
397
418
  const currentBarWidth =
398
419
  (data && data[i] && data[i].barWidth) || props.barWidth || 30;
399
420
  pp +=
400
421
  'L' +
401
422
  (yAxisLabelWidth +
423
+ lineConfig.initialSpacing +
402
424
  6 -
403
425
  (initialSpacing - currentBarWidth / 2) -
404
426
  lineConfig.dataPointsWidth / 2 +
405
427
  (currentBarWidth + spacing) * i) +
406
428
  ' ' +
407
429
  (containerHeight -
408
- lineConfig.shiftY +
409
- 10 -
410
- (data[i].value * containerHeight) / maxValue) +
430
+ lineConfig.shiftY -
431
+ (lineData[i].value * containerHeight) / maxValue) +
411
432
  ' ';
412
433
  }
413
434
  setPoints(pp.replace('L', 'M'));
414
435
  } else {
415
436
  let p1Array = [];
416
- for (let i = 0; i < data.length; i++) {
437
+ for (let i = 0; i < lineData.length; i++) {
438
+ if (i < lineConfig.startIndex || i > lineConfig.endIndex) continue;
417
439
  const currentBarWidth =
418
440
  (data && data[i] && data[i].barWidth) || props.barWidth || 30;
419
441
  p1Array.push([
420
442
  yAxisLabelWidth +
443
+ lineConfig.initialSpacing +
421
444
  6 -
422
445
  (initialSpacing - currentBarWidth / 2) -
423
446
  lineConfig.dataPointsWidth / 2 +
424
447
  (currentBarWidth + spacing) * i,
425
448
  containerHeight -
426
- lineConfig.shiftY +
427
- 10 -
428
- (data[i].value * containerHeight) / maxValue,
449
+ lineConfig.shiftY -
450
+ (lineData[i].value * containerHeight) / maxValue,
429
451
  ]);
430
452
  let xx = svgPath(p1Array, bezierCommand);
431
453
  setPoints(xx);
@@ -441,14 +463,18 @@ export const BarChart = (props: PropTypes) => {
441
463
  animationDuration,
442
464
  containerHeight,
443
465
  data,
466
+ lineData,
444
467
  decreaseWidth,
445
468
  initialSpacing,
446
469
  labelsAppear,
470
+ lineConfig.initialSpacing,
447
471
  lineConfig.curved,
448
472
  lineConfig.dataPointsWidth,
449
473
  lineConfig.shiftY,
450
474
  lineConfig.isAnimated,
451
475
  lineConfig.delay,
476
+ lineConfig.startIndex,
477
+ lineConfig.endIndex,
452
478
  maxValue,
453
479
  // moveBar,
454
480
  props.barWidth,
@@ -537,7 +563,7 @@ export const BarChart = (props: PropTypes) => {
537
563
  : value.toString(),
538
564
  });
539
565
  }
540
- if(noOfSectionsBelowXAxis){
566
+ if (noOfSectionsBelowXAxis) {
541
567
  for (let i = 1; i <= noOfSectionsBelowXAxis; i++) {
542
568
  let value = stepValue * -i;
543
569
  if (props.showFractionalValues || props.roundToDigits) {
@@ -545,9 +571,10 @@ export const BarChart = (props: PropTypes) => {
545
571
  }
546
572
  horizSectionsBelow.push({
547
573
  value: props.yAxisLabelTexts
548
- ? props.yAxisLabelTexts[noOfSectionsBelowXAxis - i] ?? value.toString()
549
- : value.toString(),
550
- })
574
+ ? props.yAxisLabelTexts[noOfSectionsBelowXAxis - i] ??
575
+ value.toString()
576
+ : value.toString(),
577
+ });
551
578
  }
552
579
  }
553
580
 
@@ -602,7 +629,7 @@ export const BarChart = (props: PropTypes) => {
602
629
  ? props.width || totalWidth
603
630
  : props.width || totalWidth + 11,
604
631
  },
605
- yAxisSide === 'right' && {transform:[{rotateY:'180deg'}]}
632
+ yAxisSide === 'right' && {transform: [{rotateY: '180deg'}]},
606
633
  ]}>
607
634
  <View
608
635
  style={[
@@ -628,13 +655,16 @@ export const BarChart = (props: PropTypes) => {
628
655
  style={[
629
656
  yAxisTextStyle,
630
657
  index === noOfSections && {marginBottom: stepHeight / -2},
631
- horizontal ? {
632
- transform: [
633
- {rotate: '270deg'},
634
- {translateY: yAxisAtTop ? 0 : 50},
635
- ],
636
- }:
637
- yAxisSide === 'right' && {transform:[{rotateY:'180deg'}]}
658
+ horizontal
659
+ ? {
660
+ transform: [
661
+ {rotate: '270deg'},
662
+ {translateY: yAxisAtTop ? 0 : 50},
663
+ ],
664
+ }
665
+ : yAxisSide === 'right' && {
666
+ transform: [{rotateY: '180deg'}],
667
+ },
638
668
  ]}>
639
669
  {label}
640
670
  </Text>
@@ -745,7 +775,8 @@ export const BarChart = (props: PropTypes) => {
745
775
  ? props.width || totalWidth
746
776
  : props.width || totalWidth + 11,
747
777
  },
748
- index===0&&{marginTop:stepHeight/2}
778
+ yAxisSide === 'right' && {transform: [{rotateY: '180deg'}]},
779
+ index === 0 && {marginTop: stepHeight / 2},
749
780
  ]}>
750
781
  <View
751
782
  style={[
@@ -759,10 +790,10 @@ export const BarChart = (props: PropTypes) => {
759
790
  transform: [{translateX: totalWidth + yAxisThickness}],
760
791
  },
761
792
  {
762
- height: index===0?stepHeight*1.5:stepHeight,
793
+ height: index === 0 ? stepHeight * 1.5 : stepHeight,
763
794
  width: yAxisLabelWidth,
764
795
  },
765
- index===0&&{marginTop:-stepHeight/2}
796
+ index === 0 && {marginTop: -stepHeight / 2},
766
797
  ]}>
767
798
  {!hideYAxisText ? (
768
799
  <Text
@@ -777,16 +808,16 @@ export const BarChart = (props: PropTypes) => {
777
808
  {translateY: yAxisAtTop ? 0 : 50},
778
809
  ],
779
810
  },
811
+ yAxisSide === 'right' && {
812
+ transform: [{rotateY: '180deg'}],
813
+ },
780
814
  ]}>
781
815
  {label}
782
816
  </Text>
783
817
  ) : null}
784
818
  </View>
785
819
  <View
786
- style={[
787
- styles.leftPart,
788
- {backgroundColor: backgroundColor},
789
- ]}>
820
+ style={[styles.leftPart, {backgroundColor: backgroundColor}]}>
790
821
  {hideRules ? null : (
791
822
  <Rule
792
823
  config={{
@@ -803,7 +834,7 @@ export const BarChart = (props: PropTypes) => {
803
834
  )}
804
835
  </View>
805
836
  </View>
806
- )
837
+ );
807
838
  })}
808
839
  </>
809
840
  );
@@ -842,7 +873,10 @@ export const BarChart = (props: PropTypes) => {
842
873
  };
843
874
 
844
875
  const renderDataPoints = () => {
845
- return data.map((item: any, index: number) => {
876
+ return lineData.map((item: any, index: number) => {
877
+ if (index < lineConfig.startIndex || index > lineConfig.endIndex){
878
+ return null;
879
+ }
846
880
  // console.log('comes in');
847
881
  const currentBarWidth = item.barWidth || props.barWidth || 30;
848
882
  if (lineConfig.dataPointsShape === 'rectangular') {
@@ -851,6 +885,7 @@ export const BarChart = (props: PropTypes) => {
851
885
  <Rect
852
886
  x={
853
887
  yAxisLabelWidth +
888
+ lineConfig.initialSpacing +
854
889
  6 -
855
890
  (initialSpacing - currentBarWidth / 2) -
856
891
  lineConfig.dataPointsWidth +
@@ -859,8 +894,7 @@ export const BarChart = (props: PropTypes) => {
859
894
  y={
860
895
  containerHeight -
861
896
  lineConfig.shiftY -
862
- lineConfig.dataPointsHeight / 2 +
863
- 10 -
897
+ lineConfig.dataPointsHeight / 2 -
864
898
  (item.value * containerHeight) / maxValue
865
899
  }
866
900
  width={lineConfig.dataPointsWidth}
@@ -873,6 +907,7 @@ export const BarChart = (props: PropTypes) => {
873
907
  fontSize={item.textFontSize || lineConfig.textFontSize}
874
908
  x={
875
909
  yAxisLabelWidth +
910
+ lineConfig.initialSpacing +
876
911
  6 -
877
912
  (initialSpacing - currentBarWidth / 2) -
878
913
  lineConfig.dataPointsWidth +
@@ -882,8 +917,7 @@ export const BarChart = (props: PropTypes) => {
882
917
  y={
883
918
  containerHeight -
884
919
  lineConfig.shiftY -
885
- lineConfig.dataPointsHeight / 2 +
886
- 10 -
920
+ lineConfig.dataPointsHeight / 2 -
887
921
  (item.value * containerHeight) / maxValue +
888
922
  (item.textShiftY || lineConfig.textShiftY || 0)
889
923
  }>
@@ -898,6 +932,7 @@ export const BarChart = (props: PropTypes) => {
898
932
  <Circle
899
933
  cx={
900
934
  yAxisLabelWidth +
935
+ lineConfig.initialSpacing +
901
936
  6 -
902
937
  (initialSpacing - currentBarWidth / 2) -
903
938
  lineConfig.dataPointsWidth / 2 +
@@ -905,8 +940,7 @@ export const BarChart = (props: PropTypes) => {
905
940
  }
906
941
  cy={
907
942
  containerHeight -
908
- lineConfig.shiftY +
909
- 10 -
943
+ lineConfig.shiftY -
910
944
  (item.value * containerHeight) / maxValue
911
945
  }
912
946
  r={lineConfig.dataPointsRadius}
@@ -918,6 +952,7 @@ export const BarChart = (props: PropTypes) => {
918
952
  fontSize={item.textFontSize || lineConfig.textFontSize}
919
953
  x={
920
954
  yAxisLabelWidth +
955
+ lineConfig.initialSpacing +
921
956
  6 -
922
957
  (initialSpacing - currentBarWidth / 2) -
923
958
  lineConfig.dataPointsWidth +
@@ -927,8 +962,7 @@ export const BarChart = (props: PropTypes) => {
927
962
  y={
928
963
  containerHeight -
929
964
  lineConfig.shiftY -
930
- lineConfig.dataPointsHeight / 2 +
931
- 10 -
965
+ lineConfig.dataPointsHeight / 2 -
932
966
  (item.value * containerHeight) / maxValue +
933
967
  (item.textShiftY || lineConfig.textShiftY || 0)
934
968
  }>
@@ -1109,14 +1143,15 @@ export const BarChart = (props: PropTypes) => {
1109
1143
  {props.hideAxesAndRules !== true && renderHorizSections()}
1110
1144
  <ScrollView
1111
1145
  ref={scrollRef}
1112
- onContentSizeChange={()=>{
1113
- if(scrollRef.current && scrollToEnd){
1146
+ onContentSizeChange={() => {
1147
+ if (scrollRef.current && scrollToEnd) {
1114
1148
  scrollRef.current.scrollToEnd({animated: scrollAnimation});
1115
1149
  }
1116
1150
  }}
1117
1151
  style={[
1118
1152
  {
1119
- marginLeft: yAxisSide === 'right' ? -yAxisLabelWidth+10 : yAxisLabelWidth,
1153
+ marginLeft:
1154
+ yAxisSide === 'right' ? -yAxisLabelWidth + 10 : yAxisLabelWidth,
1120
1155
  position: 'absolute',
1121
1156
  bottom: stepHeight * -0.5 - 60 + xAxisThickness,
1122
1157
  },
@@ -1127,9 +1162,11 @@ export const BarChart = (props: PropTypes) => {
1127
1162
  contentContainerStyle={[
1128
1163
  {
1129
1164
  // backgroundColor: 'yellow',
1130
- height: containerHeight + 130 + horizSectionsBelow.length * stepHeight,
1165
+ height:
1166
+ containerHeight + 130 + horizSectionsBelow.length * stepHeight,
1131
1167
  paddingLeft: initialSpacing,
1132
- paddingBottom:horizSectionsBelow.length * stepHeight + labelsExtraHeight,
1168
+ paddingBottom:
1169
+ horizSectionsBelow.length * stepHeight + labelsExtraHeight,
1133
1170
  alignItems: 'flex-end',
1134
1171
  },
1135
1172
  !props.width && {width: totalWidth},
@@ -1224,4 +1261,4 @@ export const BarChart = (props: PropTypes) => {
1224
1261
  </ScrollView>
1225
1262
  </View>
1226
1263
  );
1227
- };
1264
+ };
@@ -33,6 +33,7 @@ type propTypes = {
33
33
  height?: number;
34
34
  noOfSections?: number;
35
35
  maxValue?: number;
36
+ minValue?: number;
36
37
  stepHeight?: number;
37
38
  stepValue?: number;
38
39
  spacing?: number;
@@ -103,6 +104,15 @@ type propTypes = {
103
104
  yAxisIndicesColor?: ColorValue;
104
105
  yAxisSide?: string;
105
106
 
107
+ startIndex?: number;
108
+ startIndex1?: number;
109
+ startIndex2?: number;
110
+ startIndex3?: number;
111
+ endIndex?: number;
112
+ endIndex1?: number;
113
+ endIndex2?: number;
114
+ endIndex3?: number;
115
+
106
116
  color?: string;
107
117
  color1?: string;
108
118
  color2?: string;
@@ -192,6 +202,7 @@ type propTypes = {
192
202
  yAxisLabelSuffix?: String;
193
203
  scrollToEnd?: Boolean;
194
204
  scrollAnimation?: Boolean;
205
+ noOfSectionsBelowXAxis?: number;
195
206
  };
196
207
  type referenceConfigType = {
197
208
  thickness: number;
@@ -280,6 +291,27 @@ export const LineChart = (props: propTypes) => {
280
291
  const yAxisLabelSuffix = props.yAxisLabelSuffix || '';
281
292
  const yAxisSide = props.yAxisSide || 'left';
282
293
 
294
+ const startIndex1 =
295
+ props.startIndex1 === 0 ? 0 : props.startIndex1 || props.startIndex || 0;
296
+
297
+ let endIndex1;
298
+ if (props.endIndex1 === undefined || props.endIndex1 === null) {
299
+ if (props.endIndex === undefined || props.endIndex === null) {
300
+ endIndex1 = data.length - 1;
301
+ } else {
302
+ endIndex1 = props.endIndex;
303
+ }
304
+ } else {
305
+ endIndex1 = props.endIndex1;
306
+ }
307
+
308
+ const startIndex2 = props.startIndex2 || 0;
309
+ const endIndex2 =
310
+ props.endIndex2 === 0 ? 0 : props.endIndex2 || data2.length - 1;
311
+
312
+ const startIndex3 = props.startIndex3 || 0;
313
+ const endIndex3 =
314
+ props.endIndex3 === 0 ? 0 : props.endIndex3 || data3.length - 1;
283
315
 
284
316
  if (!initialData) {
285
317
  initialData = [...data];
@@ -456,15 +488,39 @@ export const LineChart = (props: propTypes) => {
456
488
  const xAxisColor = props.xAxisColor || 'black';
457
489
 
458
490
  let totalWidth = initialSpacing;
459
- let maxItem = 0;
491
+ let maxItem = 0,
492
+ minItem = 0;
460
493
  data.forEach((item: itemType) => {
461
494
  if (item.value > maxItem) {
462
495
  maxItem = item.value;
463
496
  }
497
+ if (item.value < minItem) {
498
+ minItem = item.value;
499
+ }
464
500
  totalWidth += spacing;
465
501
  });
466
502
 
467
- const maxValue = props.maxValue || maxItem || 10;
503
+ if (props.showFractionalValues || props.roundToDigits) {
504
+ maxItem *= 10 * (props.roundToDigits || 1);
505
+ maxItem = maxItem + (10 - (maxItem % 10));
506
+ maxItem /= 10 * (props.roundToDigits || 1);
507
+ maxItem = parseFloat(maxItem.toFixed(props.roundToDigits || 1));
508
+
509
+ if (minItem !== 0) {
510
+ minItem *= 10 * (props.roundToDigits || 1);
511
+ minItem = minItem - (10 + (minItem % 10));
512
+ minItem /= 10 * (props.roundToDigits || 1);
513
+ minItem = parseFloat(minItem.toFixed(props.roundToDigits || 1));
514
+ }
515
+ } else {
516
+ maxItem = maxItem + (10 - (maxItem % 10));
517
+ if (minItem !== 0) {
518
+ minItem = minItem - (10 + (minItem % 10));
519
+ }
520
+ }
521
+
522
+ const maxValue = props.maxValue || maxItem;
523
+ const minValue = props.minValue || minItem;
468
524
 
469
525
  useEffect(() => {
470
526
  // console.log('comes here............')
@@ -497,7 +553,7 @@ export const LineChart = (props: propTypes) => {
497
553
  pp3 = '';
498
554
  if (!props.curved) {
499
555
  for (let i = 0; i < data.length; i++) {
500
- if (!animateOnDataChange) {
556
+ if (i >= startIndex1 && i <= endIndex1 && !animateOnDataChange) {
501
557
  pp +=
502
558
  'L' +
503
559
  (initialSpacing - dataPointsWidth1 / 2 + spacing * i) +
@@ -508,7 +564,7 @@ export const LineChart = (props: propTypes) => {
508
564
  ' ';
509
565
  setPoints(pp.replace('L', 'M'));
510
566
  }
511
- if (data2.length) {
567
+ if (data2.length && i >= startIndex2 && i <= endIndex2) {
512
568
  pp2 +=
513
569
  'L' +
514
570
  (initialSpacing - dataPointsWidth2 / 2 + spacing * i) +
@@ -518,7 +574,7 @@ export const LineChart = (props: propTypes) => {
518
574
  (data2[i].value * containerHeight) / maxValue) +
519
575
  ' ';
520
576
  }
521
- if (data3.length) {
577
+ if (data3.length && i >= startIndex3 && i <= endIndex3) {
522
578
  pp3 +=
523
579
  'L' +
524
580
  (initialSpacing - dataPointsWidth3 / 2 + spacing * i) +
@@ -622,11 +678,13 @@ export const LineChart = (props: propTypes) => {
622
678
  p2Array = [],
623
679
  p3Array = [];
624
680
  for (let i = 0; i < data.length; i++) {
625
- p1Array.push([
626
- initialSpacing - dataPointsWidth1 / 2 + spacing * i,
627
- containerHeight + 10 - (data[i].value * containerHeight) / maxValue,
628
- ]);
629
- if (data2.length) {
681
+ if (i >= startIndex1 && i <= endIndex1) {
682
+ p1Array.push([
683
+ initialSpacing - dataPointsWidth1 / 2 + spacing * i,
684
+ containerHeight + 10 - (data[i].value * containerHeight) / maxValue,
685
+ ]);
686
+ }
687
+ if (data2.length && i >= startIndex2 && i <= endIndex2) {
630
688
  p2Array.push([
631
689
  initialSpacing - dataPointsWidth2 / 2 + spacing * i,
632
690
  containerHeight +
@@ -634,7 +692,7 @@ export const LineChart = (props: propTypes) => {
634
692
  (data2[i].value * containerHeight) / maxValue,
635
693
  ]);
636
694
  }
637
- if (data3.length) {
695
+ if (data3.length && i >= startIndex3 && i <= endIndex3) {
638
696
  p3Array.push([
639
697
  initialSpacing - dataPointsWidth3 / 2 + spacing * i,
640
698
  containerHeight +
@@ -765,20 +823,20 @@ export const LineChart = (props: propTypes) => {
765
823
  props.curved,
766
824
  spacing,
767
825
  xAxisThickness,
826
+ startIndex1,
827
+ endIndex1,
828
+ startIndex2,
829
+ endIndex2,
830
+ startIndex3,
831
+ endIndex3,
768
832
  ]);
769
833
 
770
- if (props.showFractionalValues || props.roundToDigits) {
771
- maxItem *= 10 * (props.roundToDigits || 1);
772
- maxItem = maxItem + (10 - (maxItem % 10));
773
- maxItem /= 10 * (props.roundToDigits || 1);
774
- maxItem = parseFloat(maxItem.toFixed(props.roundToDigits || 1));
775
- } else {
776
- maxItem = maxItem + (10 - (maxItem % 10));
777
- }
778
-
779
834
  const horizSections = [{value: '0'}];
835
+ const horizSectionsBelow = [];
780
836
  const stepHeight = props.stepHeight || containerHeight / noOfSections;
781
837
  const stepValue = props.stepValue || maxValue / noOfSections;
838
+ const noOfSectionsBelowXAxis =
839
+ props.noOfSectionsBelowXAxis || -minValue / stepValue;
782
840
  const thickness1 = props.thickness1;
783
841
  const thickness2 = props.thickness2;
784
842
  const thickness3 = props.thickness3;
@@ -939,6 +997,20 @@ export const LineChart = (props: propTypes) => {
939
997
  : value.toString(),
940
998
  });
941
999
  }
1000
+ if (noOfSectionsBelowXAxis) {
1001
+ for (let i = 1; i <= noOfSectionsBelowXAxis; i++) {
1002
+ let value = stepValue * -i;
1003
+ if (props.showFractionalValues || props.roundToDigits) {
1004
+ value = parseFloat(value.toFixed(props.roundToDigits || 1));
1005
+ }
1006
+ horizSectionsBelow.push({
1007
+ value: props.yAxisLabelTexts
1008
+ ? props.yAxisLabelTexts[noOfSectionsBelowXAxis - i] ??
1009
+ value.toString()
1010
+ : value.toString(),
1011
+ });
1012
+ }
1013
+ }
942
1014
 
943
1015
  const renderLabel = (
944
1016
  index: number,
@@ -1078,7 +1150,7 @@ export const LineChart = (props: propTypes) => {
1078
1150
  {
1079
1151
  width: (props.width ? props.width : totalWidth) + 15,
1080
1152
  },
1081
- yAxisSide === 'right' && {transform:[{rotateY:'180deg'}]}
1153
+ yAxisSide === 'right' && {transform: [{rotateY: '180deg'}]},
1082
1154
  ]}>
1083
1155
  <View
1084
1156
  style={[
@@ -1095,7 +1167,9 @@ export const LineChart = (props: propTypes) => {
1095
1167
  ellipsizeMode={'clip'}
1096
1168
  style={[
1097
1169
  yAxisTextStyle,
1098
- yAxisSide === 'right' && {transform:[{rotateY:'180deg'}]},
1170
+ yAxisSide === 'right' && {
1171
+ transform: [{rotateY: '180deg'}],
1172
+ },
1099
1173
  index === noOfSections && {
1100
1174
  marginBottom: stepHeight / -2,
1101
1175
  },
@@ -1190,6 +1264,70 @@ export const LineChart = (props: propTypes) => {
1190
1264
  </View>
1191
1265
  );
1192
1266
  })}
1267
+
1268
+ {horizSectionsBelow.map((sectionItems, index) => {
1269
+ let label = getLabel(sectionItems.value);
1270
+ if (hideOrigin && index === horizSections.length - 1) {
1271
+ label = '';
1272
+ }
1273
+ return (
1274
+ <View
1275
+ key={index}
1276
+ style={[
1277
+ styles.horizBar,
1278
+ {
1279
+ width: (props.width ? props.width : totalWidth) + 15,
1280
+ },
1281
+ index === 0 && {marginTop: stepHeight / 2},
1282
+ yAxisSide === 'right' && {transform: [{rotateY: '180deg'}]},
1283
+ ]}>
1284
+ <View
1285
+ style={[
1286
+ styles.leftLabel,
1287
+ {
1288
+ borderRightWidth: yAxisThickness,
1289
+ borderColor: yAxisColor,
1290
+ marginLeft: 1,
1291
+ },
1292
+ {
1293
+ height: index === 0 ? stepHeight * 1.5 : stepHeight,
1294
+ width: yAxisLabelWidth,
1295
+ },
1296
+ index === 0 && {marginTop: -stepHeight / 2},
1297
+ ]}>
1298
+ {!hideYAxisText ? (
1299
+ <Text
1300
+ numberOfLines={1}
1301
+ ellipsizeMode={'clip'}
1302
+ style={[
1303
+ yAxisTextStyle,
1304
+ index === 0 && {marginBottom: stepHeight / -2},
1305
+ yAxisSide === 'right' && {
1306
+ transform: [{rotateY: '180deg'}],
1307
+ },
1308
+ ]}>
1309
+ {label}
1310
+ </Text>
1311
+ ) : null}
1312
+ </View>
1313
+ <View
1314
+ style={[styles.leftPart, {backgroundColor: backgroundColor}]}>
1315
+ {hideRules ? null : (
1316
+ <Rule
1317
+ config={{
1318
+ thickness: rulesThickness,
1319
+ color: rulesColor,
1320
+ width: (props.width || totalWidth) + 11,
1321
+ dashWidth: dashWidth,
1322
+ dashGap: dashGap,
1323
+ type: rulesType,
1324
+ }}
1325
+ />
1326
+ )}
1327
+ </View>
1328
+ </View>
1329
+ );
1330
+ })}
1193
1331
  </>
1194
1332
  );
1195
1333
  };
@@ -1210,8 +1348,11 @@ export const LineChart = (props: propTypes) => {
1210
1348
  dataPtsRadius,
1211
1349
  textColor,
1212
1350
  textFontSize,
1351
+ startIndex,
1352
+ endIndex,
1213
1353
  ) => {
1214
1354
  return dataForRender.map((item: itemType, index: number) => {
1355
+ if (index < startIndex || index > endIndex) return null;
1215
1356
  if (item.hideDataPoint) {
1216
1357
  return null;
1217
1358
  }
@@ -1418,7 +1559,7 @@ export const LineChart = (props: propTypes) => {
1418
1559
  {dataPointLabelComponent()}
1419
1560
  </View>
1420
1561
  ) : null
1421
- ) : text ? (
1562
+ ) : text || item.dataPointText ? (
1422
1563
  !showTextOnPress || index === selectedIndex ? (
1423
1564
  <CanvasText
1424
1565
  fill={item.textColor || textColor}
@@ -1436,7 +1577,7 @@ export const LineChart = (props: propTypes) => {
1436
1577
  (item.value * containerHeight) / maxValue +
1437
1578
  (item.textShiftY || props.textShiftY || 0)
1438
1579
  }>
1439
- {text}
1580
+ {!showTextOnPress ? item.dataPointText : text}
1440
1581
  </CanvasText>
1441
1582
  ) : null
1442
1583
  ) : null}
@@ -1481,11 +1622,11 @@ export const LineChart = (props: propTypes) => {
1481
1622
  <View
1482
1623
  style={{
1483
1624
  position: 'absolute',
1484
- height: containerHeight + 10,
1625
+ height: containerHeight + 10 + horizSectionsBelow.length * stepHeight,
1485
1626
  bottom: 60, //stepHeight * -0.5 + xAxisThickness,
1486
1627
  width: totalWidth,
1487
1628
  zIndex: -1,
1488
- // backgroundColor: 'rgba(200,150,150,0.1)'
1629
+ // backgroundColor: 'rgba(200,150,150,0.6)'
1489
1630
  }}>
1490
1631
  <Svg>
1491
1632
  <Path
@@ -1530,6 +1671,7 @@ export const LineChart = (props: propTypes) => {
1530
1671
  {renderSpecificVerticalLines(data)}
1531
1672
  {renderSpecificVerticalLines(data2)}
1532
1673
 
1674
+ {/*** !!! Here it's done thrice intentionally, trying to make it to only 1 breaks things !!! ***/}
1533
1675
  {!hideDataPoints1
1534
1676
  ? renderDataPoints(
1535
1677
  data,
@@ -1540,6 +1682,8 @@ export const LineChart = (props: propTypes) => {
1540
1682
  dataPointsRadius1,
1541
1683
  textColor1,
1542
1684
  textFontSize1,
1685
+ startIndex1,
1686
+ endIndex1,
1543
1687
  )
1544
1688
  : null}
1545
1689
  {!hideDataPoints2
@@ -1552,6 +1696,8 @@ export const LineChart = (props: propTypes) => {
1552
1696
  dataPointsRadius2,
1553
1697
  textColor2,
1554
1698
  textFontSize2,
1699
+ startIndex2,
1700
+ endIndex2,
1555
1701
  )
1556
1702
  : null}
1557
1703
  {!hideDataPoints3
@@ -1564,6 +1710,8 @@ export const LineChart = (props: propTypes) => {
1564
1710
  dataPointsRadius3,
1565
1711
  textColor3,
1566
1712
  textFontSize3,
1713
+ startIndex3,
1714
+ endIndex3,
1567
1715
  )
1568
1716
  : null}
1569
1717
  </Svg>
@@ -1587,7 +1735,7 @@ export const LineChart = (props: propTypes) => {
1587
1735
  <Animated.View
1588
1736
  style={{
1589
1737
  position: 'absolute',
1590
- height: containerHeight + 10,
1738
+ height: containerHeight + 10 + horizSectionsBelow.length * stepHeight,
1591
1739
  bottom: 60, //stepHeight * -0.5 + xAxisThickness,
1592
1740
  width: animatedWidth,
1593
1741
  zIndex: -1,
@@ -1637,6 +1785,7 @@ export const LineChart = (props: propTypes) => {
1637
1785
  {renderSpecificVerticalLines(data2)}
1638
1786
  {renderSpecificVerticalLines(data3)}
1639
1787
 
1788
+ {/*** !!! Here it's done thrice intentionally, trying to make it to only 1 breaks things !!! ***/}
1640
1789
  {!hideDataPoints1
1641
1790
  ? renderDataPoints(
1642
1791
  data,
@@ -1647,6 +1796,8 @@ export const LineChart = (props: propTypes) => {
1647
1796
  dataPointsRadius1,
1648
1797
  textColor1,
1649
1798
  textFontSize1,
1799
+ startIndex1,
1800
+ endIndex1,
1650
1801
  )
1651
1802
  : null}
1652
1803
  {!hideDataPoints2
@@ -1659,6 +1810,8 @@ export const LineChart = (props: propTypes) => {
1659
1810
  dataPointsRadius2,
1660
1811
  textColor2,
1661
1812
  textFontSize2,
1813
+ startIndex2,
1814
+ endIndex2,
1662
1815
  )
1663
1816
  : null}
1664
1817
  {!hideDataPoints3
@@ -1671,6 +1824,8 @@ export const LineChart = (props: propTypes) => {
1671
1824
  dataPointsRadius3,
1672
1825
  textColor3,
1673
1826
  textFontSize3,
1827
+ startIndex3,
1828
+ endIndex3,
1674
1829
  )
1675
1830
  : null}
1676
1831
  </Svg>
@@ -1679,30 +1834,40 @@ export const LineChart = (props: propTypes) => {
1679
1834
  };
1680
1835
 
1681
1836
  return (
1682
- <View style={[styles.container, {height: containerHeight}, yAxisSide === 'right' && {marginLeft: yAxisLabelWidth + yAxisThickness }]}>
1837
+ <View
1838
+ style={[
1839
+ styles.container,
1840
+ {height: containerHeight + horizSectionsBelow.length * stepHeight},
1841
+ yAxisSide === 'right' && {marginLeft: yAxisLabelWidth + yAxisThickness},
1842
+ ]}>
1683
1843
  {props.hideAxesAndRules !== true && renderHorizSections()}
1684
1844
  {/* {sectionsOverlay()} */}
1685
1845
  <ScrollView
1686
1846
  horizontal
1687
1847
  contentContainerStyle={[
1688
1848
  {
1689
- height: containerHeight + 130,
1690
- width: totalWidth -20,
1849
+ height:
1850
+ containerHeight + 130 + horizSectionsBelow.length * stepHeight,
1851
+ width: totalWidth - 20,
1852
+ paddingBottom: horizSectionsBelow.length * stepHeight,
1691
1853
  // backgroundColor: 'yellow'
1692
1854
  },
1693
- !props.width && {width: totalWidth -20},
1855
+ !props.width && {width: totalWidth - 20},
1694
1856
  ]}
1695
1857
  scrollEnabled={!disableScroll}
1696
1858
  ref={scrollRef}
1697
- onContentSizeChange={()=>{
1698
- if(scrollRef.current && scrollToEnd){
1859
+ onContentSizeChange={() => {
1860
+ if (scrollRef.current && scrollToEnd) {
1699
1861
  scrollRef.current.scrollToEnd({animated: scrollAnimation});
1700
1862
  }
1701
1863
  }}
1702
1864
  showsHorizontalScrollIndicator={showScrollIndicator}
1703
1865
  style={[
1704
1866
  {
1705
- marginLeft: yAxisSide === 'right' ? -yAxisLabelWidth - yAxisThickness + 6 : yAxisLabelWidth + yAxisThickness,
1867
+ marginLeft:
1868
+ yAxisSide === 'right'
1869
+ ? -yAxisLabelWidth - yAxisThickness + 6
1870
+ : yAxisLabelWidth + yAxisThickness,
1706
1871
  position: 'absolute',
1707
1872
  bottom: stepHeight * -0.5 - 60, //stepHeight * -0.5 + xAxisThickness,
1708
1873
  paddingRight: 100,
package/src/todos.md ADDED
@@ -0,0 +1,7 @@
1
+ ## To-dos in documentation-
2
+
3
+ 1. Prepare a doc for Bar chart with negative values
4
+ 2. Prepare a doc for Line chart with negative values
5
+ 3. Prepare a doc for Bar chart with y axis on right side
6
+ 4. Prepare a doc for Line chart with y axis on right side
7
+ 5. Prepare a doc for Bar chart combined with Line chart having a separate data for the Line chart