react-native-gifted-charts 1.0.4 → 1.0.7

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.4",
3
+ "version": "1.0.7",
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": [
@@ -32,6 +32,8 @@ type propTypes = {
32
32
  horizontal: Boolean;
33
33
  intactTopLabel: Boolean;
34
34
  barBorderRadius?: number;
35
+ containerHeight?: number;
36
+ maxValue?: number;
35
37
  };
36
38
  type itemType = {
37
39
  value?: number;
@@ -54,12 +56,19 @@ type itemType = {
54
56
  };
55
57
 
56
58
  const Animated2DWithGradient = (props: propTypes) => {
57
- const {item, opacity, animationDuration, noGradient, noAnimation} = props;
59
+ const {
60
+ item,
61
+ opacity,
62
+ animationDuration,
63
+ noGradient,
64
+ noAnimation,
65
+ containerHeight,
66
+ maxValue,
67
+ } = props;
58
68
  const [height, setHeight] = useState(noAnimation ? props.height : 2);
59
69
  const [initialRender, setInitialRender] = useState(
60
70
  noAnimation ? false : true,
61
71
  );
62
- // console.log('comes to animated2DWithGradient', item);
63
72
 
64
73
  useEffect(() => {
65
74
  if (!noAnimation) {
@@ -97,9 +106,19 @@ const Animated2DWithGradient = (props: propTypes) => {
97
106
  position: 'absolute',
98
107
  bottom: 0,
99
108
  width: '100%',
100
- height: height,
109
+ height: noAnimation
110
+ ? (Math.abs(item.value) * (containerHeight || 200)) /
111
+ (maxValue || 200)
112
+ : height,
101
113
  }}>
102
- <View style={{width: '100%', height: height}}>
114
+ <View
115
+ style={{
116
+ width: '100%',
117
+ height: noAnimation
118
+ ? (Math.abs(item.value) * (containerHeight || 200)) /
119
+ (maxValue || 200)
120
+ : height,
121
+ }}>
103
122
  {noGradient ? (
104
123
  <View
105
124
  style={[
@@ -223,13 +242,14 @@ const Animated2DWithGradient = (props: propTypes) => {
223
242
  height: item.barWidth || 30,
224
243
  width: item.barWidth || 30,
225
244
  justifyContent:
226
- (props.horizontal && !props.intactTopLabel) || item.value < 0
245
+ (props.horizontal && !props.intactTopLabel) ||
246
+ item.value < 0
227
247
  ? 'center'
228
248
  : 'flex-end',
229
249
  alignItems: 'center',
230
250
  opacity: opacity,
231
251
  },
232
- item.value < 0 && {transform:[{rotate:'180deg'}]},
252
+ item.value < 0 && {transform: [{rotate: '180deg'}]},
233
253
  props.horizontal &&
234
254
  !props.intactTopLabel && {transform: [{rotate: '270deg'}]},
235
255
  item.topLabelContainerStyle,
@@ -243,4 +263,4 @@ const Animated2DWithGradient = (props: propTypes) => {
243
263
  );
244
264
  };
245
265
 
246
- export default Animated2DWithGradient;
266
+ export default Animated2DWithGradient;
@@ -121,18 +121,29 @@ const RenderBars = (props: Props) => {
121
121
  rotateLabel
122
122
  ? props.horizontal
123
123
  ? {transform: [{rotate: '330deg'}]}
124
- : {transform: [{rotate: value < 0 ? '240deg' : '60deg'}, {translateX: value < 0 ? 56 : 0}, {translateY: value < 0 ? 32 : 0}]}
124
+ : {
125
+ transform: [
126
+ {rotate: value < 0 ? '240deg' : '60deg'},
127
+ {translateX: value < 0 ? 56 : 0},
128
+ {translateY: value < 0 ? 32 : 0},
129
+ ],
130
+ }
125
131
  : props.horizontal
126
132
  ? {transform: [{rotate: '-90deg'}]}
127
133
  : value < 0
128
- ?{transform:[{rotate:'180deg'},{translateY:autoShiftLabels?0:32}]}
129
- :{},
134
+ ? {
135
+ transform: [
136
+ {rotate: '180deg'},
137
+ {translateY: autoShiftLabels ? 0 : 32},
138
+ ],
139
+ }
140
+ : {},
130
141
  ]}>
131
142
  {item.labelComponent ? (
132
143
  item.labelComponent()
133
144
  ) : (
134
145
  <Text
135
- style={[labelTextStyle, {textAlign: 'center'}]}
146
+ style={labelTextStyle || {textAlign: 'center'}}
136
147
  numberOfLines={1}>
137
148
  {label || ''}
138
149
  </Text>
@@ -141,7 +152,11 @@ const RenderBars = (props: Props) => {
141
152
  );
142
153
  };
143
154
 
144
- const renderAnimatedLabel = (label: String, labelTextStyle: any, value: number) => {
155
+ const renderAnimatedLabel = (
156
+ label: String,
157
+ labelTextStyle: any,
158
+ value: number,
159
+ ) => {
145
160
  return (
146
161
  <Animated.View
147
162
  style={[
@@ -158,7 +173,7 @@ const RenderBars = (props: Props) => {
158
173
  bottom: rotateLabel ? -40 : -25,
159
174
  opacity: appearingOpacity,
160
175
  },
161
- value < 0 && {transform:[{rotate:'180deg'}]},
176
+ value < 0 && {transform: [{rotate: '180deg'}]},
162
177
  rotateLabel
163
178
  ? props.horizontal
164
179
  ? {transform: [{rotate: '330deg'}]}
@@ -171,7 +186,7 @@ const RenderBars = (props: Props) => {
171
186
  item.labelComponent()
172
187
  ) : (
173
188
  <Text
174
- style={[labelTextStyle, {textAlign: 'center'}]}
189
+ style={labelTextStyle || {textAlign: 'center'}}
175
190
  numberOfLines={1}>
176
191
  {label || ''}
177
192
  </Text>
@@ -255,7 +270,7 @@ const RenderBars = (props: Props) => {
255
270
  : 'flex-end',
256
271
  alignItems: 'center',
257
272
  },
258
- item.value < 0 && {transform:[{rotate:'180deg'}]},
273
+ item.value < 0 && {transform: [{rotate: '180deg'}]},
259
274
  props.horizontal &&
260
275
  !props.intactTopLabel && {transform: [{rotate: '270deg'}]},
261
276
  item.topLabelContainerStyle,
@@ -277,13 +292,27 @@ const RenderBars = (props: Props) => {
277
292
  // overflow: 'visible',
278
293
  marginBottom: 60,
279
294
  width: item.barWidth || props.barWidth || 30,
280
- height: item.value>=0 &&(!isThreeD || isAnimated) && item.topLabelComponent
281
- ? (item.topLabelComponentHeight || 30) +
282
- (Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)
283
- : (Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200),
295
+ height:
296
+ item.value >= 0 &&
297
+ (!isThreeD || isAnimated) &&
298
+ item.topLabelComponent
299
+ ? (item.topLabelComponentHeight || 30) +
300
+ (Math.abs(item.value) * (containerHeight || 200)) /
301
+ (maxValue || 200)
302
+ : (Math.abs(item.value) * (containerHeight || 200)) /
303
+ (maxValue || 200),
284
304
  marginRight: spacing,
285
305
  },
286
- item.value < 0 && {transform:[{translateY:(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)},{rotateZ:'180deg'}]},
306
+ item.value < 0 && {
307
+ transform: [
308
+ {
309
+ translateY:
310
+ (Math.abs(item.value) * (containerHeight || 200)) /
311
+ (maxValue || 200),
312
+ },
313
+ {rotateZ: '180deg'},
314
+ ],
315
+ },
287
316
  // !isThreeD && !item.showGradient && !props.showGradient &&
288
317
  // { backgroundColor: item.frontColor || props.frontColor || 'black' },
289
318
  side !== 'right' && {zIndex: data.length - index},
@@ -333,7 +362,10 @@ const RenderBars = (props: Props) => {
333
362
  topLabelComponent={item.topLabelComponent}
334
363
  opacity={opacity || 1}
335
364
  animationDuration={animationDuration || 800}
336
- height={(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)}
365
+ height={
366
+ (Math.abs(item.value) * (containerHeight || 200)) /
367
+ (maxValue || 200)
368
+ }
337
369
  intactTopLabel={props.intactTopLabel}
338
370
  horizontal={props.horizontal}
339
371
  />
@@ -358,7 +390,10 @@ const RenderBars = (props: Props) => {
358
390
  opacity={opacity || 1}
359
391
  horizontal={props.horizontal}
360
392
  intactTopLabel={props.intactTopLabel}
361
- height={(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)}
393
+ height={
394
+ (Math.abs(item.value) * (containerHeight || 200)) /
395
+ (maxValue || 200)
396
+ }
362
397
  value={item.value}
363
398
  />
364
399
  )
@@ -373,7 +408,12 @@ const RenderBars = (props: Props) => {
373
408
  roundedTop={props.roundedTop || false}
374
409
  gradientColor={props.gradientColor}
375
410
  frontColor={props.frontColor || 'black'}
376
- height={(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)}
411
+ containerHeight={containerHeight}
412
+ maxValue={maxValue}
413
+ height={
414
+ (Math.abs(item.value) * (containerHeight || 200)) /
415
+ (maxValue || 200)
416
+ }
377
417
  cappedBars={props.cappedBars}
378
418
  capThickness={props.capThickness}
379
419
  capColor={props.capColor}
@@ -396,7 +436,12 @@ const RenderBars = (props: Props) => {
396
436
  gradientColor={props.gradientColor}
397
437
  noGradient
398
438
  frontColor={props.frontColor || 'black'}
399
- height={(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)}
439
+ containerHeight={containerHeight}
440
+ maxValue={maxValue}
441
+ height={
442
+ (Math.abs(item.value) * (containerHeight || 200)) /
443
+ (maxValue || 200)
444
+ }
400
445
  cappedBars={props.cappedBars}
401
446
  capThickness={props.capThickness}
402
447
  capColor={props.capColor}
@@ -417,7 +462,12 @@ const RenderBars = (props: Props) => {
417
462
  noGradient
418
463
  noAnimation
419
464
  frontColor={props.frontColor || 'black'}
420
- height={(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)}
465
+ containerHeight={containerHeight}
466
+ maxValue={maxValue}
467
+ height={
468
+ (Math.abs(item.value) * (containerHeight || 200)) /
469
+ (maxValue || 200)
470
+ }
421
471
  cappedBars={props.cappedBars}
422
472
  capThickness={props.capThickness}
423
473
  capColor={props.capColor}
@@ -428,10 +478,10 @@ const RenderBars = (props: Props) => {
428
478
  />
429
479
  )}
430
480
  {isAnimated
431
- ? renderAnimatedLabel(item.label || '', item.labelTextStyle,item.value)
432
- : renderLabel(item.label || '', item.labelTextStyle,item.value)}
481
+ ? renderAnimatedLabel(item.label || '', item.labelTextStyle, item.value)
482
+ : renderLabel(item.label || '', item.labelTextStyle, item.value)}
433
483
  </TouchableOpacity>
434
484
  );
435
485
  };
436
486
 
437
- export default RenderBars;
487
+ export default RenderBars;
@@ -141,7 +141,9 @@ const RenderStackBars = (props: Props) => {
141
141
  stackItem.borderBottomRightRadius || 0,
142
142
  },
143
143
  ]}
144
- />
144
+ >
145
+ {stackItem.innerBarComponent && stackItem.innerBarComponent()}
146
+ </TouchableOpacity>
145
147
  );
146
148
  })}
147
149
  </View>
@@ -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;
@@ -121,8 +122,10 @@ type PropTypes = {
121
122
  autoShiftLabels?: Boolean;
122
123
  scrollToEnd?: Boolean;
123
124
  scrollAnimation?: Boolean;
125
+ labelsExtraHeight?: number;
124
126
  };
125
127
  type lineConfigType = {
128
+ initialSpacing?: number;
126
129
  curved?: Boolean;
127
130
  isAnimated?: Boolean;
128
131
  delay?: number;
@@ -139,6 +142,8 @@ type lineConfigType = {
139
142
  textShiftX?: number;
140
143
  textShiftY?: number;
141
144
  shiftY?: number;
145
+ startIndex?: number;
146
+ endIndex?: number;
142
147
  };
143
148
  type referenceConfigType = {
144
149
  thickness: number;
@@ -174,7 +179,12 @@ export const BarChart = (props: PropTypes) => {
174
179
  const scrollRef = useRef();
175
180
  const [points, setPoints] = useState('');
176
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;
177
186
  const defaultLineConfig = {
187
+ initialSpacing: initialSpacing,
178
188
  curved: false,
179
189
  isAnimated: false,
180
190
  thickness: 1,
@@ -191,9 +201,16 @@ export const BarChart = (props: PropTypes) => {
191
201
  textShiftY: 0,
192
202
  shiftY: 0,
193
203
  delay: 0,
204
+ startIndex: 0,
205
+ endIndex: lineData.length - 1,
194
206
  };
195
207
  const lineConfig = props.lineConfig
196
208
  ? {
209
+ initialSpacing:
210
+ props.lineConfig.initialSpacing === 0
211
+ ? 0
212
+ : props.lineConfig.initialSpacing ||
213
+ defaultLineConfig.initialSpacing,
197
214
  curved: props.lineConfig.curved || defaultLineConfig.curved,
198
215
  isAnimated: props.lineConfig.isAnimated || defaultLineConfig.isAnimated,
199
216
  thickness: props.lineConfig.thickness || defaultLineConfig.thickness,
@@ -219,6 +236,11 @@ export const BarChart = (props: PropTypes) => {
219
236
  textShiftY: props.lineConfig.textShiftY || defaultLineConfig.textShiftY,
220
237
  shiftY: props.lineConfig.shiftY || defaultLineConfig.shiftY,
221
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,
222
244
  }
223
245
  : defaultLineConfig;
224
246
  const containerHeight = props.height || 200;
@@ -226,14 +248,15 @@ export const BarChart = (props: PropTypes) => {
226
248
  const horizSections = [{value: '0'}];
227
249
  const horizSectionsBelow = [];
228
250
  const stepHeight = props.stepHeight || containerHeight / noOfSections;
229
- const data = useMemo(() => props.data || [], [props.data]);
230
251
  const spacing = props.spacing === 0 ? 0 : props.spacing ? props.spacing : 20;
231
252
  const labelWidth = props.labelWidth || 0;
232
253
  const scrollToEnd = props.scrollToEnd || false;
233
254
  const scrollAnimation = props.scrollAnimation === false ? false : true;
255
+ const labelsExtraHeight = props.labelsExtraHeight || 0;
234
256
 
235
257
  let totalWidth = spacing;
236
- let maxItem = 0, minItem = 0;
258
+ let maxItem = 0,
259
+ minItem = 0;
237
260
  if (props.stackData) {
238
261
  props.stackData.forEach(stackItem => {
239
262
  // console.log('stackItem', stackItem);
@@ -245,7 +268,7 @@ export const BarChart = (props: PropTypes) => {
245
268
  if (stackSum > maxItem) {
246
269
  maxItem = stackSum;
247
270
  }
248
- if(stackSum < minItem){
271
+ if (stackSum < minItem) {
249
272
  minItem = stackSum;
250
273
  }
251
274
  totalWidth +=
@@ -257,7 +280,7 @@ export const BarChart = (props: PropTypes) => {
257
280
  if (item.value > maxItem) {
258
281
  maxItem = item.value;
259
282
  }
260
- if(item.value < minItem){
283
+ if (item.value < minItem) {
261
284
  minItem = item.value;
262
285
  }
263
286
  totalWidth +=
@@ -271,7 +294,7 @@ export const BarChart = (props: PropTypes) => {
271
294
  maxItem = maxItem + (10 - (maxItem % 10));
272
295
  maxItem /= 10 * (props.roundToDigits || 1);
273
296
  maxItem = parseFloat(maxItem.toFixed(props.roundToDigits || 1));
274
- if(minItem !== 0){
297
+ if (minItem !== 0) {
275
298
  minItem *= 10 * (props.roundToDigits || 1);
276
299
  minItem = minItem - (10 + (minItem % 10));
277
300
  minItem /= 10 * (props.roundToDigits || 1);
@@ -279,8 +302,8 @@ export const BarChart = (props: PropTypes) => {
279
302
  }
280
303
  } else {
281
304
  maxItem = maxItem + (10 - (maxItem % 10));
282
- if(minItem !== 0){
283
- minItem = minItem - (10 + (minItem % 10))
305
+ if (minItem !== 0) {
306
+ minItem = minItem - (10 + (minItem % 10));
284
307
  }
285
308
  }
286
309
 
@@ -288,11 +311,10 @@ export const BarChart = (props: PropTypes) => {
288
311
  const minValue = props.minValue || minItem;
289
312
 
290
313
  const stepValue = props.stepValue || maxValue / noOfSections;
291
- const noOfSectionsBelowXAxis = props.noOfSectionsBelowXAxis || (-minValue / stepValue);
314
+ const noOfSectionsBelowXAxis =
315
+ props.noOfSectionsBelowXAxis || -minValue / stepValue;
292
316
  const disableScroll = props.disableScroll || false;
293
317
  const showScrollIndicator = props.showScrollIndicator || false;
294
- const initialSpacing =
295
- props.initialSpacing === 0 ? 0 : props.initialSpacing || 40;
296
318
  // const oldData = props.oldData || [];
297
319
  const side = props.side || '';
298
320
  const rotateLabel = props.rotateLabel || false;
@@ -391,39 +413,41 @@ export const BarChart = (props: PropTypes) => {
391
413
  if (showLine) {
392
414
  let pp = '';
393
415
  if (!lineConfig.curved) {
394
- 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;
395
418
  const currentBarWidth =
396
419
  (data && data[i] && data[i].barWidth) || props.barWidth || 30;
397
420
  pp +=
398
421
  'L' +
399
422
  (yAxisLabelWidth +
423
+ lineConfig.initialSpacing +
400
424
  6 -
401
425
  (initialSpacing - currentBarWidth / 2) -
402
426
  lineConfig.dataPointsWidth / 2 +
403
427
  (currentBarWidth + spacing) * i) +
404
428
  ' ' +
405
429
  (containerHeight -
406
- lineConfig.shiftY +
407
- 10 -
408
- (data[i].value * containerHeight) / maxValue) +
430
+ lineConfig.shiftY -
431
+ (lineData[i].value * containerHeight) / maxValue) +
409
432
  ' ';
410
433
  }
411
434
  setPoints(pp.replace('L', 'M'));
412
435
  } else {
413
436
  let p1Array = [];
414
- 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;
415
439
  const currentBarWidth =
416
440
  (data && data[i] && data[i].barWidth) || props.barWidth || 30;
417
441
  p1Array.push([
418
442
  yAxisLabelWidth +
443
+ lineConfig.initialSpacing +
419
444
  6 -
420
445
  (initialSpacing - currentBarWidth / 2) -
421
446
  lineConfig.dataPointsWidth / 2 +
422
447
  (currentBarWidth + spacing) * i,
423
448
  containerHeight -
424
- lineConfig.shiftY +
425
- 10 -
426
- (data[i].value * containerHeight) / maxValue,
449
+ lineConfig.shiftY -
450
+ (lineData[i].value * containerHeight) / maxValue,
427
451
  ]);
428
452
  let xx = svgPath(p1Array, bezierCommand);
429
453
  setPoints(xx);
@@ -439,14 +463,18 @@ export const BarChart = (props: PropTypes) => {
439
463
  animationDuration,
440
464
  containerHeight,
441
465
  data,
466
+ lineData,
442
467
  decreaseWidth,
443
468
  initialSpacing,
444
469
  labelsAppear,
470
+ lineConfig.initialSpacing,
445
471
  lineConfig.curved,
446
472
  lineConfig.dataPointsWidth,
447
473
  lineConfig.shiftY,
448
474
  lineConfig.isAnimated,
449
475
  lineConfig.delay,
476
+ lineConfig.startIndex,
477
+ lineConfig.endIndex,
450
478
  maxValue,
451
479
  // moveBar,
452
480
  props.barWidth,
@@ -535,7 +563,7 @@ export const BarChart = (props: PropTypes) => {
535
563
  : value.toString(),
536
564
  });
537
565
  }
538
- if(noOfSectionsBelowXAxis){
566
+ if (noOfSectionsBelowXAxis) {
539
567
  for (let i = 1; i <= noOfSectionsBelowXAxis; i++) {
540
568
  let value = stepValue * -i;
541
569
  if (props.showFractionalValues || props.roundToDigits) {
@@ -543,9 +571,10 @@ export const BarChart = (props: PropTypes) => {
543
571
  }
544
572
  horizSectionsBelow.push({
545
573
  value: props.yAxisLabelTexts
546
- ? props.yAxisLabelTexts[noOfSectionsBelowXAxis - i] ?? value.toString()
547
- : value.toString(),
548
- })
574
+ ? props.yAxisLabelTexts[noOfSectionsBelowXAxis - i] ??
575
+ value.toString()
576
+ : value.toString(),
577
+ });
549
578
  }
550
579
  }
551
580
 
@@ -600,7 +629,7 @@ export const BarChart = (props: PropTypes) => {
600
629
  ? props.width || totalWidth
601
630
  : props.width || totalWidth + 11,
602
631
  },
603
- yAxisSide === 'right' && {transform:[{rotateY:'180deg'}]}
632
+ yAxisSide === 'right' && {transform: [{rotateY: '180deg'}]},
604
633
  ]}>
605
634
  <View
606
635
  style={[
@@ -626,13 +655,16 @@ export const BarChart = (props: PropTypes) => {
626
655
  style={[
627
656
  yAxisTextStyle,
628
657
  index === noOfSections && {marginBottom: stepHeight / -2},
629
- horizontal ? {
630
- transform: [
631
- {rotate: '270deg'},
632
- {translateY: yAxisAtTop ? 0 : 50},
633
- ],
634
- }:
635
- 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
+ },
636
668
  ]}>
637
669
  {label}
638
670
  </Text>
@@ -743,7 +775,8 @@ export const BarChart = (props: PropTypes) => {
743
775
  ? props.width || totalWidth
744
776
  : props.width || totalWidth + 11,
745
777
  },
746
- index===0&&{marginTop:stepHeight/2}
778
+ yAxisSide === 'right' && {transform: [{rotateY: '180deg'}]},
779
+ index === 0 && {marginTop: stepHeight / 2},
747
780
  ]}>
748
781
  <View
749
782
  style={[
@@ -757,10 +790,10 @@ export const BarChart = (props: PropTypes) => {
757
790
  transform: [{translateX: totalWidth + yAxisThickness}],
758
791
  },
759
792
  {
760
- height: index===0?stepHeight*1.5:stepHeight,
793
+ height: index === 0 ? stepHeight * 1.5 : stepHeight,
761
794
  width: yAxisLabelWidth,
762
795
  },
763
- index===0&&{marginTop:-stepHeight/2}
796
+ index === 0 && {marginTop: -stepHeight / 2},
764
797
  ]}>
765
798
  {!hideYAxisText ? (
766
799
  <Text
@@ -775,16 +808,16 @@ export const BarChart = (props: PropTypes) => {
775
808
  {translateY: yAxisAtTop ? 0 : 50},
776
809
  ],
777
810
  },
811
+ yAxisSide === 'right' && {
812
+ transform: [{rotateY: '180deg'}],
813
+ },
778
814
  ]}>
779
815
  {label}
780
816
  </Text>
781
817
  ) : null}
782
818
  </View>
783
819
  <View
784
- style={[
785
- styles.leftPart,
786
- {backgroundColor: backgroundColor},
787
- ]}>
820
+ style={[styles.leftPart, {backgroundColor: backgroundColor}]}>
788
821
  {hideRules ? null : (
789
822
  <Rule
790
823
  config={{
@@ -801,7 +834,7 @@ export const BarChart = (props: PropTypes) => {
801
834
  )}
802
835
  </View>
803
836
  </View>
804
- )
837
+ );
805
838
  })}
806
839
  </>
807
840
  );
@@ -840,7 +873,10 @@ export const BarChart = (props: PropTypes) => {
840
873
  };
841
874
 
842
875
  const renderDataPoints = () => {
843
- 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
+ }
844
880
  // console.log('comes in');
845
881
  const currentBarWidth = item.barWidth || props.barWidth || 30;
846
882
  if (lineConfig.dataPointsShape === 'rectangular') {
@@ -849,6 +885,7 @@ export const BarChart = (props: PropTypes) => {
849
885
  <Rect
850
886
  x={
851
887
  yAxisLabelWidth +
888
+ lineConfig.initialSpacing +
852
889
  6 -
853
890
  (initialSpacing - currentBarWidth / 2) -
854
891
  lineConfig.dataPointsWidth +
@@ -857,8 +894,7 @@ export const BarChart = (props: PropTypes) => {
857
894
  y={
858
895
  containerHeight -
859
896
  lineConfig.shiftY -
860
- lineConfig.dataPointsHeight / 2 +
861
- 10 -
897
+ lineConfig.dataPointsHeight / 2 -
862
898
  (item.value * containerHeight) / maxValue
863
899
  }
864
900
  width={lineConfig.dataPointsWidth}
@@ -871,6 +907,7 @@ export const BarChart = (props: PropTypes) => {
871
907
  fontSize={item.textFontSize || lineConfig.textFontSize}
872
908
  x={
873
909
  yAxisLabelWidth +
910
+ lineConfig.initialSpacing +
874
911
  6 -
875
912
  (initialSpacing - currentBarWidth / 2) -
876
913
  lineConfig.dataPointsWidth +
@@ -880,8 +917,7 @@ export const BarChart = (props: PropTypes) => {
880
917
  y={
881
918
  containerHeight -
882
919
  lineConfig.shiftY -
883
- lineConfig.dataPointsHeight / 2 +
884
- 10 -
920
+ lineConfig.dataPointsHeight / 2 -
885
921
  (item.value * containerHeight) / maxValue +
886
922
  (item.textShiftY || lineConfig.textShiftY || 0)
887
923
  }>
@@ -896,6 +932,7 @@ export const BarChart = (props: PropTypes) => {
896
932
  <Circle
897
933
  cx={
898
934
  yAxisLabelWidth +
935
+ lineConfig.initialSpacing +
899
936
  6 -
900
937
  (initialSpacing - currentBarWidth / 2) -
901
938
  lineConfig.dataPointsWidth / 2 +
@@ -903,8 +940,7 @@ export const BarChart = (props: PropTypes) => {
903
940
  }
904
941
  cy={
905
942
  containerHeight -
906
- lineConfig.shiftY +
907
- 10 -
943
+ lineConfig.shiftY -
908
944
  (item.value * containerHeight) / maxValue
909
945
  }
910
946
  r={lineConfig.dataPointsRadius}
@@ -916,6 +952,7 @@ export const BarChart = (props: PropTypes) => {
916
952
  fontSize={item.textFontSize || lineConfig.textFontSize}
917
953
  x={
918
954
  yAxisLabelWidth +
955
+ lineConfig.initialSpacing +
919
956
  6 -
920
957
  (initialSpacing - currentBarWidth / 2) -
921
958
  lineConfig.dataPointsWidth +
@@ -925,8 +962,7 @@ export const BarChart = (props: PropTypes) => {
925
962
  y={
926
963
  containerHeight -
927
964
  lineConfig.shiftY -
928
- lineConfig.dataPointsHeight / 2 +
929
- 10 -
965
+ lineConfig.dataPointsHeight / 2 -
930
966
  (item.value * containerHeight) / maxValue +
931
967
  (item.textShiftY || lineConfig.textShiftY || 0)
932
968
  }>
@@ -1095,23 +1131,27 @@ export const BarChart = (props: PropTypes) => {
1095
1131
  style={[
1096
1132
  styles.container,
1097
1133
  {
1098
- height: containerHeight + horizSectionsBelow.length * stepHeight,
1134
+ height:
1135
+ containerHeight +
1136
+ horizSectionsBelow.length * stepHeight +
1137
+ labelsExtraHeight,
1099
1138
  },
1100
- yAxisSide === 'right' && {marginLeft: yAxisLabelWidth + yAxisThickness },
1139
+ yAxisSide === 'right' && {marginLeft: yAxisLabelWidth + yAxisThickness},
1101
1140
  props.width && {width: props.width},
1102
1141
  horizontal && {transform: [{rotate: '90deg'}, {translateY: -15}]},
1103
1142
  ]}>
1104
1143
  {props.hideAxesAndRules !== true && renderHorizSections()}
1105
1144
  <ScrollView
1106
1145
  ref={scrollRef}
1107
- onContentSizeChange={()=>{
1108
- if(scrollRef.current && scrollToEnd){
1146
+ onContentSizeChange={() => {
1147
+ if (scrollRef.current && scrollToEnd) {
1109
1148
  scrollRef.current.scrollToEnd({animated: scrollAnimation});
1110
1149
  }
1111
1150
  }}
1112
1151
  style={[
1113
1152
  {
1114
- marginLeft: yAxisSide === 'right' ? -yAxisLabelWidth+10 : yAxisLabelWidth,
1153
+ marginLeft:
1154
+ yAxisSide === 'right' ? -yAxisLabelWidth + 10 : yAxisLabelWidth,
1115
1155
  position: 'absolute',
1116
1156
  bottom: stepHeight * -0.5 - 60 + xAxisThickness,
1117
1157
  },
@@ -1122,9 +1162,11 @@ export const BarChart = (props: PropTypes) => {
1122
1162
  contentContainerStyle={[
1123
1163
  {
1124
1164
  // backgroundColor: 'yellow',
1125
- height: containerHeight + 130 + horizSectionsBelow.length * stepHeight,
1165
+ height:
1166
+ containerHeight + 130 + horizSectionsBelow.length * stepHeight,
1126
1167
  paddingLeft: initialSpacing,
1127
- paddingBottom:horizSectionsBelow.length * stepHeight,
1168
+ paddingBottom:
1169
+ horizSectionsBelow.length * stepHeight + labelsExtraHeight,
1128
1170
  alignItems: 'flex-end',
1129
1171
  },
1130
1172
  !props.width && {width: totalWidth},
@@ -1219,4 +1261,4 @@ export const BarChart = (props: PropTypes) => {
1219
1261
  </ScrollView>
1220
1262
  </View>
1221
1263
  );
1222
- };
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,
@@ -966,7 +1038,7 @@ export const LineChart = (props: propTypes) => {
966
1038
  labelComponent()
967
1039
  ) : (
968
1040
  <Text
969
- style={[labelTextStyle, {textAlign: 'center'}]}
1041
+ style={labelTextStyle || {textAlign: 'center'}}
970
1042
  numberOfLines={1}>
971
1043
  {label || ''}
972
1044
  </Text>
@@ -1004,7 +1076,7 @@ export const LineChart = (props: propTypes) => {
1004
1076
  labelComponent()
1005
1077
  ) : (
1006
1078
  <Text
1007
- style={[labelTextStyle, {textAlign: 'center'}]}
1079
+ style={labelTextStyle || {textAlign: 'center'}}
1008
1080
  numberOfLines={1}>
1009
1081
  {label || ''}
1010
1082
  </Text>
@@ -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
  }
@@ -1476,16 +1617,26 @@ export const LineChart = (props: propTypes) => {
1476
1617
  endFillColor: string,
1477
1618
  startOpacity: number,
1478
1619
  endOpacity: number,
1620
+ hideDataPoints: Boolean,
1621
+ dataPointsShape,
1622
+ dataPointsWidth,
1623
+ dataPointsHeight,
1624
+ dataPointsColor,
1625
+ dataPointsRadius,
1626
+ textColor,
1627
+ textFontSize,
1628
+ startIndex,
1629
+ endIndex,
1479
1630
  ) => {
1480
1631
  return (
1481
1632
  <View
1482
1633
  style={{
1483
1634
  position: 'absolute',
1484
- height: containerHeight + 10,
1635
+ height: containerHeight + 10 + horizSectionsBelow.length * stepHeight,
1485
1636
  bottom: 60, //stepHeight * -0.5 + xAxisThickness,
1486
1637
  width: totalWidth,
1487
1638
  zIndex: -1,
1488
- // backgroundColor: 'rgba(200,150,150,0.1)'
1639
+ // backgroundColor: 'rgba(200,150,150,0.6)'
1489
1640
  }}>
1490
1641
  <Svg>
1491
1642
  <Path
@@ -1530,40 +1681,18 @@ export const LineChart = (props: propTypes) => {
1530
1681
  {renderSpecificVerticalLines(data)}
1531
1682
  {renderSpecificVerticalLines(data2)}
1532
1683
 
1533
- {!hideDataPoints1
1684
+ {!hideDataPoints
1534
1685
  ? renderDataPoints(
1535
1686
  data,
1536
- dataPointsShape1,
1537
- dataPointsWidth1,
1538
- dataPointsHeight1,
1539
- dataPointsColor1,
1540
- dataPointsRadius1,
1541
- textColor1,
1542
- textFontSize1,
1543
- )
1544
- : null}
1545
- {!hideDataPoints2
1546
- ? renderDataPoints(
1547
- data2,
1548
- dataPointsShape2,
1549
- dataPointsWidth2,
1550
- dataPointsHeight2,
1551
- dataPointsColor2,
1552
- dataPointsRadius2,
1553
- textColor2,
1554
- textFontSize2,
1555
- )
1556
- : null}
1557
- {!hideDataPoints3
1558
- ? renderDataPoints(
1559
- data3,
1560
- dataPointsShape3,
1561
- dataPointsWidth3,
1562
- dataPointsHeight3,
1563
- dataPointsColor3,
1564
- dataPointsRadius3,
1565
- textColor3,
1566
- textFontSize3,
1687
+ dataPointsShape,
1688
+ dataPointsWidth,
1689
+ dataPointsHeight,
1690
+ dataPointsColor,
1691
+ dataPointsRadius,
1692
+ textColor,
1693
+ textFontSize,
1694
+ startIndex,
1695
+ endIndex,
1567
1696
  )
1568
1697
  : null}
1569
1698
  </Svg>
@@ -1581,13 +1710,23 @@ export const LineChart = (props: propTypes) => {
1581
1710
  endFillColor: string,
1582
1711
  startOpacity: number,
1583
1712
  endOpacity: number,
1713
+ hideDataPoints: Boolean,
1714
+ dataPointsShape,
1715
+ dataPointsWidth,
1716
+ dataPointsHeight,
1717
+ dataPointsColor,
1718
+ dataPointsRadius,
1719
+ textColor,
1720
+ textFontSize,
1721
+ startIndex,
1722
+ endIndex,
1584
1723
  ) => {
1585
1724
  // console.log('animatedWidth is-------->', animatedWidth);
1586
1725
  return (
1587
1726
  <Animated.View
1588
1727
  style={{
1589
1728
  position: 'absolute',
1590
- height: containerHeight + 10,
1729
+ height: containerHeight + 10 + horizSectionsBelow.length * stepHeight,
1591
1730
  bottom: 60, //stepHeight * -0.5 + xAxisThickness,
1592
1731
  width: animatedWidth,
1593
1732
  zIndex: -1,
@@ -1637,40 +1776,18 @@ export const LineChart = (props: propTypes) => {
1637
1776
  {renderSpecificVerticalLines(data2)}
1638
1777
  {renderSpecificVerticalLines(data3)}
1639
1778
 
1640
- {!hideDataPoints1
1779
+ {!hideDataPoints
1641
1780
  ? renderDataPoints(
1642
1781
  data,
1643
- dataPointsShape1,
1644
- dataPointsWidth1,
1645
- dataPointsHeight1,
1646
- dataPointsColor1,
1647
- dataPointsRadius1,
1648
- textColor1,
1649
- textFontSize1,
1650
- )
1651
- : null}
1652
- {!hideDataPoints2
1653
- ? renderDataPoints(
1654
- data2,
1655
- dataPointsShape2,
1656
- dataPointsWidth2,
1657
- dataPointsHeight2,
1658
- dataPointsColor2,
1659
- dataPointsRadius2,
1660
- textColor2,
1661
- textFontSize2,
1662
- )
1663
- : null}
1664
- {!hideDataPoints3
1665
- ? renderDataPoints(
1666
- data3,
1667
- dataPointsShape3,
1668
- dataPointsWidth3,
1669
- dataPointsHeight3,
1670
- dataPointsColor3,
1671
- dataPointsRadius3,
1672
- textColor3,
1673
- textFontSize3,
1782
+ dataPointsShape,
1783
+ dataPointsWidth,
1784
+ dataPointsHeight,
1785
+ dataPointsColor,
1786
+ dataPointsRadius,
1787
+ textColor,
1788
+ textFontSize,
1789
+ startIndex,
1790
+ endIndex,
1674
1791
  )
1675
1792
  : null}
1676
1793
  </Svg>
@@ -1679,30 +1796,40 @@ export const LineChart = (props: propTypes) => {
1679
1796
  };
1680
1797
 
1681
1798
  return (
1682
- <View style={[styles.container, {height: containerHeight}, yAxisSide === 'right' && {marginLeft: yAxisLabelWidth + yAxisThickness }]}>
1799
+ <View
1800
+ style={[
1801
+ styles.container,
1802
+ {height: containerHeight + horizSectionsBelow.length * stepHeight},
1803
+ yAxisSide === 'right' && {marginLeft: yAxisLabelWidth + yAxisThickness},
1804
+ ]}>
1683
1805
  {props.hideAxesAndRules !== true && renderHorizSections()}
1684
1806
  {/* {sectionsOverlay()} */}
1685
1807
  <ScrollView
1686
1808
  horizontal
1687
1809
  contentContainerStyle={[
1688
1810
  {
1689
- height: containerHeight + 130,
1690
- width: totalWidth -20,
1811
+ height:
1812
+ containerHeight + 130 + horizSectionsBelow.length * stepHeight,
1813
+ width: totalWidth - 20,
1814
+ paddingBottom: horizSectionsBelow.length * stepHeight,
1691
1815
  // backgroundColor: 'yellow'
1692
1816
  },
1693
- !props.width && {width: totalWidth -20},
1817
+ !props.width && {width: totalWidth - 20},
1694
1818
  ]}
1695
1819
  scrollEnabled={!disableScroll}
1696
1820
  ref={scrollRef}
1697
- onContentSizeChange={()=>{
1698
- if(scrollRef.current && scrollToEnd){
1821
+ onContentSizeChange={() => {
1822
+ if (scrollRef.current && scrollToEnd) {
1699
1823
  scrollRef.current.scrollToEnd({animated: scrollAnimation});
1700
1824
  }
1701
1825
  }}
1702
1826
  showsHorizontalScrollIndicator={showScrollIndicator}
1703
1827
  style={[
1704
1828
  {
1705
- marginLeft: yAxisSide === 'right' ? -yAxisLabelWidth - yAxisThickness + 6 : yAxisLabelWidth + yAxisThickness,
1829
+ marginLeft:
1830
+ yAxisSide === 'right'
1831
+ ? -yAxisLabelWidth - yAxisThickness + 6
1832
+ : yAxisLabelWidth + yAxisThickness,
1706
1833
  position: 'absolute',
1707
1834
  bottom: stepHeight * -0.5 - 60, //stepHeight * -0.5 + xAxisThickness,
1708
1835
  paddingRight: 100,
@@ -1759,6 +1886,16 @@ export const LineChart = (props: propTypes) => {
1759
1886
  endFillColor1,
1760
1887
  startOpacity1,
1761
1888
  endOpacity1,
1889
+ hideDataPoints1,
1890
+ dataPointsShape1,
1891
+ dataPointsWidth1,
1892
+ dataPointsHeight1,
1893
+ dataPointsColor1,
1894
+ dataPointsRadius1,
1895
+ textColor1,
1896
+ textFontSize1,
1897
+ startIndex1,
1898
+ endIndex1,
1762
1899
  )
1763
1900
  : renderLine(
1764
1901
  points,
@@ -1769,6 +1906,16 @@ export const LineChart = (props: propTypes) => {
1769
1906
  endFillColor1,
1770
1907
  startOpacity1,
1771
1908
  endOpacity1,
1909
+ hideDataPoints1,
1910
+ dataPointsShape1,
1911
+ dataPointsWidth1,
1912
+ dataPointsHeight1,
1913
+ dataPointsColor1,
1914
+ dataPointsRadius1,
1915
+ textColor1,
1916
+ textFontSize1,
1917
+ startIndex1,
1918
+ endIndex1,
1772
1919
  )}
1773
1920
  {points2
1774
1921
  ? isAnimated
@@ -1782,6 +1929,16 @@ export const LineChart = (props: propTypes) => {
1782
1929
  endFillColor2,
1783
1930
  startOpacity2,
1784
1931
  endOpacity2,
1932
+ hideDataPoints2,
1933
+ dataPointsShape2,
1934
+ dataPointsWidth2,
1935
+ dataPointsHeight2,
1936
+ dataPointsColor2,
1937
+ dataPointsRadius2,
1938
+ textColor2,
1939
+ textFontSize2,
1940
+ startIndex2,
1941
+ endIndex2,
1785
1942
  )
1786
1943
  : renderLine(
1787
1944
  points2,
@@ -1792,6 +1949,16 @@ export const LineChart = (props: propTypes) => {
1792
1949
  endFillColor2,
1793
1950
  startOpacity2,
1794
1951
  endOpacity2,
1952
+ hideDataPoints2,
1953
+ dataPointsShape2,
1954
+ dataPointsWidth2,
1955
+ dataPointsHeight2,
1956
+ dataPointsColor2,
1957
+ dataPointsRadius2,
1958
+ textColor2,
1959
+ textFontSize2,
1960
+ startIndex2,
1961
+ endIndex2,
1795
1962
  )
1796
1963
  : null}
1797
1964
  {points3
@@ -1806,6 +1973,16 @@ export const LineChart = (props: propTypes) => {
1806
1973
  endFillColor3,
1807
1974
  startOpacity3,
1808
1975
  endOpacity3,
1976
+ hideDataPoints3,
1977
+ dataPointsShape3,
1978
+ dataPointsWidth3,
1979
+ dataPointsHeight3,
1980
+ dataPointsColor3,
1981
+ dataPointsRadius3,
1982
+ textColor3,
1983
+ textFontSize3,
1984
+ startIndex3,
1985
+ endIndex3,
1809
1986
  )
1810
1987
  : renderLine(
1811
1988
  points3,
@@ -1816,6 +1993,16 @@ export const LineChart = (props: propTypes) => {
1816
1993
  endFillColor3,
1817
1994
  startOpacity3,
1818
1995
  endOpacity3,
1996
+ hideDataPoints3,
1997
+ dataPointsShape3,
1998
+ dataPointsWidth3,
1999
+ dataPointsHeight3,
2000
+ dataPointsColor3,
2001
+ dataPointsRadius3,
2002
+ textColor3,
2003
+ textFontSize3,
2004
+ startIndex3,
2005
+ endIndex3,
1819
2006
  )
1820
2007
  : null}
1821
2008
  {data.map((item: itemType, index: number) => {
package/src/todos.md ADDED
@@ -0,0 +1,8 @@
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
8
+ 6. Prepare a doc for Line chart with breaks