react-native-gifted-charts 1.4.21 → 1.4.22
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/dist/BarChart/Animated2DWithGradient.d.ts +3 -0
- package/dist/BarChart/Animated2DWithGradient.js +113 -1
- package/dist/BarChart/RenderBars.d.ts +3 -0
- package/dist/BarChart/RenderBars.js +264 -1
- package/dist/BarChart/RenderStackBars.d.ts +3 -0
- package/dist/BarChart/RenderStackBars.js +172 -1
- package/dist/BarChart/index.d.ts +2 -0
- package/dist/BarChart/index.js +233 -1
- package/dist/BarChart/styles.d.ts +45 -0
- package/dist/BarChart/styles.js +46 -1
- package/dist/Components/AnimatedThreeDBar/index.d.ts +3 -0
- package/dist/Components/AnimatedThreeDBar/index.js +129 -1
- package/dist/Components/AnimatedThreeDBar/styles.d.ts +10 -0
- package/dist/Components/AnimatedThreeDBar/styles.js +13 -1
- package/dist/Components/BarAndLineChartsWrapper/index.d.ts +3 -0
- package/dist/Components/BarAndLineChartsWrapper/index.js +128 -1
- package/dist/Components/BarAndLineChartsWrapper/renderHorizSections.d.ts +2 -0
- package/dist/Components/BarAndLineChartsWrapper/renderHorizSections.js +322 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.d.ts +3 -0
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.js +76 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.d.ts +2 -0
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.js +50 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.d.ts +1 -0
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.js +25 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.d.ts +1 -0
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.js +20 -1
- package/dist/Components/BarAndLineChartsWrapper/renderVerticalLines.d.ts +2 -0
- package/dist/Components/BarAndLineChartsWrapper/renderVerticalLines.js +94 -1
- package/dist/Components/BarSpecificComponents/barBackgroundPattern.d.ts +2 -0
- package/dist/Components/BarSpecificComponents/barBackgroundPattern.js +9 -1
- package/dist/Components/BarSpecificComponents/cap.d.ts +2 -0
- package/dist/Components/BarSpecificComponents/cap.js +16 -1
- package/dist/Components/BarSpecificComponents/tooltip.d.ts +15 -0
- package/dist/Components/BarSpecificComponents/tooltip.js +40 -1
- package/dist/Components/common/LinearGradient.d.ts +16 -0
- package/dist/Components/common/LinearGradient.js +15 -1
- package/dist/Components/common/Pointer.d.ts +1 -0
- package/dist/Components/common/Pointer.js +16 -1
- package/dist/Components/common/StripAndLabel.d.ts +1 -0
- package/dist/Components/common/StripAndLabel.js +43 -1
- package/dist/Components/lineSvg.d.ts +14 -0
- package/dist/Components/lineSvg.js +22 -1
- package/dist/LineChart/LineChartBicolor.d.ts +2 -0
- package/dist/LineChart/LineChartBicolor.js +294 -1
- package/dist/LineChart/index.d.ts +2 -0
- package/dist/LineChart/index.js +1089 -1
- package/dist/LineChart/styles.d.ts +43 -0
- package/dist/LineChart/styles.js +46 -1
- package/dist/PieChart/index.d.ts +2 -0
- package/dist/PieChart/index.js +99 -1
- package/dist/PieChart/main.d.ts +2 -0
- package/dist/PieChart/main.js +182 -1
- package/dist/PieChartPro/index.d.ts +2 -0
- package/dist/PieChartPro/index.js +124 -1
- package/dist/PopulationPyramid/index.d.ts +2 -0
- package/dist/PopulationPyramid/index.js +130 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +12 -1
- package/package.json +3 -3
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const styles: {
|
|
2
|
+
container: {
|
|
3
|
+
width: "100%";
|
|
4
|
+
marginBottom: number;
|
|
5
|
+
marginRight: number;
|
|
6
|
+
};
|
|
7
|
+
horizBar: {
|
|
8
|
+
flexDirection: "row";
|
|
9
|
+
};
|
|
10
|
+
leftLabel: {
|
|
11
|
+
justifyContent: "center";
|
|
12
|
+
alignItems: "center";
|
|
13
|
+
};
|
|
14
|
+
lastLeftLabel: {
|
|
15
|
+
justifyContent: "center";
|
|
16
|
+
alignItems: "center";
|
|
17
|
+
};
|
|
18
|
+
leftPart: {
|
|
19
|
+
justifyContent: "center";
|
|
20
|
+
};
|
|
21
|
+
lastLeftPart: {
|
|
22
|
+
justifyContent: "flex-end";
|
|
23
|
+
};
|
|
24
|
+
line: {
|
|
25
|
+
width: "100%";
|
|
26
|
+
height: number;
|
|
27
|
+
backgroundColor: string;
|
|
28
|
+
opacity: number;
|
|
29
|
+
};
|
|
30
|
+
lastLine: {
|
|
31
|
+
width: "100%";
|
|
32
|
+
height: number;
|
|
33
|
+
backgroundColor: string;
|
|
34
|
+
};
|
|
35
|
+
bottomLabel: {
|
|
36
|
+
width: "100%";
|
|
37
|
+
};
|
|
38
|
+
customDataPointContainer: {
|
|
39
|
+
position: "absolute";
|
|
40
|
+
justifyContent: "center";
|
|
41
|
+
alignItems: "center";
|
|
42
|
+
};
|
|
43
|
+
};
|
package/dist/LineChart/styles.js
CHANGED
|
@@ -1 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
export var styles = StyleSheet.create({
|
|
3
|
+
container: {
|
|
4
|
+
width: '100%',
|
|
5
|
+
marginBottom: 40,
|
|
6
|
+
marginRight: 40,
|
|
7
|
+
},
|
|
8
|
+
horizBar: {
|
|
9
|
+
flexDirection: 'row',
|
|
10
|
+
},
|
|
11
|
+
leftLabel: {
|
|
12
|
+
justifyContent: 'center',
|
|
13
|
+
alignItems: 'center',
|
|
14
|
+
},
|
|
15
|
+
lastLeftLabel: {
|
|
16
|
+
justifyContent: 'center',
|
|
17
|
+
alignItems: 'center',
|
|
18
|
+
},
|
|
19
|
+
leftPart: {
|
|
20
|
+
justifyContent: 'center',
|
|
21
|
+
// width: '100%',
|
|
22
|
+
},
|
|
23
|
+
lastLeftPart: {
|
|
24
|
+
justifyContent: 'flex-end',
|
|
25
|
+
// width: '100%',
|
|
26
|
+
},
|
|
27
|
+
line: {
|
|
28
|
+
width: '100%',
|
|
29
|
+
height: 1,
|
|
30
|
+
backgroundColor: 'gray',
|
|
31
|
+
opacity: 0.5,
|
|
32
|
+
},
|
|
33
|
+
lastLine: {
|
|
34
|
+
width: '100%',
|
|
35
|
+
height: 1,
|
|
36
|
+
backgroundColor: 'black',
|
|
37
|
+
},
|
|
38
|
+
bottomLabel: {
|
|
39
|
+
width: '100%',
|
|
40
|
+
},
|
|
41
|
+
customDataPointContainer: {
|
|
42
|
+
position: 'absolute',
|
|
43
|
+
justifyContent: 'center',
|
|
44
|
+
alignItems: 'center',
|
|
45
|
+
},
|
|
46
|
+
});
|
package/dist/PieChart/index.js
CHANGED
|
@@ -1 +1,99 @@
|
|
|
1
|
-
var
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { View } from 'react-native';
|
|
14
|
+
import { PieChartMain } from './main';
|
|
15
|
+
import { pieColors, usePieChart } from 'gifted-charts-core';
|
|
16
|
+
export var PieChart = function (props) {
|
|
17
|
+
var _a = usePieChart(props), radius = _a.radius, extraRadiusForFocused = _a.extraRadiusForFocused, selectedIndex = _a.selectedIndex, setSelectedIndex = _a.setSelectedIndex, startAngle = _a.startAngle, total = _a.total, donut = _a.donut, isThreeD = _a.isThreeD, semiCircle = _a.semiCircle, inwardExtraLengthForFocused = _a.inwardExtraLengthForFocused, canvasWidth = _a.canvasWidth, canvasHeight = _a.canvasHeight, innerRadius = _a.innerRadius, innerCircleColor = _a.innerCircleColor, innerCircleBorderWidth = _a.innerCircleBorderWidth, innerCircleBorderColor = _a.innerCircleBorderColor, shiftInnerCenterX = _a.shiftInnerCenterX, shiftInnerCenterY = _a.shiftInnerCenterY, tiltAngle = _a.tiltAngle, isDataShifted = _a.isDataShifted, paddingHorizontal = _a.paddingHorizontal, paddingVertical = _a.paddingVertical;
|
|
18
|
+
var renderInnerCircle = function (innerRadius, innerCircleBorderWidth) {
|
|
19
|
+
if (props.centerLabelComponent || (donut && !isDataShifted)) {
|
|
20
|
+
return (_jsx(View, { style: [
|
|
21
|
+
{
|
|
22
|
+
height: innerRadius * 2,
|
|
23
|
+
width: innerRadius * 2,
|
|
24
|
+
borderRadius: innerRadius,
|
|
25
|
+
position: 'absolute',
|
|
26
|
+
// zIndex: 100,
|
|
27
|
+
alignSelf: 'center',
|
|
28
|
+
backgroundColor: innerCircleColor,
|
|
29
|
+
left: canvasWidth / 2 -
|
|
30
|
+
innerRadius +
|
|
31
|
+
shiftInnerCenterX +
|
|
32
|
+
extraRadiusForFocused +
|
|
33
|
+
paddingHorizontal / 2,
|
|
34
|
+
top: canvasHeight / 2 -
|
|
35
|
+
innerRadius +
|
|
36
|
+
shiftInnerCenterY +
|
|
37
|
+
extraRadiusForFocused +
|
|
38
|
+
paddingVertical / 2,
|
|
39
|
+
borderWidth: innerCircleBorderWidth,
|
|
40
|
+
borderColor: innerCircleBorderColor,
|
|
41
|
+
justifyContent: 'center',
|
|
42
|
+
alignItems: 'center',
|
|
43
|
+
},
|
|
44
|
+
isThreeD && {
|
|
45
|
+
borderTopWidth: innerCircleBorderWidth * 5,
|
|
46
|
+
borderLeftWidth: shiftInnerCenterX
|
|
47
|
+
? innerCircleBorderWidth * 2
|
|
48
|
+
: innerCircleBorderWidth,
|
|
49
|
+
transform: [{ rotateX: tiltAngle }],
|
|
50
|
+
},
|
|
51
|
+
semiCircle &&
|
|
52
|
+
isThreeD && {
|
|
53
|
+
borderTopWidth: isThreeD
|
|
54
|
+
? innerCircleBorderWidth * 5
|
|
55
|
+
: innerCircleBorderWidth,
|
|
56
|
+
borderLeftWidth: 0.5,
|
|
57
|
+
borderLeftColor: innerCircleColor,
|
|
58
|
+
borderBottomWidth: 0,
|
|
59
|
+
borderRightWidth: 0.5,
|
|
60
|
+
borderRightColor: innerCircleColor,
|
|
61
|
+
},
|
|
62
|
+
], children: _jsx(View, { style: { marginTop: semiCircle ? -0.5 * innerRadius : 0 }, children: props.centerLabelComponent ? props.centerLabelComponent() : null }) }));
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
};
|
|
66
|
+
if (!total)
|
|
67
|
+
return null;
|
|
68
|
+
return (_jsxs(View, { style: {
|
|
69
|
+
height: (radius + extraRadiusForFocused + paddingVertical / 2) *
|
|
70
|
+
(props.semiCircle ? 1 : 2),
|
|
71
|
+
width: (radius + extraRadiusForFocused + paddingHorizontal / 2) * 2,
|
|
72
|
+
overflow: 'hidden',
|
|
73
|
+
}, children: [_jsx(View, { style: { position: 'absolute' }, children: _jsx(PieChartMain, __assign({}, props, { selectedIndex: selectedIndex, setSelectedIndex: setSelectedIndex, paddingHorizontal: paddingHorizontal, paddingVertical: paddingVertical, extraRadiusForFocused: extraRadiusForFocused })) }), renderInnerCircle(innerRadius, innerCircleBorderWidth), props.data.length > 1 &&
|
|
74
|
+
props.data[selectedIndex] && // don't forget to add this one so there are no errors when the data is empty / updating
|
|
75
|
+
(props.focusOnPress || props.sectionAutoFocus) &&
|
|
76
|
+
selectedIndex !== -1 && (_jsx(View, { pointerEvents: "box-none", style: {
|
|
77
|
+
position: 'absolute',
|
|
78
|
+
top: -extraRadiusForFocused,
|
|
79
|
+
left: -extraRadiusForFocused,
|
|
80
|
+
}, children: _jsx(PieChartMain, __assign({}, props, { data: [
|
|
81
|
+
{
|
|
82
|
+
value: props.data[selectedIndex].value,
|
|
83
|
+
text: props.data[selectedIndex].text,
|
|
84
|
+
color: props.data[selectedIndex].color ||
|
|
85
|
+
pieColors[selectedIndex % 9],
|
|
86
|
+
strokeColor: props.data[selectedIndex].strokeColor || undefined,
|
|
87
|
+
strokeWidth: props.data[selectedIndex].strokeWidth || undefined,
|
|
88
|
+
gradientCenterColor: props.data[selectedIndex].gradientCenterColor || undefined,
|
|
89
|
+
shiftTextX: props.data[selectedIndex].shiftTextX || undefined,
|
|
90
|
+
shiftTextY: props.data[selectedIndex].shiftTextY || undefined,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
value: total - props.data[selectedIndex].value,
|
|
94
|
+
onPress: function () { return alert('black'); },
|
|
95
|
+
peripheral: true,
|
|
96
|
+
strokeWidth: 0,
|
|
97
|
+
},
|
|
98
|
+
], radius: radius + extraRadiusForFocused, initialAngle: startAngle, innerRadius: props.innerRadius || radius / 2.5, isBiggerPie: true, setSelectedIndex: setSelectedIndex, paddingHorizontal: paddingHorizontal, paddingVertical: paddingVertical, extraRadiusForFocused: extraRadiusForFocused })) })), renderInnerCircle(innerRadius - inwardExtraLengthForFocused, inwardExtraLengthForFocused ? 0 : innerCircleBorderWidth)] }));
|
|
99
|
+
};
|
package/dist/PieChart/main.js
CHANGED
|
@@ -1 +1,182 @@
|
|
|
1
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import Svg, { Path, Circle, Text as SvgText, Defs, RadialGradient, Stop, G, } from 'react-native-svg';
|
|
5
|
+
import { getPieChartMainProps, pieColors, } from 'gifted-charts-core';
|
|
6
|
+
import { rnVersion } from '../utils';
|
|
7
|
+
export var PieChartMain = function (props) {
|
|
8
|
+
var _a = getPieChartMainProps(props), isThreeD = _a.isThreeD, isBiggerPie = _a.isBiggerPie, data = _a.data, showInnerComponent = _a.showInnerComponent, radius = _a.radius, canvasWidth = _a.canvasWidth, canvasHeight = _a.canvasHeight, shadowWidth = _a.shadowWidth, backgroundColor = _a.backgroundColor, shadowColor = _a.shadowColor, semiCircle = _a.semiCircle, pi = _a.pi, initialAngle = _a.initialAngle, shadow = _a.shadow, donut = _a.donut, strokeWidth = _a.strokeWidth, strokeColor = _a.strokeColor, innerRadius = _a.innerRadius, showText = _a.showText, textColor = _a.textColor, textSize = _a.textSize, tiltAngle = _a.tiltAngle, labelsPosition = _a.labelsPosition, showTextBackground = _a.showTextBackground, textBackgroundColor = _a.textBackgroundColor, showValuesAsLabels = _a.showValuesAsLabels, showGradient = _a.showGradient, gradientCenterColor = _a.gradientCenterColor, toggleFocusOnPress = _a.toggleFocusOnPress, minShiftX = _a.minShiftX, minShiftY = _a.minShiftY, total = _a.total, horizAdjustment = _a.horizAdjustment, vertAdjustment = _a.vertAdjustment, cx = _a.cx, cy = _a.cy, pData = _a.pData, mData = _a.mData, paddingHorizontal = _a.paddingHorizontal, paddingVertical = _a.paddingVertical, extraRadiusForFocused = _a.extraRadiusForFocused;
|
|
9
|
+
return (_jsxs(View, { pointerEvents: "box-none", style: [
|
|
10
|
+
{
|
|
11
|
+
backgroundColor: backgroundColor,
|
|
12
|
+
height: semiCircle
|
|
13
|
+
? (canvasHeight + paddingVertical) / 2 + extraRadiusForFocused
|
|
14
|
+
: canvasHeight + paddingVertical + extraRadiusForFocused * 2,
|
|
15
|
+
width: canvasWidth + paddingHorizontal + extraRadiusForFocused * 2,
|
|
16
|
+
overflow: 'hidden',
|
|
17
|
+
},
|
|
18
|
+
isThreeD && { transform: [{ rotateX: tiltAngle }] },
|
|
19
|
+
], children: [_jsxs(Svg, { pointerEvents: rnVersion >= 720000 ? 'box-none' : 'auto', viewBox: "".concat(strokeWidth / -2 + minShiftX - extraRadiusForFocused - paddingHorizontal / 2, " ").concat(strokeWidth / -2 +
|
|
20
|
+
minShiftY -
|
|
21
|
+
extraRadiusForFocused -
|
|
22
|
+
paddingVertical / 2, " ").concat((radius + extraRadiusForFocused + strokeWidth) * 2 +
|
|
23
|
+
paddingHorizontal +
|
|
24
|
+
horizAdjustment +
|
|
25
|
+
(horizAdjustment ? strokeWidth : 0), " ").concat((radius + extraRadiusForFocused + strokeWidth) * 2 +
|
|
26
|
+
paddingVertical +
|
|
27
|
+
vertAdjustment +
|
|
28
|
+
(vertAdjustment ? strokeWidth : 0)), height: (radius + extraRadiusForFocused) * 2 + strokeWidth + paddingVertical, width: (radius + extraRadiusForFocused) * 2 + strokeWidth + paddingHorizontal, children: [_jsx(Defs, { children: data.map(function (item, index) {
|
|
29
|
+
return (_jsxs(RadialGradient, { id: 'grad' + index, cx: "50%", cy: "50%", rx: "50%", ry: "50%", fx: "50%", fy: "50%", gradientUnits: "userSpaceOnUse", children: [_jsx(Stop, { offset: "0%", stopColor: item.gradientCenterColor || gradientCenterColor, stopOpacity: "1" }), _jsx(Stop, { offset: "100%", stopColor: item.color || pieColors[index % 9], stopOpacity: "1" })] }, index + ''));
|
|
30
|
+
}) }), data.length === 1 ? (_jsx(_Fragment, { children: _jsx(Circle, { cx: cx, cy: cy, r: radius, fill: showGradient
|
|
31
|
+
? "url(#grad".concat(0, ")")
|
|
32
|
+
: data[0].color || pieColors[0 % 9], onPress: function () {
|
|
33
|
+
data[0].onPress
|
|
34
|
+
? data[0].onPress()
|
|
35
|
+
: props.onPress
|
|
36
|
+
? props.onPress(data[0], 0)
|
|
37
|
+
: null;
|
|
38
|
+
} }) })) : (data.map(function (item, index) {
|
|
39
|
+
// console.log('index', index);
|
|
40
|
+
var nextItem;
|
|
41
|
+
if (index === pData.length - 1)
|
|
42
|
+
nextItem = pData[0];
|
|
43
|
+
else
|
|
44
|
+
nextItem = pData[index + 1];
|
|
45
|
+
var sx = cx * (1 + Math.sin(2 * pi * pData[index] + initialAngle)) +
|
|
46
|
+
(item.shiftX || 0);
|
|
47
|
+
var sy = cy * (1 - Math.cos(2 * pi * pData[index] + initialAngle)) +
|
|
48
|
+
(item.shiftY || 0);
|
|
49
|
+
var ax = cx * (1 + Math.sin(2 * pi * nextItem + initialAngle)) +
|
|
50
|
+
(item.shiftX || 0);
|
|
51
|
+
var ay = cy * (1 - Math.cos(2 * pi * nextItem + initialAngle)) +
|
|
52
|
+
(item.shiftY || 0);
|
|
53
|
+
if (isBiggerPie && index)
|
|
54
|
+
return null;
|
|
55
|
+
return (_jsx(Path, { d: "M ".concat(cx + (item.shiftX || 0), " ").concat(cy + (item.shiftY || 0), " L ").concat(sx, " ").concat(sy, " A ").concat(radius, " ").concat(radius, " 0 ").concat(semiCircle ? 0 : data[index].value > total / 2 ? 1 : 0, " 1 ").concat(ax, " ").concat(ay, " L ").concat(cx + (item.shiftX || 0), " ").concat(cy + (item.shiftY || 0)), stroke: item.strokeColor || strokeColor, strokeWidth: props.focusOnPress && props.selectedIndex === index
|
|
56
|
+
? 0
|
|
57
|
+
: item.strokeWidth === 0
|
|
58
|
+
? 0
|
|
59
|
+
: item.strokeWidth || strokeWidth, fill: props.selectedIndex === index || item.peripheral
|
|
60
|
+
? 'transparent'
|
|
61
|
+
: showGradient
|
|
62
|
+
? "url(#grad".concat(index, ")")
|
|
63
|
+
: item.color || pieColors[index % 9], onPress: function () {
|
|
64
|
+
if (item.onPress) {
|
|
65
|
+
item.onPress();
|
|
66
|
+
}
|
|
67
|
+
else if (props.onPress) {
|
|
68
|
+
props.onPress(item, index);
|
|
69
|
+
}
|
|
70
|
+
if (props.focusOnPress) {
|
|
71
|
+
if (props.selectedIndex === index || props.isBiggerPie) {
|
|
72
|
+
if (toggleFocusOnPress) {
|
|
73
|
+
props.setSelectedIndex(-1);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
props.setSelectedIndex(index);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} }, index + 'a'));
|
|
81
|
+
})), (showText || showInnerComponent) &&
|
|
82
|
+
data.map(function (item, index) {
|
|
83
|
+
var _a, _b, _c, _d, _e, _f;
|
|
84
|
+
var localPieInnerComponent = (_a = item.pieInnerComponent) !== null && _a !== void 0 ? _a : props.pieInnerComponent;
|
|
85
|
+
if (isBiggerPie && index)
|
|
86
|
+
return null;
|
|
87
|
+
if (!props.data[index].value)
|
|
88
|
+
return null;
|
|
89
|
+
var mx = cx * (1 + Math.sin(2 * pi * mData[index] + initialAngle));
|
|
90
|
+
var my = cy * (1 - Math.cos(2 * pi * mData[index] + initialAngle));
|
|
91
|
+
var midx = (mx + cx) / 2;
|
|
92
|
+
var midy = (my + cy) / 2;
|
|
93
|
+
var x = midx, y = midy;
|
|
94
|
+
var labelPosition = item.labelPosition || labelsPosition;
|
|
95
|
+
if (labelPosition === 'onBorder') {
|
|
96
|
+
x = mx;
|
|
97
|
+
y = my;
|
|
98
|
+
}
|
|
99
|
+
else if (labelPosition === 'outward') {
|
|
100
|
+
x = (midx + mx) / 2;
|
|
101
|
+
y = (midy + my) / 2;
|
|
102
|
+
}
|
|
103
|
+
else if (labelPosition === 'inward') {
|
|
104
|
+
x = (midx + cx) / 2;
|
|
105
|
+
y = (midy + cy) / 2;
|
|
106
|
+
}
|
|
107
|
+
x += item.shiftX || 0;
|
|
108
|
+
y += item.shiftY || 0;
|
|
109
|
+
if (data.length === 1) {
|
|
110
|
+
if (donut) {
|
|
111
|
+
y =
|
|
112
|
+
(radius -
|
|
113
|
+
innerRadius +
|
|
114
|
+
(item.textBackgroundRadius ||
|
|
115
|
+
props.textBackgroundRadius ||
|
|
116
|
+
item.textSize ||
|
|
117
|
+
textSize)) /
|
|
118
|
+
2;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
y = cy;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return (_jsxs(React.Fragment, { children: [showTextBackground ? (_jsx(Circle, { cx: x + ((_c = (_b = item.shiftTextBackgroundX) !== null && _b !== void 0 ? _b : item.shiftTextX) !== null && _c !== void 0 ? _c : 0), cy: y +
|
|
125
|
+
((_e = (_d = item.shiftTextBackgroundY) !== null && _d !== void 0 ? _d : item.shiftTextY) !== null && _e !== void 0 ? _e : 0) -
|
|
126
|
+
(item.textSize || textSize) / 4, r: item.textBackgroundRadius ||
|
|
127
|
+
props.textBackgroundRadius ||
|
|
128
|
+
item.textSize ||
|
|
129
|
+
textSize, fill: item.textBackgroundColor || textBackgroundColor, onPress: function () {
|
|
130
|
+
item.onLabelPress
|
|
131
|
+
? item.onLabelPress()
|
|
132
|
+
: props.onLabelPress
|
|
133
|
+
? props.onLabelPress(item, index)
|
|
134
|
+
: item.onPress
|
|
135
|
+
? item.onPress()
|
|
136
|
+
: props.onPress
|
|
137
|
+
? props.onPress(item, index)
|
|
138
|
+
: null;
|
|
139
|
+
if (props.focusOnPress) {
|
|
140
|
+
if (props.selectedIndex === index) {
|
|
141
|
+
if (toggleFocusOnPress) {
|
|
142
|
+
props.setSelectedIndex(-1);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
props.setSelectedIndex(index);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
} })) : null, _jsx(SvgText, { fill: item.textColor || textColor || pieColors[(index + 2) % 9], fontSize: item.textSize || textSize, fontFamily: item.font || props.font, fontWeight: item.fontWeight || props.fontWeight, fontStyle: item.fontStyle || props.fontStyle || 'normal', x: x +
|
|
150
|
+
(item.shiftTextX || 0) -
|
|
151
|
+
(item.textSize || textSize) / 1.8, y: y + (item.shiftTextY || 0), onPress: function () {
|
|
152
|
+
item.onLabelPress
|
|
153
|
+
? item.onLabelPress()
|
|
154
|
+
: props.onLabelPress
|
|
155
|
+
? props.onLabelPress(item, index)
|
|
156
|
+
: item.onPress
|
|
157
|
+
? item.onPress()
|
|
158
|
+
: props.onPress
|
|
159
|
+
? props.onPress(item, index)
|
|
160
|
+
: null;
|
|
161
|
+
if (props.focusOnPress) {
|
|
162
|
+
if (props.selectedIndex === index) {
|
|
163
|
+
if (toggleFocusOnPress) {
|
|
164
|
+
props.setSelectedIndex(-1);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
props.setSelectedIndex(index);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}, children: item.text || (showValuesAsLabels ? item.value + '' : '') }), localPieInnerComponent ? (_jsx(G, { x: x, y: y, children: (_f = localPieInnerComponent === null || localPieInnerComponent === void 0 ? void 0 : localPieInnerComponent(item, index)) !== null && _f !== void 0 ? _f : null })) : null] }, index));
|
|
172
|
+
})] }), isThreeD && shadow && !semiCircle ? (_jsx(View, { style: {
|
|
173
|
+
width: radius * 2,
|
|
174
|
+
height: radius * 2,
|
|
175
|
+
backgroundColor: shadowColor,
|
|
176
|
+
borderRadius: radius,
|
|
177
|
+
position: 'absolute',
|
|
178
|
+
top: shadowWidth + paddingVertical / 2,
|
|
179
|
+
left: paddingHorizontal / 2,
|
|
180
|
+
zIndex: -1,
|
|
181
|
+
} })) : null] }));
|
|
182
|
+
};
|
|
@@ -1 +1,124 @@
|
|
|
1
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import { useEffect } from 'react';
|
|
14
|
+
import { pieColors, usePiePro, } from 'gifted-charts-core';
|
|
15
|
+
import { Defs, Path, Stop, Svg, Text as SvgText, RadialGradient, } from 'react-native-svg';
|
|
16
|
+
import { Animated, View } from 'react-native';
|
|
17
|
+
export var PieChartPro = function (props) {
|
|
18
|
+
var _a = usePiePro(props), radius = _a.radius, total = _a.total, donut = _a.donut, strokeWidth = _a.strokeWidth, maxStrokeWidth = _a.maxStrokeWidth, animationDuration = _a.animationDuration, initial = _a.initial, dInitial = _a.dInitial, dFinal = _a.dFinal, getStartCaps = _a.getStartCaps, getEndCaps = _a.getEndCaps, getTextCoordinates = _a.getTextCoordinates, height = _a.height, heightFactor = _a.heightFactor, svgProps = _a.svgProps;
|
|
19
|
+
var data = props.data, curvedStartEdges = props.curvedStartEdges, curvedEndEdges = props.curvedEndEdges, _b = props.edgesRadius, edgesRadius = _b === void 0 ? 0 : _b, showGradient = props.showGradient, ring = props.ring, centerLabelComponent = props.centerLabelComponent, strokeDashArray = props.strokeDashArray, semiCircle = props.semiCircle;
|
|
20
|
+
var isAnimated = props.isAnimated;
|
|
21
|
+
if (!props.semiCircle && data.some(function (dataItem) { return dataItem.value > total / 2; })) {
|
|
22
|
+
// if we have an obtuse arc, we cant animate
|
|
23
|
+
isAnimated = false;
|
|
24
|
+
}
|
|
25
|
+
var AnimatedPath = Animated.createAnimatedComponent(Path);
|
|
26
|
+
var AnimatedText = Animated.createAnimatedComponent(SvgText);
|
|
27
|
+
var animatedValues = data.map(function (i) { return new Animated.Value(0); });
|
|
28
|
+
var animatedOpacityValue = new Animated.Value(0);
|
|
29
|
+
var animatedPaths = data.map(function (item, index) {
|
|
30
|
+
var _a;
|
|
31
|
+
return (_a = animatedValues[index]) === null || _a === void 0 ? void 0 : _a.interpolate({
|
|
32
|
+
inputRange: [0, 1],
|
|
33
|
+
outputRange: [dInitial[index], dFinal[index]],
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
var animatedOpacity = animatedOpacityValue.interpolate({
|
|
37
|
+
inputRange: [0, 1],
|
|
38
|
+
outputRange: [0, 1],
|
|
39
|
+
});
|
|
40
|
+
useEffect(function () {
|
|
41
|
+
Animated.timing(animatedOpacityValue, {
|
|
42
|
+
toValue: 1,
|
|
43
|
+
duration: 10,
|
|
44
|
+
useNativeDriver: true,
|
|
45
|
+
delay: animationDuration,
|
|
46
|
+
}).start();
|
|
47
|
+
animatedValues.forEach(function (animatedValue) {
|
|
48
|
+
return Animated.timing(animatedValue, {
|
|
49
|
+
toValue: 1,
|
|
50
|
+
duration: animationDuration,
|
|
51
|
+
useNativeDriver: true,
|
|
52
|
+
}).start();
|
|
53
|
+
});
|
|
54
|
+
}, [data]);
|
|
55
|
+
var adjustHeight = height * heightFactor;
|
|
56
|
+
var rnSvgProps = semiCircle ? {} : svgProps;
|
|
57
|
+
return (_jsxs(View, { style: {
|
|
58
|
+
display: 'flex',
|
|
59
|
+
justifyContent: 'center',
|
|
60
|
+
alignItems: 'center',
|
|
61
|
+
height: adjustHeight,
|
|
62
|
+
width: height * 2,
|
|
63
|
+
}, children: [_jsx(View, { style: semiCircle
|
|
64
|
+
? { position: 'absolute', bottom: 0 }
|
|
65
|
+
: { position: 'absolute' }, children: centerLabelComponent ? centerLabelComponent() : null }), _jsx(Svg, __assign({}, rnSvgProps, { viewBox: semiCircle
|
|
66
|
+
? ""
|
|
67
|
+
: "".concat(-maxStrokeWidth * 1.5, " ").concat(-maxStrokeWidth - (semiCircle ? height / 2 : 0), " ").concat(adjustHeight, " ").concat(adjustHeight), transform: semiCircle
|
|
68
|
+
? []
|
|
69
|
+
: [{ scaleY: maxStrokeWidth ? 1 + maxStrokeWidth / (radius * 2) : 1 }], children: total ? (_jsxs(_Fragment, { children: [_jsx(Defs, { children: data.map(function (item, index) {
|
|
70
|
+
return (_jsxs(RadialGradient, { id: 'grad' + index, cx: "50%", cy: "50%", rx: "50%", ry: "50%", fx: "50%", fy: "50%", gradientUnits: "userSpaceOnUse", children: [_jsx(Stop, { offset: "0%", stopColor: item.gradientCenterColor, stopOpacity: "1" }), _jsx(Stop, { offset: "100%", stopColor: item.color || pieColors[index % 9], stopOpacity: "1" })] }, index + ''));
|
|
71
|
+
}) }), data.map(function (item, index) {
|
|
72
|
+
var _a, _b, _c, _d;
|
|
73
|
+
var borderWidth = (_a = item.strokeWidth) !== null && _a !== void 0 ? _a : strokeWidth;
|
|
74
|
+
var borderColor = (_c = (_b = item.strokeColor) !== null && _b !== void 0 ? _b : props.strokeColor) !== null && _c !== void 0 ? _c : (borderWidth ? 'black' : 'transparent');
|
|
75
|
+
var strokeDashArrayLocal = (_d = item.strokeDashArray) !== null && _d !== void 0 ? _d : strokeDashArray;
|
|
76
|
+
return (_jsx(AnimatedPath, { id: "renderPath", d: isAnimated ? animatedPaths[index] : dFinal[index], fill: ring
|
|
77
|
+
? 'transparent'
|
|
78
|
+
: showGradient
|
|
79
|
+
? "url(#grad".concat(index, ")")
|
|
80
|
+
: data[index].color || pieColors[index % 9], strokeWidth: borderWidth, strokeDasharray: strokeDashArrayLocal, stroke: borderColor }, "path".concat(index)));
|
|
81
|
+
}), donut
|
|
82
|
+
? data.map(function (item, index) {
|
|
83
|
+
if (curvedStartEdges ||
|
|
84
|
+
edgesRadius ||
|
|
85
|
+
item.isStartEdgeCurved ||
|
|
86
|
+
item.startEdgeRadius)
|
|
87
|
+
return (_jsx(AnimatedPath, { d: "".concat(initial, " ").concat(getStartCaps(index, item)), opacity: isAnimated ? animatedOpacity : 1, fill: showGradient
|
|
88
|
+
? "url(#grad".concat(index, ")")
|
|
89
|
+
: data[index].color || pieColors[index % 9] }, "cap".concat(index)));
|
|
90
|
+
return null;
|
|
91
|
+
})
|
|
92
|
+
: null, donut
|
|
93
|
+
? data.map(function (item, index) {
|
|
94
|
+
if (curvedEndEdges ||
|
|
95
|
+
edgesRadius ||
|
|
96
|
+
item.isEndEdgeCurved ||
|
|
97
|
+
item.endEdgeRadius)
|
|
98
|
+
return (_jsx(Path, { d: "".concat(initial, " ").concat(getEndCaps(index, item)), fill: showGradient
|
|
99
|
+
? "url(#grad".concat(index, ")")
|
|
100
|
+
: data[index].color || pieColors[index % 9] }, "cap".concat(index)));
|
|
101
|
+
return null;
|
|
102
|
+
})
|
|
103
|
+
: null, data.map(function (item, index) {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
var _c = getTextCoordinates(index, item.labelPosition), x = _c.x, y = _c.y;
|
|
106
|
+
return (_jsx(AnimatedText, {
|
|
107
|
+
// style={{ pointerEvents: 'all' }}
|
|
108
|
+
fill: item.textColor ||
|
|
109
|
+
props.textColor ||
|
|
110
|
+
pieColors[(index + 2) % 9], opacity: isAnimated ? animatedOpacity : 1, fontSize: item.textSize || props.textSize, fontFamily: item.font || props.font, fontWeight: item.fontWeight || props.fontWeight, fontStyle: item.fontStyle || props.fontStyle || 'normal', x: x +
|
|
111
|
+
(item.shiftTextX || 0) -
|
|
112
|
+
((_b = (_a = item.textSize) !== null && _a !== void 0 ? _a : props.textSize) !== null && _b !== void 0 ? _b : 0) / 1.8, y: y + (item.shiftTextY || 0), onPress: function () {
|
|
113
|
+
var _a;
|
|
114
|
+
item.onLabelPress
|
|
115
|
+
? item.onLabelPress()
|
|
116
|
+
: props.onLabelPress
|
|
117
|
+
? props.onLabelPress(item, index)
|
|
118
|
+
: item.onPress
|
|
119
|
+
? item.onPress()
|
|
120
|
+
: (_a = props.onPress) === null || _a === void 0 ? void 0 : _a.call(props, item, index);
|
|
121
|
+
}, children: item.text ||
|
|
122
|
+
(props.showValuesAsLabels ? item.value + '' : '') }, "label".concat(index)));
|
|
123
|
+
})] })) : null }))] }));
|
|
124
|
+
};
|