@@ -1932,29 +1932,29 @@ axes.drawOne = function(gd, ax, opts) {
19321932 push = { x : 0 , y : 0 , r : 0 , l : 0 , t : 0 , b : 0 } ;
19331933
19341934 var bbox = ax . _boundingBox ;
1935- var titleOffset = getTitleOffset ( gd , ax ) ;
1935+ var pos = axes . getPxPosition ( gd , ax ) ;
19361936 var anchorAxDomainIndex ;
19371937 var offset ;
19381938
19391939 switch ( axLetter + s ) {
19401940 case 'xb' :
19411941 anchorAxDomainIndex = 0 ;
1942- offset = bbox . top - titleOffset ;
1942+ offset = bbox . top - pos ;
19431943 push [ s ] = bbox . height ;
19441944 break ;
19451945 case 'xt' :
19461946 anchorAxDomainIndex = 1 ;
1947- offset = titleOffset - bbox . bottom ;
1947+ offset = pos - bbox . bottom ;
19481948 push [ s ] = bbox . height ;
19491949 break ;
19501950 case 'yl' :
19511951 anchorAxDomainIndex = 0 ;
1952- offset = titleOffset - bbox . right ;
1952+ offset = pos - bbox . right ;
19531953 push [ s ] = bbox . width ;
19541954 break ;
19551955 case 'yr' :
19561956 anchorAxDomainIndex = 1 ;
1957- offset = bbox . left - titleOffset ;
1957+ offset = bbox . left - pos ;
19581958 push [ s ] = bbox . width ;
19591959 break ;
19601960 }
@@ -2658,14 +2658,28 @@ function drawDividers(gd, ax, opts) {
26582658 . attr ( 'd' , opts . path ) ;
26592659}
26602660
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 ) {
26622676 var gs = gd . _fullLayout . _size ;
26632677 var axLetter = ax . _id . charAt ( 0 ) ;
26642678 var side = ax . side ;
26652679 var anchorAxis ;
26662680
26672681 if ( ax . anchor !== 'free' ) {
2668- anchorAxis = axisIds . getFromId ( gd , ax . anchor ) ;
2682+ anchorAxis = ax . _anchorAxis ;
26692683 } else if ( axLetter === 'x' ) {
26702684 anchorAxis = {
26712685 _offset : gs . t + ( 1 - ( ax . position || 0 ) ) * gs . h ,
@@ -2683,7 +2697,7 @@ function getTitleOffset(gd, ax) {
26832697 } else if ( side === 'bottom' || side === 'right' ) {
26842698 return anchorAxis . _offset + anchorAxis . _length ;
26852699 }
2686- }
2700+ } ;
26872701
26882702function drawTitle ( gd , ax ) {
26892703 var fullLayout = gd . _fullLayout ;
@@ -2699,8 +2713,7 @@ function drawTitle(gd, ax) {
26992713 titleStandoff = 10 + fontSize * offsetBase + ( ax . linewidth ? ax . linewidth - 1 : 0 ) ;
27002714 }
27012715
2702- var titleOffset = getTitleOffset ( gd , ax ) ;
2703-
2716+ var pos = axes . getPxPosition ( gd , ax ) ;
27042717 var transform , x , y ;
27052718
27062719 if ( axLetter === 'x' ) {
@@ -2711,7 +2724,7 @@ function drawTitle(gd, ax) {
27112724 } else {
27122725 y = titleStandoff + fontSize * ( ax . showticklabels ? 1.5 : 0.5 ) ;
27132726 }
2714- y += titleOffset ;
2727+ y += pos ;
27152728 } else {
27162729 y = ax . _offset + ax . _length / 2 ;
27172730
@@ -2720,7 +2733,7 @@ function drawTitle(gd, ax) {
27202733 } else {
27212734 x = - titleStandoff - fontSize * ( ax . showticklabels ? 0.5 : 0 ) ;
27222735 }
2723- x += titleOffset ;
2736+ x += pos ;
27242737
27252738 transform = { rotate : '-90' , offset : 0 } ;
27262739 }
0 commit comments