victory-pie 11.2.0 → 11.4.2
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/CHANGELOG.md +17 -0
- package/dist/victory-pie.js +25069 -20280
- package/dist/victory-pie.min.js +1 -9
- package/es/components/helper-methods.js +165 -0
- package/es/components/victory-pie.js +140 -0
- package/es/index.js +2 -0
- package/lib/components/helper-methods.js +187 -171
- package/lib/components/victory-pie.js +150 -161
- package/lib/index.js +12 -2
- package/package.json +6 -4
- package/src/components/helper-methods.js +6 -7
- package/src/components/victory-pie.js +1 -1
|
@@ -1,171 +1,187 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
style
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
var
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
var
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
var
|
|
124
|
-
var
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
return
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
},
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
|
|
5
|
+
var _omit2 = require("lodash/omit");
|
|
6
|
+
|
|
7
|
+
var _omit3 = _interopRequireDefault(_omit2);
|
|
8
|
+
|
|
9
|
+
var _isFunction2 = require("lodash/isFunction");
|
|
10
|
+
|
|
11
|
+
var _isFunction3 = _interopRequireDefault(_isFunction2);
|
|
12
|
+
|
|
13
|
+
var _defaults2 = require("lodash/defaults");
|
|
14
|
+
|
|
15
|
+
var _defaults3 = _interopRequireDefault(_defaults2);
|
|
16
|
+
|
|
17
|
+
var _assign2 = require("lodash/assign");
|
|
18
|
+
|
|
19
|
+
var _assign3 = _interopRequireDefault(_assign2);
|
|
20
|
+
|
|
21
|
+
var _d3Shape = require("d3-shape");
|
|
22
|
+
|
|
23
|
+
var d3Shape = _interopRequireWildcard(_d3Shape);
|
|
24
|
+
|
|
25
|
+
var _victoryCore = require("victory-core");
|
|
26
|
+
|
|
27
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
28
|
+
|
|
29
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
|
+
|
|
31
|
+
/*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2, 45, 135, 180, 225, 315] }]*/
|
|
32
|
+
exports.default = {
|
|
33
|
+
degreesToRadians: function (degrees) {
|
|
34
|
+
return degrees * (Math.PI / 180);
|
|
35
|
+
},
|
|
36
|
+
checkForValidText: function (text) {
|
|
37
|
+
if (text === undefined || text === null) {
|
|
38
|
+
return text;
|
|
39
|
+
} else {
|
|
40
|
+
return "" + text;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
getSliceStyle: function (datum, index, calculatedValues) {
|
|
44
|
+
var style = calculatedValues.style,
|
|
45
|
+
colors = calculatedValues.colors;
|
|
46
|
+
|
|
47
|
+
var fill = this.getColor(style, colors, index);
|
|
48
|
+
var dataStyles = (0, _omit3.default)(datum, ["_x", "_y", "x", "y", "label"]);
|
|
49
|
+
return (0, _defaults3.default)({}, dataStyles, { fill: fill }, style.data);
|
|
50
|
+
},
|
|
51
|
+
getBaseProps: function (props, fallbackProps) {
|
|
52
|
+
props = _victoryCore.Helpers.modifyProps(props, fallbackProps, "pie");
|
|
53
|
+
var calculatedValues = this.getCalculatedValues(props);
|
|
54
|
+
var slices = calculatedValues.slices,
|
|
55
|
+
style = calculatedValues.style,
|
|
56
|
+
pathFunction = calculatedValues.pathFunction,
|
|
57
|
+
data = calculatedValues.data,
|
|
58
|
+
origin = calculatedValues.origin;
|
|
59
|
+
|
|
60
|
+
var childProps = {
|
|
61
|
+
parent: {
|
|
62
|
+
standalone: props.standalone, slices: slices, pathFunction: pathFunction,
|
|
63
|
+
width: props.width, height: props.height, style: style.parent
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
for (var index = 0, len = slices.length; index < len; index++) {
|
|
68
|
+
var slice = slices[index];
|
|
69
|
+
var datum = data[index];
|
|
70
|
+
var eventKey = datum.eventKey || index;
|
|
71
|
+
var dataProps = {
|
|
72
|
+
index: index, slice: slice, pathFunction: pathFunction, datum: datum, data: data, origin: origin,
|
|
73
|
+
style: this.getSliceStyle(datum, index, calculatedValues)
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
childProps[eventKey] = {
|
|
77
|
+
data: dataProps,
|
|
78
|
+
labels: this.getLabelProps(props, dataProps, calculatedValues)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return childProps;
|
|
82
|
+
},
|
|
83
|
+
getLabelProps: function (props, dataProps, calculatedValues) {
|
|
84
|
+
var index = dataProps.index,
|
|
85
|
+
datum = dataProps.datum,
|
|
86
|
+
data = dataProps.data,
|
|
87
|
+
slice = dataProps.slice;
|
|
88
|
+
var style = calculatedValues.style,
|
|
89
|
+
radius = calculatedValues.radius,
|
|
90
|
+
origin = calculatedValues.origin;
|
|
91
|
+
|
|
92
|
+
var labelStyle = _victoryCore.Helpers.evaluateStyle((0, _assign3.default)({ padding: 0 }, style.labels), datum, props.active);
|
|
93
|
+
var labelRadius = _victoryCore.Helpers.evaluateProp(props.labelRadius, datum);
|
|
94
|
+
var labelPosition = this.getLabelPosition(radius, labelRadius, labelStyle);
|
|
95
|
+
var position = labelPosition.centroid(slice);
|
|
96
|
+
var orientation = this.getLabelOrientation(slice);
|
|
97
|
+
return {
|
|
98
|
+
index: index, datum: datum, data: data, slice: slice, orientation: orientation,
|
|
99
|
+
style: labelStyle,
|
|
100
|
+
x: Math.round(position[0]) + origin.x,
|
|
101
|
+
y: Math.round(position[1]) + origin.y,
|
|
102
|
+
text: this.getLabelText(props, datum, index),
|
|
103
|
+
textAnchor: labelStyle.textAnchor || this.getTextAnchor(orientation),
|
|
104
|
+
verticalAnchor: labelStyle.verticalAnchor || this.getVerticalAnchor(orientation),
|
|
105
|
+
angle: labelStyle.angle
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
getCalculatedValues: function (props) {
|
|
109
|
+
var theme = props.theme,
|
|
110
|
+
colorScale = props.colorScale,
|
|
111
|
+
width = props.width,
|
|
112
|
+
height = props.height;
|
|
113
|
+
|
|
114
|
+
var styleObject = theme && theme.pie && theme.pie.style ? theme.pie.style : {};
|
|
115
|
+
var style = _victoryCore.Helpers.getStyles(props.style, styleObject, "auto", "100%");
|
|
116
|
+
var colors = Array.isArray(colorScale) ? colorScale : _victoryCore.Style.getColorScale(colorScale);
|
|
117
|
+
var padding = _victoryCore.Helpers.getPadding(props);
|
|
118
|
+
var radius = this.getRadius(props, padding);
|
|
119
|
+
var offsetWidth = (radius + padding.left + (width - radius - padding.right)) / 2;
|
|
120
|
+
var offsetHeight = (radius + padding.top + (height - radius - padding.bottom)) / 2;
|
|
121
|
+
var origin = { x: offsetWidth, y: offsetHeight };
|
|
122
|
+
var data = _victoryCore.Data.getData(props);
|
|
123
|
+
var slices = this.getSlices(props, data);
|
|
124
|
+
var pathFunction = d3Shape.arc().cornerRadius(props.cornerRadius).outerRadius(radius).innerRadius(props.innerRadius);
|
|
125
|
+
return { style: style, colors: colors, padding: padding, radius: radius, data: data, slices: slices, pathFunction: pathFunction, origin: origin };
|
|
126
|
+
},
|
|
127
|
+
getColor: function (style, colors, index) {
|
|
128
|
+
if (style && style.data && style.data.fill) {
|
|
129
|
+
return style.data.fill;
|
|
130
|
+
}
|
|
131
|
+
return colors && colors[index % colors.length];
|
|
132
|
+
},
|
|
133
|
+
getRadius: function (props, padding) {
|
|
134
|
+
return Math.min(props.width - padding.left - padding.right, props.height - padding.top - padding.bottom) / 2;
|
|
135
|
+
},
|
|
136
|
+
getLabelPosition: function (radius, labelRadius, style) {
|
|
137
|
+
var padding = style && style.padding || 0;
|
|
138
|
+
var arcRadius = labelRadius || radius + padding;
|
|
139
|
+
return d3Shape.arc().outerRadius(arcRadius).innerRadius(arcRadius);
|
|
140
|
+
},
|
|
141
|
+
getLabelOrientation: function (slice) {
|
|
142
|
+
var radiansToDegrees = function (radians) {
|
|
143
|
+
return radians * (180 / Math.PI);
|
|
144
|
+
};
|
|
145
|
+
var start = radiansToDegrees(slice.startAngle);
|
|
146
|
+
var end = radiansToDegrees(slice.endAngle);
|
|
147
|
+
var degree = start + (end - start) / 2;
|
|
148
|
+
if (degree < 45 || degree > 315) {
|
|
149
|
+
return "top";
|
|
150
|
+
} else if (degree >= 45 && degree < 135) {
|
|
151
|
+
return "right";
|
|
152
|
+
} else if (degree >= 135 && degree < 225) {
|
|
153
|
+
return "bottom";
|
|
154
|
+
} else {
|
|
155
|
+
return "left";
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
getTextAnchor: function (orientation) {
|
|
159
|
+
if (orientation === "top" || orientation === "bottom") {
|
|
160
|
+
return "middle";
|
|
161
|
+
}
|
|
162
|
+
return orientation === "right" ? "start" : "end";
|
|
163
|
+
},
|
|
164
|
+
getVerticalAnchor: function (orientation) {
|
|
165
|
+
if (orientation === "left" || orientation === "right") {
|
|
166
|
+
return "middle";
|
|
167
|
+
}
|
|
168
|
+
return orientation === "bottom" ? "start" : "end";
|
|
169
|
+
},
|
|
170
|
+
getLabelText: function (props, datum, index) {
|
|
171
|
+
var text = void 0;
|
|
172
|
+
if (datum.label) {
|
|
173
|
+
text = datum.label;
|
|
174
|
+
} else if (Array.isArray(props.labels)) {
|
|
175
|
+
text = props.labels[index];
|
|
176
|
+
} else {
|
|
177
|
+
text = (0, _isFunction3.default)(props.labels) ? props.labels(datum) : datum.xName || datum._x;
|
|
178
|
+
}
|
|
179
|
+
return this.checkForValidText(text);
|
|
180
|
+
},
|
|
181
|
+
getSlices: function (props, data) {
|
|
182
|
+
var layoutFunction = d3Shape.pie().sort(null).startAngle(this.degreesToRadians(props.startAngle)).endAngle(this.degreesToRadians(props.endAngle)).padAngle(this.degreesToRadians(props.padAngle)).value(function (datum) {
|
|
183
|
+
return datum._y;
|
|
184
|
+
});
|
|
185
|
+
return layoutFunction(data);
|
|
186
|
+
}
|
|
187
|
+
};
|