gifted-charts-core 0.0.48 → 0.0.50
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/PieChart/pro.d.ts +1 -1
- package/src/PieChart/pro.js +21 -17
- package/src/PieChart/pro.ts +14 -20
package/package.json
CHANGED
package/src/PieChart/pro.d.ts
CHANGED
|
@@ -10,13 +10,13 @@ interface IusePiePro {
|
|
|
10
10
|
initial: string;
|
|
11
11
|
dInitial: string[];
|
|
12
12
|
dFinal: string[];
|
|
13
|
-
isAnimating?: boolean;
|
|
14
13
|
getStartCaps: (index: number, item: pieDataItem) => string;
|
|
15
14
|
getEndCaps: (index: number, item: pieDataItem) => string;
|
|
16
15
|
getTextCoordinates: (index: number, labelPos?: LabelsPosition) => {
|
|
17
16
|
x: number;
|
|
18
17
|
y: number;
|
|
19
18
|
};
|
|
19
|
+
labelsPosition: LabelsPosition;
|
|
20
20
|
}
|
|
21
21
|
export declare const usePiePro: (props: PieChartPropsType) => IusePiePro;
|
|
22
22
|
export {};
|
package/src/PieChart/pro.js
CHANGED
|
@@ -14,7 +14,15 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
14
14
|
}
|
|
15
15
|
return ar;
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
+
if (ar || !(i in from)) {
|
|
20
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
+
ar[i] = from[i];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
+
};
|
|
18
26
|
import { defaultAnimationDuration } from '../utils/constants';
|
|
19
27
|
export var usePiePro = function (props) {
|
|
20
28
|
var _a, _b;
|
|
@@ -22,14 +30,7 @@ export var usePiePro = function (props) {
|
|
|
22
30
|
var endAngle = (_a = props.endAngle) !== null && _a !== void 0 ? _a : startAngle + Math.PI * (semiCircle ? 1 : 2);
|
|
23
31
|
var total = data.reduce(function (acc, item) { return acc + item.value; }, 0);
|
|
24
32
|
var animationDuration = (_b = props.animationDuration) !== null && _b !== void 0 ? _b : defaultAnimationDuration;
|
|
25
|
-
|
|
26
|
-
useEffect(function () {
|
|
27
|
-
if (isAnimated) {
|
|
28
|
-
setIsAnimating(true);
|
|
29
|
-
setTimeout(function () { return setIsAnimating(false); }, animationDuration);
|
|
30
|
-
}
|
|
31
|
-
}, []);
|
|
32
|
-
var endAngleLocal = 0;
|
|
33
|
+
// let endAngleLocal = 0
|
|
33
34
|
var addValues = function (index) {
|
|
34
35
|
if (index < 0)
|
|
35
36
|
return 0;
|
|
@@ -45,7 +46,7 @@ export var usePiePro = function (props) {
|
|
|
45
46
|
: 'mid';
|
|
46
47
|
var getCoordinates = function (index, additionalValue, addInOnlyStart, addInOnlyEnd) {
|
|
47
48
|
var addedValue = addValues(index - 1) + (addInOnlyEnd ? 0 : additionalValue !== null && additionalValue !== void 0 ? additionalValue : 0);
|
|
48
|
-
var angle = (addedValue / total) *
|
|
49
|
+
var angle = (addedValue / total) * endAngle + startAngle;
|
|
49
50
|
var startInnerX = radius + Math.cos(angle) * innerRadius;
|
|
50
51
|
var startInnerY = radius - Math.sin(angle) * innerRadius;
|
|
51
52
|
var startOuterX = radius + Math.cos(angle) * radius;
|
|
@@ -53,7 +54,7 @@ export var usePiePro = function (props) {
|
|
|
53
54
|
var value = addValues(index - 1) +
|
|
54
55
|
data[index].value +
|
|
55
56
|
(addInOnlyStart ? 0 : additionalValue !== null && additionalValue !== void 0 ? additionalValue : 0);
|
|
56
|
-
angle = (value / total) *
|
|
57
|
+
angle = (value / total) * endAngle + startAngle;
|
|
57
58
|
var endOuterX = radius + Math.cos(angle) * radius;
|
|
58
59
|
var endOuterY = radius - Math.sin(angle) * radius;
|
|
59
60
|
var endInnerX = radius + Math.cos(angle) * innerRadius;
|
|
@@ -71,7 +72,7 @@ export var usePiePro = function (props) {
|
|
|
71
72
|
};
|
|
72
73
|
var getTextCoordinates = function (index, labelPos) {
|
|
73
74
|
var value = addValues(index - 1) + data[index].value / 2;
|
|
74
|
-
var angle = (value / total) *
|
|
75
|
+
var angle = (value / total) * endAngle + startAngle;
|
|
75
76
|
var labelPosition = labelPos || labelsPosition;
|
|
76
77
|
var x = radius +
|
|
77
78
|
Math.cos(angle) *
|
|
@@ -152,12 +153,15 @@ export var usePiePro = function (props) {
|
|
|
152
153
|
var path = "M".concat(endInnerX, ",").concat(endInnerY, " A").concat(edgeRadius, ",").concat(edgeRadius, " 0 0 1 ").concat(endOuterX, ",").concat(endOuterY);
|
|
153
154
|
return path;
|
|
154
155
|
};
|
|
155
|
-
var
|
|
156
|
+
var dataForInitialPath = isAnimated
|
|
157
|
+
? data
|
|
158
|
+
: __spreadArray(__spreadArray([], __read(data), false), [{ value: total * 100 }], false);
|
|
159
|
+
var dataForFinalPath = isAnimated ? data : __spreadArray(__spreadArray([], __read(data), false), [{ value: 0 }], false);
|
|
160
|
+
var dInitial = dataForInitialPath.map(function (item, index) {
|
|
156
161
|
return "".concat(initial || getInitial(item), " ").concat(donut ? getDonutPath(index, item) : getPath(index));
|
|
157
162
|
});
|
|
158
|
-
endAngleLocal = endAngle;
|
|
159
163
|
initial = '';
|
|
160
|
-
var dFinal =
|
|
164
|
+
var dFinal = dataForFinalPath.map(function (item, index) {
|
|
161
165
|
return "".concat(initial || getInitial(item), " ").concat(donut ? getDonutPath(index, item) : getPath(index));
|
|
162
166
|
});
|
|
163
167
|
return {
|
|
@@ -170,9 +174,9 @@ export var usePiePro = function (props) {
|
|
|
170
174
|
initial: initial,
|
|
171
175
|
dInitial: dInitial,
|
|
172
176
|
dFinal: dFinal,
|
|
173
|
-
isAnimating: isAnimating,
|
|
174
177
|
getStartCaps: getStartCaps,
|
|
175
178
|
getEndCaps: getEndCaps,
|
|
176
|
-
getTextCoordinates: getTextCoordinates
|
|
179
|
+
getTextCoordinates: getTextCoordinates,
|
|
180
|
+
labelsPosition: labelsPosition
|
|
177
181
|
};
|
|
178
182
|
};
|
package/src/PieChart/pro.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
1
|
import { defaultAnimationDuration } from '../utils/constants'
|
|
3
2
|
import { PieChartPropsType, pieDataItem } from './types'
|
|
4
3
|
import { LabelsPosition } from '../utils/types'
|
|
@@ -13,13 +12,13 @@ interface IusePiePro {
|
|
|
13
12
|
initial: string
|
|
14
13
|
dInitial: string[]
|
|
15
14
|
dFinal: string[]
|
|
16
|
-
isAnimating?: boolean
|
|
17
15
|
getStartCaps: (index: number, item: pieDataItem) => string
|
|
18
16
|
getEndCaps: (index: number, item: pieDataItem) => string
|
|
19
17
|
getTextCoordinates: (
|
|
20
18
|
index: number,
|
|
21
19
|
labelPos?: LabelsPosition
|
|
22
20
|
) => { x: number; y: number }
|
|
21
|
+
labelsPosition: LabelsPosition
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
@@ -38,16 +37,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
38
37
|
const total = data.reduce((acc, item) => acc + item.value, 0)
|
|
39
38
|
const animationDuration = props.animationDuration ?? defaultAnimationDuration
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (isAnimated) {
|
|
45
|
-
setIsAnimating(true)
|
|
46
|
-
setTimeout(() => setIsAnimating(false), animationDuration)
|
|
47
|
-
}
|
|
48
|
-
}, [])
|
|
49
|
-
|
|
50
|
-
let endAngleLocal = 0
|
|
40
|
+
// let endAngleLocal = 0
|
|
51
41
|
|
|
52
42
|
const addValues = (index: number) => {
|
|
53
43
|
if (index < 0) return 0
|
|
@@ -69,7 +59,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
69
59
|
) => {
|
|
70
60
|
const addedValue =
|
|
71
61
|
addValues(index - 1) + (addInOnlyEnd ? 0 : additionalValue ?? 0)
|
|
72
|
-
let angle = (addedValue / total) *
|
|
62
|
+
let angle = (addedValue / total) * endAngle + startAngle
|
|
73
63
|
const startInnerX = radius + Math.cos(angle) * innerRadius
|
|
74
64
|
const startInnerY = radius - Math.sin(angle) * innerRadius
|
|
75
65
|
const startOuterX = radius + Math.cos(angle) * radius
|
|
@@ -79,7 +69,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
79
69
|
addValues(index - 1) +
|
|
80
70
|
data[index].value +
|
|
81
71
|
(addInOnlyStart ? 0 : additionalValue ?? 0)
|
|
82
|
-
angle = (value / total) *
|
|
72
|
+
angle = (value / total) * endAngle + startAngle
|
|
83
73
|
|
|
84
74
|
const endOuterX = radius + Math.cos(angle) * radius
|
|
85
75
|
const endOuterY = radius - Math.sin(angle) * radius
|
|
@@ -101,7 +91,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
101
91
|
|
|
102
92
|
const getTextCoordinates = (index: number, labelPos?: LabelsPosition) => {
|
|
103
93
|
const value = addValues(index - 1) + data[index].value / 2
|
|
104
|
-
const angle = (value / total) *
|
|
94
|
+
const angle = (value / total) * endAngle + startAngle
|
|
105
95
|
|
|
106
96
|
const labelPosition: LabelsPosition = labelPos || labelsPosition
|
|
107
97
|
|
|
@@ -227,16 +217,20 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
227
217
|
return path
|
|
228
218
|
}
|
|
229
219
|
|
|
230
|
-
const
|
|
220
|
+
const dataForInitialPath = isAnimated
|
|
221
|
+
? data
|
|
222
|
+
: [...data, { value: total * 100 }]
|
|
223
|
+
const dataForFinalPath = isAnimated ? data : [...data, { value: 0 }]
|
|
224
|
+
|
|
225
|
+
const dInitial = dataForInitialPath.map(
|
|
231
226
|
(item, index) =>
|
|
232
227
|
`${initial || getInitial(item)} ${
|
|
233
228
|
donut ? getDonutPath(index, item) : getPath(index)
|
|
234
229
|
}`
|
|
235
230
|
)
|
|
236
231
|
|
|
237
|
-
endAngleLocal = endAngle
|
|
238
232
|
initial = ''
|
|
239
|
-
const dFinal =
|
|
233
|
+
const dFinal = dataForFinalPath.map(
|
|
240
234
|
(item, index) =>
|
|
241
235
|
`${initial || getInitial(item)} ${
|
|
242
236
|
donut ? getDonutPath(index, item) : getPath(index)
|
|
@@ -253,9 +247,9 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
253
247
|
initial,
|
|
254
248
|
dInitial,
|
|
255
249
|
dFinal,
|
|
256
|
-
isAnimating,
|
|
257
250
|
getStartCaps,
|
|
258
251
|
getEndCaps,
|
|
259
|
-
getTextCoordinates
|
|
252
|
+
getTextCoordinates,
|
|
253
|
+
labelsPosition
|
|
260
254
|
}
|
|
261
255
|
}
|