react-native-gifted-charts 1.4.16 → 1.4.18
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 +2 -2
- package/src/BarChart/Animated2DWithGradient.tsx +3 -3
- package/src/BarChart/RenderBars.tsx +98 -32
- package/src/BarChart/RenderStackBars.tsx +7 -33
- package/src/BarChart/index.tsx +20 -10
- package/src/Components/BarAndLineChartsWrapper/index.tsx +2 -0
- package/src/Components/BarAndLineChartsWrapper/renderHorizSections.tsx +8 -5
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.tsx +1 -1
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.tsx +3 -2
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.tsx +1 -1
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.tsx +1 -1
- package/src/Components/BarAndLineChartsWrapper/renderVerticalLines.tsx +4 -4
- package/src/Components/BarSpecificComponents/barBackgroundPattern.tsx +15 -15
- package/src/Components/BarSpecificComponents/cap.tsx +1 -1
- package/src/Components/BarSpecificComponents/tooltip.tsx +59 -0
- package/src/Components/common/LinearGradient.tsx +6 -6
- package/src/Components/common/Pointer.tsx +1 -1
- package/src/Components/common/StripAndLabel.tsx +1 -1
- package/src/LineChart/LineChartBicolor.tsx +13 -13
- package/src/LineChart/index.tsx +120 -55
- package/src/PieChart/index.tsx +4 -1
- package/src/index.tsx +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gifted-charts",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.18",
|
|
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": [
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"registry": "https://registry.npmjs.org/"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"gifted-charts-core": "^0.1.
|
|
28
|
+
"gifted-charts-core": "^0.1.16"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@babel/core": "^7.22.5",
|
|
@@ -2,7 +2,7 @@ import React, {useEffect, useState} from 'react';
|
|
|
2
2
|
import {View, LayoutAnimation, Platform, UIManager, Text} from 'react-native';
|
|
3
3
|
import Svg, {Defs, Rect} from 'react-native-svg';
|
|
4
4
|
import Cap from '../Components/BarSpecificComponents/cap';
|
|
5
|
-
import LinearGradient from
|
|
5
|
+
import LinearGradient from '../Components/common/LinearGradient';
|
|
6
6
|
import {Animated2DWithGradientPropsType} from 'gifted-charts-core';
|
|
7
7
|
|
|
8
8
|
if (Platform.OS === 'android') {
|
|
@@ -22,8 +22,6 @@ const Animated2DWithGradient = (props: Animated2DWithGradientPropsType) => {
|
|
|
22
22
|
animationDuration,
|
|
23
23
|
noGradient,
|
|
24
24
|
noAnimation,
|
|
25
|
-
containerHeight,
|
|
26
|
-
maxValue,
|
|
27
25
|
barMarginBottom,
|
|
28
26
|
barInnerComponent,
|
|
29
27
|
intactTopLabel,
|
|
@@ -46,6 +44,8 @@ const Animated2DWithGradient = (props: Animated2DWithGradientPropsType) => {
|
|
|
46
44
|
} else {
|
|
47
45
|
elevate();
|
|
48
46
|
}
|
|
47
|
+
} else {
|
|
48
|
+
setHeight(props.height);
|
|
49
49
|
}
|
|
50
50
|
}, [props.height]);
|
|
51
51
|
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
barDataItem,
|
|
12
12
|
AxesAndRulesDefaults,
|
|
13
13
|
} from 'gifted-charts-core';
|
|
14
|
+
import Tooltip from '../Components/BarSpecificComponents/tooltip';
|
|
14
15
|
|
|
15
16
|
const RenderBars = (props: RenderBarsPropsType) => {
|
|
16
17
|
const {
|
|
@@ -32,7 +33,9 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
32
33
|
animationDuration,
|
|
33
34
|
autoShiftLabels,
|
|
34
35
|
label,
|
|
36
|
+
secondaryLabel,
|
|
35
37
|
labelTextStyle,
|
|
38
|
+
secondaryLabelTextStyle,
|
|
36
39
|
xAxisTextNumberOfLines,
|
|
37
40
|
xAxisLabelsVerticalShift,
|
|
38
41
|
renderTooltip,
|
|
@@ -57,6 +60,8 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
57
60
|
stepValue,
|
|
58
61
|
negativeStepHeight,
|
|
59
62
|
negativeStepValue,
|
|
63
|
+
autoCenterTooltip,
|
|
64
|
+
secondaryXAxis,
|
|
60
65
|
} = props;
|
|
61
66
|
|
|
62
67
|
const heightFactor =
|
|
@@ -89,7 +94,12 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
89
94
|
? 0
|
|
90
95
|
: item.barMarginBottom || props.barMarginBottom || 0;
|
|
91
96
|
|
|
92
|
-
const renderLabel = (
|
|
97
|
+
const renderLabel = (
|
|
98
|
+
top: boolean,
|
|
99
|
+
label: String,
|
|
100
|
+
labelTextStyle: any,
|
|
101
|
+
value: number,
|
|
102
|
+
) => {
|
|
93
103
|
return (
|
|
94
104
|
<View
|
|
95
105
|
style={[
|
|
@@ -102,12 +112,16 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
102
112
|
left: spacing / -2,
|
|
103
113
|
position: 'absolute',
|
|
104
114
|
height: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
|
|
105
|
-
bottom:
|
|
106
|
-
(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
bottom: top
|
|
116
|
+
? (containerHeight || 200) +
|
|
117
|
+
(secondaryXAxis?.labelsDistanceFromXaxis ?? 15)
|
|
118
|
+
: (rotateLabel
|
|
119
|
+
? -40
|
|
120
|
+
: -6 -
|
|
121
|
+
xAxisTextNumberOfLines * 18 -
|
|
122
|
+
xAxisLabelsVerticalShift) -
|
|
123
|
+
barMarginBottom -
|
|
124
|
+
labelsDistanceFromXaxis,
|
|
111
125
|
},
|
|
112
126
|
rotateLabel
|
|
113
127
|
? horizontal
|
|
@@ -134,7 +148,21 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
134
148
|
}
|
|
135
149
|
: {},
|
|
136
150
|
]}>
|
|
137
|
-
{
|
|
151
|
+
{top ? (
|
|
152
|
+
item.secondaryLabelComponent ? (
|
|
153
|
+
item.secondaryLabelComponent()
|
|
154
|
+
) : (
|
|
155
|
+
<Text
|
|
156
|
+
style={[
|
|
157
|
+
{textAlign: 'center'},
|
|
158
|
+
rtl && horizontal && {transform: [{rotate: '180deg'}]},
|
|
159
|
+
labelTextStyle,
|
|
160
|
+
]}
|
|
161
|
+
numberOfLines={xAxisTextNumberOfLines}>
|
|
162
|
+
{label}
|
|
163
|
+
</Text>
|
|
164
|
+
)
|
|
165
|
+
) : item.labelComponent ? (
|
|
138
166
|
item.labelComponent()
|
|
139
167
|
) : (
|
|
140
168
|
<Text
|
|
@@ -144,7 +172,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
144
172
|
labelTextStyle,
|
|
145
173
|
]}
|
|
146
174
|
numberOfLines={xAxisTextNumberOfLines}>
|
|
147
|
-
{label
|
|
175
|
+
{label}
|
|
148
176
|
</Text>
|
|
149
177
|
)}
|
|
150
178
|
</View>
|
|
@@ -152,6 +180,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
152
180
|
};
|
|
153
181
|
|
|
154
182
|
const renderAnimatedLabel = (
|
|
183
|
+
top: boolean,
|
|
155
184
|
label: String,
|
|
156
185
|
labelTextStyle: any,
|
|
157
186
|
value: number,
|
|
@@ -168,11 +197,14 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
168
197
|
left: spacing / -2,
|
|
169
198
|
position: 'absolute',
|
|
170
199
|
height: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
|
|
171
|
-
bottom:
|
|
172
|
-
(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
200
|
+
bottom: top
|
|
201
|
+
? (containerHeight || 200) +
|
|
202
|
+
(secondaryXAxis?.labelsDistanceFromXaxis ?? 15)
|
|
203
|
+
: (rotateLabel
|
|
204
|
+
? -40
|
|
205
|
+
: -6 -
|
|
206
|
+
xAxisTextNumberOfLines * 18 -
|
|
207
|
+
xAxisLabelsVerticalShift) - barMarginBottom,
|
|
176
208
|
opacity: appearingOpacity,
|
|
177
209
|
},
|
|
178
210
|
value < 0 && {transform: [{rotate: '180deg'}]},
|
|
@@ -195,7 +227,21 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
195
227
|
}
|
|
196
228
|
: {},
|
|
197
229
|
]}>
|
|
198
|
-
{
|
|
230
|
+
{top ? (
|
|
231
|
+
item.secondaryLabelComponent ? (
|
|
232
|
+
item.secondaryLabelComponent()
|
|
233
|
+
) : (
|
|
234
|
+
<Text
|
|
235
|
+
style={[
|
|
236
|
+
{textAlign: 'center'},
|
|
237
|
+
rtl && horizontal && {transform: [{rotate: '180deg'}]},
|
|
238
|
+
labelTextStyle,
|
|
239
|
+
]}
|
|
240
|
+
numberOfLines={xAxisTextNumberOfLines}>
|
|
241
|
+
{label}
|
|
242
|
+
</Text>
|
|
243
|
+
)
|
|
244
|
+
) : item.labelComponent ? (
|
|
199
245
|
item.labelComponent()
|
|
200
246
|
) : (
|
|
201
247
|
<Text
|
|
@@ -205,7 +251,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
205
251
|
labelTextStyle,
|
|
206
252
|
]}
|
|
207
253
|
numberOfLines={xAxisTextNumberOfLines}>
|
|
208
|
-
{label
|
|
254
|
+
{label}
|
|
209
255
|
</Text>
|
|
210
256
|
)}
|
|
211
257
|
</Animated.View>
|
|
@@ -328,7 +374,10 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
328
374
|
const barContent = () => {
|
|
329
375
|
const isBarBelowXaxisAndInvisible =
|
|
330
376
|
item.value < 0 && !noOfSectionsBelowXAxis;
|
|
331
|
-
const animated2DWithGradient = (
|
|
377
|
+
const animated2DWithGradient = (
|
|
378
|
+
noGradient: boolean,
|
|
379
|
+
noAnimation: boolean,
|
|
380
|
+
) => (
|
|
332
381
|
<Animated2DWithGradient
|
|
333
382
|
{...commonPropsFor2Dand3Dbars}
|
|
334
383
|
animationDuration={animationDuration || 800}
|
|
@@ -394,12 +443,41 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
394
443
|
animated2DWithGradient(true, true)
|
|
395
444
|
)}
|
|
396
445
|
{isAnimated
|
|
397
|
-
? renderAnimatedLabel(label, labelTextStyle, item.value)
|
|
398
|
-
: renderLabel(label, labelTextStyle, item.value)}
|
|
446
|
+
? renderAnimatedLabel(false, label, labelTextStyle, item.value)
|
|
447
|
+
: renderLabel(false, label, labelTextStyle, item.value)}
|
|
448
|
+
{secondaryXAxis
|
|
449
|
+
? isAnimated
|
|
450
|
+
? renderAnimatedLabel(
|
|
451
|
+
true,
|
|
452
|
+
secondaryLabel,
|
|
453
|
+
secondaryLabelTextStyle,
|
|
454
|
+
item.value,
|
|
455
|
+
)
|
|
456
|
+
: renderLabel(
|
|
457
|
+
true,
|
|
458
|
+
secondaryLabel,
|
|
459
|
+
secondaryLabelTextStyle,
|
|
460
|
+
item.value,
|
|
461
|
+
)
|
|
462
|
+
: null}
|
|
399
463
|
</>
|
|
400
464
|
);
|
|
401
465
|
};
|
|
402
466
|
|
|
467
|
+
const tooltipProps = {
|
|
468
|
+
barHeight,
|
|
469
|
+
barWidth: item.barWidth || barWidth,
|
|
470
|
+
item,
|
|
471
|
+
index,
|
|
472
|
+
isLast: index === data.length - 1,
|
|
473
|
+
leftSpacing,
|
|
474
|
+
leftShiftForLastIndexTooltip,
|
|
475
|
+
leftShiftForTooltip: item.leftShiftForTooltip ?? leftShiftForTooltip ?? 0,
|
|
476
|
+
renderTooltip,
|
|
477
|
+
autoCenterTooltip,
|
|
478
|
+
horizontal,
|
|
479
|
+
};
|
|
480
|
+
|
|
403
481
|
return (
|
|
404
482
|
<>
|
|
405
483
|
{pressDisabled ? (
|
|
@@ -440,19 +518,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
440
518
|
</TouchableOpacity>
|
|
441
519
|
)}
|
|
442
520
|
{renderTooltip && selectedIndex === index && (
|
|
443
|
-
<
|
|
444
|
-
style={{
|
|
445
|
-
position: 'absolute',
|
|
446
|
-
bottom: barHeight + 60,
|
|
447
|
-
left:
|
|
448
|
-
index === data.length - 1
|
|
449
|
-
? leftSpacing - leftShiftForLastIndexTooltip
|
|
450
|
-
: leftSpacing -
|
|
451
|
-
(item?.leftShiftForTooltip ?? leftShiftForTooltip ?? 0),
|
|
452
|
-
zIndex: 1000,
|
|
453
|
-
}}>
|
|
454
|
-
{renderTooltip(item, index)}
|
|
455
|
-
</View>
|
|
521
|
+
<Tooltip {...tooltipProps} />
|
|
456
522
|
)}
|
|
457
523
|
</>
|
|
458
524
|
);
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
BarDefaults,
|
|
15
15
|
StackedBarChartPropsType,
|
|
16
16
|
} from 'gifted-charts-core';
|
|
17
|
+
import Tooltip from '../Components/BarSpecificComponents/tooltip';
|
|
17
18
|
|
|
18
19
|
if (Platform.OS === 'android') {
|
|
19
20
|
UIManager.setLayoutAnimationEnabledExperimental &&
|
|
@@ -34,12 +35,9 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
34
35
|
xAxisTextNumberOfLines,
|
|
35
36
|
xAxisLabelsVerticalShift,
|
|
36
37
|
renderTooltip,
|
|
37
|
-
leftShiftForTooltip,
|
|
38
|
-
leftShiftForLastIndexTooltip,
|
|
39
38
|
selectedIndex,
|
|
40
39
|
setSelectedIndex,
|
|
41
40
|
activeOpacity,
|
|
42
|
-
stackData,
|
|
43
41
|
animationDuration = BarDefaults.animationDuration,
|
|
44
42
|
barBorderWidth,
|
|
45
43
|
barBorderColor,
|
|
@@ -51,6 +49,7 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
51
49
|
showValuesAsTopLabel,
|
|
52
50
|
autoShiftLabelsForNegativeStacks = true,
|
|
53
51
|
labelsDistanceFromXaxis = 0,
|
|
52
|
+
horizontal,
|
|
54
53
|
} = props;
|
|
55
54
|
const {
|
|
56
55
|
cotainsNegative,
|
|
@@ -61,7 +60,6 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
61
60
|
borderTopRightRadius,
|
|
62
61
|
borderBottomLeftRadius,
|
|
63
62
|
borderBottomRightRadius,
|
|
64
|
-
leftSpacing,
|
|
65
63
|
disablePress,
|
|
66
64
|
totalHeight,
|
|
67
65
|
height,
|
|
@@ -70,6 +68,7 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
70
68
|
getPosition,
|
|
71
69
|
lowestBarPosition,
|
|
72
70
|
getStackBorderRadii,
|
|
71
|
+
tooltipProps,
|
|
73
72
|
} = useRenderStackBars(props);
|
|
74
73
|
|
|
75
74
|
const renderLabel = (label: String, labelTextStyle: any) => {
|
|
@@ -85,10 +84,10 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
85
84
|
: -labelsDistanceFromXaxis,
|
|
86
85
|
},
|
|
87
86
|
rotateLabel
|
|
88
|
-
?
|
|
87
|
+
? horizontal
|
|
89
88
|
? {transform: [{rotate: '330deg'}]}
|
|
90
89
|
: {transform: [{rotate: '60deg'}]}
|
|
91
|
-
:
|
|
90
|
+
: horizontal
|
|
92
91
|
? {transform: [{rotate: '-90deg'}]}
|
|
93
92
|
: {},
|
|
94
93
|
]}>
|
|
@@ -268,7 +267,7 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
268
267
|
alignItems: 'center',
|
|
269
268
|
},
|
|
270
269
|
cotainsNegative && {transform: [{translateY: totalHeight * 2}]},
|
|
271
|
-
|
|
270
|
+
horizontal &&
|
|
272
271
|
!props.intactTopLabel && {transform: [{rotate: '270deg'}]},
|
|
273
272
|
item.topLabelContainerStyle,
|
|
274
273
|
]}>
|
|
@@ -331,19 +330,6 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
331
330
|
}
|
|
332
331
|
: null,
|
|
333
332
|
]}>
|
|
334
|
-
{/* {props.showVerticalLines && (
|
|
335
|
-
<View
|
|
336
|
-
style={{
|
|
337
|
-
zIndex: props.verticalLinesZIndex,
|
|
338
|
-
position: 'absolute',
|
|
339
|
-
height: (containerHeight || 200) + 15,
|
|
340
|
-
width: props.verticalLinesThickness,
|
|
341
|
-
bottom: 0,
|
|
342
|
-
left: (item.barWidth || props.barWidth || 30) / 2,
|
|
343
|
-
backgroundColor: props.verticalLinesColor,
|
|
344
|
-
}}
|
|
345
|
-
/>
|
|
346
|
-
)} */}
|
|
347
333
|
{(props.showXAxisIndices || item.showXAxisIndex) && (
|
|
348
334
|
<View
|
|
349
335
|
style={{
|
|
@@ -364,19 +350,7 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
|
|
|
364
350
|
{renderLabel(label || '', labelTextStyle)}
|
|
365
351
|
</View>
|
|
366
352
|
{renderTooltip && selectedIndex === index && (
|
|
367
|
-
<
|
|
368
|
-
style={{
|
|
369
|
-
position: 'absolute',
|
|
370
|
-
bottom: totalHeight + 60,
|
|
371
|
-
left:
|
|
372
|
-
index === stackData.length - 1
|
|
373
|
-
? leftSpacing - leftShiftForLastIndexTooltip
|
|
374
|
-
: leftSpacing -
|
|
375
|
-
(item.leftShiftForTooltip ?? leftShiftForTooltip ?? 0),
|
|
376
|
-
zIndex: 1000,
|
|
377
|
-
}}>
|
|
378
|
-
{renderTooltip(item, index)}
|
|
379
|
-
</View>
|
|
353
|
+
<Tooltip {...tooltipProps} />
|
|
380
354
|
)}
|
|
381
355
|
</>
|
|
382
356
|
);
|
package/src/BarChart/index.tsx
CHANGED
|
@@ -16,7 +16,7 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
16
16
|
const scrollRef = props.scrollRef ?? useRef(null);
|
|
17
17
|
const remainingScrollViewProps = {
|
|
18
18
|
onScroll: (ev: any) => props.onScroll?.(ev),
|
|
19
|
-
onTouchStart: evt => {
|
|
19
|
+
onTouchStart: (evt: any) => {
|
|
20
20
|
if (props.renderTooltip) {
|
|
21
21
|
setSelectedIndex(-1);
|
|
22
22
|
}
|
|
@@ -141,7 +141,7 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
141
141
|
});
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
-
const renderStripAndLabel = pointerLabelComponent => {
|
|
144
|
+
const renderStripAndLabel = (pointerLabelComponent: any) => {
|
|
145
145
|
let pointerItemLocal,
|
|
146
146
|
pointerYLocal = pointerY;
|
|
147
147
|
|
|
@@ -204,12 +204,16 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
204
204
|
barWidth / 2;
|
|
205
205
|
setPointerX(z);
|
|
206
206
|
setPointerIndex(factor);
|
|
207
|
+
|
|
207
208
|
let item, y;
|
|
208
209
|
item = (props.stackData ?? data)[factor];
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
let stackSum = 0;
|
|
211
|
+
if ('stacks' in item) {
|
|
212
|
+
stackSum = item.stacks.reduce(
|
|
213
|
+
(acc: number, stack: any) => acc + (stack.value ?? 0),
|
|
214
|
+
0,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
213
217
|
y =
|
|
214
218
|
containerHeight -
|
|
215
219
|
((stackSum ?? item.value) * containerHeight) / maxValue -
|
|
@@ -248,10 +252,13 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
248
252
|
setPointerX(z);
|
|
249
253
|
setPointerIndex(factor);
|
|
250
254
|
item = (props.stackData ?? data)[factor];
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
+
let stackSum = 0;
|
|
256
|
+
if ('stacks' in item) {
|
|
257
|
+
item.stacks?.reduce(
|
|
258
|
+
(acc: number, stack: any) => acc + (stack.value ?? 0),
|
|
259
|
+
0,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
255
262
|
y =
|
|
256
263
|
containerHeight -
|
|
257
264
|
((stackSum ?? item.value) * containerHeight) / maxValue -
|
|
@@ -326,6 +333,7 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
326
333
|
return props.stackData.map((item, index) => {
|
|
327
334
|
return (
|
|
328
335
|
<RenderStackBars
|
|
336
|
+
key={index}
|
|
329
337
|
stackData={props.stackData || []}
|
|
330
338
|
isAnimated={isAnimated}
|
|
331
339
|
animationDuration={animationDuration}
|
|
@@ -342,6 +350,7 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
342
350
|
} else {
|
|
343
351
|
return data.map((item, index) => (
|
|
344
352
|
<RenderBars
|
|
353
|
+
key={index}
|
|
345
354
|
data={data}
|
|
346
355
|
side={side}
|
|
347
356
|
minHeight={props.minHeight ?? (isAnimated && !isThreeD ? 0.1 : 0)}
|
|
@@ -376,6 +385,7 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
376
385
|
scrollRef={scrollRef}
|
|
377
386
|
renderChartContent={renderChartContent}
|
|
378
387
|
remainingScrollViewProps={remainingScrollViewProps}
|
|
388
|
+
nestedScrollEnabled={props.nestedScrollEnabled}
|
|
379
389
|
/>
|
|
380
390
|
);
|
|
381
391
|
};
|
|
@@ -53,6 +53,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
53
53
|
onEndReached,
|
|
54
54
|
onStartReached,
|
|
55
55
|
onMomentumScrollEnd,
|
|
56
|
+
nestedScrollEnabled,
|
|
56
57
|
extraWidthDueToDataPoint = 0, // extraWidthDueToDataPoint will be receved from props onlhy in case of LineCharts, for other charts it will be undefined and will default to 0
|
|
57
58
|
} = props;
|
|
58
59
|
|
|
@@ -125,6 +126,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
125
126
|
onScrollBeginDrag={() => {
|
|
126
127
|
setCanMomentum(true);
|
|
127
128
|
}}
|
|
129
|
+
nestedScrollEnabled={nestedScrollEnabled}
|
|
128
130
|
onMomentumScrollEnd={({nativeEvent}) => {
|
|
129
131
|
if (onMomentumScrollEnd) {
|
|
130
132
|
onMomentumScrollEnd();
|
|
@@ -62,6 +62,7 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
62
62
|
secondaryYAxis,
|
|
63
63
|
onlyReferenceLines,
|
|
64
64
|
renderReferenceLines,
|
|
65
|
+
secondaryXAxis,
|
|
65
66
|
} = props;
|
|
66
67
|
|
|
67
68
|
const {
|
|
@@ -183,7 +184,12 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
183
184
|
style={[
|
|
184
185
|
styles.leftPart,
|
|
185
186
|
{
|
|
186
|
-
|
|
187
|
+
borderLeftColor: yAxisColor,
|
|
188
|
+
borderRightColor: yAxisColor,
|
|
189
|
+
borderTopColor: secondaryXAxis?.color ?? xAxisColor,
|
|
190
|
+
borderTopWidth: secondaryXAxis
|
|
191
|
+
? secondaryXAxis.thickness ?? xAxisThickness
|
|
192
|
+
: 0,
|
|
187
193
|
backgroundColor: backgroundColor,
|
|
188
194
|
width: (props.width || totalWidth - spacing) + endSpacing,
|
|
189
195
|
},
|
|
@@ -201,10 +207,7 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
201
207
|
) =>
|
|
202
208
|
horizSections.map((sectionItems, index) => {
|
|
203
209
|
let label = getLabelTextsForSecondaryYAxis(sectionItems.value, index);
|
|
204
|
-
if (
|
|
205
|
-
secondaryYAxisConfig.hideOrigin &&
|
|
206
|
-
index === secondaryHorizSections.length - 1
|
|
207
|
-
) {
|
|
210
|
+
if (secondaryYAxisConfig.hideOrigin && index === 0) {
|
|
208
211
|
label = '';
|
|
209
212
|
}
|
|
210
213
|
return (
|
|
@@ -5,7 +5,7 @@ import {renderSpecificVerticalLines} from './renderSpecificVerticalLines';
|
|
|
5
5
|
import {renderDataPoints} from './renderDataPoints';
|
|
6
6
|
import {renderSpecificDataPoints} from './renderSpecificDataPoints';
|
|
7
7
|
|
|
8
|
-
const RenderLineInBarChart = props => {
|
|
8
|
+
const RenderLineInBarChart = (props: any) => {
|
|
9
9
|
const {
|
|
10
10
|
yAxisLabelWidth,
|
|
11
11
|
initialSpacing,
|
|
@@ -4,7 +4,7 @@ import {View} from 'react-native';
|
|
|
4
4
|
import {getXForLineInBar, getYForLineInBar} from 'gifted-charts-core';
|
|
5
5
|
import {Rect, Text as CanvasText, Circle} from 'react-native-svg';
|
|
6
6
|
|
|
7
|
-
export const renderDataPoints = props => {
|
|
7
|
+
export const renderDataPoints = (props: any) => {
|
|
8
8
|
const {
|
|
9
9
|
data,
|
|
10
10
|
lineConfig,
|
|
@@ -22,7 +22,8 @@ export const renderDataPoints = props => {
|
|
|
22
22
|
const currentBarWidth = item.barWidth || barWidth || 30;
|
|
23
23
|
const customDataPoint = item.customDataPoint || lineConfig.customDataPoint;
|
|
24
24
|
const value =
|
|
25
|
-
item.value ??
|
|
25
|
+
item.value ??
|
|
26
|
+
item.stacks.reduce((total: number, item: any) => total + item.value, 0);
|
|
26
27
|
if (customDataPoint) {
|
|
27
28
|
return (
|
|
28
29
|
<View
|
package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import React, {Fragment} from 'react';
|
|
|
2
2
|
import {getXForLineInBar, getYForLineInBar} from 'gifted-charts-core';
|
|
3
3
|
import {Circle, Rect, Text as CanvasText} from 'react-native-svg';
|
|
4
4
|
|
|
5
|
-
export const renderSpecificDataPoints = props => {
|
|
5
|
+
export const renderSpecificDataPoints = (props: any) => {
|
|
6
6
|
const {
|
|
7
7
|
data,
|
|
8
8
|
barWidth,
|
|
@@ -3,7 +3,7 @@ import {View} from 'react-native';
|
|
|
3
3
|
import {chartTypes} from 'gifted-charts-core';
|
|
4
4
|
import {Line, Svg} from 'react-native-svg';
|
|
5
5
|
|
|
6
|
-
const RenderVerticalLines = props => {
|
|
6
|
+
const RenderVerticalLines = (props: any) => {
|
|
7
7
|
const {
|
|
8
8
|
verticalLinesAr,
|
|
9
9
|
verticalLinesSpacing,
|
|
@@ -29,7 +29,7 @@ const RenderVerticalLines = props => {
|
|
|
29
29
|
xAxisLabelsVerticalShift,
|
|
30
30
|
} = props;
|
|
31
31
|
|
|
32
|
-
const getHeightOfVerticalLine = index => {
|
|
32
|
+
const getHeightOfVerticalLine = (index: number) => {
|
|
33
33
|
if (verticalLinesUptoDataPoint) {
|
|
34
34
|
if (index < data.length) {
|
|
35
35
|
return (
|
|
@@ -107,8 +107,8 @@ const RenderVerticalLines = props => {
|
|
|
107
107
|
(chartType === chartTypes.BAR
|
|
108
108
|
? totalSpacing - 1
|
|
109
109
|
: verticalLinesSpacing
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
? verticalLinesSpacing * (index + 1)
|
|
111
|
+
: index * spacing + (initialSpacing - 2));
|
|
112
112
|
|
|
113
113
|
return (
|
|
114
114
|
<Line
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import Svg, {Defs, Rect} from 'react-native-svg';
|
|
3
3
|
|
|
4
|
-
const BarBackgroundPattern = props => {
|
|
4
|
+
const BarBackgroundPattern = (props: any) => {
|
|
5
5
|
const {
|
|
6
6
|
barBackgroundPatternFromItem,
|
|
7
7
|
barBackgroundPatternFromProps,
|
|
@@ -10,20 +10,20 @@ const BarBackgroundPattern = props => {
|
|
|
10
10
|
} = props;
|
|
11
11
|
return (
|
|
12
12
|
<Svg>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
<Defs>
|
|
14
|
+
{barBackgroundPatternFromItem
|
|
15
|
+
? barBackgroundPatternFromItem()
|
|
16
|
+
: barBackgroundPatternFromProps()}
|
|
17
|
+
</Defs>
|
|
18
|
+
<Rect
|
|
19
|
+
stroke="transparent"
|
|
20
|
+
x="1"
|
|
21
|
+
y="1"
|
|
22
|
+
width="100%"
|
|
23
|
+
height="100%"
|
|
24
|
+
fill={`url(#${patternIdFromItem ?? patternIdFromProps})`}
|
|
25
|
+
/>
|
|
26
|
+
</Svg>
|
|
27
27
|
);
|
|
28
28
|
};
|
|
29
29
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React, {useState} from 'react';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
|
+
|
|
4
|
+
interface TooltipProps {
|
|
5
|
+
barHeight: number;
|
|
6
|
+
barWidth: number;
|
|
7
|
+
item: any;
|
|
8
|
+
index: number;
|
|
9
|
+
isLast: boolean;
|
|
10
|
+
leftSpacing: number;
|
|
11
|
+
leftShiftForLastIndexTooltip: number;
|
|
12
|
+
leftShiftForTooltip: number;
|
|
13
|
+
renderTooltip?: Function;
|
|
14
|
+
autoCenterTooltip?: boolean;
|
|
15
|
+
horizontal?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const Tooltip = (props: TooltipProps) => {
|
|
19
|
+
const {
|
|
20
|
+
barHeight,
|
|
21
|
+
barWidth,
|
|
22
|
+
item,
|
|
23
|
+
index,
|
|
24
|
+
isLast,
|
|
25
|
+
leftSpacing,
|
|
26
|
+
leftShiftForLastIndexTooltip,
|
|
27
|
+
leftShiftForTooltip,
|
|
28
|
+
renderTooltip,
|
|
29
|
+
autoCenterTooltip,
|
|
30
|
+
horizontal,
|
|
31
|
+
} = props;
|
|
32
|
+
|
|
33
|
+
const [leftShiftTooltipForCentering, setLeftShiftTooltipForCentering] =
|
|
34
|
+
useState(0);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<View
|
|
38
|
+
style={{
|
|
39
|
+
position: 'absolute',
|
|
40
|
+
bottom: barHeight + 60,
|
|
41
|
+
left:
|
|
42
|
+
leftSpacing -
|
|
43
|
+
(isLast ? leftShiftForLastIndexTooltip : leftShiftForTooltip) -
|
|
44
|
+
leftShiftTooltipForCentering,
|
|
45
|
+
zIndex: 1000,
|
|
46
|
+
transform: [{rotate: horizontal ? '-90deg' : '0deg'}],
|
|
47
|
+
}}
|
|
48
|
+
onLayout={event => {
|
|
49
|
+
if (!autoCenterTooltip) return;
|
|
50
|
+
const {width} = event.nativeEvent.layout;
|
|
51
|
+
const shift = (width - barWidth) / 2;
|
|
52
|
+
if (shift > 0) setLeftShiftTooltipForCentering(shift);
|
|
53
|
+
}}>
|
|
54
|
+
{renderTooltip?.(item, index)}
|
|
55
|
+
</View>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default Tooltip;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {ViewStyle} from "react-native";
|
|
3
2
|
|
|
4
3
|
type LinearGradientProps = {
|
|
5
|
-
style?:
|
|
6
|
-
start?: {
|
|
7
|
-
end?: {
|
|
4
|
+
style?: any;
|
|
5
|
+
start?: {x: number; y: number};
|
|
6
|
+
end?: {x: number; y: number};
|
|
8
7
|
colors: string[];
|
|
9
|
-
|
|
8
|
+
children?: any;
|
|
9
|
+
};
|
|
10
10
|
|
|
11
11
|
let LinearGradient: React.FC<LinearGradientProps>;
|
|
12
12
|
|
|
@@ -19,7 +19,7 @@ try {
|
|
|
19
19
|
LinearGradient = require('expo-linear-gradient').LinearGradient;
|
|
20
20
|
} catch (e) {
|
|
21
21
|
throw new Error(
|
|
22
|
-
'Gradient package was not found. Make sure "react-native-linear-gradient" or "expo-linear-gradient" is installed'
|
|
22
|
+
'Gradient package was not found. Make sure "react-native-linear-gradient" or "expo-linear-gradient" is installed',
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -3,7 +3,7 @@ import {View} from 'react-native';
|
|
|
3
3
|
import Svg, {Line} from 'react-native-svg';
|
|
4
4
|
import {getTopAndLeftForStripAndLabel} from 'gifted-charts-core';
|
|
5
5
|
|
|
6
|
-
export const StripAndLabel = props => {
|
|
6
|
+
export const StripAndLabel = (props: any) => {
|
|
7
7
|
const {
|
|
8
8
|
pointerX,
|
|
9
9
|
pointerLabelWidth,
|
|
@@ -191,7 +191,7 @@ export const LineChartBicolor = (props: LineChartBicolorPropsType) => {
|
|
|
191
191
|
outputRange: [0, totalWidth],
|
|
192
192
|
});
|
|
193
193
|
|
|
194
|
-
const onStripPress = (item, index) => {
|
|
194
|
+
const onStripPress = (item: any, index: number) => {
|
|
195
195
|
setSelectedIndex(index);
|
|
196
196
|
if (props.onFocus) {
|
|
197
197
|
props.onFocus(item, index);
|
|
@@ -199,16 +199,16 @@ export const LineChartBicolor = (props: LineChartBicolorPropsType) => {
|
|
|
199
199
|
};
|
|
200
200
|
|
|
201
201
|
const renderDataPoints = (
|
|
202
|
-
dataForRender,
|
|
203
|
-
dataPtsShape,
|
|
204
|
-
dataPtsWidth,
|
|
205
|
-
dataPtsHeight,
|
|
206
|
-
dataPtsColor,
|
|
207
|
-
dataPtsRadius,
|
|
208
|
-
textColor,
|
|
209
|
-
textFontSize,
|
|
210
|
-
startIndex,
|
|
211
|
-
endIndex,
|
|
202
|
+
dataForRender: any,
|
|
203
|
+
dataPtsShape: any,
|
|
204
|
+
dataPtsWidth: any,
|
|
205
|
+
dataPtsHeight: any,
|
|
206
|
+
dataPtsColor: any,
|
|
207
|
+
dataPtsRadius: any,
|
|
208
|
+
textColor: any,
|
|
209
|
+
textFontSize: any,
|
|
210
|
+
startIndex: number,
|
|
211
|
+
endIndex: number,
|
|
212
212
|
) => {
|
|
213
213
|
return dataForRender.map((item: bicolorLineDataItem, index: number) => {
|
|
214
214
|
if (index < startIndex || index > endIndex) return null;
|
|
@@ -496,7 +496,7 @@ export const LineChartBicolor = (props: LineChartBicolorPropsType) => {
|
|
|
496
496
|
strokeDashArray.length === 2 &&
|
|
497
497
|
typeof strokeDashArray[0] === 'number' &&
|
|
498
498
|
typeof strokeDashArray[1] === 'number'
|
|
499
|
-
? pointsArray.map((points, index) => (
|
|
499
|
+
? pointsArray.map((points: any, index: number) => (
|
|
500
500
|
<Path
|
|
501
501
|
key={index}
|
|
502
502
|
d={points.points}
|
|
@@ -506,7 +506,7 @@ export const LineChartBicolor = (props: LineChartBicolorPropsType) => {
|
|
|
506
506
|
strokeDasharray={strokeDashArray}
|
|
507
507
|
/>
|
|
508
508
|
))
|
|
509
|
-
: pointsArray.map((points, index) => {
|
|
509
|
+
: pointsArray.map((points: any, index: number) => {
|
|
510
510
|
return (
|
|
511
511
|
<Path
|
|
512
512
|
key={index}
|
package/src/LineChart/index.tsx
CHANGED
|
@@ -66,6 +66,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
66
66
|
arrow4Points,
|
|
67
67
|
arrow5Points,
|
|
68
68
|
secondaryArrowPoints,
|
|
69
|
+
pointerIndex,
|
|
69
70
|
setPointerIndex,
|
|
70
71
|
pointerX,
|
|
71
72
|
setPointerX,
|
|
@@ -312,6 +313,8 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
312
313
|
parentWidth: props.parentWidth ?? screenWidth,
|
|
313
314
|
});
|
|
314
315
|
|
|
316
|
+
const {secondaryXAxis} = props;
|
|
317
|
+
|
|
315
318
|
const widthValuesFromSet = useMemo(
|
|
316
319
|
() => dataSet?.map(set => new Animated.Value(0)),
|
|
317
320
|
[],
|
|
@@ -413,10 +416,10 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
413
416
|
useEffect(() => {
|
|
414
417
|
decreaseWidth();
|
|
415
418
|
labelsAppear();
|
|
416
|
-
widthValuesFromSet?.forEach((item, index) => {
|
|
419
|
+
widthValuesFromSet?.forEach((item: any, index: number) => {
|
|
417
420
|
setTimeout(
|
|
418
421
|
() => {
|
|
419
|
-
decreaseWidthsFromSet
|
|
422
|
+
decreaseWidthsFromSet();
|
|
420
423
|
},
|
|
421
424
|
animateTogether ? 0 : animationDuration * index,
|
|
422
425
|
);
|
|
@@ -457,6 +460,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
457
460
|
]);
|
|
458
461
|
|
|
459
462
|
const renderLabel = (
|
|
463
|
+
top: boolean,
|
|
460
464
|
index: number,
|
|
461
465
|
label: String,
|
|
462
466
|
labelTextStyle: any,
|
|
@@ -467,7 +471,11 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
467
471
|
style={[
|
|
468
472
|
{
|
|
469
473
|
position: 'absolute',
|
|
470
|
-
bottom:
|
|
474
|
+
bottom: top
|
|
475
|
+
? containerHeight +
|
|
476
|
+
60 +
|
|
477
|
+
(secondaryXAxis?.labelsDistanceFromXaxis ?? 15)
|
|
478
|
+
: 54 - xAxisTextNumberOfLines * 18,
|
|
471
479
|
zIndex: 10,
|
|
472
480
|
width: spacing + labelsExtraHeight,
|
|
473
481
|
left:
|
|
@@ -484,7 +492,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
484
492
|
<Text
|
|
485
493
|
style={[{textAlign: 'center'}, labelTextStyle]}
|
|
486
494
|
numberOfLines={xAxisTextNumberOfLines}>
|
|
487
|
-
{label
|
|
495
|
+
{label}
|
|
488
496
|
</Text>
|
|
489
497
|
)}
|
|
490
498
|
</View>
|
|
@@ -492,6 +500,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
492
500
|
};
|
|
493
501
|
|
|
494
502
|
const renderAnimatedLabel = (
|
|
503
|
+
top: boolean,
|
|
495
504
|
index: number,
|
|
496
505
|
label: String,
|
|
497
506
|
labelTextStyle: any,
|
|
@@ -505,7 +514,13 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
505
514
|
? 40
|
|
506
515
|
: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
|
|
507
516
|
position: 'absolute',
|
|
508
|
-
bottom:
|
|
517
|
+
bottom: top
|
|
518
|
+
? containerHeight +
|
|
519
|
+
60 +
|
|
520
|
+
(secondaryXAxis?.labelsDistanceFromXaxis ?? 15)
|
|
521
|
+
: rotateLabel
|
|
522
|
+
? 10
|
|
523
|
+
: 54 - xAxisTextNumberOfLines * 18,
|
|
509
524
|
zIndex: 10,
|
|
510
525
|
width: spacing,
|
|
511
526
|
left:
|
|
@@ -522,7 +537,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
522
537
|
<Text
|
|
523
538
|
style={[{textAlign: 'center'}, labelTextStyle]}
|
|
524
539
|
numberOfLines={xAxisTextNumberOfLines}>
|
|
525
|
-
{label
|
|
540
|
+
{label}
|
|
526
541
|
</Text>
|
|
527
542
|
)}
|
|
528
543
|
</Animated.View>
|
|
@@ -554,7 +569,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
554
569
|
outputRange: [0, totalWidth],
|
|
555
570
|
});
|
|
556
571
|
|
|
557
|
-
const onStripPress = (item, index) => {
|
|
572
|
+
const onStripPress = (item: any, index: number) => {
|
|
558
573
|
if (props.focusedDataPointIndex === undefined || !props.onFocus) {
|
|
559
574
|
setSelectedIndex(index);
|
|
560
575
|
}
|
|
@@ -564,20 +579,20 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
564
579
|
};
|
|
565
580
|
|
|
566
581
|
const renderDataPoints = (
|
|
567
|
-
hideDataPoints,
|
|
568
|
-
dataForRender,
|
|
569
|
-
originalDataFromProps,
|
|
570
|
-
dataPtsShape,
|
|
571
|
-
dataPtsWidth,
|
|
572
|
-
dataPtsHeight,
|
|
573
|
-
dataPtsColor,
|
|
574
|
-
dataPtsRadius,
|
|
575
|
-
textColor,
|
|
576
|
-
textFontSize,
|
|
577
|
-
startIndex,
|
|
578
|
-
endIndex,
|
|
579
|
-
isSecondary,
|
|
580
|
-
showValuesAsDataPointsText,
|
|
582
|
+
hideDataPoints: any,
|
|
583
|
+
dataForRender: any,
|
|
584
|
+
originalDataFromProps: any,
|
|
585
|
+
dataPtsShape: any,
|
|
586
|
+
dataPtsWidth: any,
|
|
587
|
+
dataPtsHeight: any,
|
|
588
|
+
dataPtsColor: any,
|
|
589
|
+
dataPtsRadius: any,
|
|
590
|
+
textColor: any,
|
|
591
|
+
textFontSize: any,
|
|
592
|
+
startIndex: any,
|
|
593
|
+
endIndex: any,
|
|
594
|
+
isSecondary: any,
|
|
595
|
+
showValuesAsDataPointsText: any,
|
|
581
596
|
) => {
|
|
582
597
|
const getYOrSecondaryY = isSecondary ? getSecondaryY : getY;
|
|
583
598
|
return dataForRender.map((item: lineDataItem, index: number) => {
|
|
@@ -928,6 +943,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
928
943
|
pointerConfig?.secondaryPointerColor || pointerColor;
|
|
929
944
|
break;
|
|
930
945
|
}
|
|
946
|
+
if (!pointerYLocal) return;
|
|
931
947
|
|
|
932
948
|
return Pointer({
|
|
933
949
|
pointerX,
|
|
@@ -944,26 +960,43 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
944
960
|
const renderStripAndLabel = () => {
|
|
945
961
|
let pointerItemLocal, pointerYLocal;
|
|
946
962
|
|
|
947
|
-
pointerItemLocal = [
|
|
963
|
+
pointerItemLocal = [
|
|
964
|
+
{...pointerItem, value: props.data?.[pointerIndex]?.value},
|
|
965
|
+
];
|
|
948
966
|
let arr = [pointerY];
|
|
949
967
|
if (pointerY2 !== 0) {
|
|
950
968
|
arr.push(pointerY2);
|
|
951
|
-
pointerItemLocal.push(
|
|
969
|
+
pointerItemLocal.push({
|
|
970
|
+
...pointerItem,
|
|
971
|
+
value: props.data2?.[pointerIndex]?.value,
|
|
972
|
+
});
|
|
952
973
|
}
|
|
953
974
|
if (pointerY3 !== 0) {
|
|
954
975
|
arr.push(pointerY3);
|
|
955
|
-
pointerItemLocal.push(
|
|
976
|
+
pointerItemLocal.push({
|
|
977
|
+
...pointerItem,
|
|
978
|
+
value: props.data3?.[pointerIndex]?.value,
|
|
979
|
+
});
|
|
956
980
|
}
|
|
957
981
|
if (pointerY4 !== 0) {
|
|
958
982
|
arr.push(pointerY4);
|
|
959
|
-
pointerItemLocal.push(
|
|
983
|
+
pointerItemLocal.push({
|
|
984
|
+
...pointerItem,
|
|
985
|
+
value: props.data4?.[pointerIndex]?.value,
|
|
986
|
+
});
|
|
960
987
|
}
|
|
961
988
|
if (pointerY5 !== 0) {
|
|
962
989
|
arr.push(pointerY5);
|
|
963
|
-
pointerItemLocal.push(
|
|
990
|
+
pointerItemLocal.push({
|
|
991
|
+
...pointerItem,
|
|
992
|
+
value: props.data5?.[pointerIndex]?.value,
|
|
993
|
+
});
|
|
964
994
|
}
|
|
965
995
|
if (secondaryPointerY !== 0) {
|
|
966
|
-
pointerItemLocal.push(
|
|
996
|
+
pointerItemLocal.push({
|
|
997
|
+
...pointerItem,
|
|
998
|
+
value: props.secondaryData?.[pointerIndex]?.value,
|
|
999
|
+
});
|
|
967
1000
|
}
|
|
968
1001
|
pointerYLocal = Math.min(...arr);
|
|
969
1002
|
|
|
@@ -1051,11 +1084,11 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1051
1084
|
endOpacity: number,
|
|
1052
1085
|
strokeDashArray: Array<number> | undefined | null,
|
|
1053
1086
|
showArrow: boolean,
|
|
1054
|
-
arrowPoints,
|
|
1055
|
-
arrowStrokeWidth,
|
|
1056
|
-
arrowStrokeColor,
|
|
1057
|
-
arrowFillColor,
|
|
1058
|
-
key,
|
|
1087
|
+
arrowPoints: any,
|
|
1088
|
+
arrowStrokeWidth: any,
|
|
1089
|
+
arrowStrokeColor: any,
|
|
1090
|
+
arrowFillColor: any,
|
|
1091
|
+
key: any,
|
|
1059
1092
|
) => {
|
|
1060
1093
|
if (!points) return null;
|
|
1061
1094
|
const isCurved = points.includes('C');
|
|
@@ -1104,7 +1137,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1104
1137
|
lineSvgPropsOuter.strokeDasharray = strokeDashArray;
|
|
1105
1138
|
}
|
|
1106
1139
|
return (
|
|
1107
|
-
<Svg>
|
|
1140
|
+
<Svg onPress={props.onBackgroundPress}>
|
|
1108
1141
|
{lineGradient && getLineGradientComponent()}
|
|
1109
1142
|
{points.includes(SEGMENT_START) || points.includes(RANGE_ENTER) ? (
|
|
1110
1143
|
ar.map((item, index) => {
|
|
@@ -1143,6 +1176,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1143
1176
|
)}
|
|
1144
1177
|
{isNthAreaChart && (
|
|
1145
1178
|
<Path
|
|
1179
|
+
onPress={props.onChartAreaPress}
|
|
1146
1180
|
d={fillPoints}
|
|
1147
1181
|
fill={
|
|
1148
1182
|
props.areaGradientId
|
|
@@ -1293,7 +1327,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1293
1327
|
);
|
|
1294
1328
|
};
|
|
1295
1329
|
|
|
1296
|
-
const activatePointers = x => {
|
|
1330
|
+
const activatePointers = (x: number) => {
|
|
1297
1331
|
let factor = (x - initialSpacing) / spacing;
|
|
1298
1332
|
factor = Math.round(factor);
|
|
1299
1333
|
factor = Math.min(factor, (data0 ?? data).length - 1);
|
|
@@ -1371,6 +1405,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1371
1405
|
(pointerRadius || pointerHeight / 2) +
|
|
1372
1406
|
10;
|
|
1373
1407
|
setSecondaryPointerY(y);
|
|
1408
|
+
// @ts-ignore
|
|
1374
1409
|
setSecondaryPointerItem(item);
|
|
1375
1410
|
}
|
|
1376
1411
|
}
|
|
@@ -1378,11 +1413,12 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1378
1413
|
if (dataSet[0].data[factor]) {
|
|
1379
1414
|
const ysForDataSet = dataSet.map(set => {
|
|
1380
1415
|
const item = set.data[factor];
|
|
1381
|
-
const y =
|
|
1382
|
-
containerHeight -
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1416
|
+
const y = item
|
|
1417
|
+
? containerHeight -
|
|
1418
|
+
(item.value * containerHeight) / maxValue -
|
|
1419
|
+
(pointerRadius || pointerHeight / 2) +
|
|
1420
|
+
10
|
|
1421
|
+
: 0;
|
|
1386
1422
|
return y;
|
|
1387
1423
|
});
|
|
1388
1424
|
setPointerYsForDataSet(ysForDataSet);
|
|
@@ -1401,11 +1437,11 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1401
1437
|
startOpacity: number,
|
|
1402
1438
|
endOpacity: number,
|
|
1403
1439
|
strokeDashArray: Array<number> | undefined | null,
|
|
1404
|
-
showArrow,
|
|
1405
|
-
arrowPoints,
|
|
1406
|
-
arrowStrokeWidth,
|
|
1407
|
-
arrowStrokeColor,
|
|
1408
|
-
arrowFillColor,
|
|
1440
|
+
showArrow: any,
|
|
1441
|
+
arrowPoints: any,
|
|
1442
|
+
arrowStrokeWidth: any,
|
|
1443
|
+
arrowStrokeColor: any,
|
|
1444
|
+
arrowFillColor: any,
|
|
1409
1445
|
key?: number,
|
|
1410
1446
|
) => {
|
|
1411
1447
|
return (
|
|
@@ -1514,6 +1550,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1514
1550
|
(pointerRadius || pointerHeight / 2) +
|
|
1515
1551
|
10;
|
|
1516
1552
|
setSecondaryPointerY(y);
|
|
1553
|
+
// @ts-ignore
|
|
1517
1554
|
setSecondaryPointerItem(item);
|
|
1518
1555
|
}
|
|
1519
1556
|
}
|
|
@@ -1599,11 +1636,11 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1599
1636
|
startOpacity: number,
|
|
1600
1637
|
endOpacity: number,
|
|
1601
1638
|
strokeDashArray: Array<number> | undefined | null,
|
|
1602
|
-
showArrow,
|
|
1603
|
-
arrowPoints,
|
|
1604
|
-
arrowStrokeWidth,
|
|
1605
|
-
arrowStrokeColor,
|
|
1606
|
-
arrowFillColor,
|
|
1639
|
+
showArrow: any,
|
|
1640
|
+
arrowPoints: any,
|
|
1641
|
+
arrowStrokeWidth: any,
|
|
1642
|
+
arrowStrokeColor: any,
|
|
1643
|
+
arrowFillColor: any,
|
|
1607
1644
|
key?: number,
|
|
1608
1645
|
) => {
|
|
1609
1646
|
return (
|
|
@@ -1712,7 +1749,9 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1712
1749
|
(item.value * containerHeight) / secondaryMaxValue -
|
|
1713
1750
|
(pointerRadius || pointerHeight / 2) +
|
|
1714
1751
|
10;
|
|
1752
|
+
|
|
1715
1753
|
setSecondaryPointerY(y);
|
|
1754
|
+
// @ts-ignore
|
|
1716
1755
|
setSecondaryPointerItem(item);
|
|
1717
1756
|
}
|
|
1718
1757
|
}
|
|
@@ -1720,11 +1759,12 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1720
1759
|
if (dataSet[0].data[factor]) {
|
|
1721
1760
|
const ysForDataSet = dataSet.map(set => {
|
|
1722
1761
|
const item = set.data[factor];
|
|
1723
|
-
const y =
|
|
1724
|
-
containerHeight -
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1762
|
+
const y = item
|
|
1763
|
+
? containerHeight -
|
|
1764
|
+
(item.value * containerHeight) / maxValue -
|
|
1765
|
+
(pointerRadius || pointerHeight / 2) +
|
|
1766
|
+
10
|
|
1767
|
+
: 0;
|
|
1728
1768
|
return y;
|
|
1729
1769
|
});
|
|
1730
1770
|
setPointerYsForDataSet(ysForDataSet);
|
|
@@ -2116,10 +2156,18 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2116
2156
|
</View>
|
|
2117
2157
|
) : null}
|
|
2118
2158
|
{(data0 ?? data).map((item: lineDataItem, index: number) => {
|
|
2159
|
+
const secondaryLabel =
|
|
2160
|
+
item.secondaryLabel ?? secondaryXAxis?.labelTexts?.[index] ?? '';
|
|
2161
|
+
const secondaryLabelTextStyle =
|
|
2162
|
+
item.secondaryLabelTextStyle ??
|
|
2163
|
+
secondaryXAxis?.labelsTextStyle ??
|
|
2164
|
+
item.labelTextStyle ??
|
|
2165
|
+
props.xAxisLabelTextStyle;
|
|
2119
2166
|
return (
|
|
2120
2167
|
<View key={index}>
|
|
2121
2168
|
{isAnimated
|
|
2122
2169
|
? renderAnimatedLabel(
|
|
2170
|
+
false,
|
|
2123
2171
|
index,
|
|
2124
2172
|
item.label ||
|
|
2125
2173
|
(props.xAxisLabelTexts && props.xAxisLabelTexts[index]
|
|
@@ -2129,6 +2177,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2129
2177
|
item.labelComponent,
|
|
2130
2178
|
)
|
|
2131
2179
|
: renderLabel(
|
|
2180
|
+
false,
|
|
2132
2181
|
index,
|
|
2133
2182
|
item.label ||
|
|
2134
2183
|
(props.xAxisLabelTexts && props.xAxisLabelTexts[index]
|
|
@@ -2137,7 +2186,23 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2137
2186
|
item.labelTextStyle || props.xAxisLabelTextStyle,
|
|
2138
2187
|
item.labelComponent,
|
|
2139
2188
|
)}
|
|
2140
|
-
{
|
|
2189
|
+
{secondaryXAxis
|
|
2190
|
+
? isAnimated
|
|
2191
|
+
? renderAnimatedLabel(
|
|
2192
|
+
true,
|
|
2193
|
+
index,
|
|
2194
|
+
secondaryLabel,
|
|
2195
|
+
secondaryLabelTextStyle,
|
|
2196
|
+
item.secondaryLabelComponent,
|
|
2197
|
+
)
|
|
2198
|
+
: renderLabel(
|
|
2199
|
+
true,
|
|
2200
|
+
index,
|
|
2201
|
+
secondaryLabel,
|
|
2202
|
+
secondaryLabelTextStyle,
|
|
2203
|
+
item.secondaryLabelComponent,
|
|
2204
|
+
)
|
|
2205
|
+
: null}
|
|
2141
2206
|
</View>
|
|
2142
2207
|
);
|
|
2143
2208
|
})}
|
package/src/PieChart/index.tsx
CHANGED
|
@@ -29,7 +29,10 @@ export const PieChart = (props: PieChartPropsType) => {
|
|
|
29
29
|
paddingVertical,
|
|
30
30
|
} = usePieChart(props);
|
|
31
31
|
|
|
32
|
-
const renderInnerCircle = (
|
|
32
|
+
const renderInnerCircle = (
|
|
33
|
+
innerRadius: number,
|
|
34
|
+
innerCircleBorderWidth: number,
|
|
35
|
+
) => {
|
|
33
36
|
if (props.centerLabelComponent || (donut && !isDataShifted)) {
|
|
34
37
|
return (
|
|
35
38
|
<View
|