From 5358c75c678ce48671adf600b2d9437322d61697 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Mon, 20 Nov 2017 23:33:37 -0800 Subject: [PATCH] [stats][boxplot] fix container props calculation, outliers to bottom layer --- packages/vx-stats/src/boxplot/BoxPlot.js | 78 ++++++++++++++++-------- 1 file changed, 54 insertions(+), 24 deletions(-) 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 &&