gifted-charts-core 0.0.51 → 0.1.0
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 +20 -13
- package/src/PieChart/pro.ts +11 -7
- 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
|
@@ -26,17 +26,18 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
26
26
|
import { defaultAnimationDuration } from '../utils/constants';
|
|
27
27
|
export var usePiePro = function (props) {
|
|
28
28
|
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;
|
|
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 ? 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
30
|
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);
|
|
31
|
+
var total = data.reduce(function (acc, item) { return acc + (item === null || item === void 0 ? void 0 : item.value); }, 0);
|
|
32
32
|
var animationDuration = (_b = props.animationDuration) !== null && _b !== void 0 ? _b : defaultAnimationDuration;
|
|
33
33
|
// let endAngleLocal = 0
|
|
34
34
|
var addValues = function (index) {
|
|
35
|
+
var _a;
|
|
35
36
|
if (index < 0)
|
|
36
37
|
return 0;
|
|
37
38
|
var sum = 0;
|
|
38
39
|
for (var i = 0; i <= index; i++)
|
|
39
|
-
sum += data[i].value;
|
|
40
|
+
sum += (_a = data[i]) === null || _a === void 0 ? void 0 : _a.value;
|
|
40
41
|
return sum;
|
|
41
42
|
};
|
|
42
43
|
var labelsPosition = props.labelsPosition
|
|
@@ -45,6 +46,7 @@ export var usePiePro = function (props) {
|
|
|
45
46
|
? 'outward'
|
|
46
47
|
: 'mid';
|
|
47
48
|
var getCoordinates = function (index, additionalValue, addInOnlyStart, addInOnlyEnd, totalParam) {
|
|
49
|
+
var _a;
|
|
48
50
|
var addedValue = addValues(index - 1) + (addInOnlyEnd ? 0 : additionalValue !== null && additionalValue !== void 0 ? additionalValue : 0);
|
|
49
51
|
var angle = (addedValue / (totalParam !== null && totalParam !== void 0 ? totalParam : total)) * endAngle + startAngle;
|
|
50
52
|
var startInnerX = radius + Math.cos(angle) * innerRadius;
|
|
@@ -52,7 +54,7 @@ export var usePiePro = function (props) {
|
|
|
52
54
|
var startOuterX = radius + Math.cos(angle) * radius;
|
|
53
55
|
var startOuterY = radius - Math.sin(angle) * radius;
|
|
54
56
|
var value = addValues(index - 1) +
|
|
55
|
-
data[index].value +
|
|
57
|
+
((_a = data[index]) === null || _a === void 0 ? void 0 : _a.value) +
|
|
56
58
|
(addInOnlyStart ? 0 : additionalValue !== null && additionalValue !== void 0 ? additionalValue : 0);
|
|
57
59
|
angle = (value / (totalParam !== null && totalParam !== void 0 ? totalParam : total)) * endAngle + startAngle;
|
|
58
60
|
var endOuterX = radius + Math.cos(angle) * radius;
|
|
@@ -71,7 +73,8 @@ export var usePiePro = function (props) {
|
|
|
71
73
|
};
|
|
72
74
|
};
|
|
73
75
|
var getTextCoordinates = function (index, labelPos) {
|
|
74
|
-
var
|
|
76
|
+
var _a;
|
|
77
|
+
var value = addValues(index - 1) + ((_a = data[index]) === null || _a === void 0 ? void 0 : _a.value) / 2;
|
|
75
78
|
var angle = (value / total) * endAngle + startAngle;
|
|
76
79
|
var labelPosition = labelPos || labelsPosition;
|
|
77
80
|
var x = radius +
|
|
@@ -105,16 +108,20 @@ export var usePiePro = function (props) {
|
|
|
105
108
|
return "M".concat(radius + innerRadius, ",").concat(radius, " h").concat(radius - innerRadius, " ");
|
|
106
109
|
};
|
|
107
110
|
var getPath = function (index, totalParam) {
|
|
108
|
-
var _a;
|
|
109
|
-
var
|
|
110
|
-
var isLargeArc =
|
|
111
|
-
|
|
111
|
+
var _a, _b;
|
|
112
|
+
var _c = getCoordinates(index, 0, false, false, totalParam), endOuterX = _c.endOuterX, endOuterY = _c.endOuterY;
|
|
113
|
+
var isLargeArc = semiCircle
|
|
114
|
+
? 0
|
|
115
|
+
: ((_a = data[index]) === null || _a === void 0 ? void 0 : _a.value) / (totalParam !== null && totalParam !== void 0 ? totalParam : total) > 0.5
|
|
116
|
+
? 1
|
|
117
|
+
: 0;
|
|
118
|
+
var arc = "A".concat(radius + ((_b = props.strokeWidth) !== null && _b !== void 0 ? _b : 0) / 2, ",").concat(radius, " 0 ").concat(isLargeArc, " 0 ");
|
|
112
119
|
var path = "".concat(arc, " ").concat(endOuterX, ", ").concat(endOuterY, "\n L").concat(radius, ",").concat(radius, " ");
|
|
113
120
|
initial = "M".concat(radius, ",").concat(radius, " L").concat(endOuterX, ",").concat(endOuterY);
|
|
114
121
|
return path;
|
|
115
122
|
};
|
|
116
123
|
var getDonutPath = function (index, item, totalParam) {
|
|
117
|
-
var _a;
|
|
124
|
+
var _a, _b;
|
|
118
125
|
var additionalForStart = item.isStartEdgeCurved || item.startEdgeRadius
|
|
119
126
|
? (radius - innerRadius) / (radius / 20)
|
|
120
127
|
: 0;
|
|
@@ -123,10 +130,10 @@ export var usePiePro = function (props) {
|
|
|
123
130
|
: 0;
|
|
124
131
|
var cropAtEnd = !!(index === data.length - 1 &&
|
|
125
132
|
(item.isEndEdgeCurved || item.endEdgeRadius));
|
|
126
|
-
var
|
|
127
|
-
var isLargeArc = data[index].value / (totalParam !== null && totalParam !== void 0 ? totalParam : total) > 0.5 ? 1 : 0;
|
|
133
|
+
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;
|
|
134
|
+
var isLargeArc = ((_a = data[index]) === null || _a === void 0 ? void 0 : _a.value) / (totalParam !== null && totalParam !== void 0 ? totalParam : total) > 0.5 ? 1 : 0;
|
|
128
135
|
var innerArc = "A".concat(innerRadius, ",").concat(innerRadius, " 0 ").concat(isLargeArc, " 1 ");
|
|
129
|
-
var outerArc = "A".concat(radius + ((
|
|
136
|
+
var outerArc = "A".concat(radius + ((_b = props.strokeWidth) !== null && _b !== void 0 ? _b : 0) / 2, ",").concat(radius, " 0 ").concat(isLargeArc, " 0 ");
|
|
130
137
|
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
138
|
initial = "M".concat(endInnerX, ",").concat(endInnerY, " L").concat(endOuterX, ",").concat(endOuterY, " ");
|
|
132
139
|
return path;
|
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
|
|
@@ -187,7 +191,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
|
|
|
187
191
|
totalParam
|
|
188
192
|
)
|
|
189
193
|
|
|
190
|
-
const isLargeArc = data[index]
|
|
194
|
+
const isLargeArc = data[index]?.value / (totalParam ?? total) > 0.5 ? 1 : 0
|
|
191
195
|
|
|
192
196
|
const innerArc = `A${innerRadius},${innerRadius} 0 ${isLargeArc} 1 `
|
|
193
197
|
const outerArc = `A${
|
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';
|