@@ -406,7 +406,7 @@ module.exports = Element.extend({
406
406
var options = me . options ;
407
407
var tickOpts = options . ticks ;
408
408
var ticks = me . getTicks ( ) ;
409
- var labelSizes , maxLabelWidth , maxLabelHeight , tickWidth , maxHeight , maxLabelDiagonal ;
409
+ var labelSizes , maxLabelWidth , maxLabelHeight , maxWidth , tickWidth , maxHeight , maxLabelDiagonal ;
410
410
411
411
var labelRotation = tickOpts . minRotation || 0 ;
412
412
@@ -419,10 +419,12 @@ module.exports = Element.extend({
419
419
420
420
// Estimate the width of each grid based on the canvas width, the maximum
421
421
// label width and the number of tick intervals
422
- tickWidth = ( me . chart . width - maxLabelWidth ) / ( ticks . length - 1 ) ;
422
+ maxWidth = Math . min ( me . maxWidth , me . chart . width - maxLabelWidth ) ;
423
+ tickWidth = options . offset ? me . maxWidth / ticks . length : maxWidth / ( ticks . length - 1 ) ;
423
424
424
425
// Allow 3 pixels x2 padding either side for label readability
425
426
if ( maxLabelWidth + 6 > tickWidth ) {
427
+ tickWidth = maxWidth / ( ticks . length - ( options . offset ? 0.5 : 1 ) ) ;
426
428
maxHeight = me . maxHeight - getTickMarkLength ( options . gridLines )
427
429
- tickOpts . padding - getScaleLabelHeight ( options . scaleLabel ) ;
428
430
maxLabelDiagonal = Math . sqrt ( maxLabelWidth * maxLabelWidth + maxLabelHeight * maxLabelHeight ) ;
@@ -521,8 +523,11 @@ module.exports = Element.extend({
521
523
paddingLeft = firstLabelSize . width / 2 ;
522
524
paddingRight = lastLabelSize . width / 2 ;
523
525
}
524
- me . paddingLeft = Math . max ( paddingLeft - offsetLeft , 0 ) + 3 ; // add 3 px to move away from canvas edges
525
- me . paddingRight = Math . max ( paddingRight - offsetRight , 0 ) + 3 ;
526
+
527
+ // Adjust padding taking into account changes in offsets
528
+ // and add 3 px to move away from canvas edges
529
+ me . paddingLeft = Math . max ( ( paddingLeft - offsetLeft ) * me . width / ( me . width - offsetLeft ) , 0 ) + 3 ;
530
+ me . paddingRight = Math . max ( ( paddingRight - offsetRight ) * me . width / ( me . width - offsetRight ) , 0 ) + 3 ;
526
531
} else {
527
532
// A vertical axis is more constrained by the width. Labels are the
528
533
// dominant factor here, so get that length first and account for padding
0 commit comments