From 37115c6412ffad66735e58896d9aaabd372ad1cc Mon Sep 17 00:00:00 2001 From: mAAdhaTTah Date: Mon, 4 Feb 2019 11:53:59 -0500 Subject: [PATCH] Accept object for label orientation --- demo/components/victory-box-plot-demo.js | 7 +++++++ packages/victory-box-plot/src/helper-methods.js | 9 +++++++-- packages/victory-box-plot/src/victory-box-plot.js | 11 ++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/demo/components/victory-box-plot-demo.js b/demo/components/victory-box-plot-demo.js index 7b38af7b4..14e8252a3 100644 --- a/demo/components/victory-box-plot-demo.js +++ b/demo/components/victory-box-plot-demo.js @@ -182,6 +182,13 @@ export default class App extends React.Component { { type: 2, min: 4, max: 20, median: 10, q1: 7, q3: 15 }, { type: 3, min: 3, max: 12, median: 6, q1: 5, q3: 10 } ]} + labelOrientation={{ + q1: "top", + q3: "top", + min: "bottom", + max: "bottom", + median: "bottom" + }} /> diff --git a/packages/victory-box-plot/src/helper-methods.js b/packages/victory-box-plot/src/helper-methods.js index 76a126203..bc12a5067 100644 --- a/packages/victory-box-plot/src/helper-methods.js +++ b/packages/victory-box-plot/src/helper-methods.js @@ -274,8 +274,13 @@ const getText = (props, type) => { return Array.isArray(labelProp) ? labelProp[index] : labelProp; }; +const getOrientation = (labelOrientation, type) => + typeof labelOrientation === "object" && + labelOrientation[type] || labelOrientation; + const getLabelProps = (props, text, type) => { const { datum, positions, index, boxWidth, horizontal, labelOrientation, style } = props; + const orientation = getOrientation(labelOrientation, type); const namespace = `${type}Labels`; const labelStyle = style[namespace] || style.labels; const defaultVerticalAnchor = horizontal ? "end" : "middle"; @@ -285,8 +290,8 @@ const getLabelProps = (props, text, type) => { const getDefaultPosition = (coord) => { const sign = { - x: labelOrientation === "left" ? -1 : 1, - y: labelOrientation === "top" ? -1 : 1 + x: orientation === "left" ? -1 : 1, + y: orientation === "top" ? -1 : 1 }; return positions[coord] + (sign[coord] * width) / 2 + sign[coord] * (labelStyle.padding || 0); }; diff --git a/packages/victory-box-plot/src/victory-box-plot.js b/packages/victory-box-plot/src/victory-box-plot.js index 7d31213f5..aa029db3c 100644 --- a/packages/victory-box-plot/src/victory-box-plot.js +++ b/packages/victory-box-plot/src/victory-box-plot.js @@ -82,7 +82,16 @@ class VictoryBoxPlot extends React.Component { }) ), horizontal: PropTypes.bool, - labelOrientation: PropTypes.oneOf(["top", "bottom", "left", "right"]), + labelOrientation: PropTypes.oneOfType([ + PropTypes.oneOf(["top", "bottom", "left", "right"]), + PropTypes.exact({ + q1: PropTypes.oneOf(["top", "bottom", "left", "right"]).isRequired, + q3: PropTypes.oneOf(["top", "bottom", "left", "right"]).isRequired, + min: PropTypes.oneOf(["top", "bottom", "left", "right"]).isRequired, + max: PropTypes.oneOf(["top", "bottom", "left", "right"]).isRequired, + median: PropTypes.oneOf(["top", "bottom", "left", "right"]).isRequired, + }) + ]), labels: PropTypes.bool, max: PropTypes.oneOfType([ PropTypes.func,