@@ -1946,29 +1946,29 @@ axes.drawOne = function(gd, ax, opts) {
1946
1946
push = { x : 0 , y : 0 , r : 0 , l : 0 , t : 0 , b : 0 } ;
1947
1947
1948
1948
var bbox = ax . _boundingBox ;
1949
- var counterAx = mainPlotinfo [ counterLetter + 'axis' ] ;
1949
+ var titleOffset = getTitleOffset ( gd , ax ) ;
1950
1950
var anchorAxDomainIndex ;
1951
1951
var offset ;
1952
1952
1953
1953
switch ( axLetter + s ) {
1954
1954
case 'xb' :
1955
1955
anchorAxDomainIndex = 0 ;
1956
- offset = bbox . top - counterAx . _length - counterAx . _offset ;
1956
+ offset = bbox . top - titleOffset ;
1957
1957
push [ s ] = bbox . height ;
1958
1958
break ;
1959
1959
case 'xt' :
1960
1960
anchorAxDomainIndex = 1 ;
1961
- offset = counterAx . _offset - bbox . bottom ;
1961
+ offset = titleOffset - bbox . bottom ;
1962
1962
push [ s ] = bbox . height ;
1963
1963
break ;
1964
1964
case 'yl' :
1965
1965
anchorAxDomainIndex = 0 ;
1966
- offset = counterAx . _offset - bbox . right ;
1966
+ offset = titleOffset - bbox . right ;
1967
1967
push [ s ] = bbox . width ;
1968
1968
break ;
1969
1969
case 'yr' :
1970
1970
anchorAxDomainIndex = 1 ;
1971
- offset = bbox . left - counterAx . _length - counterAx . _offset ;
1971
+ offset = bbox . left - titleOffset ;
1972
1972
push [ s ] = bbox . width ;
1973
1973
break ;
1974
1974
}
@@ -1980,6 +1980,7 @@ axes.drawOne = function(gd, ax, opts) {
1980
1980
if ( push [ s ] > 0 ) {
1981
1981
push [ s ] += offset ;
1982
1982
}
1983
+
1983
1984
if ( ax . title . text !== fullLayout . _dfltTitle [ axLetter ] ) {
1984
1985
push [ s ] += ax . title . font . size ;
1985
1986
}
@@ -2647,11 +2648,37 @@ function drawDividers(gd, ax, opts) {
2647
2648
. attr ( 'd' , opts . path ) ;
2648
2649
}
2649
2650
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
+
2650
2678
function drawTitle ( gd , ax ) {
2651
2679
var fullLayout = gd . _fullLayout ;
2652
2680
var axId = ax . _id ;
2653
2681
var axLetter = axId . charAt ( 0 ) ;
2654
- var gs = fullLayout . _size ;
2655
2682
var fontSize = ax . title . font . size ;
2656
2683
2657
2684
var titleStandoff ;
@@ -2662,36 +2689,28 @@ function drawTitle(gd, ax) {
2662
2689
titleStandoff = 10 + fontSize * offsetBase + ( ax . linewidth ? ax . linewidth - 1 : 0 ) ;
2663
2690
}
2664
2691
2665
- var transform , counterAxis , x , y ;
2692
+ var titleOffset = getTitleOffset ( gd , ax ) ;
2666
2693
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 ;
2671
2695
2696
+ if ( axLetter === 'x' ) {
2672
2697
x = ax . _offset + ax . _length / 2 ;
2673
2698
2674
2699
if ( ax . side === 'top' ) {
2675
2700
y = - titleStandoff - fontSize * ( ax . showticklabels ? 1 : 0 ) ;
2676
2701
} else {
2677
- y = counterAxis . _length + titleStandoff +
2678
- fontSize * ( ax . showticklabels ? 1.5 : 0.5 ) ;
2702
+ y = titleStandoff + fontSize * ( ax . showticklabels ? 1.5 : 0.5 ) ;
2679
2703
}
2680
- y += counterAxis . _offset ;
2704
+ y += titleOffset ;
2681
2705
} else {
2682
- counterAxis = ( ax . anchor === 'free' ) ?
2683
- { _offset : gs . l + ( ax . position || 0 ) * gs . w , _length : 0 } :
2684
- axisIds . getFromId ( gd , ax . anchor ) ;
2685
-
2686
2706
y = ax . _offset + ax . _length / 2 ;
2687
2707
2688
2708
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 ) ;
2691
2710
} else {
2692
2711
x = - titleStandoff - fontSize * ( ax . showticklabels ? 0.5 : 0 ) ;
2693
2712
}
2694
- x += counterAxis . _offset ;
2713
+ x += titleOffset ;
2695
2714
2696
2715
transform = { rotate : '-90' , offset : 0 } ;
2697
2716
}
0 commit comments