@@ -1946,29 +1946,29 @@ axes.drawOne = function(gd, ax, opts) {
19461946 push = { x : 0 , y : 0 , r : 0 , l : 0 , t : 0 , b : 0 } ;
19471947
19481948 var bbox = ax . _boundingBox ;
1949- var counterAx = mainPlotinfo [ counterLetter + 'axis' ] ;
1949+ var titleOffset = getTitleOffset ( gd , ax ) ;
19501950 var anchorAxDomainIndex ;
19511951 var offset ;
19521952
19531953 switch ( axLetter + s ) {
19541954 case 'xb' :
19551955 anchorAxDomainIndex = 0 ;
1956- offset = bbox . top - counterAx . _length - counterAx . _offset ;
1956+ offset = bbox . top - titleOffset ;
19571957 push [ s ] = bbox . height ;
19581958 break ;
19591959 case 'xt' :
19601960 anchorAxDomainIndex = 1 ;
1961- offset = counterAx . _offset - bbox . bottom ;
1961+ offset = titleOffset - bbox . bottom ;
19621962 push [ s ] = bbox . height ;
19631963 break ;
19641964 case 'yl' :
19651965 anchorAxDomainIndex = 0 ;
1966- offset = counterAx . _offset - bbox . right ;
1966+ offset = titleOffset - bbox . right ;
19671967 push [ s ] = bbox . width ;
19681968 break ;
19691969 case 'yr' :
19701970 anchorAxDomainIndex = 1 ;
1971- offset = bbox . left - counterAx . _length - counterAx . _offset ;
1971+ offset = bbox . left - titleOffset ;
19721972 push [ s ] = bbox . width ;
19731973 break ;
19741974 }
@@ -1980,6 +1980,7 @@ axes.drawOne = function(gd, ax, opts) {
19801980 if ( push [ s ] > 0 ) {
19811981 push [ s ] += offset ;
19821982 }
1983+
19831984 if ( ax . title . text !== fullLayout . _dfltTitle [ axLetter ] ) {
19841985 push [ s ] += ax . title . font . size ;
19851986 }
@@ -2647,11 +2648,37 @@ function drawDividers(gd, ax, opts) {
26472648 . attr ( 'd' , opts . path ) ;
26482649}
26492650
2651+ function getTitleOffset ( gd , ax ) {
2652+ var gs = gd . _fullLayout . _size ;
2653+ var axLetter = ax . _id . charAt ( 0 ) ;
2654+ var side = ax . side ;
2655+ var anchorAxis ;
2656+
2657+ if ( ax . anchor !== 'free' ) {
2658+ anchorAxis = axisIds . getFromId ( gd , ax . anchor ) ;
2659+ } else if ( axLetter === 'x' ) {
2660+ anchorAxis = {
2661+ _offset : gs . t + ( 1 - ( ax . position || 0 ) ) * gs . h ,
2662+ _length : 0
2663+ } ;
2664+ } else if ( axLetter === 'y' ) {
2665+ anchorAxis = {
2666+ _offset : gs . l + ( ax . position || 0 ) * gs . w ,
2667+ _length : 0
2668+ } ;
2669+ }
2670+
2671+ if ( side === 'top' || side === 'left' ) {
2672+ return anchorAxis . _offset ;
2673+ } else if ( side === 'bottom' || side === 'right' ) {
2674+ return anchorAxis . _offset + anchorAxis . _length ;
2675+ }
2676+ }
2677+
26502678function drawTitle ( gd , ax ) {
26512679 var fullLayout = gd . _fullLayout ;
26522680 var axId = ax . _id ;
26532681 var axLetter = axId . charAt ( 0 ) ;
2654- var gs = fullLayout . _size ;
26552682 var fontSize = ax . title . font . size ;
26562683
26572684 var titleStandoff ;
@@ -2662,36 +2689,28 @@ function drawTitle(gd, ax) {
26622689 titleStandoff = 10 + fontSize * offsetBase + ( ax . linewidth ? ax . linewidth - 1 : 0 ) ;
26632690 }
26642691
2665- var transform , counterAxis , x , y ;
2692+ var titleOffset = getTitleOffset ( gd , ax ) ;
26662693
2667- if ( axLetter === 'x' ) {
2668- counterAxis = ( ax . anchor === 'free' ) ?
2669- { _offset : gs . t + ( 1 - ( ax . position || 0 ) ) * gs . h , _length : 0 } :
2670- axisIds . getFromId ( gd , ax . anchor ) ;
2694+ var transform , x , y ;
26712695
2696+ if ( axLetter === 'x' ) {
26722697 x = ax . _offset + ax . _length / 2 ;
26732698
26742699 if ( ax . side === 'top' ) {
26752700 y = - titleStandoff - fontSize * ( ax . showticklabels ? 1 : 0 ) ;
26762701 } else {
2677- y = counterAxis . _length + titleStandoff +
2678- fontSize * ( ax . showticklabels ? 1.5 : 0.5 ) ;
2702+ y = titleStandoff + fontSize * ( ax . showticklabels ? 1.5 : 0.5 ) ;
26792703 }
2680- y += counterAxis . _offset ;
2704+ y += titleOffset ;
26812705 } else {
2682- counterAxis = ( ax . anchor === 'free' ) ?
2683- { _offset : gs . l + ( ax . position || 0 ) * gs . w , _length : 0 } :
2684- axisIds . getFromId ( gd , ax . anchor ) ;
2685-
26862706 y = ax . _offset + ax . _length / 2 ;
26872707
26882708 if ( ax . side === 'right' ) {
2689- x = counterAxis . _length + titleStandoff +
2690- fontSize * ( ax . showticklabels ? 1 : 0.5 ) ;
2709+ x = titleStandoff + fontSize * ( ax . showticklabels ? 1 : 0.5 ) ;
26912710 } else {
26922711 x = - titleStandoff - fontSize * ( ax . showticklabels ? 0.5 : 0 ) ;
26932712 }
2694- x += counterAxis . _offset ;
2713+ x += titleOffset ;
26952714
26962715 transform = { rotate : '-90' , offset : 0 } ;
26972716 }
0 commit comments