react-native-gifted-charts 1.2.22 → 1.2.25

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.22",
3
+ "version": "1.2.25",
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": [
@@ -29,6 +29,7 @@ type Props = {
29
29
  containerHeight?: number;
30
30
  maxValue: number;
31
31
  spacing?: number;
32
+ propSpacing?: number;
32
33
  data?: any;
33
34
  barWidth?: number;
34
35
  sideWidth?: number;
@@ -48,10 +49,6 @@ type Props = {
48
49
  capThickness?: number;
49
50
  capColor?: ColorValue;
50
51
  capRadius?: number;
51
- showVerticalLines: Boolean;
52
- verticalLinesThickness: number;
53
- verticalLinesColor: ColorValue;
54
- verticalLinesZIndex: number;
55
52
  showXAxisIndices: Boolean;
56
53
  xAxisIndicesHeight: number;
57
54
  xAxisIndicesWidth: number;
@@ -65,6 +62,10 @@ type Props = {
65
62
  barMarginBottom?: number;
66
63
  onPress?: Function;
67
64
  xAxisTextNumberOfLines: number;
65
+ renderTooltip: Function;
66
+ initialSpacing: number;
67
+ selectedIndex: number;
68
+ setSelectedIndex: Function;
68
69
  };
69
70
  type itemType = {
70
71
  value?: number;
@@ -100,6 +101,7 @@ const RenderBars = (props: Props) => {
100
101
  containerHeight,
101
102
  maxValue,
102
103
  spacing,
104
+ propSpacing,
103
105
  side,
104
106
  data,
105
107
  // oldValue,
@@ -114,6 +116,10 @@ const RenderBars = (props: Props) => {
114
116
  label,
115
117
  labelTextStyle,
116
118
  xAxisTextNumberOfLines,
119
+ renderTooltip,
120
+ initialSpacing,
121
+ selectedIndex,
122
+ setSelectedIndex,
117
123
  } = props;
118
124
 
119
125
  const barMarginBottom =
@@ -318,139 +324,207 @@ const RenderBars = (props: Props) => {
318
324
  );
319
325
  };
320
326
 
327
+ const barHeight =
328
+ (item.value >= 0 && (!isThreeD || isAnimated) && item.topLabelComponent
329
+ ? (item.topLabelComponentHeight || 30) +
330
+ (Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)
331
+ : (Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)) -
332
+ barMarginBottom;
333
+
334
+ let leftSpacing = initialSpacing;
335
+ for (let i = 0; i < index; i++) {
336
+ leftSpacing +=
337
+ (data[i].spacing === 0 ? 0 : data[i].spacing || propSpacing) +
338
+ (data[i].barWidth || props.barWidth || 30);
339
+ }
340
+
321
341
  return (
322
- <TouchableOpacity
323
- disabled={item.disablePress || props.disablePress}
324
- activeOpacity={props.activeOpacity || 0.2}
325
- onPress={() => {
326
- item.onPress
327
- ? item.onPress()
328
- : props.onPress
329
- ? props.onPress(item, index)
330
- : null;
331
- }}
332
- style={[
333
- {
334
- // overflow: 'visible',
335
- marginBottom: 60 + barMarginBottom,
336
- width: item.barWidth || props.barWidth || 30,
337
- height:
338
- (item.value >= 0 &&
339
- (!isThreeD || isAnimated) &&
340
- item.topLabelComponent
341
- ? (item.topLabelComponentHeight || 30) +
342
+ <>
343
+ <TouchableOpacity
344
+ disabled={item.disablePress || props.disablePress}
345
+ activeOpacity={props.activeOpacity || 0.2}
346
+ onPress={() => {
347
+ if (renderTooltip) {
348
+ setSelectedIndex(index);
349
+ }
350
+ item.onPress
351
+ ? item.onPress()
352
+ : props.onPress
353
+ ? props.onPress(item, index)
354
+ : null;
355
+ }}
356
+ style={[
357
+ {
358
+ // overflow: 'visible',
359
+ marginBottom: 60 + barMarginBottom,
360
+ width: item.barWidth || props.barWidth || 30,
361
+ height: barHeight,
362
+ marginRight: spacing,
363
+ },
364
+ item.value < 0 && {
365
+ transform: [
366
+ {
367
+ translateY:
368
+ (Math.abs(item.value) * (containerHeight || 200)) /
369
+ (maxValue || 200),
370
+ },
371
+ {rotateZ: '180deg'},
372
+ ],
373
+ },
374
+ // !isThreeD && !item.showGradient && !props.showGradient &&
375
+ // { backgroundColor: item.frontColor || props.frontColor || 'black' },
376
+ side !== 'right' && {zIndex: data.length - index},
377
+ ]}>
378
+ {/* {props.showVerticalLines && (
379
+ <View
380
+ style={{
381
+ zIndex: props.verticalLinesZIndex,
382
+ position: 'absolute',
383
+ height: (containerHeight || 200) + 15,
384
+ width: props.verticalLinesThickness,
385
+ bottom: 0,
386
+ left: (item.barWidth || props.barWidth || 30) / 2,
387
+ backgroundColor: props.verticalLinesColor,
388
+ }}
389
+ />
390
+ )} */}
391
+ {props.showXAxisIndices && (
392
+ <View
393
+ style={{
394
+ zIndex: 2,
395
+ position: 'absolute',
396
+ height: props.xAxisIndicesHeight,
397
+ width: props.xAxisIndicesWidth,
398
+ bottom: 0,
399
+ left: (item.barWidth || props.barWidth || 30) / 2,
400
+ backgroundColor: props.xAxisIndicesColor,
401
+ }}
402
+ />
403
+ )}
404
+ {isThreeD ? (
405
+ isAnimated ? (
406
+ <AnimatedBar
407
+ barBackgroundPattern={
408
+ item.barBackgroundPattern || props.barBackgroundPattern
409
+ }
410
+ patternId={item.patternId || props.patternId}
411
+ topLabelContainerStyle={item.topLabelContainerStyle}
412
+ width={item.barWidth || props.barWidth || 30}
413
+ sideWidth={
414
+ item.sideWidth ||
415
+ props.sideWidth ||
416
+ (item.barWidth || props.barWidth || 30) / 2
417
+ }
418
+ side={side || 'left'}
419
+ frontColor={item.frontColor || props.frontColor || ''}
420
+ sideColor={item.sideColor || props.sideColor || ''}
421
+ topColor={item.topColor || props.topColor || ''}
422
+ showGradient={item.showGradient || props.showGradient || false}
423
+ gradientColor={item.gradientColor || props.gradientColor}
424
+ topLabelComponent={item.topLabelComponent}
425
+ opacity={opacity || 1}
426
+ animationDuration={animationDuration || 800}
427
+ height={
342
428
  (Math.abs(item.value) * (containerHeight || 200)) /
343
- (maxValue || 200)
344
- : (Math.abs(item.value) * (containerHeight || 200)) /
345
- (maxValue || 200)) - barMarginBottom,
346
- marginRight: spacing,
347
- },
348
- item.value < 0 && {
349
- transform: [
350
- {
351
- translateY:
429
+ (maxValue || 200) -
430
+ barMarginBottom
431
+ }
432
+ intactTopLabel={props.intactTopLabel}
433
+ horizontal={props.horizontal}
434
+ />
435
+ ) : (
436
+ <ThreeDBar
437
+ barBackgroundPattern={
438
+ item.barBackgroundPattern || props.barBackgroundPattern
439
+ }
440
+ patternId={item.patternId || props.patternId}
441
+ style={{}}
442
+ color={''}
443
+ topLabelContainerStyle={item.topLabelContainerStyle}
444
+ width={item.barWidth || props.barWidth || 30}
445
+ sideWidth={
446
+ item.sideWidth ||
447
+ props.sideWidth ||
448
+ (item.barWidth || props.barWidth || 30) / 2
449
+ }
450
+ side={side || 'left'}
451
+ frontColor={item.frontColor || props.frontColor || ''}
452
+ sideColor={item.sideColor || props.sideColor || ''}
453
+ topColor={item.topColor || props.topColor || ''}
454
+ showGradient={item.showGradient || props.showGradient || false}
455
+ gradientColor={item.gradientColor || props.gradientColor}
456
+ topLabelComponent={item.topLabelComponent || Function}
457
+ opacity={opacity || 1}
458
+ horizontal={props.horizontal}
459
+ intactTopLabel={props.intactTopLabel}
460
+ height={
352
461
  (Math.abs(item.value) * (containerHeight || 200)) /
353
- (maxValue || 200),
354
- },
355
- {rotateZ: '180deg'},
356
- ],
357
- },
358
- // !isThreeD && !item.showGradient && !props.showGradient &&
359
- // { backgroundColor: item.frontColor || props.frontColor || 'black' },
360
- side !== 'right' && {zIndex: data.length - index},
361
- ]}>
362
- {props.showVerticalLines && (
363
- <View
364
- style={{
365
- zIndex: props.verticalLinesZIndex,
366
- position: 'absolute',
367
- height: (containerHeight || 200) + 15,
368
- width: props.verticalLinesThickness,
369
- bottom: 0,
370
- left: (item.barWidth || props.barWidth || 30) / 2,
371
- backgroundColor: props.verticalLinesColor,
372
- }}
373
- />
374
- )}
375
- {props.showXAxisIndices && (
376
- <View
377
- style={{
378
- zIndex: 2,
379
- position: 'absolute',
380
- height: props.xAxisIndicesHeight,
381
- width: props.xAxisIndicesWidth,
382
- bottom: 0,
383
- left: (item.barWidth || props.barWidth || 30) / 2,
384
- backgroundColor: props.xAxisIndicesColor,
385
- }}
386
- />
387
- )}
388
- {isThreeD ? (
389
- isAnimated ? (
390
- <AnimatedBar
391
- barBackgroundPattern={
392
- item.barBackgroundPattern || props.barBackgroundPattern
393
- }
394
- patternId={item.patternId || props.patternId}
395
- topLabelContainerStyle={item.topLabelContainerStyle}
396
- width={item.barWidth || props.barWidth || 30}
397
- sideWidth={
398
- item.sideWidth ||
399
- props.sideWidth ||
400
- (item.barWidth || props.barWidth || 30) / 2
401
- }
402
- side={side || 'left'}
403
- frontColor={item.frontColor || props.frontColor || ''}
404
- sideColor={item.sideColor || props.sideColor || ''}
405
- topColor={item.topColor || props.topColor || ''}
406
- showGradient={item.showGradient || props.showGradient || false}
407
- gradientColor={item.gradientColor || props.gradientColor}
408
- topLabelComponent={item.topLabelComponent}
409
- opacity={opacity || 1}
462
+ (maxValue || 200) -
463
+ barMarginBottom
464
+ }
465
+ value={item.value}
466
+ />
467
+ )
468
+ ) : item.showGradient || props.showGradient ? (
469
+ isAnimated ? (
470
+ <Animated2DWithGradient
471
+ barBackgroundPattern={props.barBackgroundPattern}
472
+ patternId={props.patternId}
473
+ barWidth={props.barWidth}
474
+ item={item}
475
+ opacity={opacity}
476
+ animationDuration={animationDuration || 800}
477
+ roundedBottom={props.roundedBottom || false}
478
+ roundedTop={props.roundedTop || false}
479
+ gradientColor={props.gradientColor}
480
+ frontColor={props.frontColor || 'black'}
481
+ containerHeight={containerHeight}
482
+ maxValue={maxValue}
483
+ height={
484
+ (Math.abs(item.value) * (containerHeight || 200)) /
485
+ (maxValue || 200)
486
+ }
487
+ barMarginBottom={barMarginBottom}
488
+ cappedBars={props.cappedBars}
489
+ capThickness={props.capThickness}
490
+ capColor={props.capColor}
491
+ capRadius={props.capRadius}
492
+ horizontal={props.horizontal}
493
+ intactTopLabel={props.intactTopLabel}
494
+ barBorderRadius={props.barBorderRadius || 0}
495
+ />
496
+ ) : (
497
+ static2DWithGradient(item)
498
+ )
499
+ ) : isAnimated ? (
500
+ <Animated2DWithGradient
501
+ barBackgroundPattern={props.barBackgroundPattern}
502
+ patternId={props.patternId}
503
+ barWidth={props.barWidth}
504
+ item={item}
505
+ opacity={opacity}
410
506
  animationDuration={animationDuration || 800}
507
+ roundedBottom={props.roundedBottom || false}
508
+ roundedTop={props.roundedTop || false}
509
+ gradientColor={props.gradientColor}
510
+ noGradient
511
+ frontColor={props.frontColor || 'black'}
512
+ containerHeight={containerHeight}
513
+ maxValue={maxValue}
411
514
  height={
412
515
  (Math.abs(item.value) * (containerHeight || 200)) /
413
- (maxValue || 200) -
414
- barMarginBottom
415
- }
416
- intactTopLabel={props.intactTopLabel}
417
- horizontal={props.horizontal}
418
- />
419
- ) : (
420
- <ThreeDBar
421
- barBackgroundPattern={
422
- item.barBackgroundPattern || props.barBackgroundPattern
423
- }
424
- patternId={item.patternId || props.patternId}
425
- style={{}}
426
- color={''}
427
- topLabelContainerStyle={item.topLabelContainerStyle}
428
- width={item.barWidth || props.barWidth || 30}
429
- sideWidth={
430
- item.sideWidth ||
431
- props.sideWidth ||
432
- (item.barWidth || props.barWidth || 30) / 2
516
+ (maxValue || 200)
433
517
  }
434
- side={side || 'left'}
435
- frontColor={item.frontColor || props.frontColor || ''}
436
- sideColor={item.sideColor || props.sideColor || ''}
437
- topColor={item.topColor || props.topColor || ''}
438
- showGradient={item.showGradient || props.showGradient || false}
439
- gradientColor={item.gradientColor || props.gradientColor}
440
- topLabelComponent={item.topLabelComponent || Function}
441
- opacity={opacity || 1}
518
+ barMarginBottom={barMarginBottom}
519
+ cappedBars={props.cappedBars}
520
+ capThickness={props.capThickness}
521
+ capColor={props.capColor}
522
+ capRadius={props.capRadius}
442
523
  horizontal={props.horizontal}
443
524
  intactTopLabel={props.intactTopLabel}
444
- height={
445
- (Math.abs(item.value) * (containerHeight || 200)) /
446
- (maxValue || 200) -
447
- barMarginBottom
448
- }
449
- value={item.value}
525
+ barBorderRadius={props.barBorderRadius || 0}
450
526
  />
451
- )
452
- ) : item.showGradient || props.showGradient ? (
453
- isAnimated ? (
527
+ ) : (
454
528
  <Animated2DWithGradient
455
529
  barBackgroundPattern={props.barBackgroundPattern}
456
530
  patternId={props.patternId}
@@ -461,6 +535,8 @@ const RenderBars = (props: Props) => {
461
535
  roundedBottom={props.roundedBottom || false}
462
536
  roundedTop={props.roundedTop || false}
463
537
  gradientColor={props.gradientColor}
538
+ noGradient
539
+ noAnimation
464
540
  frontColor={props.frontColor || 'black'}
465
541
  containerHeight={containerHeight}
466
542
  maxValue={maxValue}
@@ -477,71 +553,23 @@ const RenderBars = (props: Props) => {
477
553
  intactTopLabel={props.intactTopLabel}
478
554
  barBorderRadius={props.barBorderRadius || 0}
479
555
  />
480
- ) : (
481
- static2DWithGradient(item)
482
- )
483
- ) : isAnimated ? (
484
- <Animated2DWithGradient
485
- barBackgroundPattern={props.barBackgroundPattern}
486
- patternId={props.patternId}
487
- barWidth={props.barWidth}
488
- item={item}
489
- opacity={opacity}
490
- animationDuration={animationDuration || 800}
491
- roundedBottom={props.roundedBottom || false}
492
- roundedTop={props.roundedTop || false}
493
- gradientColor={props.gradientColor}
494
- noGradient
495
- frontColor={props.frontColor || 'black'}
496
- containerHeight={containerHeight}
497
- maxValue={maxValue}
498
- height={
499
- (Math.abs(item.value) * (containerHeight || 200)) /
500
- (maxValue || 200)
501
- }
502
- barMarginBottom={barMarginBottom}
503
- cappedBars={props.cappedBars}
504
- capThickness={props.capThickness}
505
- capColor={props.capColor}
506
- capRadius={props.capRadius}
507
- horizontal={props.horizontal}
508
- intactTopLabel={props.intactTopLabel}
509
- barBorderRadius={props.barBorderRadius || 0}
510
- />
511
- ) : (
512
- <Animated2DWithGradient
513
- barBackgroundPattern={props.barBackgroundPattern}
514
- patternId={props.patternId}
515
- barWidth={props.barWidth}
516
- item={item}
517
- opacity={opacity}
518
- animationDuration={animationDuration || 800}
519
- roundedBottom={props.roundedBottom || false}
520
- roundedTop={props.roundedTop || false}
521
- gradientColor={props.gradientColor}
522
- noGradient
523
- noAnimation
524
- frontColor={props.frontColor || 'black'}
525
- containerHeight={containerHeight}
526
- maxValue={maxValue}
527
- height={
528
- (Math.abs(item.value) * (containerHeight || 200)) /
529
- (maxValue || 200)
530
- }
531
- barMarginBottom={barMarginBottom}
532
- cappedBars={props.cappedBars}
533
- capThickness={props.capThickness}
534
- capColor={props.capColor}
535
- capRadius={props.capRadius}
536
- horizontal={props.horizontal}
537
- intactTopLabel={props.intactTopLabel}
538
- barBorderRadius={props.barBorderRadius || 0}
539
- />
556
+ )}
557
+ {isAnimated
558
+ ? renderAnimatedLabel(label, labelTextStyle, item.value)
559
+ : renderLabel(label, labelTextStyle, item.value)}
560
+ </TouchableOpacity>
561
+ {renderTooltip && selectedIndex === index && (
562
+ <View
563
+ style={{
564
+ position: 'absolute',
565
+ bottom: barHeight + 60,
566
+ left: leftSpacing,
567
+ zIndex: 1000,
568
+ }}>
569
+ {renderTooltip(item, index)}
570
+ </View>
540
571
  )}
541
- {isAnimated
542
- ? renderAnimatedLabel(label, labelTextStyle, item.value)
543
- : renderLabel(label, labelTextStyle, item.value)}
544
- </TouchableOpacity>
572
+ </>
545
573
  );
546
574
  };
547
575
 
@@ -20,14 +20,11 @@ type Props = {
20
20
  containerHeight?: number;
21
21
  maxValue: number;
22
22
  spacing?: number;
23
+ propSpacing?: number;
23
24
  data?: any;
24
25
  barWidth?: number;
25
26
 
26
27
  rotateLabel?: Boolean;
27
- showVerticalLines: Boolean;
28
- verticalLinesThickness: number;
29
- verticalLinesColor: ColorValue;
30
- verticalLinesZIndex: number;
31
28
  showXAxisIndices: Boolean;
32
29
  xAxisIndicesHeight: number;
33
30
  xAxisIndicesWidth: number;
@@ -39,12 +36,19 @@ type Props = {
39
36
  barBackgroundPattern?: Function;
40
37
  patternId?: String;
41
38
  xAxisTextNumberOfLines: number;
39
+ renderTooltip: Function;
40
+ initialSpacing: number;
41
+ selectedIndex: number;
42
+ setSelectedIndex: Function;
43
+ activeOpacity: number;
44
+ stackData: Array<itemType>;
42
45
  };
43
46
  type itemType = {
44
47
  value?: number;
45
48
  onPress?: any;
46
49
  label?: String;
47
50
  barWidth?: number;
51
+ spacing?: number;
48
52
  labelTextStyle?: any;
49
53
  topLabelComponent?: Function;
50
54
  topLabelContainerStyle?: any;
@@ -63,15 +67,29 @@ const RenderStackBars = (props: Props) => {
63
67
  barBackgroundPattern,
64
68
  patternId,
65
69
  item,
70
+ index,
66
71
  containerHeight,
67
72
  maxValue,
68
73
  spacing,
74
+ propSpacing,
69
75
  rotateLabel,
70
76
  xAxisThickness,
71
77
  label,
72
78
  labelTextStyle,
73
79
  xAxisTextNumberOfLines,
80
+ renderTooltip,
81
+ initialSpacing,
82
+ selectedIndex,
83
+ setSelectedIndex,
84
+ activeOpacity,
85
+ stackData,
74
86
  } = props;
87
+ let leftSpacing = initialSpacing;
88
+ for (let i = 0; i < index; i++) {
89
+ leftSpacing +=
90
+ (stackData[i].spacing === 0 ? 0 : stackData[i].spacing || propSpacing) +
91
+ (stackData[i].stacks[0].barWidth || props.barWidth || 30);
92
+ }
75
93
  const disablePress = props.disablePress || false;
76
94
  const renderLabel = (label: String, labelTextStyle: any) => {
77
95
  return (
@@ -123,7 +141,15 @@ const RenderStackBars = (props: Props) => {
123
141
  const cotainsNegative = item.stacks.some(item => item.value < 0);
124
142
  return (
125
143
  <>
126
- <View
144
+ <TouchableOpacity
145
+ disabled={disablePress}
146
+ activeOpacity={activeOpacity}
147
+ onPress={() => {
148
+ setSelectedIndex(index);
149
+ if (item.onPress) {
150
+ item.onPress();
151
+ }
152
+ }}
127
153
  style={[
128
154
  {
129
155
  position: 'absolute',
@@ -142,7 +168,8 @@ const RenderStackBars = (props: Props) => {
142
168
  <TouchableOpacity
143
169
  key={index}
144
170
  onPress={stackItem.onPress}
145
- disabled={disablePress}
171
+ activeOpacity={activeOpacity}
172
+ disabled={disablePress || !stackItem.onPress}
146
173
  style={[
147
174
  {
148
175
  position: 'absolute',
@@ -187,7 +214,7 @@ const RenderStackBars = (props: Props) => {
187
214
  />
188
215
  </Svg>
189
216
  )}
190
- </View>
217
+ </TouchableOpacity>
191
218
  {item.topLabelComponent && (
192
219
  <View
193
220
  style={[
@@ -214,45 +241,58 @@ const RenderStackBars = (props: Props) => {
214
241
  };
215
242
 
216
243
  return (
217
- <View
218
- style={[
219
- {
220
- // overflow: 'visible',
221
- marginBottom: 60,
222
- width: item.stacks[0].barWidth || props.barWidth || 30,
223
- height: totalHeight,
224
- marginRight: spacing,
225
- },
226
- ]}>
227
- {props.showVerticalLines && (
228
- <View
229
- style={{
230
- zIndex: props.verticalLinesZIndex,
231
- position: 'absolute',
232
- height: (containerHeight || 200) + 15,
233
- width: props.verticalLinesThickness,
234
- bottom: 0,
235
- left: (item.barWidth || props.barWidth || 30) / 2,
236
- backgroundColor: props.verticalLinesColor,
237
- }}
238
- />
239
- )}
240
- {props.showXAxisIndices && (
244
+ <>
245
+ <View
246
+ style={[
247
+ {
248
+ // overflow: 'visible',
249
+ marginBottom: 60,
250
+ width: item.stacks[0].barWidth || props.barWidth || 30,
251
+ height: totalHeight,
252
+ marginRight: spacing,
253
+ },
254
+ ]}>
255
+ {/* {props.showVerticalLines && (
256
+ <View
257
+ style={{
258
+ zIndex: props.verticalLinesZIndex,
259
+ position: 'absolute',
260
+ height: (containerHeight || 200) + 15,
261
+ width: props.verticalLinesThickness,
262
+ bottom: 0,
263
+ left: (item.barWidth || props.barWidth || 30) / 2,
264
+ backgroundColor: props.verticalLinesColor,
265
+ }}
266
+ />
267
+ )} */}
268
+ {props.showXAxisIndices && (
269
+ <View
270
+ style={{
271
+ zIndex: 2,
272
+ position: 'absolute',
273
+ height: props.xAxisIndicesHeight,
274
+ width: props.xAxisIndicesWidth,
275
+ bottom: 0,
276
+ left: (item.barWidth || props.barWidth || 30) / 2,
277
+ backgroundColor: props.xAxisIndicesColor,
278
+ }}
279
+ />
280
+ )}
281
+ {static2DSimple(item)}
282
+ {renderLabel(label || '', labelTextStyle)}
283
+ </View>
284
+ {renderTooltip && selectedIndex === index && (
241
285
  <View
242
286
  style={{
243
- zIndex: 2,
244
287
  position: 'absolute',
245
- height: props.xAxisIndicesHeight,
246
- width: props.xAxisIndicesWidth,
247
- bottom: 0,
248
- left: (item.barWidth || props.barWidth || 30) / 2,
249
- backgroundColor: props.xAxisIndicesColor,
250
- }}
251
- />
288
+ bottom: totalHeight + 60,
289
+ left: leftSpacing,
290
+ zIndex: 1000,
291
+ }}>
292
+ {renderTooltip(item, index)}
293
+ </View>
252
294
  )}
253
- {static2DSimple(item)}
254
- {renderLabel(label || '', labelTextStyle)}
255
- </View>
295
+ </>
256
296
  );
257
297
  };
258
298
 
@@ -84,6 +84,8 @@ type PropTypes = {
84
84
  verticalLinesThickness?: number;
85
85
  verticalLinesColor?: ColorValue;
86
86
  verticalLinesZIndex?: number;
87
+ noOfVerticalLines?: number;
88
+ verticalLinesSpacing?: number;
87
89
 
88
90
  showYAxisIndices?: Boolean;
89
91
  showXAxisIndices?: Boolean;
@@ -133,6 +135,7 @@ type PropTypes = {
133
135
  patternId?: String;
134
136
  barMarginBottom?: number;
135
137
  onPress?: Function;
138
+ renderTooltip?: Function;
136
139
  };
137
140
  type lineConfigType = {
138
141
  initialSpacing?: number;
@@ -192,6 +195,7 @@ type itemType = {
192
195
  export const BarChart = (props: PropTypes) => {
193
196
  const scrollRef = useRef();
194
197
  const [points, setPoints] = useState('');
198
+ const [selectedIndex, setSelectedIndex] = useState(-1);
195
199
  const showLine = props.showLine || false;
196
200
  const initialSpacing =
197
201
  props.initialSpacing === 0 ? 0 : props.initialSpacing || 40;
@@ -262,7 +266,7 @@ export const BarChart = (props: PropTypes) => {
262
266
  const horizSections = [{value: '0'}];
263
267
  const horizSectionsBelow = [];
264
268
  const stepHeight = props.stepHeight || containerHeight / noOfSections;
265
- const spacing = props.spacing === 0 ? 0 : props.spacing ? props.spacing : 20;
269
+ const spacing = props.spacing === 0 ? 0 : props.spacing || 20;
266
270
  const labelWidth = props.labelWidth || 0;
267
271
  const scrollToEnd = props.scrollToEnd || false;
268
272
  const scrollAnimation = props.scrollAnimation === false ? false : true;
@@ -346,6 +350,13 @@ export const BarChart = (props: PropTypes) => {
346
350
  props.verticalLinesThickness === 0 ? 0 : props.verticalLinesThickness || 1;
347
351
  const verticalLinesColor = props.verticalLinesColor || 'lightgray';
348
352
  const verticalLinesZIndex = props.verticalLinesZIndex || -1;
353
+ let verticalLinesAr = [];
354
+ props.noOfVerticalLines
355
+ ? (verticalLinesAr = [...Array(props.noOfVerticalLines).keys()])
356
+ : (verticalLinesAr = [
357
+ ...Array(props.stackData ? props.stackData.length : data.length).keys(),
358
+ ]);
359
+ const verticalLinesSpacing = props.verticalLinesSpacing || 0;
349
360
 
350
361
  const showYAxisIndices = props.showYAxisIndices || false;
351
362
  const showXAxisIndices = props.showXAxisIndices || false;
@@ -1329,6 +1340,11 @@ export const BarChart = (props: PropTypes) => {
1329
1340
  {props.hideAxesAndRules !== true && renderHorizSections()}
1330
1341
  <ScrollView
1331
1342
  ref={scrollRef}
1343
+ onTouchStart={evt => {
1344
+ if (props.renderTooltip) {
1345
+ setSelectedIndex(-1);
1346
+ }
1347
+ }}
1332
1348
  onContentSizeChange={() => {
1333
1349
  if (scrollRef.current && scrollToEnd) {
1334
1350
  scrollRef.current.scrollToEnd({animated: scrollAnimation});
@@ -1365,6 +1381,76 @@ export const BarChart = (props: PropTypes) => {
1365
1381
  // data={props.stackData || data}
1366
1382
  keyExtractor={(item, index) => index.toString()}>
1367
1383
  <Fragment>
1384
+ {showVerticalLines &&
1385
+ verticalLinesAr.map((item: itemType, index: number) => {
1386
+ let totalSpacing = initialSpacing;
1387
+ if (verticalLinesSpacing) {
1388
+ totalSpacing = verticalLinesSpacing * (index + 1);
1389
+ } else {
1390
+ if (props.stackData) {
1391
+ totalSpacing +=
1392
+ (props.stackData[0].barWidth || props.barWidth || 30) / 2;
1393
+ } else {
1394
+ totalSpacing +=
1395
+ (props.data[0].barWidth || props.barWidth || 30) / 2;
1396
+ }
1397
+ for (let i = 0; i < index; i++) {
1398
+ let actualSpacing = spacing;
1399
+ if (props.stackData) {
1400
+ if (i >= props.stackData.length - 1) {
1401
+ actualSpacing += (props.barWidth || 30) / 2;
1402
+ } else {
1403
+ if (
1404
+ props.stackData[i].spacing ||
1405
+ props.stackData[i].spacing === 0
1406
+ ) {
1407
+ actualSpacing = props.stackData[i].spacing;
1408
+ }
1409
+ if (props.stackData[i + 1].barWidth) {
1410
+ actualSpacing += props.stackData[i + 1].barWidth;
1411
+ } else {
1412
+ actualSpacing += props.barWidth || 30;
1413
+ }
1414
+ }
1415
+ } else {
1416
+ if (i >= props.data.length - 1) {
1417
+ actualSpacing += (props.barWidth || 30) / 2;
1418
+ } else {
1419
+ if (
1420
+ props.data[i].spacing ||
1421
+ props.data[i].spacing === 0
1422
+ ) {
1423
+ console.log('here for index ' + index + ' and i ' + i);
1424
+ actualSpacing = props.data[i].spacing;
1425
+ }
1426
+ if (props.data[i + 1].barWidth) {
1427
+ actualSpacing += props.data[i + 1].barWidth;
1428
+ } else {
1429
+ actualSpacing += props.barWidth || 30;
1430
+ }
1431
+ }
1432
+ }
1433
+ console.log('i = ' + i + ' actualSpacing ' + actualSpacing);
1434
+ totalSpacing += actualSpacing;
1435
+ }
1436
+ }
1437
+
1438
+ return (
1439
+ <View
1440
+ key={index}
1441
+ style={{
1442
+ position: 'absolute',
1443
+ zIndex: verticalLinesZIndex || -1,
1444
+ marginBottom: xAxisThickness,
1445
+ height: containerHeight + 15 - xAxisThickness,
1446
+ width: verticalLinesThickness,
1447
+ backgroundColor: verticalLinesColor,
1448
+ bottom: 60,
1449
+ left: totalSpacing,
1450
+ }}
1451
+ />
1452
+ );
1453
+ })}
1368
1454
  {showLine
1369
1455
  ? lineConfig.isAnimated
1370
1456
  ? renderAnimatedLine()
@@ -1375,20 +1461,18 @@ export const BarChart = (props: PropTypes) => {
1375
1461
  return (
1376
1462
  <RenderStackBars
1377
1463
  key={index}
1464
+ stackData={props.stackData}
1378
1465
  item={item}
1379
1466
  index={index}
1380
1467
  containerHeight={containerHeight}
1381
1468
  maxValue={maxValue}
1382
1469
  spacing={item.spacing === 0 ? 0 : item.spacing || spacing}
1470
+ propSpacing={spacing}
1383
1471
  xAxisThickness={xAxisThickness}
1384
1472
  barWidth={props.barWidth}
1385
1473
  opacity={opacity}
1386
- disablePress={props.disablePress}
1474
+ disablePress={item.disablePress || props.disablePress}
1387
1475
  rotateLabel={rotateLabel}
1388
- showVerticalLines={showVerticalLines}
1389
- verticalLinesThickness={verticalLinesThickness}
1390
- verticalLinesColor={verticalLinesColor}
1391
- verticalLinesZIndex={verticalLinesZIndex}
1392
1476
  showXAxisIndices={showXAxisIndices}
1393
1477
  xAxisIndicesHeight={xAxisIndicesHeight}
1394
1478
  xAxisIndicesWidth={xAxisIndicesWidth}
@@ -1408,6 +1492,11 @@ export const BarChart = (props: PropTypes) => {
1408
1492
  item.labelTextStyle || props.xAxisLabelTextStyle
1409
1493
  }
1410
1494
  xAxisTextNumberOfLines={xAxisTextNumberOfLines}
1495
+ renderTooltip={props.renderTooltip}
1496
+ initialSpacing={initialSpacing}
1497
+ selectedIndex={selectedIndex}
1498
+ setSelectedIndex={setSelectedIndex}
1499
+ activeOpacity={props.activeOpacity || 0.2}
1411
1500
  />
1412
1501
  );
1413
1502
  })
@@ -1419,6 +1508,7 @@ export const BarChart = (props: PropTypes) => {
1419
1508
  containerHeight={containerHeight}
1420
1509
  maxValue={maxValue}
1421
1510
  spacing={item.spacing === 0 ? 0 : item.spacing || spacing}
1511
+ propSpacing={spacing}
1422
1512
  side={side}
1423
1513
  data={data}
1424
1514
  barWidth={props.barWidth}
@@ -1444,10 +1534,6 @@ export const BarChart = (props: PropTypes) => {
1444
1534
  capThickness={props.capThickness}
1445
1535
  capColor={props.capColor}
1446
1536
  capRadius={props.capRadius}
1447
- showVerticalLines={showVerticalLines}
1448
- verticalLinesThickness={verticalLinesThickness}
1449
- verticalLinesColor={verticalLinesColor}
1450
- verticalLinesZIndex={verticalLinesZIndex}
1451
1537
  showXAxisIndices={showXAxisIndices}
1452
1538
  xAxisIndicesHeight={xAxisIndicesHeight}
1453
1539
  xAxisIndicesWidth={xAxisIndicesWidth}
@@ -1470,6 +1556,10 @@ export const BarChart = (props: PropTypes) => {
1470
1556
  }
1471
1557
  onPress={props.onPress}
1472
1558
  xAxisTextNumberOfLines={xAxisTextNumberOfLines}
1559
+ renderTooltip={props.renderTooltip}
1560
+ initialSpacing={initialSpacing}
1561
+ selectedIndex={selectedIndex}
1562
+ setSelectedIndex={setSelectedIndex}
1473
1563
  />
1474
1564
  ))}
1475
1565
  </Fragment>
@@ -110,6 +110,8 @@ type propTypes = {
110
110
  verticalLinesThickness?: number;
111
111
  verticalLinesColor?: ColorValue;
112
112
  verticalLinesZIndex?: number;
113
+ noOfVerticalLines?: number;
114
+ verticalLinesSpacing?: number;
113
115
  hideAxesAndRules?: Boolean;
114
116
  areaChart?: Boolean;
115
117
 
@@ -1377,6 +1379,12 @@ export const LineChart = (props: propTypes) => {
1377
1379
  const hideRules = props.hideRules || false;
1378
1380
  const showVerticalLines = props.showVerticalLines || false;
1379
1381
  const verticalLinesUptoDataPoint = props.verticalLinesUptoDataPoint || false;
1382
+ let verticalLinesAr = [];
1383
+ props.noOfVerticalLines
1384
+ ? (verticalLinesAr = [...Array(props.noOfVerticalLines).keys()])
1385
+ : (verticalLinesAr = [...Array(data.length).keys()]);
1386
+
1387
+ const verticalLinesSpacing = props.verticalLinesSpacing || 0;
1380
1388
 
1381
1389
  const showYAxisIndices = props.showYAxisIndices || false;
1382
1390
  const showXAxisIndices = props.showXAxisIndices || false;
@@ -3290,7 +3298,7 @@ export const LineChart = (props: propTypes) => {
3290
3298
  props.width && {width: props.width + 10},
3291
3299
  ]}>
3292
3300
  {showVerticalLines &&
3293
- data.map((item: itemType, index: number) => {
3301
+ verticalLinesAr.map((item: itemType, index: number) => {
3294
3302
  return (
3295
3303
  <View
3296
3304
  key={index}
@@ -3299,13 +3307,17 @@ export const LineChart = (props: propTypes) => {
3299
3307
  zIndex: verticalLinesZIndex || -1,
3300
3308
  marginBottom: xAxisThickness,
3301
3309
  height: verticalLinesUptoDataPoint
3302
- ? (item.value * containerHeight) / maxValue - xAxisThickness
3310
+ ? index < data.length
3311
+ ? (data[index].value * containerHeight) / maxValue -
3312
+ xAxisThickness
3313
+ : 0
3303
3314
  : containerHeight + 15 - xAxisThickness,
3304
3315
  width: verticalLinesThickness,
3305
3316
  backgroundColor: verticalLinesColor,
3306
3317
  bottom: 60,
3307
- left:
3308
- index * spacing + (initialSpacing - dataPointsWidth1 / 2),
3318
+ left: verticalLinesSpacing
3319
+ ? verticalLinesSpacing * (index + 1)
3320
+ : index * spacing + (initialSpacing - dataPointsWidth1 / 2),
3309
3321
  }}
3310
3322
  />
3311
3323
  );