gifted-charts-core 0.0.49 → 0.0.51
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 +0 -1
- package/src/PieChart/pro.js +45 -15
- package/src/PieChart/pro.ts +33 -17
package/package.json
CHANGED
package/src/PieChart/pro.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ 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) => {
|
package/src/PieChart/pro.js
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
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
|
+
};
|
|
1
26
|
import { defaultAnimationDuration } from '../utils/constants';
|
|
2
27
|
export var usePiePro = function (props) {
|
|
3
28
|
var _a, _b;
|
|
@@ -5,7 +30,7 @@ export var usePiePro = function (props) {
|
|
|
5
30
|
var endAngle = (_a = props.endAngle) !== null && _a !== void 0 ? _a : startAngle + Math.PI * (semiCircle ? 1 : 2);
|
|
6
31
|
var total = data.reduce(function (acc, item) { return acc + item.value; }, 0);
|
|
7
32
|
var animationDuration = (_b = props.animationDuration) !== null && _b !== void 0 ? _b : defaultAnimationDuration;
|
|
8
|
-
|
|
33
|
+
// let endAngleLocal = 0
|
|
9
34
|
var addValues = function (index) {
|
|
10
35
|
if (index < 0)
|
|
11
36
|
return 0;
|
|
@@ -19,9 +44,9 @@ export var usePiePro = function (props) {
|
|
|
19
44
|
: donut || props.centerLabelComponent
|
|
20
45
|
? 'outward'
|
|
21
46
|
: 'mid';
|
|
22
|
-
var getCoordinates = function (index, additionalValue, addInOnlyStart, addInOnlyEnd) {
|
|
47
|
+
var getCoordinates = function (index, additionalValue, addInOnlyStart, addInOnlyEnd, totalParam) {
|
|
23
48
|
var addedValue = addValues(index - 1) + (addInOnlyEnd ? 0 : additionalValue !== null && additionalValue !== void 0 ? additionalValue : 0);
|
|
24
|
-
var angle = (addedValue / total) *
|
|
49
|
+
var angle = (addedValue / (totalParam !== null && totalParam !== void 0 ? totalParam : total)) * endAngle + startAngle;
|
|
25
50
|
var startInnerX = radius + Math.cos(angle) * innerRadius;
|
|
26
51
|
var startInnerY = radius - Math.sin(angle) * innerRadius;
|
|
27
52
|
var startOuterX = radius + Math.cos(angle) * radius;
|
|
@@ -29,7 +54,7 @@ export var usePiePro = function (props) {
|
|
|
29
54
|
var value = addValues(index - 1) +
|
|
30
55
|
data[index].value +
|
|
31
56
|
(addInOnlyStart ? 0 : additionalValue !== null && additionalValue !== void 0 ? additionalValue : 0);
|
|
32
|
-
angle = (value / total) *
|
|
57
|
+
angle = (value / (totalParam !== null && totalParam !== void 0 ? totalParam : total)) * endAngle + startAngle;
|
|
33
58
|
var endOuterX = radius + Math.cos(angle) * radius;
|
|
34
59
|
var endOuterY = radius - Math.sin(angle) * radius;
|
|
35
60
|
var endInnerX = radius + Math.cos(angle) * innerRadius;
|
|
@@ -47,7 +72,7 @@ export var usePiePro = function (props) {
|
|
|
47
72
|
};
|
|
48
73
|
var getTextCoordinates = function (index, labelPos) {
|
|
49
74
|
var value = addValues(index - 1) + data[index].value / 2;
|
|
50
|
-
var angle = (value / total) *
|
|
75
|
+
var angle = (value / total) * endAngle + startAngle;
|
|
51
76
|
var labelPosition = labelPos || labelsPosition;
|
|
52
77
|
var x = radius +
|
|
53
78
|
Math.cos(angle) *
|
|
@@ -79,16 +104,16 @@ export var usePiePro = function (props) {
|
|
|
79
104
|
}
|
|
80
105
|
return "M".concat(radius + innerRadius, ",").concat(radius, " h").concat(radius - innerRadius, " ");
|
|
81
106
|
};
|
|
82
|
-
var getPath = function (index) {
|
|
107
|
+
var getPath = function (index, totalParam) {
|
|
83
108
|
var _a;
|
|
84
|
-
var _b = getCoordinates(index), endOuterX = _b.endOuterX, endOuterY = _b.endOuterY;
|
|
85
|
-
var isLargeArc = data[index].value / total > 0.5 ? 1 : 0;
|
|
109
|
+
var _b = getCoordinates(index, 0, false, false, totalParam), endOuterX = _b.endOuterX, endOuterY = _b.endOuterY;
|
|
110
|
+
var isLargeArc = data[index].value / (totalParam !== null && totalParam !== void 0 ? totalParam : total) > 0.5 ? 1 : 0;
|
|
86
111
|
var arc = "A".concat(radius + ((_a = props.strokeWidth) !== null && _a !== void 0 ? _a : 0) / 2, ",").concat(radius, " 0 ").concat(isLargeArc, " 0 ");
|
|
87
112
|
var path = "".concat(arc, " ").concat(endOuterX, ", ").concat(endOuterY, "\n L").concat(radius, ",").concat(radius, " ");
|
|
88
113
|
initial = "M".concat(radius, ",").concat(radius, " L").concat(endOuterX, ",").concat(endOuterY);
|
|
89
114
|
return path;
|
|
90
115
|
};
|
|
91
|
-
var getDonutPath = function (index, item) {
|
|
116
|
+
var getDonutPath = function (index, item, totalParam) {
|
|
92
117
|
var _a;
|
|
93
118
|
var additionalForStart = item.isStartEdgeCurved || item.startEdgeRadius
|
|
94
119
|
? (radius - innerRadius) / (radius / 20)
|
|
@@ -98,8 +123,8 @@ export var usePiePro = function (props) {
|
|
|
98
123
|
: 0;
|
|
99
124
|
var cropAtEnd = !!(index === data.length - 1 &&
|
|
100
125
|
(item.isEndEdgeCurved || item.endEdgeRadius));
|
|
101
|
-
var _b = getCoordinates(index, cropAtEnd ? additionalForEnd : additionalForStart, !cropAtEnd, cropAtEnd), startInnerX = _b.startInnerX, startInnerY = _b.startInnerY, endOuterX = _b.endOuterX, endOuterY = _b.endOuterY, endInnerX = _b.endInnerX, endInnerY = _b.endInnerY;
|
|
102
|
-
var isLargeArc = data[index].value / total > 0.5 ? 1 : 0;
|
|
126
|
+
var _b = getCoordinates(index, cropAtEnd ? additionalForEnd : additionalForStart, !cropAtEnd, cropAtEnd, totalParam), startInnerX = _b.startInnerX, startInnerY = _b.startInnerY, endOuterX = _b.endOuterX, endOuterY = _b.endOuterY, endInnerX = _b.endInnerX, endInnerY = _b.endInnerY;
|
|
127
|
+
var isLargeArc = data[index].value / (totalParam !== null && totalParam !== void 0 ? totalParam : total) > 0.5 ? 1 : 0;
|
|
103
128
|
var innerArc = "A".concat(innerRadius, ",").concat(innerRadius, " 0 ").concat(isLargeArc, " 1 ");
|
|
104
129
|
var outerArc = "A".concat(radius + ((_a = props.strokeWidth) !== null && _a !== void 0 ? _a : 0) / 2, ",").concat(radius, " 0 ").concat(isLargeArc, " 0 ");
|
|
105
130
|
var path = "".concat(outerArc, " ").concat(endOuterX, ", ").concat(endOuterY, "\n L").concat(endInnerX, ",").concat(endInnerY, " M").concat(endInnerX, ",").concat(endInnerY, " ").concat(innerArc, " ").concat(startInnerX, ",").concat(startInnerY);
|
|
@@ -128,12 +153,17 @@ export var usePiePro = function (props) {
|
|
|
128
153
|
var path = "M".concat(endInnerX, ",").concat(endInnerY, " A").concat(edgeRadius, ",").concat(edgeRadius, " 0 0 1 ").concat(endOuterX, ",").concat(endOuterY);
|
|
129
154
|
return path;
|
|
130
155
|
};
|
|
131
|
-
var
|
|
132
|
-
|
|
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) {
|
|
161
|
+
return "".concat(initial || getInitial(item), " ").concat(donut
|
|
162
|
+
? getDonutPath(index, item, total * 101)
|
|
163
|
+
: getPath(index, total * 101));
|
|
133
164
|
});
|
|
134
|
-
endAngleLocal = endAngle;
|
|
135
165
|
initial = '';
|
|
136
|
-
var dFinal =
|
|
166
|
+
var dFinal = dataForFinalPath.map(function (item, index) {
|
|
137
167
|
return "".concat(initial || getInitial(item), " ").concat(donut ? getDonutPath(index, item) : getPath(index));
|
|
138
168
|
});
|
|
139
169
|
return {
|
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,7 +12,6 @@ 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: (
|
|
@@ -39,7 +37,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
39
37
|
const total = data.reduce((acc, item) => acc + item.value, 0)
|
|
40
38
|
const animationDuration = props.animationDuration ?? defaultAnimationDuration
|
|
41
39
|
|
|
42
|
-
let endAngleLocal = 0
|
|
40
|
+
// let endAngleLocal = 0
|
|
43
41
|
|
|
44
42
|
const addValues = (index: number) => {
|
|
45
43
|
if (index < 0) return 0
|
|
@@ -57,11 +55,12 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
57
55
|
index: number,
|
|
58
56
|
additionalValue?: number,
|
|
59
57
|
addInOnlyStart?: boolean,
|
|
60
|
-
addInOnlyEnd?: boolean
|
|
58
|
+
addInOnlyEnd?: boolean,
|
|
59
|
+
totalParam?: number
|
|
61
60
|
) => {
|
|
62
61
|
const addedValue =
|
|
63
62
|
addValues(index - 1) + (addInOnlyEnd ? 0 : additionalValue ?? 0)
|
|
64
|
-
let angle = (addedValue / total) *
|
|
63
|
+
let angle = (addedValue / (totalParam ?? total)) * endAngle + startAngle
|
|
65
64
|
const startInnerX = radius + Math.cos(angle) * innerRadius
|
|
66
65
|
const startInnerY = radius - Math.sin(angle) * innerRadius
|
|
67
66
|
const startOuterX = radius + Math.cos(angle) * radius
|
|
@@ -71,7 +70,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
71
70
|
addValues(index - 1) +
|
|
72
71
|
data[index].value +
|
|
73
72
|
(addInOnlyStart ? 0 : additionalValue ?? 0)
|
|
74
|
-
angle = (value / total) *
|
|
73
|
+
angle = (value / (totalParam ?? total)) * endAngle + startAngle
|
|
75
74
|
|
|
76
75
|
const endOuterX = radius + Math.cos(angle) * radius
|
|
77
76
|
const endOuterY = radius - Math.sin(angle) * radius
|
|
@@ -93,7 +92,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
93
92
|
|
|
94
93
|
const getTextCoordinates = (index: number, labelPos?: LabelsPosition) => {
|
|
95
94
|
const value = addValues(index - 1) + data[index].value / 2
|
|
96
|
-
const angle = (value / total) *
|
|
95
|
+
const angle = (value / total) * endAngle + startAngle
|
|
97
96
|
|
|
98
97
|
const labelPosition: LabelsPosition = labelPos || labelsPosition
|
|
99
98
|
|
|
@@ -133,10 +132,16 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
133
132
|
}
|
|
134
133
|
return `M${radius + innerRadius},${radius} h${radius - innerRadius} `
|
|
135
134
|
}
|
|
136
|
-
const getPath = (index: number) => {
|
|
137
|
-
const { endOuterX, endOuterY } = getCoordinates(
|
|
135
|
+
const getPath = (index: number, totalParam?: number) => {
|
|
136
|
+
const { endOuterX, endOuterY } = getCoordinates(
|
|
137
|
+
index,
|
|
138
|
+
0,
|
|
139
|
+
false,
|
|
140
|
+
false,
|
|
141
|
+
totalParam
|
|
142
|
+
)
|
|
138
143
|
|
|
139
|
-
const isLargeArc = data[index].value / total > 0.5 ? 1 : 0
|
|
144
|
+
const isLargeArc = data[index].value / (totalParam ?? total) > 0.5 ? 1 : 0
|
|
140
145
|
|
|
141
146
|
const arc = `A${
|
|
142
147
|
radius + (props.strokeWidth ?? 0) / 2
|
|
@@ -148,7 +153,11 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
148
153
|
|
|
149
154
|
return path
|
|
150
155
|
}
|
|
151
|
-
const getDonutPath = (
|
|
156
|
+
const getDonutPath = (
|
|
157
|
+
index: number,
|
|
158
|
+
item: pieDataItem,
|
|
159
|
+
totalParam?: number
|
|
160
|
+
) => {
|
|
152
161
|
const additionalForStart =
|
|
153
162
|
item.isStartEdgeCurved || item.startEdgeRadius
|
|
154
163
|
? (radius - innerRadius) / (radius / 20)
|
|
@@ -174,10 +183,11 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
174
183
|
index,
|
|
175
184
|
cropAtEnd ? additionalForEnd : additionalForStart,
|
|
176
185
|
!cropAtEnd,
|
|
177
|
-
cropAtEnd
|
|
186
|
+
cropAtEnd,
|
|
187
|
+
totalParam
|
|
178
188
|
)
|
|
179
189
|
|
|
180
|
-
const isLargeArc = data[index].value / total > 0.5 ? 1 : 0
|
|
190
|
+
const isLargeArc = data[index].value / (totalParam ?? total) > 0.5 ? 1 : 0
|
|
181
191
|
|
|
182
192
|
const innerArc = `A${innerRadius},${innerRadius} 0 ${isLargeArc} 1 `
|
|
183
193
|
const outerArc = `A${
|
|
@@ -219,16 +229,22 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
219
229
|
return path
|
|
220
230
|
}
|
|
221
231
|
|
|
222
|
-
const
|
|
232
|
+
const dataForInitialPath = isAnimated
|
|
233
|
+
? data
|
|
234
|
+
: [...data, { value: total * 100 }]
|
|
235
|
+
const dataForFinalPath = isAnimated ? data : [...data, { value: 0 }]
|
|
236
|
+
|
|
237
|
+
const dInitial = dataForInitialPath.map(
|
|
223
238
|
(item, index) =>
|
|
224
239
|
`${initial || getInitial(item)} ${
|
|
225
|
-
donut
|
|
240
|
+
donut
|
|
241
|
+
? getDonutPath(index, item, total * 101)
|
|
242
|
+
: getPath(index, total * 101)
|
|
226
243
|
}`
|
|
227
244
|
)
|
|
228
245
|
|
|
229
|
-
endAngleLocal = endAngle
|
|
230
246
|
initial = ''
|
|
231
|
-
const dFinal =
|
|
247
|
+
const dFinal = dataForFinalPath.map(
|
|
232
248
|
(item, index) =>
|
|
233
249
|
`${initial || getInitial(item)} ${
|
|
234
250
|
donut ? getDonutPath(index, item) : getPath(index)
|