diff --git a/packages/vx-stats/src/boxplot/BoxPlot.js b/packages/vx-stats/src/boxplot/BoxPlot.js index a0435c968..57c8241c1 100644 --- a/packages/vx-stats/src/boxplot/BoxPlot.js +++ b/packages/vx-stats/src/boxplot/BoxPlot.js @@ -38,12 +38,16 @@ export default function BoxPlot({ }) { const offset = horizontal? top: left; const center = offset + boxWidth / 2; + let maxLinePos = Array(4).fill(0); let maxToBoxLinePos = Array(4).fill(0); let boxPos = Array(4).fill(0); let medianLinePos = Array(4).fill(0); let minToBoxLinePos = Array(4).fill(0); let minLinePos = Array(4).fill(0); + let containerPos = Array(4).fill(0); + + // all of these are [x0, y0, x1, y1] maxLinePos[0] = center - boxWidth / 4; maxLinePos[1] = valueScale(max); maxLinePos[2] = center + boxWidth / 4; @@ -73,6 +77,13 @@ export default function BoxPlot({ minLinePos[1] = valueScale(min); minLinePos[2] = center + boxWidth / 4; minLinePos[3] = valueScale(min); + + const valueRange = valueScale.range(); + containerPos[0] = boxPos[0]; + containerPos[1] = Math.min(...valueRange); + containerPos[2] = boxPos[2]; + containerPos[3] = Math.abs(valueRange[0] - valueRange[1]); + if (horizontal) { maxLinePos = verticalToHorizontal(maxLinePos); maxToBoxLinePos = verticalToHorizontal(maxToBoxLinePos); @@ -81,9 +92,33 @@ export default function BoxPlot({ medianLinePos = verticalToHorizontal(medianLinePos); minToBoxLinePos = verticalToHorizontal(minToBoxLinePos); minLinePos = verticalToHorizontal(minLinePos); + containerPos = verticalToHorizontal(containerPos); + containerPos[0] = Math.min(...valueRange); } return ( + {outliers.map((d, i) => { + const cx = horizontal ? valueScale(d) : center; + const cy = horizontal ? center : valueScale(d); + return ( + ); + }) + } - {outliers.map((d, i) => { - return ( - ); - }) - } {container &&