gifted-charts-core 0.1.11 → 0.1.12
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/LineChart/index.ts +2 -0
- package/src/PieChart/index.js +23 -19
- package/src/PieChart/index.ts +7 -1
- package/src/PieChart/types.d.ts +1 -0
- package/src/PieChart/types.ts +1 -0
- package/src/utils/index.js +2 -1
- package/src/utils/index.ts +2 -1
package/package.json
CHANGED
package/src/LineChart/index.ts
CHANGED
|
@@ -469,6 +469,8 @@ export const useLineChart = (props: extendedLineChartPropsType) => {
|
|
|
469
469
|
if (animateOnDataChange && animations) {
|
|
470
470
|
animations.forEach((item, index) => {
|
|
471
471
|
item.addListener((val) => {
|
|
472
|
+
if (typeof data[index] === 'undefined') { return; }
|
|
473
|
+
|
|
472
474
|
const temp = data[index]?.value ?? 0
|
|
473
475
|
data[index].value = val?.value ?? 0
|
|
474
476
|
let pp = ''
|
package/src/PieChart/index.js
CHANGED
|
@@ -17,14 +17,18 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
17
17
|
import { useEffect, useState } from 'react';
|
|
18
18
|
import { getTextSizeForPieLabels } from '../utils';
|
|
19
19
|
export var usePieChart = function (props) {
|
|
20
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
20
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
21
21
|
var radius = (_a = props.radius) !== null && _a !== void 0 ? _a : 120;
|
|
22
22
|
var extraRadiusForFocused = (_b = props.extraRadiusForFocused) !== null && _b !== void 0 ? _b : (((_c = props.focusOnPress) !== null && _c !== void 0 ? _c : props.sectionAutoFocus) ? radius / 10 : 0);
|
|
23
23
|
var pi = props.semiCircle ? Math.PI / 2 : Math.PI;
|
|
24
|
-
var
|
|
24
|
+
var _w = __read(useState((_d = props.focusedPieIndex) !== null && _d !== void 0 ? _d : -1), 2), selectedIndex = _w[0], setSelectedIndex = _w[1]; // at the start, nothing is selected
|
|
25
25
|
// because we're going to use a useEffect, we need startAngle and total to be state variables
|
|
26
|
-
var
|
|
27
|
-
var
|
|
26
|
+
var _x = __read(useState((_e = props.initialAngle) !== null && _e !== void 0 ? _e : (props.semiCircle ? -pi : 0)), 2), startAngle = _x[0], setStartAngle = _x[1];
|
|
27
|
+
var _y = __read(useState(0), 2), total = _y[0], setTotal = _y[1];
|
|
28
|
+
useEffect(function () {
|
|
29
|
+
var _a;
|
|
30
|
+
setSelectedIndex((_a = props.focusedPieIndex) !== null && _a !== void 0 ? _a : -1);
|
|
31
|
+
}, [props.focusedPieIndex]);
|
|
28
32
|
useEffect(function () {
|
|
29
33
|
var _a;
|
|
30
34
|
// Update the total, this could be use to replace the forEach : const newTotal = props.data.reduce((acc, item) => acc + item.value, 0);
|
|
@@ -63,30 +67,30 @@ export var usePieChart = function (props) {
|
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
}, [selectedIndex]);
|
|
66
|
-
var pro = props.pro, data = props.data, donut = props.donut, isThreeD = props.isThreeD, semiCircle = props.semiCircle,
|
|
67
|
-
var endAngle = (
|
|
70
|
+
var pro = props.pro, data = props.data, donut = props.donut, isThreeD = props.isThreeD, semiCircle = props.semiCircle, _z = props.inwardExtraLengthForFocused, inwardExtraLengthForFocused = _z === void 0 ? 0 : _z, _0 = props.isAnimated, isAnimated = _0 === void 0 ? false : _0, edgesRadius = props.edgesRadius;
|
|
71
|
+
var endAngle = (_f = props.endAngle) !== null && _f !== void 0 ? _f : startAngle + Math.PI * (semiCircle ? 1 : 2);
|
|
68
72
|
var canvasWidth = radius * 2;
|
|
69
73
|
var canvasHeight = isThreeD ? radius * 2.3 : radius * 2;
|
|
70
|
-
var strokeWidth = (
|
|
71
|
-
var innerRadius = (
|
|
72
|
-
var innerCircleColor = (
|
|
73
|
-
var innerCircleBorderWidth = (
|
|
74
|
-
var innerCircleBorderColor = (
|
|
75
|
-
var shiftInnerCenterX = (
|
|
76
|
-
var shiftInnerCenterY = (
|
|
77
|
-
var tiltAngle = (
|
|
74
|
+
var strokeWidth = (_g = props.strokeWidth) !== null && _g !== void 0 ? _g : 0;
|
|
75
|
+
var innerRadius = (_h = props.innerRadius) !== null && _h !== void 0 ? _h : radius / 2.5;
|
|
76
|
+
var innerCircleColor = (_k = (_j = props.innerCircleColor) !== null && _j !== void 0 ? _j : props.backgroundColor) !== null && _k !== void 0 ? _k : 'white';
|
|
77
|
+
var innerCircleBorderWidth = (_l = props.innerCircleBorderWidth) !== null && _l !== void 0 ? _l : (props.innerCircleBorderColor ? strokeWidth || 2 : 0);
|
|
78
|
+
var innerCircleBorderColor = (_m = props.innerCircleBorderColor) !== null && _m !== void 0 ? _m : 'lightgray';
|
|
79
|
+
var shiftInnerCenterX = (_o = props.shiftInnerCenterX) !== null && _o !== void 0 ? _o : 0;
|
|
80
|
+
var shiftInnerCenterY = (_p = props.shiftInnerCenterY) !== null && _p !== void 0 ? _p : 0;
|
|
81
|
+
var tiltAngle = (_q = props.tiltAngle) !== null && _q !== void 0 ? _q : '55deg';
|
|
78
82
|
var isDataShifted = false;
|
|
79
83
|
data.forEach(function (item) {
|
|
80
84
|
if (item.shiftX || item.shiftY) {
|
|
81
85
|
isDataShifted = true;
|
|
82
86
|
}
|
|
83
87
|
});
|
|
84
|
-
var textSize = getTextSizeForPieLabels((
|
|
85
|
-
var paddingHorizontal = ((
|
|
86
|
-
? ((
|
|
88
|
+
var textSize = getTextSizeForPieLabels((_r = props.textSize) !== null && _r !== void 0 ? _r : 0, radius);
|
|
89
|
+
var paddingHorizontal = ((_s = props.paddingHorizontal) !== null && _s !== void 0 ? _s : props.labelsPosition === 'onBorder')
|
|
90
|
+
? ((_t = props.textBackgroundRadius) !== null && _t !== void 0 ? _t : textSize) * 2 + 6
|
|
87
91
|
: 0;
|
|
88
|
-
var paddingVertical = ((
|
|
89
|
-
? ((
|
|
92
|
+
var paddingVertical = ((_u = props.paddingVertical) !== null && _u !== void 0 ? _u : props.labelsPosition === 'onBorder')
|
|
93
|
+
? ((_v = props.textBackgroundRadius) !== null && _v !== void 0 ? _v : textSize) * 2 + 6
|
|
90
94
|
: 0;
|
|
91
95
|
return {
|
|
92
96
|
radius: radius,
|
package/src/PieChart/index.ts
CHANGED
|
@@ -44,13 +44,19 @@ export const usePieChart = (props: IPieChartPropsType): IusePieChart => {
|
|
|
44
44
|
props.extraRadiusForFocused ??
|
|
45
45
|
(props.focusOnPress ?? props.sectionAutoFocus ? radius / 10 : 0)
|
|
46
46
|
const pi = props.semiCircle ? Math.PI / 2 : Math.PI
|
|
47
|
-
const [selectedIndex, setSelectedIndex] = useState(
|
|
47
|
+
const [selectedIndex, setSelectedIndex] = useState(
|
|
48
|
+
props.focusedPieIndex ?? -1
|
|
49
|
+
) // at the start, nothing is selected
|
|
48
50
|
// because we're going to use a useEffect, we need startAngle and total to be state variables
|
|
49
51
|
const [startAngle, setStartAngle] = useState(
|
|
50
52
|
props.initialAngle ?? (props.semiCircle ? -pi : 0)
|
|
51
53
|
)
|
|
52
54
|
const [total, setTotal] = useState(0)
|
|
53
55
|
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
setSelectedIndex(props.focusedPieIndex ?? -1)
|
|
58
|
+
}, [props.focusedPieIndex])
|
|
59
|
+
|
|
54
60
|
useEffect(() => {
|
|
55
61
|
// Update the total, this could be use to replace the forEach : const newTotal = props.data.reduce((acc, item) => acc + item.value, 0);
|
|
56
62
|
let newTotal = 0
|
package/src/PieChart/types.d.ts
CHANGED
package/src/PieChart/types.ts
CHANGED
package/src/utils/index.js
CHANGED
|
@@ -544,7 +544,8 @@ export var getAxesAndRulesProps = function (props, stepValue, negativeStepValue,
|
|
|
544
544
|
formatYLabel: props.formatYLabel
|
|
545
545
|
};
|
|
546
546
|
if (((_c = props.secondaryYAxis) !== null && _c !== void 0 ? _c : (_d = props.lineConfig) === null || _d === void 0 ? void 0 : _d.isSecondary) &&
|
|
547
|
-
maxValue !== undefined
|
|
547
|
+
maxValue !== undefined &&
|
|
548
|
+
secondaryYAxis.maxValue === undefined) {
|
|
548
549
|
axesAndRulesProps.secondaryYAxis = __assign(__assign({}, secondaryYAxis), { maxValue: maxValue });
|
|
549
550
|
}
|
|
550
551
|
return axesAndRulesProps;
|
package/src/utils/index.ts
CHANGED
|
@@ -743,7 +743,8 @@ export const getAxesAndRulesProps = (
|
|
|
743
743
|
}
|
|
744
744
|
if (
|
|
745
745
|
(props.secondaryYAxis ?? props.lineConfig?.isSecondary) &&
|
|
746
|
-
maxValue !== undefined
|
|
746
|
+
maxValue !== undefined &&
|
|
747
|
+
secondaryYAxis.maxValue === undefined
|
|
747
748
|
) {
|
|
748
749
|
axesAndRulesProps.secondaryYAxis = { ...secondaryYAxis, maxValue }
|
|
749
750
|
}
|