@@ -3821,28 +3821,105 @@ 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 ( labelsMaxH , 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 :
3870+ BBs . labelsMaxH ;
3871+
3872+ move += 2 * TEXTPAD ;
3873+
3874+ if ( ax . ticklabelposition === 'inside' ) {
3875+ move += ax . ticklen || 0 ;
38443876 }
3845- ) ;
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+
3885+ var p0 = anchorAx . d2p ( anchorAx . range [ index ] ) ;
3886+ var p1 = anchorAx . d2p ( anchorAx . range [ otherIndex ] ) ;
3887+ var dist = Math . abs ( p1 - p0 ) ;
3888+ if ( dist - move > 0 ) {
3889+ dist -= move ;
3890+ move *= 1 + move / dist ;
3891+ } else {
3892+ move = 0 ;
3893+ }
3894+
3895+ if ( ax . _id . charAt ( 0 ) !== 'y' ) move = - move ;
3896+
3897+ newRange [ index ] = anchorAx . p2d (
3898+ anchorAx . d2p ( anchorAx . range [ index ] ) +
3899+ sgn * move
3900+ ) ;
3901+
3902+ // handle partial ranges in insiderange
3903+ if (
3904+ anchorAx . autorange === 'min' ||
3905+ anchorAx . autorange === 'max reversed'
3906+ ) {
3907+ newRange [ 0 ] = null ;
3908+
3909+ anchorAx . _rangeInitial0 = undefined ;
3910+ anchorAx . _rangeInitial1 = undefined ;
3911+ } else if (
3912+ anchorAx . autorange === 'max' ||
3913+ anchorAx . autorange === 'min reversed'
3914+ ) {
3915+ newRange [ 1 ] = null ;
3916+
3917+ anchorAx . _rangeInitial0 = undefined ;
3918+ anchorAx . _rangeInitial1 = undefined ;
3919+ }
3920+
3921+ fullLayout . _insideTickLabelsUpdaterange [ anchorAx . _name + '.range' ] = newRange ;
3922+ }
38463923 }
38473924
38483925 var done = Lib . syncOrAsync ( seq ) ;
0 commit comments