@@ -3821,28 +3821,92 @@ axes.drawLabels = function(gd, ax, opts) {
38213821 } ) ;
38223822 }
38233823
3824+ var computeTickLabelBoundingBoxes = function ( ) {
3825+ var labelsMaxW = 0 ;
3826+ var labelsMaxH = 0 ;
3827+ tickLabels . each ( function ( d , i ) {
3828+ var thisLabel = selectTickLabel ( this ) ;
3829+ var mathjaxGroup = thisLabel . select ( '.text-math-group' ) ;
3830+
3831+ if ( mathjaxGroup . empty ( ) ) {
3832+ var bb ;
3833+
3834+ if ( ax . _vals [ i ] ) {
3835+ bb = ax . _vals [ i ] . bb || Drawing . bBox ( thisLabel . node ( ) ) ;
3836+ ax . _vals [ i ] . bb = bb ;
3837+ }
3838+
3839+ labelsMaxW = Math . max ( labelsMaxW , bb . width ) ;
3840+ labelsMaxH = Math . max ( labelsMaxW , bb . height ) ;
3841+ }
3842+ } ) ;
3843+
3844+ return {
3845+ labelsMaxW : labelsMaxW ,
3846+ labelsMaxH : labelsMaxH
3847+ } ;
3848+ } ;
3849+
38243850 var anchorAx = ax . _anchorAxis ;
38253851 if (
3826- anchorAx && anchorAx . autorange &&
3852+ anchorAx && ( anchorAx . autorange || anchorAx . insiderange ) &&
38273853 insideTicklabelposition ( ax ) &&
38283854 ! isLinked ( fullLayout , ax . _id )
38293855 ) {
3830- if ( ! fullLayout . _insideTickLabelsAutorange ) {
3831- fullLayout . _insideTickLabelsAutorange = { } ;
3856+ if ( ! fullLayout . _insideTickLabelsUpdaterange ) {
3857+ fullLayout . _insideTickLabelsUpdaterange = { } ;
38323858 }
3833- fullLayout . _insideTickLabelsAutorange [ anchorAx . _name + '.autorange' ] = anchorAx . autorange ;
3834-
3835- seq . push (
3836- function computeFinalTickLabelBoundingBoxes ( ) {
3837- tickLabels . each ( function ( d , i ) {
3838- var thisLabel = selectTickLabel ( this ) ;
3839- var mathjaxGroup = thisLabel . select ( '.text-math-group' ) ;
3840- if ( mathjaxGroup . empty ( ) ) {
3841- ax . _vals [ i ] . bb = Drawing . bBox ( thisLabel . node ( ) ) ;
3842- }
3843- } ) ;
3859+
3860+ if ( anchorAx . autorange ) {
3861+ fullLayout . _insideTickLabelsUpdaterange [ anchorAx . _name + '.autorange' ] = anchorAx . autorange ;
3862+
3863+ seq . push ( computeTickLabelBoundingBoxes ) ;
3864+ }
3865+
3866+ if ( anchorAx . insiderange ) {
3867+ var BBs = computeTickLabelBoundingBoxes ( ) ;
3868+ var move = ax . _id . charAt ( 0 ) === 'y' ?
3869+ BBs . labelsMaxW + 4 * TEXTPAD :
3870+ BBs . labelsMaxH ;
3871+
3872+ if ( ax . ticklabelposition === 'inside' ) {
3873+ move += ax . ticklen || 0 ;
38443874 }
3845- ) ;
3875+
3876+ if ( ax . _id . charAt ( 0 ) !== 'y' ) move = - move ;
3877+
3878+ var sgn = ( ax . side === 'right' || ax . side === 'top' ) ? 1 : - 1 ;
3879+ var index = sgn === 1 ? 1 : 0 ;
3880+ var otherIndex = sgn === 1 ? 0 : 1 ;
3881+
3882+ var newRange = [ ] ;
3883+ newRange [ otherIndex ] = anchorAx . range [ otherIndex ] ;
3884+ newRange [ index ] = anchorAx . p2d (
3885+ anchorAx . d2p ( anchorAx . range [ index ] ) +
3886+ sgn * move
3887+ ) ;
3888+
3889+ // handle partial ranges in insiderange
3890+ if (
3891+ anchorAx . autorange === 'min' ||
3892+ anchorAx . autorange === 'max reversed'
3893+ ) {
3894+ newRange [ 0 ] = null ;
3895+
3896+ anchorAx . _rangeInitial0 = undefined ;
3897+ anchorAx . _rangeInitial1 = undefined ;
3898+ } else if (
3899+ anchorAx . autorange === 'max' ||
3900+ anchorAx . autorange === 'min reversed'
3901+ ) {
3902+ newRange [ 1 ] = null ;
3903+
3904+ anchorAx . _rangeInitial0 = undefined ;
3905+ anchorAx . _rangeInitial1 = undefined ;
3906+ }
3907+
3908+ fullLayout . _insideTickLabelsUpdaterange [ anchorAx . _name + '.range' ] = newRange ;
3909+ }
38463910 }
38473911
38483912 var done = Lib . syncOrAsync ( seq ) ;
0 commit comments