gifted-charts-core 0.0.51 → 0.1.1
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.js +26 -44
- package/src/PieChart/pro.ts +17 -15
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/index.ts +2 -1
package/package.json
CHANGED
package/src/PieChart/pro.js
CHANGED
|
@@ -1,42 +1,18 @@
|
|
|
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
|
-
};
|
|
26
1
|
import { defaultAnimationDuration } from '../utils/constants';
|
|
27
2
|
export var usePiePro = function (props) {
|
|
28
3
|
var _a, _b;
|
|
29
|
-
var data = props.data, isAnimated = props.isAnimated, donut = props.donut, semiCircle = props.semiCircle, _c = props.radius, radius = _c === void 0 ? 120 : _c, _d = props.innerRadius, innerRadius = _d === void 0 ? radius / 2.5 : _d, _e = props.strokeWidth, strokeWidth = _e === void 0 ? 0 : _e, _f = props.edgesRadius, edgesRadius = _f === void 0 ? 0 : _f, _g = props.startAngle, startAngle = _g === void 0 ? 0 : _g;
|
|
4
|
+
var data = props.data, isAnimated = props.isAnimated, donut = props.donut, semiCircle = props.semiCircle, _c = props.radius, radius = _c === void 0 ? 120 : _c, _d = props.innerRadius, innerRadius = _d === void 0 ? donut ? radius / 2.5 : 0 : _d, _e = props.strokeWidth, strokeWidth = _e === void 0 ? 0 : _e, _f = props.edgesRadius, edgesRadius = _f === void 0 ? 0 : _f, _g = props.startAngle, startAngle = _g === void 0 ? 0 : _g;
|
|
30
5
|
var endAngle = (_a = props.endAngle) !== null && _a !== void 0 ? _a : startAngle + Math.PI * (semiCircle ? 1 : 2);
|
|
31
|
-
var total = data.reduce(function (acc, item) { return acc + item.value; }, 0);
|
|
6
|
+
var total = data.reduce(function (acc, item) { return acc + (item === null || item === void 0 ? void 0 : item.value); }, 0);
|
|
32
7
|
var animationDuration = (_b = props.animationDuration) !== null && _b !== void 0 ? _b : defaultAnimationDuration;
|
|
33
8
|
// let endAngleLocal = 0
|
|
34
9
|
var addValues = function (index) {
|
|
10
|
+
var _a;
|
|
35
11
|
if (index < 0)
|
|
36
12
|
return 0;
|
|
37
13
|
var sum = 0;
|
|
38
14
|
for (var i = 0; i <= index; i++)
|
|
39
|
-
sum += data[i].value;
|
|
15
|
+
sum += (_a = data[i]) === null || _a === void 0 ? void 0 : _a.value;
|
|
40
16
|
return sum;
|
|
41
17
|
};
|
|
42
18
|
var labelsPosition = props.labelsPosition
|
|
@@ -45,6 +21,7 @@ export var usePiePro = function (props) {
|
|
|
45
21
|
? 'outward'
|
|
46
22
|
: 'mid';
|
|
47
23
|
var getCoordinates = function (index, additionalValue, addInOnlyStart, addInOnlyEnd, totalParam) {
|
|
24
|
+
var _a;
|
|
48
25
|
var addedValue = addValues(index - 1) + (addInOnlyEnd ? 0 : additionalValue !== null && additionalValue !== void 0 ? additionalValue : 0);
|
|
49
26
|
var angle = (addedValue / (totalParam !== null && totalParam !== void 0 ? totalParam : total)) * endAngle + startAngle;
|
|
50
27
|
var startInnerX = radius + Math.cos(angle) * innerRadius;
|
|
@@ -52,7 +29,7 @@ export var usePiePro = function (props) {
|
|
|
52
29
|
var startOuterX = radius + Math.cos(angle) * radius;
|
|
53
30
|
var startOuterY = radius - Math.sin(angle) * radius;
|
|
54
31
|
var value = addValues(index - 1) +
|
|
55
|
-
data[index].value +
|
|
32
|
+
((_a = data[index]) === null || _a === void 0 ? void 0 : _a.value) +
|
|
56
33
|
(addInOnlyStart ? 0 : additionalValue !== null && additionalValue !== void 0 ? additionalValue : 0);
|
|
57
34
|
angle = (value / (totalParam !== null && totalParam !== void 0 ? totalParam : total)) * endAngle + startAngle;
|
|
58
35
|
var endOuterX = radius + Math.cos(angle) * radius;
|
|
@@ -71,7 +48,8 @@ export var usePiePro = function (props) {
|
|
|
71
48
|
};
|
|
72
49
|
};
|
|
73
50
|
var getTextCoordinates = function (index, labelPos) {
|
|
74
|
-
var
|
|
51
|
+
var _a;
|
|
52
|
+
var value = addValues(index - 1) + ((_a = data[index]) === null || _a === void 0 ? void 0 : _a.value) / 2;
|
|
75
53
|
var angle = (value / total) * endAngle + startAngle;
|
|
76
54
|
var labelPosition = labelPos || labelsPosition;
|
|
77
55
|
var x = radius +
|
|
@@ -105,16 +83,20 @@ export var usePiePro = function (props) {
|
|
|
105
83
|
return "M".concat(radius + innerRadius, ",").concat(radius, " h").concat(radius - innerRadius, " ");
|
|
106
84
|
};
|
|
107
85
|
var getPath = function (index, totalParam) {
|
|
108
|
-
var _a;
|
|
109
|
-
var
|
|
110
|
-
var isLargeArc =
|
|
111
|
-
|
|
86
|
+
var _a, _b;
|
|
87
|
+
var _c = getCoordinates(index, 0, false, false, totalParam), endOuterX = _c.endOuterX, endOuterY = _c.endOuterY;
|
|
88
|
+
var isLargeArc = semiCircle
|
|
89
|
+
? 0
|
|
90
|
+
: ((_a = data[index]) === null || _a === void 0 ? void 0 : _a.value) / (totalParam !== null && totalParam !== void 0 ? totalParam : total) > 0.5
|
|
91
|
+
? 1
|
|
92
|
+
: 0;
|
|
93
|
+
var arc = "A".concat(radius + ((_b = props.strokeWidth) !== null && _b !== void 0 ? _b : 0) / 2, ",").concat(radius, " 0 ").concat(isLargeArc, " 0 ");
|
|
112
94
|
var path = "".concat(arc, " ").concat(endOuterX, ", ").concat(endOuterY, "\n L").concat(radius, ",").concat(radius, " ");
|
|
113
95
|
initial = "M".concat(radius, ",").concat(radius, " L").concat(endOuterX, ",").concat(endOuterY);
|
|
114
96
|
return path;
|
|
115
97
|
};
|
|
116
98
|
var getDonutPath = function (index, item, totalParam) {
|
|
117
|
-
var _a;
|
|
99
|
+
var _a, _b;
|
|
118
100
|
var additionalForStart = item.isStartEdgeCurved || item.startEdgeRadius
|
|
119
101
|
? (radius - innerRadius) / (radius / 20)
|
|
120
102
|
: 0;
|
|
@@ -123,10 +105,14 @@ export var usePiePro = function (props) {
|
|
|
123
105
|
: 0;
|
|
124
106
|
var cropAtEnd = !!(index === data.length - 1 &&
|
|
125
107
|
(item.isEndEdgeCurved || item.endEdgeRadius));
|
|
126
|
-
var
|
|
127
|
-
var isLargeArc =
|
|
108
|
+
var _c = getCoordinates(index, cropAtEnd ? additionalForEnd : additionalForStart, !cropAtEnd, cropAtEnd, totalParam), startInnerX = _c.startInnerX, startInnerY = _c.startInnerY, endOuterX = _c.endOuterX, endOuterY = _c.endOuterY, endInnerX = _c.endInnerX, endInnerY = _c.endInnerY;
|
|
109
|
+
var isLargeArc = semiCircle
|
|
110
|
+
? 0
|
|
111
|
+
: ((_a = data[index]) === null || _a === void 0 ? void 0 : _a.value) / (totalParam !== null && totalParam !== void 0 ? totalParam : total) > 0.5
|
|
112
|
+
? 1
|
|
113
|
+
: 0;
|
|
128
114
|
var innerArc = "A".concat(innerRadius, ",").concat(innerRadius, " 0 ").concat(isLargeArc, " 1 ");
|
|
129
|
-
var outerArc = "A".concat(radius + ((
|
|
115
|
+
var outerArc = "A".concat(radius + ((_b = props.strokeWidth) !== null && _b !== void 0 ? _b : 0) / 2, ",").concat(radius, " 0 ").concat(isLargeArc, " 0 ");
|
|
130
116
|
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);
|
|
131
117
|
initial = "M".concat(endInnerX, ",").concat(endInnerY, " L").concat(endOuterX, ",").concat(endOuterY, " ");
|
|
132
118
|
return path;
|
|
@@ -153,17 +139,13 @@ export var usePiePro = function (props) {
|
|
|
153
139
|
var path = "M".concat(endInnerX, ",").concat(endInnerY, " A").concat(edgeRadius, ",").concat(edgeRadius, " 0 0 1 ").concat(endOuterX, ",").concat(endOuterY);
|
|
154
140
|
return path;
|
|
155
141
|
};
|
|
156
|
-
var
|
|
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) {
|
|
142
|
+
var dInitial = data.map(function (item, index) {
|
|
161
143
|
return "".concat(initial || getInitial(item), " ").concat(donut
|
|
162
144
|
? getDonutPath(index, item, total * 101)
|
|
163
145
|
: getPath(index, total * 101));
|
|
164
146
|
});
|
|
165
147
|
initial = '';
|
|
166
|
-
var dFinal =
|
|
148
|
+
var dFinal = data.map(function (item, index) {
|
|
167
149
|
return "".concat(initial || getInitial(item), " ").concat(donut ? getDonutPath(index, item) : getPath(index));
|
|
168
150
|
});
|
|
169
151
|
return {
|
package/src/PieChart/pro.ts
CHANGED
|
@@ -28,13 +28,13 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
28
28
|
donut,
|
|
29
29
|
semiCircle,
|
|
30
30
|
radius = 120,
|
|
31
|
-
innerRadius = radius / 2.5,
|
|
31
|
+
innerRadius = donut ? radius / 2.5 : 0,
|
|
32
32
|
strokeWidth = 0,
|
|
33
33
|
edgesRadius = 0,
|
|
34
34
|
startAngle = 0
|
|
35
35
|
} = props
|
|
36
36
|
let endAngle = props.endAngle ?? startAngle + Math.PI * (semiCircle ? 1 : 2)
|
|
37
|
-
const total = data.reduce((acc, item) => acc + item
|
|
37
|
+
const total = data.reduce((acc, item) => acc + item?.value, 0)
|
|
38
38
|
const animationDuration = props.animationDuration ?? defaultAnimationDuration
|
|
39
39
|
|
|
40
40
|
// let endAngleLocal = 0
|
|
@@ -42,7 +42,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
42
42
|
const addValues = (index: number) => {
|
|
43
43
|
if (index < 0) return 0
|
|
44
44
|
let sum = 0
|
|
45
|
-
for (let i = 0; i <= index; i++) sum += data[i]
|
|
45
|
+
for (let i = 0; i <= index; i++) sum += data[i]?.value
|
|
46
46
|
return sum
|
|
47
47
|
}
|
|
48
48
|
const labelsPosition = props.labelsPosition
|
|
@@ -68,7 +68,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
68
68
|
|
|
69
69
|
const value =
|
|
70
70
|
addValues(index - 1) +
|
|
71
|
-
data[index]
|
|
71
|
+
data[index]?.value +
|
|
72
72
|
(addInOnlyStart ? 0 : additionalValue ?? 0)
|
|
73
73
|
angle = (value / (totalParam ?? total)) * endAngle + startAngle
|
|
74
74
|
|
|
@@ -91,7 +91,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
const getTextCoordinates = (index: number, labelPos?: LabelsPosition) => {
|
|
94
|
-
const value = addValues(index - 1) + data[index]
|
|
94
|
+
const value = addValues(index - 1) + data[index]?.value / 2
|
|
95
95
|
const angle = (value / total) * endAngle + startAngle
|
|
96
96
|
|
|
97
97
|
const labelPosition: LabelsPosition = labelPos || labelsPosition
|
|
@@ -141,7 +141,11 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
141
141
|
totalParam
|
|
142
142
|
)
|
|
143
143
|
|
|
144
|
-
const isLargeArc =
|
|
144
|
+
const isLargeArc = semiCircle
|
|
145
|
+
? 0
|
|
146
|
+
: data[index]?.value / (totalParam ?? total) > 0.5
|
|
147
|
+
? 1
|
|
148
|
+
: 0
|
|
145
149
|
|
|
146
150
|
const arc = `A${
|
|
147
151
|
radius + (props.strokeWidth ?? 0) / 2
|
|
@@ -186,8 +190,11 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
186
190
|
cropAtEnd,
|
|
187
191
|
totalParam
|
|
188
192
|
)
|
|
189
|
-
|
|
190
|
-
|
|
193
|
+
const isLargeArc = semiCircle
|
|
194
|
+
? 0
|
|
195
|
+
: data[index]?.value / (totalParam ?? total) > 0.5
|
|
196
|
+
? 1
|
|
197
|
+
: 0
|
|
191
198
|
|
|
192
199
|
const innerArc = `A${innerRadius},${innerRadius} 0 ${isLargeArc} 1 `
|
|
193
200
|
const outerArc = `A${
|
|
@@ -229,12 +236,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
229
236
|
return path
|
|
230
237
|
}
|
|
231
238
|
|
|
232
|
-
const
|
|
233
|
-
? data
|
|
234
|
-
: [...data, { value: total * 100 }]
|
|
235
|
-
const dataForFinalPath = isAnimated ? data : [...data, { value: 0 }]
|
|
236
|
-
|
|
237
|
-
const dInitial = dataForInitialPath.map(
|
|
239
|
+
const dInitial = data.map(
|
|
238
240
|
(item, index) =>
|
|
239
241
|
`${initial || getInitial(item)} ${
|
|
240
242
|
donut
|
|
@@ -244,7 +246,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
244
246
|
)
|
|
245
247
|
|
|
246
248
|
initial = ''
|
|
247
|
-
const dFinal =
|
|
249
|
+
const dFinal = data.map(
|
|
248
250
|
(item, index) =>
|
|
249
251
|
`${initial || getInitial(item)} ${
|
|
250
252
|
donut ? getDonutPath(index, item) : getPath(index)
|
package/src/index.d.ts
CHANGED
|
@@ -34,5 +34,5 @@ export { getTopAndLeftForStripAndLabel } from './components/common/StripAndLabel
|
|
|
34
34
|
/********************************* common utils, constants and types ********************************
|
|
35
35
|
/***********************************************************************************************************************/
|
|
36
36
|
export { getCumulativeWidth, getLighterColor, svgQuadraticCurvePath, svgPath, bezierCommand, getSegmentString, getCurvePathWithSegments, getPreviousSegmentsLastPoint, getPathWithHighlight, getRegionPathObjects, getSegmentedPathObjects, getArrowPoints, getAxesAndRulesProps, getExtendedContainerHeightWithPadding, getSecondaryDataWithOffsetIncluded, getArrowProperty, getAllArrowProperties, maxAndMinUtil, computeMaxAndMinItems, getLabelTextUtil, getXForLineInBar, getYForLineInBar, clone, getLineConfigForBarChart, adjustToOffset } from './utils';
|
|
37
|
-
export { chartTypes, yAxisSides, loc, SEGMENT_START, SEGMENT_END, RANGE_ENTER, RANGE_EXIT, STOP, ruleTypes, AxesAndRulesDefaults, defaultArrowConfig, BarDefaults, defaultLineConfig, LineDefaults, defaultPointerConfig, pieColors, populationDefaults } from './utils/constants';
|
|
37
|
+
export { chartTypes, yAxisSides, loc, SEGMENT_START, SEGMENT_END, RANGE_ENTER, RANGE_EXIT, STOP, ruleTypes, AxesAndRulesDefaults, defaultArrowConfig, BarDefaults, defaultLineConfig, LineDefaults, defaultPointerConfig, pieColors, populationDefaults, defaultAnimationDuration } from './utils/constants';
|
|
38
38
|
export { type RuleType, type RuleTypes, type RulesConfig, type CurveType, type EdgePosition, type LabelsPosition, type PointerEvents, type secondaryYAxisType, type secondaryLineConfigType, type referenceConfigType, type arrowConfigType, type horizSectionPropTypes, type HorizSectionsType, type BarAndLineChartsWrapperTypes, type Pointer, type HighlightedRange, type LineSegment, type LineSvgProps, type LineProperties, type DataSet, type Framework } from './utils/types';
|
package/src/index.js
CHANGED
|
@@ -30,4 +30,4 @@ export { getTopAndLeftForStripAndLabel } from './components/common/StripAndLabel
|
|
|
30
30
|
/********************************* common utils, constants and types ********************************
|
|
31
31
|
/***********************************************************************************************************************/
|
|
32
32
|
export { getCumulativeWidth, getLighterColor, svgQuadraticCurvePath, svgPath, bezierCommand, getSegmentString, getCurvePathWithSegments, getPreviousSegmentsLastPoint, getPathWithHighlight, getRegionPathObjects, getSegmentedPathObjects, getArrowPoints, getAxesAndRulesProps, getExtendedContainerHeightWithPadding, getSecondaryDataWithOffsetIncluded, getArrowProperty, getAllArrowProperties, maxAndMinUtil, computeMaxAndMinItems, getLabelTextUtil, getXForLineInBar, getYForLineInBar, clone, getLineConfigForBarChart, adjustToOffset } from './utils';
|
|
33
|
-
export { chartTypes, yAxisSides, loc, SEGMENT_START, SEGMENT_END, RANGE_ENTER, RANGE_EXIT, STOP, ruleTypes, AxesAndRulesDefaults, defaultArrowConfig, BarDefaults, defaultLineConfig, LineDefaults, defaultPointerConfig, pieColors, populationDefaults } from './utils/constants';
|
|
33
|
+
export { chartTypes, yAxisSides, loc, SEGMENT_START, SEGMENT_END, RANGE_ENTER, RANGE_EXIT, STOP, ruleTypes, AxesAndRulesDefaults, defaultArrowConfig, BarDefaults, defaultLineConfig, LineDefaults, defaultPointerConfig, pieColors, populationDefaults, defaultAnimationDuration } from './utils/constants';
|