helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
- // If a box has padding, we move the left scale over to avoid ugly charts (see issue #2478)
+ // If a horizontal box has padding, we move the left boxes over to avoid ugly charts (see issue #2478)
var maxHorizontalLeftPadding = 0;
var maxHorizontalRightPadding = 0;
+ var maxVerticalTopPadding = 0;
+ var maxVerticalBottomPadding = 0;
helpers.each(topBoxes.concat(bottomBoxes), function(horizontalBox) {
if (horizontalBox.getPadding) {
}
});
+ helpers.each(leftBoxes.concat(rightBoxes), function(verticalBox) {
+ if (verticalBox.getPadding) {
+ var boxPadding = verticalBox.getPadding();
+ maxVerticalTopPadding = Math.max(maxVerticalTopPadding, boxPadding.top);
+ maxVerticalBottomPadding = Math.max(maxVerticalBottomPadding, boxPadding.bottom);
+ }
+ });
+
// At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could
// be if the axes are drawn at their minimum sizes.
// Steps 5 & 6
// We may be adding some padding to account for rotated x axis labels
var leftPaddingAddition = Math.max(maxHorizontalLeftPadding - totalLeftBoxesWidth, 0);
- var rightPaddingAddition = Math.max(maxHorizontalRightPadding - totalRightBoxesWidth, 0);
-
totalLeftBoxesWidth += leftPaddingAddition;
- totalRightBoxesWidth += rightPaddingAddition;
+ totalRightBoxesWidth += Math.max(maxHorizontalRightPadding - totalRightBoxesWidth, 0);
+
+ var topPaddingAddition = Math.max(maxVerticalTopPadding - totalTopBoxesHeight, 0);
+ totalTopBoxesHeight += topPaddingAddition;
+ totalBottomBoxesHeight += Math.max(maxVerticalBottomPadding - totalBottomBoxesHeight, 0);
// Figure out if our chart area changed. This would occur if the dataset layout label rotation
// changed due to the application of the margins in step 6. Since we can only get bigger, this is safe to do
// Step 7 - Position the boxes
var left = leftPadding + leftPaddingAddition;
- var top = topPadding;
+ var top = topPadding + topPaddingAddition;
function placeBox(box) {
if (box.isHorizontal()) {
expect(xScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(276); // halfway
expect(xScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(48); // 0 is invalid, put it on the left.
- expect(xScale.getValueForPixel(481.5)).toBeCloseTo(80, 1e-4);
+ expect(xScale.getValueForPixel(481.5)).toBeCloseToPixel(80);
expect(xScale.getValueForPixel(48)).toBeCloseTo(1, 1e-4);
expect(xScale.getValueForPixel(276)).toBeCloseTo(10, 1e-4);