From: etimberg Date: Wed, 2 Dec 2015 02:01:13 +0000 (-0500) Subject: Update scale fitting to prevent horizontal scales from jumping around. X-Git-Tag: 2.0.0-beta2~37^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf277473c6834b1451124c777c3dd7d49bfc0a36;p=thirdparty%2FChart.js.git Update scale fitting to prevent horizontal scales from jumping around. --- diff --git a/src/core/core.scaleService.js b/src/core/core.scaleService.js index a1c1f1c20..01908f76d 100644 --- a/src/core/core.scaleService.js +++ b/src/core/core.scaleService.js @@ -93,6 +93,8 @@ var horizontalScaleHeight = (height - chartHeight) / (topScales.length + bottomScales.length); // Step 4; + var maxChartHeight = height - (2 * yPadding); + var maxChartWidth = width - (2 * xPadding); var minimumScaleSizes = []; var verticalScaleMinSizeFunction = function(scaleInstance) { @@ -102,15 +104,19 @@ minSize: minSize, scale: scaleInstance, }); + + maxChartWidth -= minSize.width; }; var horizontalScaleMinSizeFunction = function(scaleInstance) { - var minSize = scaleInstance.update(chartWidth, horizontalScaleHeight); + var minSize = scaleInstance.update(maxChartWidth, horizontalScaleHeight); minimumScaleSizes.push({ horizontal: true, minSize: minSize, scale: scaleInstance, }); + + maxChartHeight -= minSize.height; }; // vertical scales @@ -121,22 +127,10 @@ helpers.each(topScales, horizontalScaleMinSizeFunction); helpers.each(bottomScales, horizontalScaleMinSizeFunction); - // Step 5 - var maxChartHeight = height - (2 * yPadding); - var maxChartWidth = width - (2 * xPadding); - - helpers.each(minimumScaleSizes, function(wrapper) { - if (wrapper.horizontal) { - maxChartHeight -= wrapper.minSize.height; - } else { - maxChartWidth -= wrapper.minSize.width; - } - }); - // At this point, maxChartHeight and maxChartWidth are the size the chart area could // be if the axes are drawn at their minimum sizes. - // Step 6 + // Steps 5 & 6 var verticalScaleFitFunction = function(scaleInstance) { var wrapper = helpers.findNextWhere(minimumScaleSizes, function(wrapper) { return wrapper.scale === scaleInstance;