react-native-gifted-charts 1.3.32 → 1.3.33
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/Animated2DWithGradient.tsx +13 -3
- package/src/BarChart/RenderBars.tsx +39 -27
- package/src/BarChart/RenderStackBars.tsx +31 -88
- package/src/BarChart/index.tsx +6 -3
- package/src/BarChart/types.ts +74 -6
- package/src/Components/AnimatedThreeDBar/index.tsx +11 -1
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart.tsx +1 -1
- package/src/LineChart/LineChartBicolor.tsx +7 -223
- package/src/LineChart/index.tsx +5 -5
- package/src/LineChart/types.ts +211 -7
- package/src/PieChart/index.tsx +3 -73
- package/src/PieChart/main.tsx +20 -71
- package/src/PieChart/types.ts +77 -0
- package/src/PopulationPyramid/types.ts +2 -2
- package/src/index.tsx +22 -1
- package/src/utils/index.tsx +1 -32
- package/src/utils/types.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gifted-charts",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.33",
|
|
4
4
|
"description": "The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar and Population Pyramid charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
|
5
5
|
"main": "src/index.tsx",
|
|
6
6
|
"files": [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {useEffect, useState} from 'react';
|
|
1
|
+
import React, {ReactNode, useEffect, useState} from 'react';
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
4
|
ColorValue,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import LinearGradient from 'react-native-linear-gradient';
|
|
11
11
|
import Svg, {Defs, Rect} from 'react-native-svg';
|
|
12
12
|
import Cap from '../Components/BarSpecificComponents/cap';
|
|
13
|
-
import {
|
|
13
|
+
import {barDataItem} from './types';
|
|
14
14
|
|
|
15
15
|
if (Platform.OS === 'android') {
|
|
16
16
|
UIManager.setLayoutAnimationEnabledExperimental &&
|
|
@@ -18,7 +18,8 @@ if (Platform.OS === 'android') {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
type propTypes = {
|
|
21
|
-
item:
|
|
21
|
+
item: barDataItem;
|
|
22
|
+
index: number;
|
|
22
23
|
height: number;
|
|
23
24
|
minHeight: number;
|
|
24
25
|
opacity?: number;
|
|
@@ -52,6 +53,7 @@ type propTypes = {
|
|
|
52
53
|
patternId?: String;
|
|
53
54
|
barMarginBottom?: number;
|
|
54
55
|
barStyle?: object;
|
|
56
|
+
barInnerComponent?: (item?: barDataItem, index?: number) => ReactNode;
|
|
55
57
|
};
|
|
56
58
|
|
|
57
59
|
const Animated2DWithGradient = (props: propTypes) => {
|
|
@@ -61,6 +63,7 @@ const Animated2DWithGradient = (props: propTypes) => {
|
|
|
61
63
|
barWidth,
|
|
62
64
|
barStyle,
|
|
63
65
|
item,
|
|
66
|
+
index,
|
|
64
67
|
opacity,
|
|
65
68
|
animationDuration,
|
|
66
69
|
noGradient,
|
|
@@ -75,6 +78,7 @@ const Animated2DWithGradient = (props: propTypes) => {
|
|
|
75
78
|
barBorderTopRightRadius,
|
|
76
79
|
barBorderBottomLeftRadius,
|
|
77
80
|
barBorderBottomRightRadius,
|
|
81
|
+
barInnerComponent,
|
|
78
82
|
intactTopLabel,
|
|
79
83
|
showValuesAsTopLabel,
|
|
80
84
|
topLabelContainerStyle,
|
|
@@ -121,6 +125,7 @@ const Animated2DWithGradient = (props: propTypes) => {
|
|
|
121
125
|
position: 'absolute',
|
|
122
126
|
bottom: 0,
|
|
123
127
|
width: '100%',
|
|
128
|
+
overflow:'hidden',
|
|
124
129
|
height:
|
|
125
130
|
(noAnimation
|
|
126
131
|
? Math.max(
|
|
@@ -314,6 +319,11 @@ const Animated2DWithGradient = (props: propTypes) => {
|
|
|
314
319
|
/>
|
|
315
320
|
</Svg>
|
|
316
321
|
)}
|
|
322
|
+
{barInnerComponent ? (
|
|
323
|
+
<View style={{height: '100%', width: '100%'}}>
|
|
324
|
+
{barInnerComponent(item,index)}
|
|
325
|
+
</View>
|
|
326
|
+
) : null}
|
|
317
327
|
</View>
|
|
318
328
|
{(item.topLabelComponent || showValuesAsTopLabel) && (
|
|
319
329
|
<View
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React, {Component} from 'react';
|
|
1
|
+
import React, {Component, ReactNode} from 'react';
|
|
2
2
|
import {View, TouchableOpacity, Animated, Text, ColorValue} from 'react-native';
|
|
3
3
|
import AnimatedThreeDBar from '../Components/AnimatedThreeDBar';
|
|
4
4
|
import LinearGradient from 'react-native-linear-gradient';
|
|
5
5
|
import Animated2DWithGradient from './Animated2DWithGradient';
|
|
6
6
|
import Cap from '../Components/BarSpecificComponents/cap';
|
|
7
7
|
import BarBackgroundPattern from '../Components/BarSpecificComponents/barBackgroundPattern';
|
|
8
|
-
import {
|
|
8
|
+
import {barDataItem} from './types';
|
|
9
9
|
import {Pointer} from '../utils/types';
|
|
10
10
|
|
|
11
11
|
type Props = {
|
|
@@ -26,7 +26,7 @@ type Props = {
|
|
|
26
26
|
side?: String;
|
|
27
27
|
labelTextStyle?: any;
|
|
28
28
|
|
|
29
|
-
item:
|
|
29
|
+
item: barDataItem;
|
|
30
30
|
index: number;
|
|
31
31
|
label: String;
|
|
32
32
|
containerHeight?: number;
|
|
@@ -67,6 +67,7 @@ type Props = {
|
|
|
67
67
|
barBorderTopRightRadius?: number;
|
|
68
68
|
barBorderBottomLeftRadius?: number;
|
|
69
69
|
barBorderBottomRightRadius?: number;
|
|
70
|
+
barInnerComponent?: (item?: barDataItem, index?: number) => ReactNode;
|
|
70
71
|
autoShiftLabels?: boolean;
|
|
71
72
|
barBackgroundPattern?: Function;
|
|
72
73
|
patternId?: String;
|
|
@@ -133,6 +134,8 @@ const RenderBars = (props: Props) => {
|
|
|
133
134
|
pointerConfig,
|
|
134
135
|
} = props;
|
|
135
136
|
|
|
137
|
+
const localBarInnerComponent = item.barInnerComponent ?? props.barInnerComponent;
|
|
138
|
+
|
|
136
139
|
const barMarginBottom =
|
|
137
140
|
item.barMarginBottom === 0
|
|
138
141
|
? 0
|
|
@@ -169,15 +172,15 @@ const RenderBars = (props: Props) => {
|
|
|
169
172
|
],
|
|
170
173
|
}
|
|
171
174
|
: horizontal
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
175
|
+
? {transform: [{rotate: '-90deg'}]}
|
|
176
|
+
: value < 0
|
|
177
|
+
? {
|
|
178
|
+
transform: [
|
|
179
|
+
{rotate: '180deg'},
|
|
180
|
+
{translateY: autoShiftLabels ? 0 : 32},
|
|
181
|
+
],
|
|
182
|
+
}
|
|
183
|
+
: {},
|
|
181
184
|
]}>
|
|
182
185
|
{item.labelComponent ? (
|
|
183
186
|
item.labelComponent()
|
|
@@ -227,8 +230,8 @@ const RenderBars = (props: Props) => {
|
|
|
227
230
|
? {transform: [{rotate: '330deg'}]}
|
|
228
231
|
: {transform: [{rotate: '60deg'}]}
|
|
229
232
|
: horizontal
|
|
230
|
-
|
|
231
|
-
|
|
233
|
+
? {transform: [{rotate: '-90deg'}]}
|
|
234
|
+
: {},
|
|
232
235
|
]}>
|
|
233
236
|
{item.labelComponent ? (
|
|
234
237
|
item.labelComponent()
|
|
@@ -247,7 +250,7 @@ const RenderBars = (props: Props) => {
|
|
|
247
250
|
);
|
|
248
251
|
};
|
|
249
252
|
|
|
250
|
-
const static2DWithGradient = (item:
|
|
253
|
+
const static2DWithGradient = (item: barDataItem) => {
|
|
251
254
|
return (
|
|
252
255
|
<>
|
|
253
256
|
<LinearGradient
|
|
@@ -352,6 +355,11 @@ const RenderBars = (props: Props) => {
|
|
|
352
355
|
)}
|
|
353
356
|
</View>
|
|
354
357
|
)}
|
|
358
|
+
{localBarInnerComponent ? (
|
|
359
|
+
<View style={{height: '100%', width: '100%'}}>
|
|
360
|
+
{localBarInnerComponent(item, index)}
|
|
361
|
+
</View>
|
|
362
|
+
) : null}
|
|
355
363
|
</>
|
|
356
364
|
);
|
|
357
365
|
};
|
|
@@ -389,16 +397,16 @@ const RenderBars = (props: Props) => {
|
|
|
389
397
|
],
|
|
390
398
|
}
|
|
391
399
|
: pointerConfig
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
400
|
+
? {
|
|
401
|
+
transform: [
|
|
402
|
+
{
|
|
403
|
+
translateY:
|
|
404
|
+
(containerHeight || 200) -
|
|
405
|
+
(barHeight - 10 + xAxisLabelsVerticalShift),
|
|
406
|
+
},
|
|
407
|
+
],
|
|
408
|
+
}
|
|
409
|
+
: null,
|
|
402
410
|
// !isThreeD && !item.showGradient && !props.showGradient &&
|
|
403
411
|
// { backgroundColor: item.frontColor || props.frontColor || 'black' },
|
|
404
412
|
side !== 'right' && {zIndex: data.length - index},
|
|
@@ -417,6 +425,7 @@ const RenderBars = (props: Props) => {
|
|
|
417
425
|
barWidth={props.barWidth || 30}
|
|
418
426
|
barStyle={barStyle}
|
|
419
427
|
item={item}
|
|
428
|
+
index={index}
|
|
420
429
|
opacity={opacity}
|
|
421
430
|
animationDuration={animationDuration || 800}
|
|
422
431
|
roundedBottom={props.roundedBottom || false}
|
|
@@ -446,6 +455,7 @@ const RenderBars = (props: Props) => {
|
|
|
446
455
|
barBorderTopRightRadius={barBorderTopRightRadius}
|
|
447
456
|
barBorderBottomLeftRadius={barBorderBottomLeftRadius}
|
|
448
457
|
barBorderBottomRightRadius={barBorderBottomRightRadius}
|
|
458
|
+
barInnerComponent={localBarInnerComponent}
|
|
449
459
|
/>
|
|
450
460
|
);
|
|
451
461
|
return (
|
|
@@ -471,10 +481,12 @@ const RenderBars = (props: Props) => {
|
|
|
471
481
|
barBackgroundPattern={
|
|
472
482
|
item.barBackgroundPattern || props.barBackgroundPattern
|
|
473
483
|
}
|
|
484
|
+
barInnerComponent={localBarInnerComponent}
|
|
474
485
|
patternId={item.patternId || props.patternId}
|
|
475
486
|
width={item.barWidth || props.barWidth || 30}
|
|
476
487
|
barStyle={barStyle}
|
|
477
488
|
item={item}
|
|
489
|
+
index={index}
|
|
478
490
|
sideWidth={
|
|
479
491
|
item.sideWidth ||
|
|
480
492
|
props.sideWidth ||
|
|
@@ -530,8 +542,8 @@ const RenderBars = (props: Props) => {
|
|
|
530
542
|
item.onPress
|
|
531
543
|
? item.onPress()
|
|
532
544
|
: props.onPress
|
|
533
|
-
|
|
534
|
-
|
|
545
|
+
? props.onPress(item, index)
|
|
546
|
+
: null;
|
|
535
547
|
}}
|
|
536
548
|
style={barWrapperStyle}>
|
|
537
549
|
{barContent()}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {useEffect, useState} from 'react';
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
4
|
TouchableOpacity,
|
|
5
5
|
Text,
|
|
6
|
-
ColorValue,
|
|
7
6
|
LayoutAnimation,
|
|
8
7
|
Platform,
|
|
9
8
|
UIManager,
|
|
@@ -11,78 +10,14 @@ import {
|
|
|
11
10
|
import LinearGradient from 'react-native-linear-gradient';
|
|
12
11
|
import Svg, {Defs, Rect} from 'react-native-svg';
|
|
13
12
|
import {BarDefaults} from '../utils/constants';
|
|
14
|
-
import {
|
|
15
|
-
import {Pointer} from '../utils/types';
|
|
13
|
+
import {StackedBarChartPropsType, stackDataItem} from './types';
|
|
16
14
|
|
|
17
15
|
if (Platform.OS === 'android') {
|
|
18
16
|
UIManager.setLayoutAnimationEnabledExperimental &&
|
|
19
17
|
UIManager.setLayoutAnimationEnabledExperimental(true);
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
style?: any;
|
|
24
|
-
width?: number;
|
|
25
|
-
height?: number;
|
|
26
|
-
color?: ColorValue;
|
|
27
|
-
topLabelComponent?: Component;
|
|
28
|
-
topLabelContainerStyle?: any;
|
|
29
|
-
opacity?: number;
|
|
30
|
-
label: String;
|
|
31
|
-
labelTextStyle?: any;
|
|
32
|
-
disablePress?: boolean;
|
|
33
|
-
|
|
34
|
-
item: stackItemType;
|
|
35
|
-
index: number;
|
|
36
|
-
containerHeight?: number;
|
|
37
|
-
maxValue: number;
|
|
38
|
-
spacing: number;
|
|
39
|
-
propSpacing?: number;
|
|
40
|
-
data?: any;
|
|
41
|
-
barWidth?: number;
|
|
42
|
-
onPress?: Function;
|
|
43
|
-
|
|
44
|
-
rotateLabel?: boolean;
|
|
45
|
-
showXAxisIndices: boolean;
|
|
46
|
-
xAxisIndicesHeight: number;
|
|
47
|
-
xAxisIndicesWidth: number;
|
|
48
|
-
xAxisIndicesColor: ColorValue;
|
|
49
|
-
horizontal: boolean;
|
|
50
|
-
intactTopLabel: boolean;
|
|
51
|
-
barBorderWidth?: number;
|
|
52
|
-
barBorderColor: ColorValue;
|
|
53
|
-
barBorderRadius?: number;
|
|
54
|
-
barBorderTopLeftRadius?: number;
|
|
55
|
-
barBorderTopRightRadius?: number;
|
|
56
|
-
barBorderBottomLeftRadius?: number;
|
|
57
|
-
barBorderBottomRightRadius?: number;
|
|
58
|
-
stackBorderRadius?: number;
|
|
59
|
-
stackBorderTopLeftRadius?: number;
|
|
60
|
-
stackBorderTopRightRadius?: number;
|
|
61
|
-
stackBorderBottomLeftRadius?: number;
|
|
62
|
-
stackBorderBottomRightRadius?: number;
|
|
63
|
-
xAxisThickness: number;
|
|
64
|
-
barBackgroundPattern?: Function;
|
|
65
|
-
patternId?: String;
|
|
66
|
-
xAxisTextNumberOfLines: number;
|
|
67
|
-
xAxisLabelsHeight?: number;
|
|
68
|
-
xAxisLabelsVerticalShift: number;
|
|
69
|
-
renderTooltip: Function | undefined;
|
|
70
|
-
leftShiftForTooltip?: number;
|
|
71
|
-
leftShiftForLastIndexTooltip: number;
|
|
72
|
-
initialSpacing: number;
|
|
73
|
-
selectedIndex: number;
|
|
74
|
-
setSelectedIndex: Function;
|
|
75
|
-
activeOpacity: number;
|
|
76
|
-
showGradient?: boolean;
|
|
77
|
-
gradientColor?: any;
|
|
78
|
-
stackData: Array<stackItemType>;
|
|
79
|
-
isAnimated?: boolean;
|
|
80
|
-
animationDuration?: number;
|
|
81
|
-
pointerConfig?: Pointer;
|
|
82
|
-
showValuesAsTopLabel?: boolean;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const RenderStackBars = (props: Props) => {
|
|
20
|
+
const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
86
21
|
const {
|
|
87
22
|
barBackgroundPattern,
|
|
88
23
|
patternId,
|
|
@@ -120,6 +55,9 @@ const RenderStackBars = (props: Props) => {
|
|
|
120
55
|
const cotainsNegative = item.stacks.some(item => item.value < 0);
|
|
121
56
|
const noAnimation = cotainsNegative || !isAnimated;
|
|
122
57
|
|
|
58
|
+
const localBarInnerComponent =
|
|
59
|
+
item.barInnerComponent ?? props.barInnerComponent;
|
|
60
|
+
|
|
123
61
|
const {
|
|
124
62
|
borderRadius,
|
|
125
63
|
borderTopLeftRadius,
|
|
@@ -195,8 +133,8 @@ const RenderStackBars = (props: Props) => {
|
|
|
195
133
|
? {transform: [{rotate: '330deg'}]}
|
|
196
134
|
: {transform: [{rotate: '60deg'}]}
|
|
197
135
|
: props.horizontal
|
|
198
|
-
|
|
199
|
-
|
|
136
|
+
? {transform: [{rotate: '-90deg'}]}
|
|
137
|
+
: {},
|
|
200
138
|
]}>
|
|
201
139
|
{item.labelComponent ? (
|
|
202
140
|
item.labelComponent()
|
|
@@ -241,25 +179,8 @@ const RenderStackBars = (props: Props) => {
|
|
|
241
179
|
setTimeout(() => elevate(), Platform.OS == 'ios' ? 10 : 100);
|
|
242
180
|
};
|
|
243
181
|
|
|
244
|
-
const barWrapper = () => {
|
|
245
|
-
return noAnimation ? (
|
|
246
|
-
static2DSimple()
|
|
247
|
-
) : (
|
|
248
|
-
<View
|
|
249
|
-
style={{
|
|
250
|
-
position: 'absolute',
|
|
251
|
-
bottom: 0,
|
|
252
|
-
height: height,
|
|
253
|
-
width: '100%',
|
|
254
|
-
overflow: 'hidden',
|
|
255
|
-
}}>
|
|
256
|
-
{static2DSimple()}
|
|
257
|
-
</View>
|
|
258
|
-
);
|
|
259
|
-
};
|
|
260
|
-
|
|
261
182
|
const static2DSimple = () => {
|
|
262
|
-
const getStackBorderRadii = (item:
|
|
183
|
+
const getStackBorderRadii = (item: stackDataItem, index: number) => {
|
|
263
184
|
const stackItem = item.stacks[index];
|
|
264
185
|
const borderRadii = {
|
|
265
186
|
borderTopLeftRadius:
|
|
@@ -398,6 +319,11 @@ const RenderStackBars = (props: Props) => {
|
|
|
398
319
|
</Svg>
|
|
399
320
|
)}
|
|
400
321
|
</TouchableOpacity>
|
|
322
|
+
{localBarInnerComponent ? (
|
|
323
|
+
<View style={{height: '100%', width: '100%'}}>
|
|
324
|
+
{localBarInnerComponent(item, index)}
|
|
325
|
+
</View>
|
|
326
|
+
) : null}
|
|
401
327
|
{(item.topLabelComponent || showValuesAsTopLabel) && (
|
|
402
328
|
<View
|
|
403
329
|
style={[
|
|
@@ -429,6 +355,23 @@ const RenderStackBars = (props: Props) => {
|
|
|
429
355
|
);
|
|
430
356
|
};
|
|
431
357
|
|
|
358
|
+
const barWrapper = () => {
|
|
359
|
+
return noAnimation ? (
|
|
360
|
+
static2DSimple()
|
|
361
|
+
) : (
|
|
362
|
+
<View
|
|
363
|
+
style={{
|
|
364
|
+
position: 'absolute',
|
|
365
|
+
bottom: 0,
|
|
366
|
+
height: height,
|
|
367
|
+
width: '100%',
|
|
368
|
+
overflow: 'hidden',
|
|
369
|
+
}}>
|
|
370
|
+
{static2DSimple()}
|
|
371
|
+
</View>
|
|
372
|
+
);
|
|
373
|
+
};
|
|
374
|
+
|
|
432
375
|
return (
|
|
433
376
|
<>
|
|
434
377
|
<View
|
package/src/BarChart/index.tsx
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
screenWidth,
|
|
23
23
|
} from '../utils/constants';
|
|
24
24
|
import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
|
|
25
|
-
import {BarChartPropsType,
|
|
25
|
+
import {BarChartPropsType, barDataItem} from './types';
|
|
26
26
|
import {BarAndLineChartsWrapperTypes} from '../utils/types';
|
|
27
27
|
import {StripAndLabel} from '../Components/common/StripAndLabel';
|
|
28
28
|
import {Pointer} from '../Components/common/Pointer';
|
|
@@ -139,7 +139,7 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
139
139
|
BarDefaults.barWidth) + spacing;
|
|
140
140
|
});
|
|
141
141
|
} else {
|
|
142
|
-
data.forEach((item:
|
|
142
|
+
data.forEach((item: barDataItem) => {
|
|
143
143
|
if (item.value > maxItem) {
|
|
144
144
|
maxItem = item.value;
|
|
145
145
|
}
|
|
@@ -156,7 +156,7 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
156
156
|
secondaryMinItem = 0;
|
|
157
157
|
|
|
158
158
|
if (lineConfig.isSecondary) {
|
|
159
|
-
lineData.forEach((item:
|
|
159
|
+
lineData.forEach((item: barDataItem) => {
|
|
160
160
|
if (item.value > secondaryMaxItem) {
|
|
161
161
|
secondaryMaxItem = item.value;
|
|
162
162
|
}
|
|
@@ -324,6 +324,8 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
324
324
|
: true
|
|
325
325
|
: false);
|
|
326
326
|
|
|
327
|
+
const barInnerComponent = props.barInnerComponent;
|
|
328
|
+
|
|
327
329
|
const labelsAppear = useCallback(() => {
|
|
328
330
|
opacValue.setValue(0);
|
|
329
331
|
Animated.timing(opacValue, {
|
|
@@ -811,6 +813,7 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
811
813
|
barBorderTopRightRadius: props.barBorderTopRightRadius,
|
|
812
814
|
barBorderBottomLeftRadius: props.barBorderBottomLeftRadius,
|
|
813
815
|
barBorderBottomRightRadius: props.barBorderBottomRightRadius,
|
|
816
|
+
barInnerComponent,
|
|
814
817
|
color: props.color,
|
|
815
818
|
showGradient: props.showGradient,
|
|
816
819
|
gradientColor: props.gradientColor,
|
package/src/BarChart/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {ColorValue, GestureResponderEvent
|
|
1
|
+
import {ColorValue, GestureResponderEvent} from 'react-native';
|
|
2
2
|
import {yAxisSides} from '../utils/constants';
|
|
3
3
|
import {
|
|
4
4
|
CurveType,
|
|
@@ -8,8 +8,9 @@ import {
|
|
|
8
8
|
referenceConfigType,
|
|
9
9
|
secondaryYAxisType,
|
|
10
10
|
} from '../utils/types';
|
|
11
|
+
import {Component, ReactNode} from 'react';
|
|
11
12
|
|
|
12
|
-
export type
|
|
13
|
+
export type stackDataItem = {
|
|
13
14
|
onPress?: any;
|
|
14
15
|
label?: String;
|
|
15
16
|
barWidth?: number;
|
|
@@ -47,11 +48,76 @@ export type stackItemType = {
|
|
|
47
48
|
borderTopRightRadius?: number;
|
|
48
49
|
borderBottomLeftRadius?: number;
|
|
49
50
|
borderBottomRightRadius?: number;
|
|
51
|
+
barInnerComponent?: (item?: stackDataItem, index?: number) => ReactNode;
|
|
50
52
|
patternId?: String;
|
|
51
53
|
leftShiftForTooltip?: number;
|
|
52
54
|
showXAxisIndex?: boolean;
|
|
53
55
|
};
|
|
54
56
|
|
|
57
|
+
export type StackedBarChartPropsType = {
|
|
58
|
+
style?: any;
|
|
59
|
+
width?: number;
|
|
60
|
+
height?: number;
|
|
61
|
+
color?: ColorValue;
|
|
62
|
+
topLabelComponent?: Component;
|
|
63
|
+
topLabelContainerStyle?: any;
|
|
64
|
+
opacity?: number;
|
|
65
|
+
label: String;
|
|
66
|
+
labelTextStyle?: any;
|
|
67
|
+
disablePress?: boolean;
|
|
68
|
+
|
|
69
|
+
item: stackDataItem;
|
|
70
|
+
index: number;
|
|
71
|
+
containerHeight?: number;
|
|
72
|
+
maxValue: number;
|
|
73
|
+
spacing: number;
|
|
74
|
+
propSpacing?: number;
|
|
75
|
+
data?: any;
|
|
76
|
+
barWidth?: number;
|
|
77
|
+
onPress?: Function;
|
|
78
|
+
|
|
79
|
+
rotateLabel?: boolean;
|
|
80
|
+
showXAxisIndices: boolean;
|
|
81
|
+
xAxisIndicesHeight: number;
|
|
82
|
+
xAxisIndicesWidth: number;
|
|
83
|
+
xAxisIndicesColor: ColorValue;
|
|
84
|
+
horizontal: boolean;
|
|
85
|
+
intactTopLabel: boolean;
|
|
86
|
+
barBorderWidth?: number;
|
|
87
|
+
barBorderColor: ColorValue;
|
|
88
|
+
barBorderRadius?: number;
|
|
89
|
+
barBorderTopLeftRadius?: number;
|
|
90
|
+
barBorderTopRightRadius?: number;
|
|
91
|
+
barBorderBottomLeftRadius?: number;
|
|
92
|
+
barBorderBottomRightRadius?: number;
|
|
93
|
+
barInnerComponent?: (item?: barDataItem | stackDataItem, index?: number) => ReactNode;
|
|
94
|
+
stackBorderRadius?: number;
|
|
95
|
+
stackBorderTopLeftRadius?: number;
|
|
96
|
+
stackBorderTopRightRadius?: number;
|
|
97
|
+
stackBorderBottomLeftRadius?: number;
|
|
98
|
+
stackBorderBottomRightRadius?: number;
|
|
99
|
+
xAxisThickness: number;
|
|
100
|
+
barBackgroundPattern?: Function;
|
|
101
|
+
patternId?: String;
|
|
102
|
+
xAxisTextNumberOfLines: number;
|
|
103
|
+
xAxisLabelsHeight?: number;
|
|
104
|
+
xAxisLabelsVerticalShift: number;
|
|
105
|
+
renderTooltip: Function | undefined;
|
|
106
|
+
leftShiftForTooltip?: number;
|
|
107
|
+
leftShiftForLastIndexTooltip: number;
|
|
108
|
+
initialSpacing: number;
|
|
109
|
+
selectedIndex: number;
|
|
110
|
+
setSelectedIndex: Function;
|
|
111
|
+
activeOpacity: number;
|
|
112
|
+
showGradient?: boolean;
|
|
113
|
+
gradientColor?: any;
|
|
114
|
+
stackData: Array<stackDataItem>;
|
|
115
|
+
isAnimated?: boolean;
|
|
116
|
+
animationDuration?: number;
|
|
117
|
+
pointerConfig?: Pointer;
|
|
118
|
+
showValuesAsTopLabel?: boolean;
|
|
119
|
+
};
|
|
120
|
+
|
|
55
121
|
export type BarChartPropsType = {
|
|
56
122
|
width?: number;
|
|
57
123
|
height?: number;
|
|
@@ -64,8 +130,8 @@ export type BarChartPropsType = {
|
|
|
64
130
|
stepHeight?: number;
|
|
65
131
|
stepValue?: number;
|
|
66
132
|
spacing?: number;
|
|
67
|
-
data?: Array<
|
|
68
|
-
stackData?: Array<
|
|
133
|
+
data?: Array<barDataItem>;
|
|
134
|
+
stackData?: Array<stackDataItem>;
|
|
69
135
|
side?: String;
|
|
70
136
|
rotateLabel?: boolean;
|
|
71
137
|
isAnimated?: boolean;
|
|
@@ -212,8 +278,9 @@ export type BarChartPropsType = {
|
|
|
212
278
|
leftShiftForTooltip?: number;
|
|
213
279
|
leftShiftForLastIndexTooltip?: number;
|
|
214
280
|
barStyle?: object;
|
|
281
|
+
barInnerComponent?: (item?: stackDataItem | barDataItem, index?: number) => ReactNode;
|
|
215
282
|
|
|
216
|
-
secondaryData?: Array<
|
|
283
|
+
secondaryData?: Array<barDataItem>;
|
|
217
284
|
secondaryYAxis?: secondaryYAxisType | boolean;
|
|
218
285
|
pointerConfig?: Pointer;
|
|
219
286
|
getPointerProps?: Function;
|
|
@@ -290,7 +357,7 @@ type arrowType = {
|
|
|
290
357
|
type sectionType = {
|
|
291
358
|
value: string;
|
|
292
359
|
};
|
|
293
|
-
export type
|
|
360
|
+
export type barDataItem = {
|
|
294
361
|
value: number;
|
|
295
362
|
onPress?: any;
|
|
296
363
|
frontColor?: ColorValue;
|
|
@@ -322,5 +389,6 @@ export type itemType = {
|
|
|
322
389
|
barMarginBottom?: number;
|
|
323
390
|
leftShiftForTooltip?: number;
|
|
324
391
|
barStyle?: object;
|
|
392
|
+
barInnerComponent?: (item?: barDataItem, index?: number) => ReactNode;
|
|
325
393
|
showXAxisIndex?: boolean;
|
|
326
394
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {useEffect, useState} from 'react';
|
|
1
|
+
import React, {ReactNode, useEffect, useState} from 'react';
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
4
|
StyleSheet,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import LinearGradient from 'react-native-linear-gradient';
|
|
12
12
|
import Svg, {Defs, Rect} from 'react-native-svg';
|
|
13
13
|
import {styles} from './styles';
|
|
14
|
+
import {barDataItem} from '../../BarChart/types';
|
|
14
15
|
|
|
15
16
|
if (Platform.OS === 'android') {
|
|
16
17
|
UIManager.setLayoutAnimationEnabledExperimental &&
|
|
@@ -42,9 +43,11 @@ type animatedBarPropTypes = {
|
|
|
42
43
|
topLabelContainerStyle?: any;
|
|
43
44
|
topLabelTextStyle?: any;
|
|
44
45
|
barBackgroundPattern?: Function;
|
|
46
|
+
barInnerComponent?: (item?: barDataItem, index?: number) => ReactNode;
|
|
45
47
|
patternId?: String;
|
|
46
48
|
barStyle?: object;
|
|
47
49
|
item: any;
|
|
50
|
+
index: number;
|
|
48
51
|
};
|
|
49
52
|
|
|
50
53
|
const TriangleCorner = (props: trianglePropTypes) => {
|
|
@@ -79,10 +82,12 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
|
|
|
79
82
|
isAnimated,
|
|
80
83
|
animationDuration,
|
|
81
84
|
item,
|
|
85
|
+
index,
|
|
82
86
|
width,
|
|
83
87
|
sideWidth,
|
|
84
88
|
barStyle,
|
|
85
89
|
barBackgroundPattern,
|
|
90
|
+
barInnerComponent,
|
|
86
91
|
patternId,
|
|
87
92
|
intactTopLabel,
|
|
88
93
|
showValuesAsTopLabel,
|
|
@@ -238,6 +243,11 @@ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
|
|
|
238
243
|
/>
|
|
239
244
|
</Svg>
|
|
240
245
|
)}
|
|
246
|
+
{barInnerComponent ? (
|
|
247
|
+
<View style={{height: '100%', width: '100%'}}>
|
|
248
|
+
{barInnerComponent(item, index)}
|
|
249
|
+
</View>
|
|
250
|
+
) : null}
|
|
241
251
|
</View>
|
|
242
252
|
|
|
243
253
|
{/******************* Top Label *****************/}
|
|
@@ -322,7 +322,7 @@ const RenderLineInBarChart = props => {
|
|
|
322
322
|
style={{
|
|
323
323
|
position: 'absolute',
|
|
324
324
|
height: containerHeight + 10,
|
|
325
|
-
left:
|
|
325
|
+
left: 6 - yAxisLabelWidth,
|
|
326
326
|
bottom: 50 + xAxisLabelsVerticalShift, //stepHeight * -0.5 + xAxisThickness,
|
|
327
327
|
width: animatedWidth,
|
|
328
328
|
zIndex: lineBehindBars ? -1 : 100000,
|