@@ -218,8 +218,11 @@ function makePadFn(ax, max) {
218
218
if ( axReverse ) max = ! max ;
219
219
}
220
220
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 ) ;
223
226
224
227
// domain-constrained axes: base extrappad on the unconstrained
225
228
// domain so it's consistent as the domain changes
@@ -228,18 +231,18 @@ function makePadFn(ax, max) {
228
231
( ax . domain [ 1 ] - ax . domain [ 0 ] ) ;
229
232
}
230
233
231
- return function getPad ( pt ) { return pt . pad + ( pt . extrapad ? extrappad : 0 ) ; } ;
234
+ return function getPad ( pt ) { return pt . pad + ( pt . extrapad ? extrappad : zero ) ; } ;
232
235
}
233
236
234
237
var TEXTPAD = 3 ;
235
238
236
- function adjustPadForInsideLabelsOnThisAxis ( extrappad , ax , max ) {
239
+ function padInsideLabelsOnThisAxis ( ax , max ) {
237
240
var ticklabelposition = ax . ticklabelposition || '' ;
238
241
var has = function ( str ) {
239
242
return ticklabelposition . indexOf ( str ) !== - 1 ;
240
243
} ;
241
244
242
- if ( ! has ( 'inside' ) ) return extrappad ;
245
+ if ( ! has ( 'inside' ) ) return 0 ;
243
246
var isTop = has ( 'top' ) ;
244
247
var isLeft = has ( 'left' ) ;
245
248
var isRight = has ( 'right' ) ;
@@ -250,27 +253,26 @@ function adjustPadForInsideLabelsOnThisAxis(extrappad, ax, max) {
250
253
( max && ( isLeft || isBottom ) ) ||
251
254
( ! max && ( isRight || isTop ) )
252
255
) {
253
- return extrappad ;
256
+ return 0 ;
254
257
}
255
258
256
259
// increase padding to make more room for inside tick labels of the axis
257
260
var fontSize = ax . tickfont ? ax . tickfont . size : 12 ;
258
261
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 ;
260
263
261
264
if ( isAligned ) {
262
- morePad *= 2 ;
263
- morePad += ( ax . tickwidth || 0 ) / 2 ;
265
+ pad *= 2 ;
266
+ pad += ( ax . tickwidth || 0 ) / 2 ;
264
267
}
265
268
266
- morePad += TEXTPAD ;
267
-
268
- extrappad = Math . max ( extrappad , morePad ) ;
269
+ pad += TEXTPAD ;
269
270
270
- return extrappad ;
271
+ return pad ;
271
272
}
272
273
273
- function adjustPadForInsideLabelsOnAnchorAxis ( extrappad , ax , max ) {
274
+ function padInsideLabelsOnAnchorAxis ( ax , max ) {
275
+ var pad = 0 ;
274
276
var anchorAxis = ( ax . _anchorAxis || { } ) ;
275
277
if ( ( anchorAxis . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 ) {
276
278
// increase padding to make more room for inside tick labels of the counter axis
@@ -287,7 +289,6 @@ function adjustPadForInsideLabelsOnAnchorAxis(extrappad, ax, max) {
287
289
) ) {
288
290
var isX = ax . _id . charAt ( 0 ) === 'x' ;
289
291
290
- var morePad = 0 ;
291
292
if ( anchorAxis . _vals ) {
292
293
var rad = Lib . deg2rad ( anchorAxis . _tickAngles [ anchorAxis . _id + 'tick' ] || 0 ) ;
293
294
var cosA = Math . abs ( Math . cos ( rad ) ) ;
@@ -296,29 +297,24 @@ function adjustPadForInsideLabelsOnAnchorAxis(extrappad, ax, max) {
296
297
// use bounding boxes
297
298
anchorAxis . _vals . forEach ( function ( t ) {
298
299
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 ;
301
302
302
- morePad = Math . max ( morePad , isX ?
303
+ pad = Math . max ( pad , isX ?
303
304
Math . max ( w * cosA , h * sinA ) :
304
305
Math . max ( h * cosA , w * sinA )
305
306
) ;
306
-
307
- // add extra pad around label
308
- morePad += 3 ;
309
307
}
310
308
} ) ;
311
309
}
312
310
313
311
if ( anchorAxis . ticks === 'inside' && anchorAxis . ticklabelposition === 'inside' ) {
314
- morePad += anchorAxis . ticklen || 0 ;
312
+ pad += anchorAxis . ticklen || 0 ;
315
313
}
316
-
317
- extrappad = Math . max ( extrappad , morePad ) ;
318
314
}
319
315
}
320
316
321
- return extrappad ;
317
+ return pad ;
322
318
}
323
319
324
320
function concatExtremes ( gd , ax , noMatch ) {
0 commit comments