diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 5384e323613..28e0e88e343 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -325,6 +325,7 @@ module.exports = Element.extend({ var context = me.ctx; var tickOpts = me.options.ticks; var labels = labelsFromTicks(me._ticks); + var margins = me.margins; // Get the width of each grid by calculating the difference // between x offsets between 0 and 1. @@ -339,7 +340,8 @@ module.exports = Element.extend({ var cosRotation, sinRotation; // Allow 3 pixels x2 padding either side for label readability - var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6; + var numLabels = labels.length - (tickOpts.offset ? 0 : 1); + var tickWidth = (me.width - (margins.left + margins.right)) / numLabels; // Max label rotation can be set or default to 90 - also act as a loop counter while (labelWidth > tickWidth && labelRotation < tickOpts.maxRotation) { diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 427343a6bb3..d0516e8ce60 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -752,13 +752,16 @@ module.exports = Scale.extend({ */ getLabelCapacity: function(exampleTime) { var me = this; + var margins = me.margins; // pick the longest format (milliseconds) for guestimation var format = me.options.time.displayFormats.millisecond; var exampleLabel = me.tickFormatFunction(exampleTime, 0, [], format); var tickLabelWidth = me.getLabelWidth(exampleLabel); - var innerWidth = me.isHorizontal() ? me.width : me.height; - var capacity = Math.floor(innerWidth / tickLabelWidth) - 1; + var innerWidth = me.isHorizontal() + ? me.width - (margins.left + margins.right) + : me.height - (margins.top + margins.bottom); + var capacity = Math.floor(innerWidth / tickLabelWidth); return capacity > 0 ? capacity : 1; }