@@ -397,6 +397,7 @@ module.exports = Element.extend({
397
397
var scaleLabelOpts = opts . scaleLabel ;
398
398
var gridLineOpts = opts . gridLines ;
399
399
var display = opts . display ;
400
+ var position = opts . position ;
400
401
var isHorizontal = me . isHorizontal ( ) ;
401
402
402
403
var tickFont = parseFontOptions ( tickOpts ) ;
@@ -456,16 +457,21 @@ module.exports = Element.extend({
456
457
me . ctx . font = tickFont . font ;
457
458
var firstLabelWidth = computeTextSize ( me . ctx , labels [ 0 ] , tickFont . font ) ;
458
459
var lastLabelWidth = computeTextSize ( me . ctx , labels [ labels . length - 1 ] , tickFont . font ) ;
460
+ var offsetLeft = me . getPixelForTick ( 0 ) - me . left ;
461
+ var offsetRight = me . right - me . getPixelForTick ( labels . length - 1 ) ;
462
+ var paddingLeft , paddingRight ;
459
463
460
464
// Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned
461
465
// which means that the right padding is dominated by the font height
462
466
if ( me . labelRotation !== 0 ) {
463
- me . paddingLeft = opts . position === 'bottom' ? ( cosRotation * firstLabelWidth ) + 3 : ( cosRotation * lineSpace ) + 3 ; // add 3 px to move away from canvas edges
464
- me . paddingRight = opts . position === 'bottom' ? ( cosRotation * lineSpace ) + 3 : ( cosRotation * lastLabelWidth ) + 3 ;
467
+ paddingLeft = position === 'bottom' ? ( cosRotation * firstLabelWidth ) : ( cosRotation * lineSpace ) ;
468
+ paddingRight = position === 'bottom' ? ( cosRotation * lineSpace ) : ( cosRotation * lastLabelWidth ) ;
465
469
} else {
466
- me . paddingLeft = firstLabelWidth / 2 + 3 ; // add 3 px to move away from canvas edges
467
- me . paddingRight = lastLabelWidth / 2 + 3 ;
470
+ paddingLeft = firstLabelWidth / 2 ;
471
+ paddingRight = lastLabelWidth / 2 ;
468
472
}
473
+ me . paddingLeft = Math . max ( paddingLeft - offsetLeft , 0 ) + 3 ; // add 3 px to move away from canvas edges
474
+ me . paddingRight = Math . max ( paddingRight - offsetRight , 0 ) + 3 ;
469
475
} else {
470
476
// A vertical axis is more constrained by the width. Labels are the
471
477
// dominant factor here, so get that length first and account for padding
0 commit comments