react-native-gifted-charts 1.2.21 → 1.2.24
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 +1 -1
- package/src/BarChart/RenderBars.tsx +219 -187
- package/src/BarChart/RenderStackBars.tsx +82 -38
- package/src/BarChart/index.tsx +29 -6
- package/src/LineChart/index.tsx +10 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gifted-charts",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.24",
|
|
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;
|
|
@@ -65,6 +66,10 @@ type Props = {
|
|
|
65
66
|
barMarginBottom?: number;
|
|
66
67
|
onPress?: Function;
|
|
67
68
|
xAxisTextNumberOfLines: number;
|
|
69
|
+
renderTooltip: Function;
|
|
70
|
+
initialSpacing: number;
|
|
71
|
+
selectedIndex: number;
|
|
72
|
+
setSelectedIndex: Function;
|
|
68
73
|
};
|
|
69
74
|
type itemType = {
|
|
70
75
|
value?: number;
|
|
@@ -100,6 +105,7 @@ const RenderBars = (props: Props) => {
|
|
|
100
105
|
containerHeight,
|
|
101
106
|
maxValue,
|
|
102
107
|
spacing,
|
|
108
|
+
propSpacing,
|
|
103
109
|
side,
|
|
104
110
|
data,
|
|
105
111
|
// oldValue,
|
|
@@ -114,6 +120,10 @@ const RenderBars = (props: Props) => {
|
|
|
114
120
|
label,
|
|
115
121
|
labelTextStyle,
|
|
116
122
|
xAxisTextNumberOfLines,
|
|
123
|
+
renderTooltip,
|
|
124
|
+
initialSpacing,
|
|
125
|
+
selectedIndex,
|
|
126
|
+
setSelectedIndex,
|
|
117
127
|
} = props;
|
|
118
128
|
|
|
119
129
|
const barMarginBottom =
|
|
@@ -318,139 +328,207 @@ const RenderBars = (props: Props) => {
|
|
|
318
328
|
);
|
|
319
329
|
};
|
|
320
330
|
|
|
331
|
+
const barHeight =
|
|
332
|
+
(item.value >= 0 && (!isThreeD || isAnimated) && item.topLabelComponent
|
|
333
|
+
? (item.topLabelComponentHeight || 30) +
|
|
334
|
+
(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)
|
|
335
|
+
: (Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)) -
|
|
336
|
+
barMarginBottom;
|
|
337
|
+
|
|
338
|
+
let leftSpacing = initialSpacing;
|
|
339
|
+
for (let i = 0; i < index; i++) {
|
|
340
|
+
leftSpacing +=
|
|
341
|
+
(data[i].spacing === 0 ? 0 : data[i].spacing || propSpacing) +
|
|
342
|
+
(data[i].barWidth || props.barWidth || 30);
|
|
343
|
+
}
|
|
344
|
+
|
|
321
345
|
return (
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
item.
|
|
341
|
-
|
|
346
|
+
<>
|
|
347
|
+
<TouchableOpacity
|
|
348
|
+
disabled={item.disablePress || props.disablePress}
|
|
349
|
+
activeOpacity={props.activeOpacity || 0.2}
|
|
350
|
+
onPress={() => {
|
|
351
|
+
if (renderTooltip) {
|
|
352
|
+
setSelectedIndex(index);
|
|
353
|
+
}
|
|
354
|
+
item.onPress
|
|
355
|
+
? item.onPress()
|
|
356
|
+
: props.onPress
|
|
357
|
+
? props.onPress(item, index)
|
|
358
|
+
: null;
|
|
359
|
+
}}
|
|
360
|
+
style={[
|
|
361
|
+
{
|
|
362
|
+
// overflow: 'visible',
|
|
363
|
+
marginBottom: 60 + barMarginBottom,
|
|
364
|
+
width: item.barWidth || props.barWidth || 30,
|
|
365
|
+
height: barHeight,
|
|
366
|
+
marginRight: spacing,
|
|
367
|
+
},
|
|
368
|
+
item.value < 0 && {
|
|
369
|
+
transform: [
|
|
370
|
+
{
|
|
371
|
+
translateY:
|
|
372
|
+
(Math.abs(item.value) * (containerHeight || 200)) /
|
|
373
|
+
(maxValue || 200),
|
|
374
|
+
},
|
|
375
|
+
{rotateZ: '180deg'},
|
|
376
|
+
],
|
|
377
|
+
},
|
|
378
|
+
// !isThreeD && !item.showGradient && !props.showGradient &&
|
|
379
|
+
// { backgroundColor: item.frontColor || props.frontColor || 'black' },
|
|
380
|
+
side !== 'right' && {zIndex: data.length - index},
|
|
381
|
+
]}>
|
|
382
|
+
{props.showVerticalLines && (
|
|
383
|
+
<View
|
|
384
|
+
style={{
|
|
385
|
+
zIndex: props.verticalLinesZIndex,
|
|
386
|
+
position: 'absolute',
|
|
387
|
+
height: (containerHeight || 200) + 15,
|
|
388
|
+
width: props.verticalLinesThickness,
|
|
389
|
+
bottom: 0,
|
|
390
|
+
left: (item.barWidth || props.barWidth || 30) / 2,
|
|
391
|
+
backgroundColor: props.verticalLinesColor,
|
|
392
|
+
}}
|
|
393
|
+
/>
|
|
394
|
+
)}
|
|
395
|
+
{props.showXAxisIndices && (
|
|
396
|
+
<View
|
|
397
|
+
style={{
|
|
398
|
+
zIndex: 2,
|
|
399
|
+
position: 'absolute',
|
|
400
|
+
height: props.xAxisIndicesHeight,
|
|
401
|
+
width: props.xAxisIndicesWidth,
|
|
402
|
+
bottom: 0,
|
|
403
|
+
left: (item.barWidth || props.barWidth || 30) / 2,
|
|
404
|
+
backgroundColor: props.xAxisIndicesColor,
|
|
405
|
+
}}
|
|
406
|
+
/>
|
|
407
|
+
)}
|
|
408
|
+
{isThreeD ? (
|
|
409
|
+
isAnimated ? (
|
|
410
|
+
<AnimatedBar
|
|
411
|
+
barBackgroundPattern={
|
|
412
|
+
item.barBackgroundPattern || props.barBackgroundPattern
|
|
413
|
+
}
|
|
414
|
+
patternId={item.patternId || props.patternId}
|
|
415
|
+
topLabelContainerStyle={item.topLabelContainerStyle}
|
|
416
|
+
width={item.barWidth || props.barWidth || 30}
|
|
417
|
+
sideWidth={
|
|
418
|
+
item.sideWidth ||
|
|
419
|
+
props.sideWidth ||
|
|
420
|
+
(item.barWidth || props.barWidth || 30) / 2
|
|
421
|
+
}
|
|
422
|
+
side={side || 'left'}
|
|
423
|
+
frontColor={item.frontColor || props.frontColor || ''}
|
|
424
|
+
sideColor={item.sideColor || props.sideColor || ''}
|
|
425
|
+
topColor={item.topColor || props.topColor || ''}
|
|
426
|
+
showGradient={item.showGradient || props.showGradient || false}
|
|
427
|
+
gradientColor={item.gradientColor || props.gradientColor}
|
|
428
|
+
topLabelComponent={item.topLabelComponent}
|
|
429
|
+
opacity={opacity || 1}
|
|
430
|
+
animationDuration={animationDuration || 800}
|
|
431
|
+
height={
|
|
342
432
|
(Math.abs(item.value) * (containerHeight || 200)) /
|
|
343
|
-
(maxValue || 200)
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
433
|
+
(maxValue || 200) -
|
|
434
|
+
barMarginBottom
|
|
435
|
+
}
|
|
436
|
+
intactTopLabel={props.intactTopLabel}
|
|
437
|
+
horizontal={props.horizontal}
|
|
438
|
+
/>
|
|
439
|
+
) : (
|
|
440
|
+
<ThreeDBar
|
|
441
|
+
barBackgroundPattern={
|
|
442
|
+
item.barBackgroundPattern || props.barBackgroundPattern
|
|
443
|
+
}
|
|
444
|
+
patternId={item.patternId || props.patternId}
|
|
445
|
+
style={{}}
|
|
446
|
+
color={''}
|
|
447
|
+
topLabelContainerStyle={item.topLabelContainerStyle}
|
|
448
|
+
width={item.barWidth || props.barWidth || 30}
|
|
449
|
+
sideWidth={
|
|
450
|
+
item.sideWidth ||
|
|
451
|
+
props.sideWidth ||
|
|
452
|
+
(item.barWidth || props.barWidth || 30) / 2
|
|
453
|
+
}
|
|
454
|
+
side={side || 'left'}
|
|
455
|
+
frontColor={item.frontColor || props.frontColor || ''}
|
|
456
|
+
sideColor={item.sideColor || props.sideColor || ''}
|
|
457
|
+
topColor={item.topColor || props.topColor || ''}
|
|
458
|
+
showGradient={item.showGradient || props.showGradient || false}
|
|
459
|
+
gradientColor={item.gradientColor || props.gradientColor}
|
|
460
|
+
topLabelComponent={item.topLabelComponent || Function}
|
|
461
|
+
opacity={opacity || 1}
|
|
462
|
+
horizontal={props.horizontal}
|
|
463
|
+
intactTopLabel={props.intactTopLabel}
|
|
464
|
+
height={
|
|
352
465
|
(Math.abs(item.value) * (containerHeight || 200)) /
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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}
|
|
466
|
+
(maxValue || 200) -
|
|
467
|
+
barMarginBottom
|
|
468
|
+
}
|
|
469
|
+
value={item.value}
|
|
470
|
+
/>
|
|
471
|
+
)
|
|
472
|
+
) : item.showGradient || props.showGradient ? (
|
|
473
|
+
isAnimated ? (
|
|
474
|
+
<Animated2DWithGradient
|
|
475
|
+
barBackgroundPattern={props.barBackgroundPattern}
|
|
476
|
+
patternId={props.patternId}
|
|
477
|
+
barWidth={props.barWidth}
|
|
478
|
+
item={item}
|
|
479
|
+
opacity={opacity}
|
|
480
|
+
animationDuration={animationDuration || 800}
|
|
481
|
+
roundedBottom={props.roundedBottom || false}
|
|
482
|
+
roundedTop={props.roundedTop || false}
|
|
483
|
+
gradientColor={props.gradientColor}
|
|
484
|
+
frontColor={props.frontColor || 'black'}
|
|
485
|
+
containerHeight={containerHeight}
|
|
486
|
+
maxValue={maxValue}
|
|
487
|
+
height={
|
|
488
|
+
(Math.abs(item.value) * (containerHeight || 200)) /
|
|
489
|
+
(maxValue || 200)
|
|
490
|
+
}
|
|
491
|
+
barMarginBottom={barMarginBottom}
|
|
492
|
+
cappedBars={props.cappedBars}
|
|
493
|
+
capThickness={props.capThickness}
|
|
494
|
+
capColor={props.capColor}
|
|
495
|
+
capRadius={props.capRadius}
|
|
496
|
+
horizontal={props.horizontal}
|
|
497
|
+
intactTopLabel={props.intactTopLabel}
|
|
498
|
+
barBorderRadius={props.barBorderRadius || 0}
|
|
499
|
+
/>
|
|
500
|
+
) : (
|
|
501
|
+
static2DWithGradient(item)
|
|
502
|
+
)
|
|
503
|
+
) : isAnimated ? (
|
|
504
|
+
<Animated2DWithGradient
|
|
505
|
+
barBackgroundPattern={props.barBackgroundPattern}
|
|
506
|
+
patternId={props.patternId}
|
|
507
|
+
barWidth={props.barWidth}
|
|
508
|
+
item={item}
|
|
509
|
+
opacity={opacity}
|
|
410
510
|
animationDuration={animationDuration || 800}
|
|
511
|
+
roundedBottom={props.roundedBottom || false}
|
|
512
|
+
roundedTop={props.roundedTop || false}
|
|
513
|
+
gradientColor={props.gradientColor}
|
|
514
|
+
noGradient
|
|
515
|
+
frontColor={props.frontColor || 'black'}
|
|
516
|
+
containerHeight={containerHeight}
|
|
517
|
+
maxValue={maxValue}
|
|
411
518
|
height={
|
|
412
519
|
(Math.abs(item.value) * (containerHeight || 200)) /
|
|
413
|
-
|
|
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
|
|
520
|
+
(maxValue || 200)
|
|
433
521
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
gradientColor={item.gradientColor || props.gradientColor}
|
|
440
|
-
topLabelComponent={item.topLabelComponent || Function}
|
|
441
|
-
opacity={opacity || 1}
|
|
522
|
+
barMarginBottom={barMarginBottom}
|
|
523
|
+
cappedBars={props.cappedBars}
|
|
524
|
+
capThickness={props.capThickness}
|
|
525
|
+
capColor={props.capColor}
|
|
526
|
+
capRadius={props.capRadius}
|
|
442
527
|
horizontal={props.horizontal}
|
|
443
528
|
intactTopLabel={props.intactTopLabel}
|
|
444
|
-
|
|
445
|
-
(Math.abs(item.value) * (containerHeight || 200)) /
|
|
446
|
-
(maxValue || 200) -
|
|
447
|
-
barMarginBottom
|
|
448
|
-
}
|
|
449
|
-
value={item.value}
|
|
529
|
+
barBorderRadius={props.barBorderRadius || 0}
|
|
450
530
|
/>
|
|
451
|
-
)
|
|
452
|
-
) : item.showGradient || props.showGradient ? (
|
|
453
|
-
isAnimated ? (
|
|
531
|
+
) : (
|
|
454
532
|
<Animated2DWithGradient
|
|
455
533
|
barBackgroundPattern={props.barBackgroundPattern}
|
|
456
534
|
patternId={props.patternId}
|
|
@@ -461,6 +539,8 @@ const RenderBars = (props: Props) => {
|
|
|
461
539
|
roundedBottom={props.roundedBottom || false}
|
|
462
540
|
roundedTop={props.roundedTop || false}
|
|
463
541
|
gradientColor={props.gradientColor}
|
|
542
|
+
noGradient
|
|
543
|
+
noAnimation
|
|
464
544
|
frontColor={props.frontColor || 'black'}
|
|
465
545
|
containerHeight={containerHeight}
|
|
466
546
|
maxValue={maxValue}
|
|
@@ -477,71 +557,23 @@ const RenderBars = (props: Props) => {
|
|
|
477
557
|
intactTopLabel={props.intactTopLabel}
|
|
478
558
|
barBorderRadius={props.barBorderRadius || 0}
|
|
479
559
|
/>
|
|
480
|
-
)
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
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
|
-
/>
|
|
560
|
+
)}
|
|
561
|
+
{isAnimated
|
|
562
|
+
? renderAnimatedLabel(label, labelTextStyle, item.value)
|
|
563
|
+
: renderLabel(label, labelTextStyle, item.value)}
|
|
564
|
+
</TouchableOpacity>
|
|
565
|
+
{renderTooltip && selectedIndex === index && (
|
|
566
|
+
<View
|
|
567
|
+
style={{
|
|
568
|
+
position: 'absolute',
|
|
569
|
+
bottom: barHeight + 60,
|
|
570
|
+
left: leftSpacing,
|
|
571
|
+
zIndex: 1000,
|
|
572
|
+
}}>
|
|
573
|
+
{renderTooltip(item, index)}
|
|
574
|
+
</View>
|
|
540
575
|
)}
|
|
541
|
-
|
|
542
|
-
? renderAnimatedLabel(label, labelTextStyle, item.value)
|
|
543
|
-
: renderLabel(label, labelTextStyle, item.value)}
|
|
544
|
-
</TouchableOpacity>
|
|
576
|
+
</>
|
|
545
577
|
);
|
|
546
578
|
};
|
|
547
579
|
|
|
@@ -20,6 +20,7 @@ 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
|
|
|
@@ -39,12 +40,19 @@ type Props = {
|
|
|
39
40
|
barBackgroundPattern?: Function;
|
|
40
41
|
patternId?: String;
|
|
41
42
|
xAxisTextNumberOfLines: number;
|
|
43
|
+
renderTooltip: Function;
|
|
44
|
+
initialSpacing: number;
|
|
45
|
+
selectedIndex: number;
|
|
46
|
+
setSelectedIndex: Function;
|
|
47
|
+
activeOpacity: number;
|
|
48
|
+
stackData: Array<itemType>;
|
|
42
49
|
};
|
|
43
50
|
type itemType = {
|
|
44
51
|
value?: number;
|
|
45
52
|
onPress?: any;
|
|
46
53
|
label?: String;
|
|
47
54
|
barWidth?: number;
|
|
55
|
+
spacing?: number;
|
|
48
56
|
labelTextStyle?: any;
|
|
49
57
|
topLabelComponent?: Function;
|
|
50
58
|
topLabelContainerStyle?: any;
|
|
@@ -63,15 +71,29 @@ const RenderStackBars = (props: Props) => {
|
|
|
63
71
|
barBackgroundPattern,
|
|
64
72
|
patternId,
|
|
65
73
|
item,
|
|
74
|
+
index,
|
|
66
75
|
containerHeight,
|
|
67
76
|
maxValue,
|
|
68
77
|
spacing,
|
|
78
|
+
propSpacing,
|
|
69
79
|
rotateLabel,
|
|
70
80
|
xAxisThickness,
|
|
71
81
|
label,
|
|
72
82
|
labelTextStyle,
|
|
73
83
|
xAxisTextNumberOfLines,
|
|
84
|
+
renderTooltip,
|
|
85
|
+
initialSpacing,
|
|
86
|
+
selectedIndex,
|
|
87
|
+
setSelectedIndex,
|
|
88
|
+
activeOpacity,
|
|
89
|
+
stackData,
|
|
74
90
|
} = props;
|
|
91
|
+
let leftSpacing = initialSpacing;
|
|
92
|
+
for (let i = 0; i < index; i++) {
|
|
93
|
+
leftSpacing +=
|
|
94
|
+
(stackData[i].spacing === 0 ? 0 : stackData[i].spacing || propSpacing) +
|
|
95
|
+
(stackData[i].stacks[0].barWidth || props.barWidth || 30);
|
|
96
|
+
}
|
|
75
97
|
const disablePress = props.disablePress || false;
|
|
76
98
|
const renderLabel = (label: String, labelTextStyle: any) => {
|
|
77
99
|
return (
|
|
@@ -123,7 +145,15 @@ const RenderStackBars = (props: Props) => {
|
|
|
123
145
|
const cotainsNegative = item.stacks.some(item => item.value < 0);
|
|
124
146
|
return (
|
|
125
147
|
<>
|
|
126
|
-
<
|
|
148
|
+
<TouchableOpacity
|
|
149
|
+
disabled={disablePress}
|
|
150
|
+
activeOpacity={activeOpacity}
|
|
151
|
+
onPress={() => {
|
|
152
|
+
setSelectedIndex(index);
|
|
153
|
+
if (item.onPress) {
|
|
154
|
+
item.onPress();
|
|
155
|
+
}
|
|
156
|
+
}}
|
|
127
157
|
style={[
|
|
128
158
|
{
|
|
129
159
|
position: 'absolute',
|
|
@@ -142,7 +172,8 @@ const RenderStackBars = (props: Props) => {
|
|
|
142
172
|
<TouchableOpacity
|
|
143
173
|
key={index}
|
|
144
174
|
onPress={stackItem.onPress}
|
|
145
|
-
|
|
175
|
+
activeOpacity={activeOpacity}
|
|
176
|
+
disabled={disablePress || !stackItem.onPress}
|
|
146
177
|
style={[
|
|
147
178
|
{
|
|
148
179
|
position: 'absolute',
|
|
@@ -187,7 +218,7 @@ const RenderStackBars = (props: Props) => {
|
|
|
187
218
|
/>
|
|
188
219
|
</Svg>
|
|
189
220
|
)}
|
|
190
|
-
</
|
|
221
|
+
</TouchableOpacity>
|
|
191
222
|
{item.topLabelComponent && (
|
|
192
223
|
<View
|
|
193
224
|
style={[
|
|
@@ -214,45 +245,58 @@ const RenderStackBars = (props: Props) => {
|
|
|
214
245
|
};
|
|
215
246
|
|
|
216
247
|
return (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
{
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
248
|
+
<>
|
|
249
|
+
<View
|
|
250
|
+
style={[
|
|
251
|
+
{
|
|
252
|
+
// overflow: 'visible',
|
|
253
|
+
marginBottom: 60,
|
|
254
|
+
width: item.stacks[0].barWidth || props.barWidth || 30,
|
|
255
|
+
height: totalHeight,
|
|
256
|
+
marginRight: spacing,
|
|
257
|
+
},
|
|
258
|
+
]}>
|
|
259
|
+
{props.showVerticalLines && (
|
|
260
|
+
<View
|
|
261
|
+
style={{
|
|
262
|
+
zIndex: props.verticalLinesZIndex,
|
|
263
|
+
position: 'absolute',
|
|
264
|
+
height: (containerHeight || 200) + 15,
|
|
265
|
+
width: props.verticalLinesThickness,
|
|
266
|
+
bottom: 0,
|
|
267
|
+
left: (item.barWidth || props.barWidth || 30) / 2,
|
|
268
|
+
backgroundColor: props.verticalLinesColor,
|
|
269
|
+
}}
|
|
270
|
+
/>
|
|
271
|
+
)}
|
|
272
|
+
{props.showXAxisIndices && (
|
|
273
|
+
<View
|
|
274
|
+
style={{
|
|
275
|
+
zIndex: 2,
|
|
276
|
+
position: 'absolute',
|
|
277
|
+
height: props.xAxisIndicesHeight,
|
|
278
|
+
width: props.xAxisIndicesWidth,
|
|
279
|
+
bottom: 0,
|
|
280
|
+
left: (item.barWidth || props.barWidth || 30) / 2,
|
|
281
|
+
backgroundColor: props.xAxisIndicesColor,
|
|
282
|
+
}}
|
|
283
|
+
/>
|
|
284
|
+
)}
|
|
285
|
+
{static2DSimple(item)}
|
|
286
|
+
{renderLabel(label || '', labelTextStyle)}
|
|
287
|
+
</View>
|
|
288
|
+
{renderTooltip && selectedIndex === index && (
|
|
241
289
|
<View
|
|
242
290
|
style={{
|
|
243
|
-
zIndex: 2,
|
|
244
291
|
position: 'absolute',
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
/>
|
|
292
|
+
bottom: totalHeight + 60,
|
|
293
|
+
left: leftSpacing,
|
|
294
|
+
zIndex: 1000,
|
|
295
|
+
}}>
|
|
296
|
+
{renderTooltip(item, index)}
|
|
297
|
+
</View>
|
|
252
298
|
)}
|
|
253
|
-
|
|
254
|
-
{renderLabel(label || '', labelTextStyle)}
|
|
255
|
-
</View>
|
|
299
|
+
</>
|
|
256
300
|
);
|
|
257
301
|
};
|
|
258
302
|
|
package/src/BarChart/index.tsx
CHANGED
|
@@ -133,6 +133,7 @@ type PropTypes = {
|
|
|
133
133
|
patternId?: String;
|
|
134
134
|
barMarginBottom?: number;
|
|
135
135
|
onPress?: Function;
|
|
136
|
+
renderTooltip?: Function;
|
|
136
137
|
};
|
|
137
138
|
type lineConfigType = {
|
|
138
139
|
initialSpacing?: number;
|
|
@@ -192,6 +193,7 @@ type itemType = {
|
|
|
192
193
|
export const BarChart = (props: PropTypes) => {
|
|
193
194
|
const scrollRef = useRef();
|
|
194
195
|
const [points, setPoints] = useState('');
|
|
196
|
+
const [selectedIndex, setSelectedIndex] = useState(-1);
|
|
195
197
|
const showLine = props.showLine || false;
|
|
196
198
|
const initialSpacing =
|
|
197
199
|
props.initialSpacing === 0 ? 0 : props.initialSpacing || 40;
|
|
@@ -262,7 +264,7 @@ export const BarChart = (props: PropTypes) => {
|
|
|
262
264
|
const horizSections = [{value: '0'}];
|
|
263
265
|
const horizSectionsBelow = [];
|
|
264
266
|
const stepHeight = props.stepHeight || containerHeight / noOfSections;
|
|
265
|
-
const spacing = props.spacing === 0 ? 0 : props.spacing
|
|
267
|
+
const spacing = props.spacing === 0 ? 0 : props.spacing || 20;
|
|
266
268
|
const labelWidth = props.labelWidth || 0;
|
|
267
269
|
const scrollToEnd = props.scrollToEnd || false;
|
|
268
270
|
const scrollAnimation = props.scrollAnimation === false ? false : true;
|
|
@@ -630,9 +632,12 @@ export const BarChart = (props: PropTypes) => {
|
|
|
630
632
|
outputRange: [0, totalWidth],
|
|
631
633
|
});
|
|
632
634
|
|
|
633
|
-
const getLabel = val => {
|
|
635
|
+
const getLabel = (val, index) => {
|
|
634
636
|
let label = '';
|
|
635
|
-
if (
|
|
637
|
+
if (
|
|
638
|
+
showFractionalValues ||
|
|
639
|
+
(props.yAxisLabelTexts && props.yAxisLabelTexts[index] !== undefined)
|
|
640
|
+
) {
|
|
636
641
|
if (val) {
|
|
637
642
|
label = val;
|
|
638
643
|
} else {
|
|
@@ -731,7 +736,7 @@ export const BarChart = (props: PropTypes) => {
|
|
|
731
736
|
props.hideAxesAndRules !== true &&
|
|
732
737
|
!hideYAxisText &&
|
|
733
738
|
horizSections.map((sectionItems, index) => {
|
|
734
|
-
let label = getLabel(sectionItems.value);
|
|
739
|
+
let label = getLabel(sectionItems.value, index);
|
|
735
740
|
if (hideOrigin && index === horizSections.length - 1) {
|
|
736
741
|
label = '';
|
|
737
742
|
}
|
|
@@ -852,6 +857,7 @@ export const BarChart = (props: PropTypes) => {
|
|
|
852
857
|
horizSectionsBelow.map((sectionItems, index) => {
|
|
853
858
|
let label = getLabel(
|
|
854
859
|
horizSectionsBelow[horizSectionsBelow.length - 1 - index].value,
|
|
860
|
+
index,
|
|
855
861
|
);
|
|
856
862
|
return (
|
|
857
863
|
<View
|
|
@@ -906,7 +912,7 @@ export const BarChart = (props: PropTypes) => {
|
|
|
906
912
|
props.hideAxesAndRules !== true &&
|
|
907
913
|
!hideYAxisText &&
|
|
908
914
|
horizSections.map((sectionItems, index) => {
|
|
909
|
-
let label = getLabel(sectionItems.value);
|
|
915
|
+
let label = getLabel(sectionItems.value, index);
|
|
910
916
|
if (hideOrigin && index === horizSections.length - 1) {
|
|
911
917
|
label = '';
|
|
912
918
|
}
|
|
@@ -1325,6 +1331,11 @@ export const BarChart = (props: PropTypes) => {
|
|
|
1325
1331
|
{props.hideAxesAndRules !== true && renderHorizSections()}
|
|
1326
1332
|
<ScrollView
|
|
1327
1333
|
ref={scrollRef}
|
|
1334
|
+
onTouchStart={evt => {
|
|
1335
|
+
if (props.renderTooltip) {
|
|
1336
|
+
setSelectedIndex(-1);
|
|
1337
|
+
}
|
|
1338
|
+
}}
|
|
1328
1339
|
onContentSizeChange={() => {
|
|
1329
1340
|
if (scrollRef.current && scrollToEnd) {
|
|
1330
1341
|
scrollRef.current.scrollToEnd({animated: scrollAnimation});
|
|
@@ -1371,15 +1382,17 @@ export const BarChart = (props: PropTypes) => {
|
|
|
1371
1382
|
return (
|
|
1372
1383
|
<RenderStackBars
|
|
1373
1384
|
key={index}
|
|
1385
|
+
stackData={props.stackData}
|
|
1374
1386
|
item={item}
|
|
1375
1387
|
index={index}
|
|
1376
1388
|
containerHeight={containerHeight}
|
|
1377
1389
|
maxValue={maxValue}
|
|
1378
1390
|
spacing={item.spacing === 0 ? 0 : item.spacing || spacing}
|
|
1391
|
+
propSpacing={spacing}
|
|
1379
1392
|
xAxisThickness={xAxisThickness}
|
|
1380
1393
|
barWidth={props.barWidth}
|
|
1381
1394
|
opacity={opacity}
|
|
1382
|
-
disablePress={props.disablePress}
|
|
1395
|
+
disablePress={item.disablePress || props.disablePress}
|
|
1383
1396
|
rotateLabel={rotateLabel}
|
|
1384
1397
|
showVerticalLines={showVerticalLines}
|
|
1385
1398
|
verticalLinesThickness={verticalLinesThickness}
|
|
@@ -1404,6 +1417,11 @@ export const BarChart = (props: PropTypes) => {
|
|
|
1404
1417
|
item.labelTextStyle || props.xAxisLabelTextStyle
|
|
1405
1418
|
}
|
|
1406
1419
|
xAxisTextNumberOfLines={xAxisTextNumberOfLines}
|
|
1420
|
+
renderTooltip={props.renderTooltip}
|
|
1421
|
+
initialSpacing={initialSpacing}
|
|
1422
|
+
selectedIndex={selectedIndex}
|
|
1423
|
+
setSelectedIndex={setSelectedIndex}
|
|
1424
|
+
activeOpacity={props.activeOpacity || 0.2}
|
|
1407
1425
|
/>
|
|
1408
1426
|
);
|
|
1409
1427
|
})
|
|
@@ -1415,6 +1433,7 @@ export const BarChart = (props: PropTypes) => {
|
|
|
1415
1433
|
containerHeight={containerHeight}
|
|
1416
1434
|
maxValue={maxValue}
|
|
1417
1435
|
spacing={item.spacing === 0 ? 0 : item.spacing || spacing}
|
|
1436
|
+
propSpacing={spacing}
|
|
1418
1437
|
side={side}
|
|
1419
1438
|
data={data}
|
|
1420
1439
|
barWidth={props.barWidth}
|
|
@@ -1466,6 +1485,10 @@ export const BarChart = (props: PropTypes) => {
|
|
|
1466
1485
|
}
|
|
1467
1486
|
onPress={props.onPress}
|
|
1468
1487
|
xAxisTextNumberOfLines={xAxisTextNumberOfLines}
|
|
1488
|
+
renderTooltip={props.renderTooltip}
|
|
1489
|
+
initialSpacing={initialSpacing}
|
|
1490
|
+
selectedIndex={selectedIndex}
|
|
1491
|
+
setSelectedIndex={setSelectedIndex}
|
|
1469
1492
|
/>
|
|
1470
1493
|
))}
|
|
1471
1494
|
</Fragment>
|
package/src/LineChart/index.tsx
CHANGED
|
@@ -1452,8 +1452,8 @@ export const LineChart = (props: propTypes) => {
|
|
|
1452
1452
|
: defaultPointerConfig.pointerComponent;
|
|
1453
1453
|
|
|
1454
1454
|
const showPointerStrip =
|
|
1455
|
-
pointerConfig && pointerConfig.showPointerStrip
|
|
1456
|
-
?
|
|
1455
|
+
pointerConfig && pointerConfig.showPointerStrip === false
|
|
1456
|
+
? false
|
|
1457
1457
|
: defaultPointerConfig.showPointerStrip;
|
|
1458
1458
|
const pointerStripHeight =
|
|
1459
1459
|
pointerConfig && pointerConfig.pointerStripHeight
|
|
@@ -1779,9 +1779,12 @@ export const LineChart = (props: propTypes) => {
|
|
|
1779
1779
|
// )
|
|
1780
1780
|
// }
|
|
1781
1781
|
|
|
1782
|
-
const getLabel = val => {
|
|
1782
|
+
const getLabel = (val, index) => {
|
|
1783
1783
|
let label = '';
|
|
1784
|
-
if (
|
|
1784
|
+
if (
|
|
1785
|
+
showFractionalValues ||
|
|
1786
|
+
(props.yAxisLabelTexts && props.yAxisLabelTexts[index] !== undefined)
|
|
1787
|
+
) {
|
|
1785
1788
|
if (val) {
|
|
1786
1789
|
label = props.yAxisOffset
|
|
1787
1790
|
? (Number(val) + props.yAxisOffset).toString()
|
|
@@ -1882,7 +1885,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
1882
1885
|
props.hideAxesAndRules !== true &&
|
|
1883
1886
|
!hideYAxisText &&
|
|
1884
1887
|
horizSections.map((sectionItems, index) => {
|
|
1885
|
-
let label = getLabel(sectionItems.value);
|
|
1888
|
+
let label = getLabel(sectionItems.value, index);
|
|
1886
1889
|
if (hideOrigin && index === horizSections.length - 1) {
|
|
1887
1890
|
label = '';
|
|
1888
1891
|
}
|
|
@@ -1987,6 +1990,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
1987
1990
|
horizSectionsBelow.map((sectionItems, index) => {
|
|
1988
1991
|
let label = getLabel(
|
|
1989
1992
|
horizSectionsBelow[horizSectionsBelow.length - 1 - index].value,
|
|
1993
|
+
index,
|
|
1990
1994
|
);
|
|
1991
1995
|
return (
|
|
1992
1996
|
<View
|
|
@@ -2041,7 +2045,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
2041
2045
|
props.hideAxesAndRules !== true &&
|
|
2042
2046
|
!hideYAxisText &&
|
|
2043
2047
|
horizSections.map((sectionItems, index) => {
|
|
2044
|
-
let label = getLabel(sectionItems.value);
|
|
2048
|
+
let label = getLabel(sectionItems.value, index);
|
|
2045
2049
|
if (hideOrigin && index === horizSections.length - 1) {
|
|
2046
2050
|
label = '';
|
|
2047
2051
|
}
|