victory-pie
Advanced tools
Comparing version 32.3.7 to 33.0.0
@@ -61,3 +61,3 @@ import _isNil from "lodash/isNil"; | ||
var slices = getSlices(props, data); | ||
return { | ||
return _assign({}, props, { | ||
style: style, | ||
@@ -70,3 +70,3 @@ colors: colors, | ||
origin: origin | ||
}; | ||
}); | ||
}; | ||
@@ -150,3 +150,3 @@ | ||
var getLabelProps = function (props, dataProps, calculatedValues) { | ||
var getLabelProps = function (text, dataProps, calculatedValues) { | ||
var index = dataProps.index, | ||
@@ -158,11 +158,25 @@ datum = dataProps.datum, | ||
defaultRadius = calculatedValues.defaultRadius, | ||
origin = calculatedValues.origin; | ||
var labelStyle = Helpers.evaluateStyle(_assign({ | ||
origin = calculatedValues.origin, | ||
width = calculatedValues.width, | ||
height = calculatedValues.height, | ||
labelRadius = calculatedValues.labelRadius, | ||
labelPosition = calculatedValues.labelPosition; | ||
var evaluatedRadius = Helpers.evaluateProp(labelRadius, _assign({ | ||
text: text | ||
}, dataProps)); | ||
var labelStyle = _assign({ | ||
padding: 0 | ||
}, style.labels), datum, props.active); | ||
var labelRadius = Helpers.evaluateProp(props.labelRadius, datum); | ||
var labelArc = getLabelArc(defaultRadius, labelRadius, labelStyle); | ||
var position = getLabelPosition(labelArc, slice, props.labelPosition); | ||
}, style.labels); | ||
var evaluatedStyle = Helpers.evaluateStyle(labelStyle, _assign({ | ||
evaluatedRadius: evaluatedRadius, | ||
text: text | ||
}, dataProps)); | ||
var labelArc = getLabelArc(defaultRadius, evaluatedRadius, evaluatedStyle); | ||
var position = getLabelPosition(labelArc, slice, labelPosition); | ||
var orientation = getLabelOrientation(slice); | ||
return { | ||
width: width, | ||
height: height, | ||
index: index, | ||
@@ -173,6 +187,6 @@ datum: datum, | ||
orientation: orientation, | ||
text: text, | ||
style: labelStyle, | ||
x: Math.round(position[0]) + origin.x, | ||
y: Math.round(position[1]) + origin.y, | ||
text: getLabelText(props, datum, index), | ||
textAnchor: labelStyle.textAnchor || getTextAnchor(orientation), | ||
@@ -191,14 +205,13 @@ verticalAnchor: labelStyle.verticalAnchor || getVerticalAnchor(orientation), | ||
origin = calculatedValues.origin, | ||
defaultRadius = calculatedValues.defaultRadius; | ||
var _props = props, | ||
labels = _props.labels, | ||
events = _props.events, | ||
sharedEvents = _props.sharedEvents, | ||
height = _props.height, | ||
width = _props.width, | ||
standalone = _props.standalone, | ||
name = _props.name, | ||
innerRadius = _props.innerRadius, | ||
cornerRadius = _props.cornerRadius, | ||
padAngle = _props.padAngle; | ||
defaultRadius = calculatedValues.defaultRadius, | ||
labels = calculatedValues.labels, | ||
events = calculatedValues.events, | ||
sharedEvents = calculatedValues.sharedEvents, | ||
height = calculatedValues.height, | ||
width = calculatedValues.width, | ||
standalone = calculatedValues.standalone, | ||
name = calculatedValues.name, | ||
innerRadius = calculatedValues.innerRadius, | ||
cornerRadius = calculatedValues.cornerRadius, | ||
padAngle = calculatedValues.padAngle; | ||
var radius = props.radius || defaultRadius; | ||
@@ -241,3 +254,3 @@ var initialChildProps = { | ||
if (text !== undefined && text !== null || labels && (events || sharedEvents)) { | ||
childProps[eventKey].labels = getLabelProps(props, dataProps, calculatedValues); | ||
childProps[eventKey].labels = getLabelProps(text, dataProps, calculatedValues); | ||
} | ||
@@ -244,0 +257,0 @@ |
145
es/slice.js
@@ -8,14 +8,2 @@ import _isFunction from "lodash/isFunction"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
import React from "react"; | ||
@@ -26,94 +14,53 @@ import PropTypes from "prop-types"; | ||
var Slice = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inherits(Slice, _React$Component); | ||
var getPath = function (props) { | ||
var slice = props.slice; | ||
function Slice() { | ||
_classCallCheck(this, Slice); | ||
return _possibleConstructorReturn(this, (Slice.__proto__ || Object.getPrototypeOf(Slice)).apply(this, arguments)); | ||
if (_isFunction(props.pathFunction)) { | ||
return props.pathFunction(slice); | ||
} | ||
_createClass(Slice, [{ | ||
key: "getPath", | ||
value: function getPath(props) { | ||
var datum = props.datum, | ||
active = props.active, | ||
slice = props.slice; | ||
var cornerRadius = Helpers.evaluateProp(props.cornerRadius, props); | ||
var innerRadius = Helpers.evaluateProp(props.innerRadius, props); | ||
var radius = Helpers.evaluateProp(props.radius, props); | ||
var padAngle = Helpers.degreesToRadians(Helpers.evaluateProp(props.padAngle, props)); | ||
var startAngle = Helpers.degreesToRadians(Helpers.evaluateProp(props.sliceStartAngle, props)); | ||
var endAngle = Helpers.degreesToRadians(Helpers.evaluateProp(props.sliceEndAngle, props)); | ||
var pathFunction = d3Shape.arc().cornerRadius(cornerRadius).outerRadius(radius).innerRadius(innerRadius); | ||
return pathFunction(_defaults({ | ||
startAngle: startAngle, | ||
endAngle: endAngle, | ||
padAngle: padAngle | ||
}, slice)); | ||
}; | ||
if (_isFunction(props.pathFunction)) { | ||
return props.pathFunction(slice); | ||
} | ||
var Slice = function (props) { | ||
var defaultTransform = props.origin ? "translate(".concat(props.origin.x, ", ").concat(props.origin.y, ")") : undefined; | ||
return React.cloneElement(props.pathComponent, _objectSpread({}, props.events, { | ||
d: getPath(props), | ||
style: Helpers.evaluateStyle(props.style, props), | ||
transform: props.transform || defaultTransform, | ||
className: props.className, | ||
role: props.role, | ||
shapeRendering: props.shapeRendering, | ||
clipPath: props.clipPath | ||
})); | ||
}; | ||
var cornerRadius = Helpers.evaluateProp(props.cornerRadius, datum, active); | ||
var innerRadius = Helpers.evaluateProp(props.innerRadius, datum, active); | ||
var radius = Helpers.evaluateProp(props.radius, datum, active); | ||
var padAngle = Helpers.degreesToRadians(Helpers.evaluateProp(props.padAngle, datum, active)); | ||
var startAngle = Helpers.degreesToRadians(Helpers.evaluateProp(props.sliceStartAngle, datum, active)); | ||
var endAngle = Helpers.degreesToRadians(Helpers.evaluateProp(props.sliceEndAngle, datum, active)); | ||
var pathFunction = d3Shape.arc().cornerRadius(cornerRadius).outerRadius(radius).innerRadius(innerRadius); | ||
return pathFunction(_defaults({ | ||
startAngle: startAngle, | ||
endAngle: endAngle, | ||
padAngle: padAngle | ||
}, slice)); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var _props = this.props, | ||
datum = _props.datum, | ||
active = _props.active, | ||
role = _props.role, | ||
shapeRendering = _props.shapeRendering, | ||
className = _props.className, | ||
origin = _props.origin, | ||
events = _props.events, | ||
pathComponent = _props.pathComponent, | ||
style = _props.style, | ||
clipPath = _props.clipPath; | ||
var defaultTransform = origin ? "translate(".concat(origin.x, ", ").concat(origin.y, ")") : undefined; | ||
var transform = this.props.transform || defaultTransform; | ||
return React.cloneElement(pathComponent, { | ||
className: className, | ||
role: role, | ||
shapeRendering: shapeRendering, | ||
events: events, | ||
transform: transform, | ||
clipPath: clipPath, | ||
style: Helpers.evaluateStyle(style, datum, active), | ||
d: this.getPath(this.props) | ||
}); | ||
} | ||
}]); | ||
return Slice; | ||
}(React.Component); | ||
Object.defineProperty(Slice, "propTypes", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: _objectSpread({}, CommonProps.primitiveProps, { | ||
cornerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
datum: PropTypes.object, | ||
innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
padAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
pathComponent: PropTypes.element, | ||
pathFunction: PropTypes.func, | ||
radius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
slice: PropTypes.object, | ||
sliceEndAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
sliceStartAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]) | ||
}) | ||
Slice.propTypes = _objectSpread({}, CommonProps.primitiveProps, { | ||
cornerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
datum: PropTypes.object, | ||
innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
padAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
pathComponent: PropTypes.element, | ||
pathFunction: PropTypes.func, | ||
radius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
slice: PropTypes.object, | ||
sliceEndAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
sliceStartAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]) | ||
}); | ||
Object.defineProperty(Slice, "defaultProps", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: { | ||
pathComponent: React.createElement(Path, null) | ||
} | ||
}); | ||
export { Slice as default }; | ||
Slice.defaultProps = { | ||
pathComponent: React.createElement(Path, null), | ||
role: "presentation", | ||
shapeRendering: "auto" | ||
}; | ||
export default Slice; |
@@ -84,3 +84,3 @@ "use strict"; | ||
var slices = getSlices(props, data); | ||
return { | ||
return (0, _assign2.default)({}, props, { | ||
style: style, | ||
@@ -93,3 +93,3 @@ colors: colors, | ||
origin: origin | ||
}; | ||
}); | ||
}; | ||
@@ -171,3 +171,3 @@ | ||
var getLabelProps = function (props, dataProps, calculatedValues) { | ||
var getLabelProps = function (text, dataProps, calculatedValues) { | ||
var index = dataProps.index, | ||
@@ -179,14 +179,27 @@ datum = dataProps.datum, | ||
defaultRadius = calculatedValues.defaultRadius, | ||
origin = calculatedValues.origin; | ||
origin = calculatedValues.origin, | ||
width = calculatedValues.width, | ||
height = calculatedValues.height, | ||
labelRadius = calculatedValues.labelRadius, | ||
labelPosition = calculatedValues.labelPosition; | ||
var labelStyle = _victoryCore.Helpers.evaluateStyle((0, _assign2.default)({ | ||
var evaluatedRadius = _victoryCore.Helpers.evaluateProp(labelRadius, (0, _assign2.default)({ | ||
text: text | ||
}, dataProps)); | ||
var labelStyle = (0, _assign2.default)({ | ||
padding: 0 | ||
}, style.labels), datum, props.active); | ||
}, style.labels); | ||
var labelRadius = _victoryCore.Helpers.evaluateProp(props.labelRadius, datum); | ||
var evaluatedStyle = _victoryCore.Helpers.evaluateStyle(labelStyle, (0, _assign2.default)({ | ||
evaluatedRadius: evaluatedRadius, | ||
text: text | ||
}, dataProps)); | ||
var labelArc = getLabelArc(defaultRadius, labelRadius, labelStyle); | ||
var position = getLabelPosition(labelArc, slice, props.labelPosition); | ||
var labelArc = getLabelArc(defaultRadius, evaluatedRadius, evaluatedStyle); | ||
var position = getLabelPosition(labelArc, slice, labelPosition); | ||
var orientation = getLabelOrientation(slice); | ||
return { | ||
width: width, | ||
height: height, | ||
index: index, | ||
@@ -197,6 +210,6 @@ datum: datum, | ||
orientation: orientation, | ||
text: text, | ||
style: labelStyle, | ||
x: Math.round(position[0]) + origin.x, | ||
y: Math.round(position[1]) + origin.y, | ||
text: getLabelText(props, datum, index), | ||
textAnchor: labelStyle.textAnchor || getTextAnchor(orientation), | ||
@@ -215,14 +228,13 @@ verticalAnchor: labelStyle.verticalAnchor || getVerticalAnchor(orientation), | ||
origin = calculatedValues.origin, | ||
defaultRadius = calculatedValues.defaultRadius; | ||
var _props = props, | ||
labels = _props.labels, | ||
events = _props.events, | ||
sharedEvents = _props.sharedEvents, | ||
height = _props.height, | ||
width = _props.width, | ||
standalone = _props.standalone, | ||
name = _props.name, | ||
innerRadius = _props.innerRadius, | ||
cornerRadius = _props.cornerRadius, | ||
padAngle = _props.padAngle; | ||
defaultRadius = calculatedValues.defaultRadius, | ||
labels = calculatedValues.labels, | ||
events = calculatedValues.events, | ||
sharedEvents = calculatedValues.sharedEvents, | ||
height = calculatedValues.height, | ||
width = calculatedValues.width, | ||
standalone = calculatedValues.standalone, | ||
name = calculatedValues.name, | ||
innerRadius = calculatedValues.innerRadius, | ||
cornerRadius = calculatedValues.cornerRadius, | ||
padAngle = calculatedValues.padAngle; | ||
var radius = props.radius || defaultRadius; | ||
@@ -264,3 +276,3 @@ var initialChildProps = { | ||
if (text !== undefined && text !== null || labels && (events || sharedEvents)) { | ||
childProps[eventKey].labels = getLabelProps(props, dataProps, calculatedValues); | ||
childProps[eventKey].labels = getLabelProps(text, dataProps, calculatedValues); | ||
} | ||
@@ -267,0 +279,0 @@ |
146
lib/slice.js
@@ -28,112 +28,60 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var getPath = function (props) { | ||
var slice = props.slice; | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var Slice = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inherits(Slice, _React$Component); | ||
function Slice() { | ||
_classCallCheck(this, Slice); | ||
return _possibleConstructorReturn(this, (Slice.__proto__ || Object.getPrototypeOf(Slice)).apply(this, arguments)); | ||
if ((0, _isFunction2.default)(props.pathFunction)) { | ||
return props.pathFunction(slice); | ||
} | ||
_createClass(Slice, [{ | ||
key: "getPath", | ||
value: function getPath(props) { | ||
var datum = props.datum, | ||
active = props.active, | ||
slice = props.slice; | ||
var cornerRadius = _victoryCore.Helpers.evaluateProp(props.cornerRadius, props); | ||
if ((0, _isFunction2.default)(props.pathFunction)) { | ||
return props.pathFunction(slice); | ||
} | ||
var innerRadius = _victoryCore.Helpers.evaluateProp(props.innerRadius, props); | ||
var cornerRadius = _victoryCore.Helpers.evaluateProp(props.cornerRadius, datum, active); | ||
var radius = _victoryCore.Helpers.evaluateProp(props.radius, props); | ||
var innerRadius = _victoryCore.Helpers.evaluateProp(props.innerRadius, datum, active); | ||
var padAngle = _victoryCore.Helpers.degreesToRadians(_victoryCore.Helpers.evaluateProp(props.padAngle, props)); | ||
var radius = _victoryCore.Helpers.evaluateProp(props.radius, datum, active); | ||
var startAngle = _victoryCore.Helpers.degreesToRadians(_victoryCore.Helpers.evaluateProp(props.sliceStartAngle, props)); | ||
var padAngle = _victoryCore.Helpers.degreesToRadians(_victoryCore.Helpers.evaluateProp(props.padAngle, datum, active)); | ||
var endAngle = _victoryCore.Helpers.degreesToRadians(_victoryCore.Helpers.evaluateProp(props.sliceEndAngle, props)); | ||
var startAngle = _victoryCore.Helpers.degreesToRadians(_victoryCore.Helpers.evaluateProp(props.sliceStartAngle, datum, active)); | ||
var pathFunction = d3Shape.arc().cornerRadius(cornerRadius).outerRadius(radius).innerRadius(innerRadius); | ||
return pathFunction((0, _defaults2.default)({ | ||
startAngle: startAngle, | ||
endAngle: endAngle, | ||
padAngle: padAngle | ||
}, slice)); | ||
}; | ||
var endAngle = _victoryCore.Helpers.degreesToRadians(_victoryCore.Helpers.evaluateProp(props.sliceEndAngle, datum, active)); | ||
var Slice = function (props) { | ||
var defaultTransform = props.origin ? "translate(".concat(props.origin.x, ", ").concat(props.origin.y, ")") : undefined; | ||
return _react.default.cloneElement(props.pathComponent, _objectSpread({}, props.events, { | ||
d: getPath(props), | ||
style: _victoryCore.Helpers.evaluateStyle(props.style, props), | ||
transform: props.transform || defaultTransform, | ||
className: props.className, | ||
role: props.role, | ||
shapeRendering: props.shapeRendering, | ||
clipPath: props.clipPath | ||
})); | ||
}; | ||
var pathFunction = d3Shape.arc().cornerRadius(cornerRadius).outerRadius(radius).innerRadius(innerRadius); | ||
return pathFunction((0, _defaults2.default)({ | ||
startAngle: startAngle, | ||
endAngle: endAngle, | ||
padAngle: padAngle | ||
}, slice)); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var _props = this.props, | ||
datum = _props.datum, | ||
active = _props.active, | ||
role = _props.role, | ||
shapeRendering = _props.shapeRendering, | ||
className = _props.className, | ||
origin = _props.origin, | ||
events = _props.events, | ||
pathComponent = _props.pathComponent, | ||
style = _props.style, | ||
clipPath = _props.clipPath; | ||
var defaultTransform = origin ? "translate(".concat(origin.x, ", ").concat(origin.y, ")") : undefined; | ||
var transform = this.props.transform || defaultTransform; | ||
return _react.default.cloneElement(pathComponent, { | ||
className: className, | ||
role: role, | ||
shapeRendering: shapeRendering, | ||
events: events, | ||
transform: transform, | ||
clipPath: clipPath, | ||
style: _victoryCore.Helpers.evaluateStyle(style, datum, active), | ||
d: this.getPath(this.props) | ||
}); | ||
} | ||
}]); | ||
return Slice; | ||
}(_react.default.Component); | ||
exports.default = Slice; | ||
Object.defineProperty(Slice, "propTypes", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: _objectSpread({}, _victoryCore.CommonProps.primitiveProps, { | ||
cornerRadius: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]), | ||
datum: _propTypes.default.object, | ||
innerRadius: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]), | ||
padAngle: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]), | ||
pathComponent: _propTypes.default.element, | ||
pathFunction: _propTypes.default.func, | ||
radius: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]), | ||
slice: _propTypes.default.object, | ||
sliceEndAngle: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]), | ||
sliceStartAngle: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]) | ||
}) | ||
Slice.propTypes = _objectSpread({}, _victoryCore.CommonProps.primitiveProps, { | ||
cornerRadius: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]), | ||
datum: _propTypes.default.object, | ||
innerRadius: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]), | ||
padAngle: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]), | ||
pathComponent: _propTypes.default.element, | ||
pathFunction: _propTypes.default.func, | ||
radius: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]), | ||
slice: _propTypes.default.object, | ||
sliceEndAngle: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]), | ||
sliceStartAngle: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]) | ||
}); | ||
Object.defineProperty(Slice, "defaultProps", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: { | ||
pathComponent: _react.default.createElement(_victoryCore.Path, null) | ||
} | ||
}); | ||
Slice.defaultProps = { | ||
pathComponent: _react.default.createElement(_victoryCore.Path, null), | ||
role: "presentation", | ||
shapeRendering: "auto" | ||
}; | ||
var _default = Slice; | ||
exports.default = _default; |
{ | ||
"name": "victory-pie", | ||
"version": "32.3.7", | ||
"version": "33.0.0", | ||
"description": "Pie Component for Victory", | ||
@@ -25,3 +25,3 @@ "keywords": [ | ||
"prop-types": "^15.5.8", | ||
"victory-core": "^32.3.7" | ||
"victory-core": "^33.0.0" | ||
}, | ||
@@ -28,0 +28,0 @@ "scripts": { |
@@ -66,3 +66,3 @@ /*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2, 45, 135, 180, 225, 315] }]*/ | ||
const slices = getSlices(props, data); | ||
return { style, colors, padding, defaultRadius, data, slices, origin }; | ||
return assign({}, props, { style, colors, padding, defaultRadius, data, slices, origin }); | ||
}; | ||
@@ -138,15 +138,25 @@ | ||
const getLabelProps = (props, dataProps, calculatedValues) => { | ||
const getLabelProps = (text, dataProps, calculatedValues) => { | ||
const { index, datum, data, slice } = dataProps; | ||
const { style, defaultRadius, origin } = calculatedValues; | ||
const labelStyle = Helpers.evaluateStyle( | ||
assign({ padding: 0 }, style.labels), | ||
datum, | ||
props.active | ||
const { | ||
style, | ||
defaultRadius, | ||
origin, | ||
width, | ||
height, | ||
labelRadius, | ||
labelPosition | ||
} = calculatedValues; | ||
const evaluatedRadius = Helpers.evaluateProp(labelRadius, assign({ text }, dataProps)); | ||
const labelStyle = assign({ padding: 0 }, style.labels); | ||
const evaluatedStyle = Helpers.evaluateStyle( | ||
labelStyle, | ||
assign({ evaluatedRadius, text }, dataProps) | ||
); | ||
const labelRadius = Helpers.evaluateProp(props.labelRadius, datum); | ||
const labelArc = getLabelArc(defaultRadius, labelRadius, labelStyle); | ||
const position = getLabelPosition(labelArc, slice, props.labelPosition); | ||
const labelArc = getLabelArc(defaultRadius, evaluatedRadius, evaluatedStyle); | ||
const position = getLabelPosition(labelArc, slice, labelPosition); | ||
const orientation = getLabelOrientation(slice); | ||
return { | ||
width, | ||
height, | ||
index, | ||
@@ -157,6 +167,6 @@ datum, | ||
orientation, | ||
text, | ||
style: labelStyle, | ||
x: Math.round(position[0]) + origin.x, | ||
y: Math.round(position[1]) + origin.y, | ||
text: getLabelText(props, datum, index), | ||
textAnchor: labelStyle.textAnchor || getTextAnchor(orientation), | ||
@@ -171,4 +181,8 @@ verticalAnchor: labelStyle.verticalAnchor || getVerticalAnchor(orientation), | ||
const calculatedValues = getCalculatedValues(props); | ||
const { slices, style, data, origin, defaultRadius } = calculatedValues; | ||
const { | ||
slices, | ||
style, | ||
data, | ||
origin, | ||
defaultRadius, | ||
labels, | ||
@@ -184,3 +198,3 @@ events, | ||
padAngle | ||
} = props; | ||
} = calculatedValues; | ||
const radius = props.radius || defaultRadius; | ||
@@ -215,3 +229,3 @@ const initialChildProps = { | ||
if ((text !== undefined && text !== null) || (labels && (events || sharedEvents))) { | ||
childProps[eventKey].labels = getLabelProps(props, dataProps, calculatedValues); | ||
childProps[eventKey].labels = getLabelProps(text, dataProps, calculatedValues); | ||
} | ||
@@ -218,0 +232,0 @@ return childProps; |
119
src/slice.js
@@ -7,70 +7,57 @@ import React from "react"; | ||
export default class Slice extends React.Component { | ||
static propTypes = { | ||
...CommonProps.primitiveProps, | ||
cornerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
datum: PropTypes.object, | ||
innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
padAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
pathComponent: PropTypes.element, | ||
pathFunction: PropTypes.func, | ||
radius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
slice: PropTypes.object, | ||
sliceEndAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
sliceStartAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]) | ||
}; | ||
const getPath = (props) => { | ||
const { slice } = props; | ||
if (isFunction(props.pathFunction)) { | ||
return props.pathFunction(slice); | ||
} | ||
const cornerRadius = Helpers.evaluateProp(props.cornerRadius, props); | ||
const innerRadius = Helpers.evaluateProp(props.innerRadius, props); | ||
const radius = Helpers.evaluateProp(props.radius, props); | ||
const padAngle = Helpers.degreesToRadians(Helpers.evaluateProp(props.padAngle, props)); | ||
const startAngle = Helpers.degreesToRadians(Helpers.evaluateProp(props.sliceStartAngle, props)); | ||
const endAngle = Helpers.degreesToRadians(Helpers.evaluateProp(props.sliceEndAngle, props)); | ||
const pathFunction = d3Shape | ||
.arc() | ||
.cornerRadius(cornerRadius) | ||
.outerRadius(radius) | ||
.innerRadius(innerRadius); | ||
return pathFunction(defaults({ startAngle, endAngle, padAngle }, slice)); | ||
}; | ||
static defaultProps = { | ||
pathComponent: <Path /> | ||
}; | ||
const Slice = (props) => { | ||
const defaultTransform = props.origin | ||
? `translate(${props.origin.x}, ${props.origin.y})` | ||
: undefined; | ||
return React.cloneElement(props.pathComponent, { | ||
...props.events, | ||
d: getPath(props), | ||
style: Helpers.evaluateStyle(props.style, props), | ||
transform: props.transform || defaultTransform, | ||
className: props.className, | ||
role: props.role, | ||
shapeRendering: props.shapeRendering, | ||
clipPath: props.clipPath | ||
}); | ||
}; | ||
getPath(props) { | ||
const { datum, active, slice } = props; | ||
if (isFunction(props.pathFunction)) { | ||
return props.pathFunction(slice); | ||
} | ||
const cornerRadius = Helpers.evaluateProp(props.cornerRadius, datum, active); | ||
const innerRadius = Helpers.evaluateProp(props.innerRadius, datum, active); | ||
const radius = Helpers.evaluateProp(props.radius, datum, active); | ||
const padAngle = Helpers.degreesToRadians(Helpers.evaluateProp(props.padAngle, datum, active)); | ||
const startAngle = Helpers.degreesToRadians( | ||
Helpers.evaluateProp(props.sliceStartAngle, datum, active) | ||
); | ||
const endAngle = Helpers.degreesToRadians( | ||
Helpers.evaluateProp(props.sliceEndAngle, datum, active) | ||
); | ||
const pathFunction = d3Shape | ||
.arc() | ||
.cornerRadius(cornerRadius) | ||
.outerRadius(radius) | ||
.innerRadius(innerRadius); | ||
return pathFunction(defaults({ startAngle, endAngle, padAngle }, slice)); | ||
} | ||
Slice.propTypes = { | ||
...CommonProps.primitiveProps, | ||
cornerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
datum: PropTypes.object, | ||
innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
padAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
pathComponent: PropTypes.element, | ||
pathFunction: PropTypes.func, | ||
radius: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
slice: PropTypes.object, | ||
sliceEndAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
sliceStartAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]) | ||
}; | ||
render() { | ||
const { | ||
datum, | ||
active, | ||
role, | ||
shapeRendering, | ||
className, | ||
origin, | ||
events, | ||
pathComponent, | ||
style, | ||
clipPath | ||
} = this.props; | ||
const defaultTransform = origin ? `translate(${origin.x}, ${origin.y})` : undefined; | ||
const transform = this.props.transform || defaultTransform; | ||
return React.cloneElement(pathComponent, { | ||
className, | ||
role, | ||
shapeRendering, | ||
events, | ||
transform, | ||
clipPath, | ||
style: Helpers.evaluateStyle(style, datum, active), | ||
d: this.getPath(this.props) | ||
}); | ||
} | ||
} | ||
Slice.defaultProps = { | ||
pathComponent: <Path />, | ||
role: "presentation", | ||
shapeRendering: "auto" | ||
}; | ||
export default Slice; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
1302087
24290
21
6
+ Addedvictory-core@33.1.7(transitive)
- Removedvictory-core@32.3.7(transitive)
Updatedvictory-core@^33.0.0