Skip to content

Commit

Permalink
Merge pull request #1447 from FormidableLabs/feature/pie-label-positi…
Browse files Browse the repository at this point in the history
…on-func-prop

allow labelPosition as a function in VictoryPie
  • Loading branch information
boygirl authored Nov 26, 2019
2 parents 26afd06 + 1dfe6fd commit 9f0f3ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/victory-pie/src/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion packages/victory-pie/src/victory-pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion stories/victory-pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,18 @@ storiesOf("VictoryPie", module)
))
.add("with a radius prop", () => <VictoryPie radius={100} />)
.add("with an origin prop", () => <VictoryPie radius={100} origin={{ x: 150, y: 150 }} />)
.add("with a label position different than centroid", () => (
.add("with a labelPosition different than centroid", () => (
<VictoryPie labelPosition={"startAngle"} />
))
.add("with a labelPosition as a function", () => (
<VictoryPie
startAngle={-90}
endAngle={90}
innerRadius={90}
data={[{ x: "Cat", y: 62 }, { x: "Bird", y: 25 }]}
labelPosition={({ index }) => (index === 0 ? "endAngle" : "startAngle")}
/>
))
.add("with custom data and colors", () => (
<VictoryPie
style={{
Expand Down

0 comments on commit 9f0f3ca

Please sign in to comment.