@@ -206,15 +206,77 @@ function makePadFn(ax, max) {
206
206
// 5% padding for points that specify extrapad: true
207
207
var extrappad = 0.05 * ax . _length ;
208
208
209
- var anchorAxis = ( ax . _anchorAxis || { } ) ;
210
- if ( ( anchorAxis . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 ) {
209
+ if (
210
+ ( ax . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 ||
211
+ ( ( ax . _anchorAxis || { } ) . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1
212
+ ) {
211
213
var axReverse = ax . autorange === 'reversed' ;
212
214
if ( ! axReverse ) {
213
215
var rng = Lib . simpleMap ( ax . range , ax . r2l ) ;
214
216
axReverse = rng [ 1 ] < rng [ 0 ] ;
215
217
}
216
218
if ( axReverse ) max = ! max ;
219
+ }
220
+
221
+ extrappad = adjustPadForInsideLabelsOnAnchorAxis ( extrappad , ax , max ) ;
222
+ extrappad = adjustPadForInsideLabelsOnThisAxis ( extrappad , ax , max ) ;
223
+
224
+ // domain-constrained axes: base extrappad on the unconstrained
225
+ // domain so it's consistent as the domain changes
226
+ if ( ( ax . constrain === 'domain' ) && ax . _inputDomain ) {
227
+ extrappad *= ( ax . _inputDomain [ 1 ] - ax . _inputDomain [ 0 ] ) /
228
+ ( ax . domain [ 1 ] - ax . domain [ 0 ] ) ;
229
+ }
230
+
231
+ if ( max ) {
232
+ return function getPadMax ( pt ) { return pt . pad + ( pt . extrapad ? extrappad : 0 ) ; } ;
233
+ } else {
234
+ return function getPadMin ( pt ) { return pt . pad + ( pt . extrapad ? extrappad : 0 ) ; } ;
235
+ }
236
+ }
237
+
238
+ var TEXTPAD = 3 ;
239
+
240
+ function adjustPadForInsideLabelsOnThisAxis ( extrappad , ax , max ) {
241
+ var ticklabelposition = ax . ticklabelposition || '' ;
242
+ var has = function ( str ) {
243
+ return ticklabelposition . indexOf ( str ) !== - 1 ;
244
+ } ;
245
+
246
+ if ( ! has ( 'inside' ) ) return extrappad ;
247
+ var isTop = has ( 'top' ) ;
248
+ var isLeft = has ( 'left' ) ;
249
+ var isRight = has ( 'right' ) ;
250
+ var isBottom = has ( 'bottom' ) ;
251
+ var isAligned = isBottom || isLeft || isTop || isRight ;
252
+
253
+ if (
254
+ ( max && ( isLeft || isBottom ) ) ||
255
+ ( ! max && ( isRight || isTop ) )
256
+ ) {
257
+ return extrappad ;
258
+ }
259
+
260
+ // increase padding to make more room for inside tick labels of the axis
261
+ var fontSize = ax . tickfont ? ax . tickfont . size : 12 ;
262
+ var isX = ax . _id . charAt ( 0 ) === 'x' ;
263
+ var morePad = ( isX ? 1.2 : 0.6 ) * fontSize ;
264
+
265
+ if ( isAligned ) {
266
+ morePad *= 2 ;
267
+ morePad += ( ax . tickwidth || 0 ) / 2 ;
268
+ }
269
+
270
+ morePad += TEXTPAD ;
271
+
272
+ extrappad = Math . max ( extrappad , morePad ) ;
217
273
274
+ return extrappad ;
275
+ }
276
+
277
+ function adjustPadForInsideLabelsOnAnchorAxis ( extrappad , ax , max ) {
278
+ var anchorAxis = ( ax . _anchorAxis || { } ) ;
279
+ if ( ( anchorAxis . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 ) {
218
280
// increase padding to make more room for inside tick labels of the counter axis
219
281
if ( (
220
282
! max && (
@@ -236,7 +298,6 @@ function makePadFn(ax, max) {
236
298
var sinA = Math . abs ( Math . sin ( rad ) ) ;
237
299
238
300
// use bounding boxes
239
- morePad = 0 ;
240
301
anchorAxis . _vals . forEach ( function ( t ) {
241
302
if ( t . bb ) {
242
303
var w = t . bb . width ;
@@ -261,18 +322,7 @@ function makePadFn(ax, max) {
261
322
}
262
323
}
263
324
264
- // domain-constrained axes: base extrappad on the unconstrained
265
- // domain so it's consistent as the domain changes
266
- if ( ( ax . constrain === 'domain' ) && ax . _inputDomain ) {
267
- extrappad *= ( ax . _inputDomain [ 1 ] - ax . _inputDomain [ 0 ] ) /
268
- ( ax . domain [ 1 ] - ax . domain [ 0 ] ) ;
269
- }
270
-
271
- if ( max ) {
272
- return function getPadMax ( pt ) { return pt . pad + ( pt . extrapad ? extrappad : 0 ) ; } ;
273
- } else {
274
- return function getPadMin ( pt ) { return pt . pad + ( pt . extrapad ? extrappad : 0 ) ; } ;
275
- }
325
+ return extrappad ;
276
326
}
277
327
278
328
function concatExtremes ( gd , ax , noMatch ) {
0 commit comments