@@ -414,7 +414,7 @@ module.exports = Element.extend({
414
414
var options = me . options ;
415
415
var tickOpts = options . ticks ;
416
416
var ticks = me . getTicks ( ) ;
417
- var labelSizes , maxLabelWidth , maxLabelHeight , tickWidth , maxHeight , maxLabelDiagonal ;
417
+ var labelSizes , maxLabelWidth , maxLabelHeight , maxWidth , tickWidth , maxHeight , maxLabelDiagonal ;
418
418
419
419
var labelRotation = tickOpts . minRotation || 0 ;
420
420
@@ -427,10 +427,12 @@ module.exports = Element.extend({
427
427
428
428
// Estimate the width of each grid based on the canvas width, the maximum
429
429
// label width and the number of tick intervals
430
- tickWidth = ( me . chart . width - maxLabelWidth ) / ( ticks . length - 1 ) ;
430
+ maxWidth = Math . min ( me . maxWidth , me . chart . width - maxLabelWidth ) ;
431
+ tickWidth = options . offset ? me . maxWidth / ticks . length : maxWidth / ( ticks . length - 1 ) ;
431
432
432
433
// Allow 3 pixels x2 padding either side for label readability
433
434
if ( maxLabelWidth + 6 > tickWidth ) {
435
+ tickWidth = maxWidth / ( ticks . length - ( options . offset ? 0.5 : 1 ) ) ;
434
436
maxHeight = me . maxHeight - getTickMarkLength ( options . gridLines )
435
437
- tickOpts . padding - getScaleLabelHeight ( options . scaleLabel ) ;
436
438
maxLabelDiagonal = Math . sqrt ( maxLabelWidth * maxLabelWidth + maxLabelHeight * maxLabelHeight ) ;
@@ -529,8 +531,11 @@ module.exports = Element.extend({
529
531
paddingLeft = firstLabelSize . width / 2 ;
530
532
paddingRight = lastLabelSize . width / 2 ;
531
533
}
532
- me . paddingLeft = Math . max ( paddingLeft - offsetLeft , 0 ) + 3 ; // add 3 px to move away from canvas edges
533
- me . paddingRight = Math . max ( paddingRight - offsetRight , 0 ) + 3 ;
534
+
535
+ // Adjust padding taking into account changes in offsets
536
+ // and add 3 px to move away from canvas edges
537
+ me . paddingLeft = Math . max ( ( paddingLeft - offsetLeft ) * me . width / ( me . width - offsetLeft ) , 0 ) + 3 ;
538
+ me . paddingRight = Math . max ( ( paddingRight - offsetRight ) * me . width / ( me . width - offsetRight ) , 0 ) + 3 ;
534
539
} else {
535
540
// A vertical axis is more constrained by the width. Labels are the
536
541
// dominant factor here, so get that length first and account for padding
0 commit comments