@@ -218,8 +218,11 @@ function makePadFn(ax, max) {
218218 if ( axReverse ) max = ! max ;
219219 }
220220
221- extrappad = adjustPadForInsideLabelsOnAnchorAxis ( extrappad , ax , max ) ;
222- extrappad = adjustPadForInsideLabelsOnThisAxis ( extrappad , ax , max ) ;
221+ var A = padInsideLabelsOnAnchorAxis ( ax , max ) ;
222+ var B = padInsideLabelsOnThisAxis ( ax , max ) ;
223+
224+ var zero = Math . max ( A , B ) ;
225+ extrappad = Math . max ( zero , extrappad ) ;
223226
224227 // domain-constrained axes: base extrappad on the unconstrained
225228 // domain so it's consistent as the domain changes
@@ -228,18 +231,18 @@ function makePadFn(ax, max) {
228231 ( ax . domain [ 1 ] - ax . domain [ 0 ] ) ;
229232 }
230233
231- return function getPad ( pt ) { return pt . pad + ( pt . extrapad ? extrappad : 0 ) ; } ;
234+ return function getPad ( pt ) { return pt . pad + ( pt . extrapad ? extrappad : zero ) ; } ;
232235}
233236
234237var TEXTPAD = 3 ;
235238
236- function adjustPadForInsideLabelsOnThisAxis ( extrappad , ax , max ) {
239+ function padInsideLabelsOnThisAxis ( ax , max ) {
237240 var ticklabelposition = ax . ticklabelposition || '' ;
238241 var has = function ( str ) {
239242 return ticklabelposition . indexOf ( str ) !== - 1 ;
240243 } ;
241244
242- if ( ! has ( 'inside' ) ) return extrappad ;
245+ if ( ! has ( 'inside' ) ) return 0 ;
243246 var isTop = has ( 'top' ) ;
244247 var isLeft = has ( 'left' ) ;
245248 var isRight = has ( 'right' ) ;
@@ -250,27 +253,26 @@ function adjustPadForInsideLabelsOnThisAxis(extrappad, ax, max) {
250253 ( max && ( isLeft || isBottom ) ) ||
251254 ( ! max && ( isRight || isTop ) )
252255 ) {
253- return extrappad ;
256+ return 0 ;
254257 }
255258
256259 // increase padding to make more room for inside tick labels of the axis
257260 var fontSize = ax . tickfont ? ax . tickfont . size : 12 ;
258261 var isX = ax . _id . charAt ( 0 ) === 'x' ;
259- var morePad = ( isX ? 1.2 : 0.6 ) * fontSize ;
262+ var pad = ( isX ? 1.2 : 0.6 ) * fontSize ;
260263
261264 if ( isAligned ) {
262- morePad *= 2 ;
263- morePad += ( ax . tickwidth || 0 ) / 2 ;
265+ pad *= 2 ;
266+ pad += ( ax . tickwidth || 0 ) / 2 ;
264267 }
265268
266- morePad += TEXTPAD ;
267-
268- extrappad = Math . max ( extrappad , morePad ) ;
269+ pad += TEXTPAD ;
269270
270- return extrappad ;
271+ return pad ;
271272}
272273
273- function adjustPadForInsideLabelsOnAnchorAxis ( extrappad , ax , max ) {
274+ function padInsideLabelsOnAnchorAxis ( ax , max ) {
275+ var pad = 0 ;
274276 var anchorAxis = ( ax . _anchorAxis || { } ) ;
275277 if ( ( anchorAxis . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 ) {
276278 // increase padding to make more room for inside tick labels of the counter axis
@@ -287,7 +289,6 @@ function adjustPadForInsideLabelsOnAnchorAxis(extrappad, ax, max) {
287289 ) ) {
288290 var isX = ax . _id . charAt ( 0 ) === 'x' ;
289291
290- var morePad = 0 ;
291292 if ( anchorAxis . _vals ) {
292293 var rad = Lib . deg2rad ( anchorAxis . _tickAngles [ anchorAxis . _id + 'tick' ] || 0 ) ;
293294 var cosA = Math . abs ( Math . cos ( rad ) ) ;
@@ -296,29 +297,24 @@ function adjustPadForInsideLabelsOnAnchorAxis(extrappad, ax, max) {
296297 // use bounding boxes
297298 anchorAxis . _vals . forEach ( function ( t ) {
298299 if ( t . bb ) {
299- var w = t . bb . width ;
300- var h = t . bb . height ;
300+ var w = 2 * TEXTPAD + t . bb . width ;
301+ var h = 2 * TEXTPAD + t . bb . height ;
301302
302- morePad = Math . max ( morePad , isX ?
303+ pad = Math . max ( pad , isX ?
303304 Math . max ( w * cosA , h * sinA ) :
304305 Math . max ( h * cosA , w * sinA )
305306 ) ;
306-
307- // add extra pad around label
308- morePad += 3 ;
309307 }
310308 } ) ;
311309 }
312310
313311 if ( anchorAxis . ticks === 'inside' && anchorAxis . ticklabelposition === 'inside' ) {
314- morePad += anchorAxis . ticklen || 0 ;
312+ pad += anchorAxis . ticklen || 0 ;
315313 }
316-
317- extrappad = Math . max ( extrappad , morePad ) ;
318314 }
319315 }
320316
321- return extrappad ;
317+ return pad ;
322318}
323319
324320function concatExtremes ( gd , ax , noMatch ) {
0 commit comments