diff --git a/src/core/core.layouts.js b/src/core/core.layouts.js index ae6526e3850..3988e28f9cd 100644 --- a/src/core/core.layouts.js +++ b/src/core/core.layouts.js @@ -98,21 +98,6 @@ function adjustWithPadding(outerDims, boxCorner, maxPadding) { }); } - -function getMargin(horizontal, outerDims, maxPadding) { - function marginForPositions(positions) { - var margin = {}; - positions.forEach(function(pos) { - margin[pos] = Math.max(outerDims[pos], maxPadding[pos]); - }); - return margin; - } - - return horizontal - ? marginForPositions(['left', 'right']) - : marginForPositions(['top', 'bottom']); -} - function updateChartArea(chartArea, outerDims, maxPadding) { var newWidth = chartArea.outerWidth - getCombinedMax(maxPadding, outerDims, 'left', 'right'); var newHeight = chartArea.outerHeight - getCombinedMax(maxPadding, outerDims, 'top', 'bottom'); @@ -133,11 +118,7 @@ function fitBoxes(boxes, chartArea, outerDims) { layout = boxes[i]; box = layout.box; - box.update( - layout.width || chartArea.w, - layout.height || chartArea.h, - getMargin(layout.horizontal, outerDims, maxPadding) - ); + box.update(layout.width || chartArea.w, layout.height || chartArea.h); updateMaxPadding(maxPadding, box); if (updateChartArea(chartArea, outerDims, maxPadding) && refitBoxes.length) { // Dimensions changed and there were non full width boxes before this @@ -337,13 +318,13 @@ module.exports = { setLayoutDims(verticalBoxes.concat(horizontalBoxes), chartArea); - // First fit vertical boxes, starting from padding and no margins + // First fit vertical boxes outerDims = fitBoxes(verticalBoxes, chartArea, padding); // Adjust chart area based on vertical boxes. updateChartArea(chartArea, outerDims, maxPadding); - // Fit horizontal boxes, providing vertical box widths as margins + // Then fit horizontal boxes outerDims = fitBoxes(horizontalBoxes, chartArea, outerDims); // Adjust chart area based on horizontal boxes @@ -357,9 +338,7 @@ module.exports = { // Make sure horizontal boxes have correct width helpers.each(horizontalBoxes, function(layout) { - if (!layout.box.fullWidth) { - layout.box.width = chartArea.w; - } + layout.box.width = chartArea.w; }); // Adjust top/left of outerDims and boxCorner with padding if needed diff --git a/src/core/core.scale.js b/src/core/core.scale.js index b6b62f3e7b2..74123e28083 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -240,7 +240,7 @@ var Scale = Element.extend({ helpers.callback(this.options.beforeUpdate, [this]); }, - update: function(maxWidth, maxHeight, margins) { + update: function(maxWidth, maxHeight) { var me = this; var i, ilen, labels, label, ticks, tick; @@ -250,12 +250,6 @@ var Scale = Element.extend({ // Absorb the master measurements me.maxWidth = maxWidth; me.maxHeight = maxHeight; - me.margins = helpers.extend({ - left: 0, - right: 0, - top: 0, - bottom: 0 - }, margins); me._maxLabelLines = 0; me.longestLabelWidth = 0; @@ -476,8 +470,7 @@ var Scale = Element.extend({ // Width if (isHorizontal) { - // subtract the margins to line up with the chartArea if we are a full width scale - minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth; + minSize.width = me.maxWidth; } else if (display) { minSize.width = getTickMarkLength(gridLineOpts) + getScaleLabelHeight(scaleLabelOpts); } @@ -552,26 +545,10 @@ var Scale = Element.extend({ } } - me.handleMargins(); - me.width = minSize.width; me.height = minSize.height; }, - /** - * Handle margins and padding interactions - * @private - */ - handleMargins: function() { - var me = this; - if (me.margins) { - me.paddingLeft = Math.max(me.paddingLeft, me.margins.left); - me.paddingTop = Math.max(me.paddingTop, me.margins.top); - me.paddingRight = Math.max(me.paddingRight, me.margins.right); - me.paddingBottom = Math.max(me.paddingBottom, me.margins.bottom); - } - }, - afterFit: function() { helpers.callback(this.options.afterFit, [this]); }, @@ -685,15 +662,13 @@ var Scale = Element.extend({ } if (me.isHorizontal()) { var tickWidth = me.width / Math.max((numTicks - (offset ? 0 : 1)), 1); - var pixel = (tickWidth * index) + me.paddingLeft; + var pixel = (tickWidth * index); if (offset) { pixel += tickWidth / 2; } - var finalVal = me.left + pixel; - finalVal += me.isFullWidth() ? me.margins.left : 0; - return finalVal; + return me.left + pixel; } return me.top + (index * (me.height / (numTicks - 1))); }, diff --git a/src/plugins/plugin.legend.js b/src/plugins/plugin.legend.js index b6101561dc8..3350393ab54 100644 --- a/src/plugins/plugin.legend.js +++ b/src/plugins/plugin.legend.js @@ -130,7 +130,7 @@ var Legend = Element.extend({ // Any function can be extended by the legend type beforeUpdate: noop, - update: function(maxWidth, maxHeight, margins) { + update: function(maxWidth, maxHeight) { var me = this; // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;) @@ -139,7 +139,6 @@ var Legend = Element.extend({ // Absorb the master measurements me.maxWidth = maxWidth; me.maxHeight = maxHeight; - me.margins = margins; // Dimensions me.beforeSetDimensions(); diff --git a/src/plugins/plugin.title.js b/src/plugins/plugin.title.js index 0f37b6004f8..aa8b10a39c0 100644 --- a/src/plugins/plugin.title.js +++ b/src/plugins/plugin.title.js @@ -34,7 +34,7 @@ var Title = Element.extend({ // These methods are ordered by lifecycle. Utilities then follow. beforeUpdate: noop, - update: function(maxWidth, maxHeight, margins) { + update: function(maxWidth, maxHeight) { var me = this; // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;) @@ -43,7 +43,6 @@ var Title = Element.extend({ // Absorb the master measurements me.maxWidth = maxWidth; me.maxHeight = maxHeight; - me.margins = margins; // Dimensions me.beforeSetDimensions(); diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 22a1d9ed30b..f26ce646d92 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -786,10 +786,6 @@ module.exports = Scale.extend({ var format = displayFormats[timeOpts.unit] || displayFormats.millisecond; var exampleLabel = me.tickFormatFunction(exampleTime, 0, ticksFromTimestamps(me, [exampleTime], me._majorUnit), format); var size = me._getLabelSize(exampleLabel); - - // Using margins instead of padding because padding is not calculated - // at this point (buildTicks). Margins are provided from previous calculation - // in layout steps 5/6 var capacity = Math.floor(me.isHorizontal() ? me.width / size.w : me.height / size.h); if (me.options.offset) { diff --git a/test/specs/core.layouts.tests.js b/test/specs/core.layouts.tests.js index 8a0e2b42d62..d6a0b062c48 100644 --- a/test/specs/core.layouts.tests.js +++ b/test/specs/core.layouts.tests.js @@ -172,7 +172,7 @@ describe('Chart.layouts', function() { expect(chart.scales.yScale.paddingLeft).toBeCloseToPixel(0); expect(chart.scales.yScale.paddingTop).toBeCloseToPixel(7); expect(chart.scales.yScale.paddingRight).toBeCloseToPixel(0); - expect(chart.scales.yScale.paddingBottom).toBeCloseToPixel(30); + expect(chart.scales.yScale.paddingBottom).toBeCloseToPixel(7); }); it('should fit scales that overlap the chart area', function() { @@ -306,8 +306,8 @@ describe('Chart.layouts', function() { expect(chart.scales.xScale1.top).toBeCloseToPixel(484); expect(chart.scales.xScale2.bottom).toBeCloseToPixel(62); - expect(chart.scales.xScale2.left).toBeCloseToPixel(0); - expect(chart.scales.xScale2.right).toBeCloseToPixel(512); + expect(chart.scales.xScale2.left).toBeCloseToPixel(39); + expect(chart.scales.xScale2.right).toBeCloseToPixel(496); expect(chart.scales.xScale2.top).toBeCloseToPixel(32); // Is yScale at the right spot diff --git a/test/specs/scale.linear.tests.js b/test/specs/scale.linear.tests.js index af33512ff6e..383d7480d44 100644 --- a/test/specs/scale.linear.tests.js +++ b/test/specs/scale.linear.tests.js @@ -910,13 +910,13 @@ describe('Linear Scale', function() { var yScale = chart.scales.yScale0; expect(xScale.paddingTop).toBeCloseToPixel(0); expect(xScale.paddingBottom).toBeCloseToPixel(0); - expect(xScale.paddingLeft).toEqual(yScale.width); + expect(xScale.paddingLeft).toBeCloseToPixel(12); expect(xScale.paddingRight).toBeCloseToPixel(13.5); expect(xScale.width).toBeCloseToPixel(468 - 6); // minus lineSpace expect(xScale.height).toBeCloseToPixel(30); - expect(yScale.paddingTop).toBeCloseToPixel(32); - expect(yScale.paddingBottom).toBeCloseToPixel(30); + expect(yScale.paddingTop).toBeCloseToPixel(7); + expect(yScale.paddingBottom).toBeCloseToPixel(7); expect(yScale.paddingLeft).toBeCloseToPixel(0); expect(yScale.paddingRight).toBeCloseToPixel(0); expect(yScale.width).toBeCloseToPixel(30 + 6); // plus lineSpace @@ -929,13 +929,13 @@ describe('Linear Scale', function() { expect(xScale.paddingTop).toBeCloseToPixel(0); expect(xScale.paddingBottom).toBeCloseToPixel(0); - expect(xScale.paddingLeft).toEqual(yScale.width); + expect(xScale.paddingLeft).toBeCloseToPixel(12); expect(xScale.paddingRight).toBeCloseToPixel(13.5); expect(xScale.width).toBeCloseToPixel(440); expect(xScale.height).toBeCloseToPixel(53); - expect(yScale.paddingTop).toBeCloseToPixel(32); - expect(yScale.paddingBottom).toBeCloseToPixel(53); + expect(yScale.paddingTop).toBeCloseToPixel(7); + expect(yScale.paddingBottom).toBeCloseToPixel(7); expect(yScale.paddingLeft).toBeCloseToPixel(0); expect(yScale.paddingRight).toBeCloseToPixel(0); expect(yScale.width).toBeCloseToPixel(58);