victory-pie
Advanced tools
Comparing version 30.3.1 to 30.5.0
@@ -99,3 +99,3 @@ import _isPlainObject from "lodash/isPlainObject"; | ||
var getLabelPosition = function (radius, labelRadius, style) { | ||
var getLabelArc = function (radius, labelRadius, style) { | ||
var padding = style && style.padding || 0; | ||
@@ -106,2 +106,11 @@ var arcRadius = labelRadius || radius + padding; | ||
var getLabelPosition = function (arc, slice, position) { | ||
var construct = { | ||
startAngle: position === "startAngle" ? slice.endAngle : slice.startAngle, | ||
endAngle: position === "endAngle" ? slice.startAngle : slice.endAngle | ||
}; | ||
var clonedArc = Object.assign({}, slice, construct); | ||
return arc.centroid(clonedArc); | ||
}; | ||
var getLabelOrientation = function (slice) { | ||
@@ -155,4 +164,4 @@ var radiansToDegrees = function (radians) { | ||
var labelRadius = Helpers.evaluateProp(props.labelRadius, datum); | ||
var labelPosition = getLabelPosition(radius, labelRadius, labelStyle); | ||
var position = labelPosition.centroid(slice); | ||
var labelArc = getLabelArc(radius, labelRadius, labelStyle); | ||
var position = getLabelPosition(labelArc, slice, props.labelPosition); | ||
var orientation = getLabelOrientation(slice); | ||
@@ -159,0 +168,0 @@ return { |
@@ -28,3 +28,4 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
startAngle: 0, | ||
colorScale: ["#ffffff", "#f0f0f0", "#d9d9d9", "#bdbdbd", "#969696", "#737373", "#525252", "#252525", "#000000"] | ||
colorScale: ["#ffffff", "#f0f0f0", "#d9d9d9", "#bdbdbd", "#969696", "#737373", "#525252", "#252525", "#000000"], | ||
labelPosition: "centroid" | ||
}; | ||
@@ -140,2 +141,3 @@ var animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"]; | ||
labelComponent: PropTypes.element, | ||
labelPosition: PropTypes.oneOf(["startAngle", "centroid", "endAngle"]), | ||
labelRadius: PropTypes.oneOfType([CustomPropTypes.nonNegative, PropTypes.func]), | ||
@@ -142,0 +144,0 @@ labels: PropTypes.oneOfType([PropTypes.func, PropTypes.array]), |
@@ -120,3 +120,3 @@ "use strict"; | ||
var getLabelPosition = function (radius, labelRadius, style) { | ||
var getLabelArc = function (radius, labelRadius, style) { | ||
var padding = style && style.padding || 0; | ||
@@ -127,2 +127,11 @@ var arcRadius = labelRadius || radius + padding; | ||
var getLabelPosition = function (arc, slice, position) { | ||
var construct = { | ||
startAngle: position === "startAngle" ? slice.endAngle : slice.startAngle, | ||
endAngle: position === "endAngle" ? slice.startAngle : slice.endAngle | ||
}; | ||
var clonedArc = Object.assign({}, slice, construct); | ||
return arc.centroid(clonedArc); | ||
}; | ||
var getLabelOrientation = function (slice) { | ||
@@ -179,4 +188,4 @@ var radiansToDegrees = function (radians) { | ||
var labelPosition = getLabelPosition(radius, labelRadius, labelStyle); | ||
var position = labelPosition.centroid(slice); | ||
var labelArc = getLabelArc(radius, labelRadius, labelStyle); | ||
var position = getLabelPosition(labelArc, slice, props.labelPosition); | ||
var orientation = getLabelOrientation(slice); | ||
@@ -183,0 +192,0 @@ return { |
@@ -41,3 +41,4 @@ "use strict"; | ||
startAngle: 0, | ||
colorScale: ["#ffffff", "#f0f0f0", "#d9d9d9", "#bdbdbd", "#969696", "#737373", "#525252", "#252525", "#000000"] | ||
colorScale: ["#ffffff", "#f0f0f0", "#d9d9d9", "#bdbdbd", "#969696", "#737373", "#525252", "#252525", "#000000"], | ||
labelPosition: "centroid" | ||
}; | ||
@@ -154,2 +155,3 @@ var animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"]; | ||
labelComponent: _propTypes.default.element, | ||
labelPosition: _propTypes.default.oneOf(["startAngle", "centroid", "endAngle"]), | ||
labelRadius: _propTypes.default.oneOfType([_victoryCore.PropTypes.nonNegative, _propTypes.default.func]), | ||
@@ -156,0 +158,0 @@ labels: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.array]), |
{ | ||
"name": "victory-pie", | ||
"version": "30.3.1", | ||
"version": "30.5.0", | ||
"description": "Pie Component for Victory", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -253,2 +253,18 @@ # VictoryPie | ||
### labelPosition | ||
`type: "centroid" || "startAngle" || "endAngle"` | ||
The `labelPosition` prop defines the position inside the arc that will be used for positioning each slice label. If this props is not set, the label position will default to the centroid of the arc itself. | ||
*default:* `"centroid"` | ||
```playground | ||
<VictoryPie | ||
data={sampleData} | ||
labelPosition="endAngle" | ||
style={{ labels: { fill: "white", fontSize: 20, fontWeight: "bold" } }} | ||
/> | ||
``` | ||
### labelRadius | ||
@@ -255,0 +271,0 @@ |
@@ -90,3 +90,3 @@ /*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2, 45, 135, 180, 225, 315] }]*/ | ||
const getLabelPosition = (radius, labelRadius, style) => { | ||
const getLabelArc = (radius, labelRadius, style) => { | ||
const padding = style && style.padding || 0; | ||
@@ -99,2 +99,11 @@ const arcRadius = labelRadius || radius + padding; | ||
const getLabelPosition = (arc, slice, position) => { | ||
const construct = { | ||
startAngle: position === "startAngle" ? slice.endAngle : slice.startAngle, | ||
endAngle: position === "endAngle" ? slice.startAngle : slice.endAngle | ||
}; | ||
const clonedArc = Object.assign({}, slice, construct); | ||
return arc.centroid(clonedArc); | ||
}; | ||
const getLabelOrientation = (slice) => { | ||
@@ -139,4 +148,4 @@ const radiansToDegrees = (radians) => { | ||
const labelRadius = Helpers.evaluateProp(props.labelRadius, datum); | ||
const labelPosition = getLabelPosition(radius, labelRadius, labelStyle); | ||
const position = labelPosition.centroid(slice); | ||
const labelArc = getLabelArc(radius, labelRadius, labelStyle); | ||
const position = getLabelPosition(labelArc, slice, props.labelPosition); | ||
const orientation = getLabelOrientation(slice); | ||
@@ -143,0 +152,0 @@ return { |
@@ -30,3 +30,4 @@ /*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2] }]*/ | ||
"#000000" | ||
] | ||
], | ||
labelPosition: "centroid" | ||
}; | ||
@@ -104,2 +105,3 @@ | ||
labelComponent: PropTypes.element, | ||
labelPosition: PropTypes.oneOf(["startAngle", "centroid", "endAngle"]), | ||
labelRadius: PropTypes.oneOfType([ CustomPropTypes.nonNegative, PropTypes.func ]), | ||
@@ -106,0 +108,0 @@ labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]), |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1333678
24196
508