From 56bafe2a112a6cae8a4509f77b3c90307ef00d98 Mon Sep 17 00:00:00 2001 From: boygirl Date: Mon, 25 Nov 2019 20:43:57 -0800 Subject: [PATCH 1/2] allow labelPosition as a function in VictoryPie --- packages/victory-pie/src/helper-methods.js | 6 +++++- packages/victory-pie/src/victory-pie.js | 5 ++++- stories/victory-pie.js | 11 ++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/victory-pie/src/helper-methods.js b/packages/victory-pie/src/helper-methods.js index 6dae879b8..e928dd1c1 100644 --- a/packages/victory-pie/src/helper-methods.js +++ b/packages/victory-pie/src/helper-methods.js @@ -137,11 +137,15 @@ const getVerticalAnchor = (orientation) => { const getLabelProps = (text, dataProps, calculatedValues) => { const { index, datum, data, slice } = dataProps; - const { style, defaultRadius, origin, width, height, labelPosition } = calculatedValues; + const { style, defaultRadius, origin, width, height } = calculatedValues; const labelRadius = Helpers.evaluateProp( calculatedValues.labelRadius, assign({ text }, dataProps) ); + const labelPosition = Helpers.evaluateProp( + calculatedValues.labelPosition, + assign({ text }, dataProps) + ); const labelStyle = assign({ padding: 0 }, style.labels); const evaluatedStyle = Helpers.evaluateStyle( labelStyle, diff --git a/packages/victory-pie/src/victory-pie.js b/packages/victory-pie/src/victory-pie.js index 188fc74bc..46fe86bfe 100644 --- a/packages/victory-pie/src/victory-pie.js +++ b/packages/victory-pie/src/victory-pie.js @@ -123,7 +123,10 @@ class VictoryPie extends React.Component { height: CustomPropTypes.nonNegative, innerRadius: PropTypes.oneOfType([CustomPropTypes.nonNegative, PropTypes.func]), labelComponent: PropTypes.element, - labelPosition: PropTypes.oneOf(["startAngle", "centroid", "endAngle"]), + labelPosition: PropTypes.oneOfType([ + PropTypes.func, + PropTypes.oneOf(["startAngle", "centroid", "endAngle"]) + ]), labelRadius: PropTypes.oneOfType([CustomPropTypes.nonNegative, PropTypes.func]), labels: PropTypes.oneOfType([PropTypes.func, PropTypes.array]), name: PropTypes.string, diff --git a/stories/victory-pie.js b/stories/victory-pie.js index c69cbb32f..33a573aa2 100644 --- a/stories/victory-pie.js +++ b/stories/victory-pie.js @@ -45,9 +45,18 @@ storiesOf("VictoryPie", module) )) .add("with a radius prop", () => ) .add("with an origin prop", () => ) - .add("with a label position different than centroid", () => ( + .add("with a labelPosition different than centroid", () => ( )) + .add("with a labelPosition as a function", () => ( + index === 0 ? "endAngle" : "startAngle"} + /> + )) .add("with custom data and colors", () => ( Date: Mon, 25 Nov 2019 21:14:59 -0800 Subject: [PATCH 2/2] prettier --- stories/victory-pie.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stories/victory-pie.js b/stories/victory-pie.js index 33a573aa2..72a5807ef 100644 --- a/stories/victory-pie.js +++ b/stories/victory-pie.js @@ -54,7 +54,7 @@ storiesOf("VictoryPie", module) endAngle={90} innerRadius={90} data={[{ x: "Cat", y: 62 }, { x: "Bird", y: 25 }]} - labelPosition={({ index }) => index === 0 ? "endAngle" : "startAngle"} + labelPosition={({ index }) => (index === 0 ? "endAngle" : "startAngle")} /> )) .add("with custom data and colors", () => (