Skip to content

Commit

Permalink
Use margins instead of assuming padding of 1 label
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Mar 6, 2019
1 parent 5f31185 commit 8b65c6c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/scales/scale.time.js
Expand Up @@ -752,13 +752,20 @@ 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;

// Using marings instead of padding because padding is not calculated
// at this point, but margins are provided from previous calculation
// in layout steps 5/6
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;
}
Expand Down

0 comments on commit 8b65c6c

Please sign in to comment.