@@ -1932,29 +1932,29 @@ axes.drawOne = function(gd, ax, opts) {
1932
1932
push = { x : 0 , y : 0 , r : 0 , l : 0 , t : 0 , b : 0 } ;
1933
1933
1934
1934
var bbox = ax . _boundingBox ;
1935
- var titleOffset = getTitleOffset ( gd , ax ) ;
1935
+ var pos = axes . getPxPosition ( gd , ax ) ;
1936
1936
var anchorAxDomainIndex ;
1937
1937
var offset ;
1938
1938
1939
1939
switch ( axLetter + s ) {
1940
1940
case 'xb' :
1941
1941
anchorAxDomainIndex = 0 ;
1942
- offset = bbox . top - titleOffset ;
1942
+ offset = bbox . top - pos ;
1943
1943
push [ s ] = bbox . height ;
1944
1944
break ;
1945
1945
case 'xt' :
1946
1946
anchorAxDomainIndex = 1 ;
1947
- offset = titleOffset - bbox . bottom ;
1947
+ offset = pos - bbox . bottom ;
1948
1948
push [ s ] = bbox . height ;
1949
1949
break ;
1950
1950
case 'yl' :
1951
1951
anchorAxDomainIndex = 0 ;
1952
- offset = titleOffset - bbox . right ;
1952
+ offset = pos - bbox . right ;
1953
1953
push [ s ] = bbox . width ;
1954
1954
break ;
1955
1955
case 'yr' :
1956
1956
anchorAxDomainIndex = 1 ;
1957
- offset = bbox . left - titleOffset ;
1957
+ offset = bbox . left - pos ;
1958
1958
push [ s ] = bbox . width ;
1959
1959
break ;
1960
1960
}
@@ -2658,14 +2658,28 @@ function drawDividers(gd, ax, opts) {
2658
2658
. attr ( 'd' , opts . path ) ;
2659
2659
}
2660
2660
2661
- function getTitleOffset ( gd , ax ) {
2661
+ /**
2662
+ * Get axis position in px, that is the distance for the graph's
2663
+ * top (left) edge for x (y) axes.
2664
+ *
2665
+ * @param {DOM element } gd
2666
+ * @param {object } ax (full) axis object
2667
+ * - {string} _id
2668
+ * - {string} side
2669
+ * if anchored:
2670
+ * - {object} _anchorAxis
2671
+ * Otherwise:
2672
+ * - {number} position
2673
+ * @return {number }
2674
+ */
2675
+ axes . getPxPosition = function ( gd , ax ) {
2662
2676
var gs = gd . _fullLayout . _size ;
2663
2677
var axLetter = ax . _id . charAt ( 0 ) ;
2664
2678
var side = ax . side ;
2665
2679
var anchorAxis ;
2666
2680
2667
2681
if ( ax . anchor !== 'free' ) {
2668
- anchorAxis = axisIds . getFromId ( gd , ax . anchor ) ;
2682
+ anchorAxis = ax . _anchorAxis ;
2669
2683
} else if ( axLetter === 'x' ) {
2670
2684
anchorAxis = {
2671
2685
_offset : gs . t + ( 1 - ( ax . position || 0 ) ) * gs . h ,
@@ -2683,7 +2697,7 @@ function getTitleOffset(gd, ax) {
2683
2697
} else if ( side === 'bottom' || side === 'right' ) {
2684
2698
return anchorAxis . _offset + anchorAxis . _length ;
2685
2699
}
2686
- }
2700
+ } ;
2687
2701
2688
2702
function drawTitle ( gd , ax ) {
2689
2703
var fullLayout = gd . _fullLayout ;
@@ -2699,8 +2713,7 @@ function drawTitle(gd, ax) {
2699
2713
titleStandoff = 10 + fontSize * offsetBase + ( ax . linewidth ? ax . linewidth - 1 : 0 ) ;
2700
2714
}
2701
2715
2702
- var titleOffset = getTitleOffset ( gd , ax ) ;
2703
-
2716
+ var pos = axes . getPxPosition ( gd , ax ) ;
2704
2717
var transform , x , y ;
2705
2718
2706
2719
if ( axLetter === 'x' ) {
@@ -2711,7 +2724,7 @@ function drawTitle(gd, ax) {
2711
2724
} else {
2712
2725
y = titleStandoff + fontSize * ( ax . showticklabels ? 1.5 : 0.5 ) ;
2713
2726
}
2714
- y += titleOffset ;
2727
+ y += pos ;
2715
2728
} else {
2716
2729
y = ax . _offset + ax . _length / 2 ;
2717
2730
@@ -2720,7 +2733,7 @@ function drawTitle(gd, ax) {
2720
2733
} else {
2721
2734
x = - titleStandoff - fontSize * ( ax . showticklabels ? 0.5 : 0 ) ;
2722
2735
}
2723
- x += titleOffset ;
2736
+ x += pos ;
2724
2737
2725
2738
transform = { rotate : '-90' , offset : 0 } ;
2726
2739
}
0 commit comments