@@ -1637,6 +1637,10 @@ axes.drawOne = function(gd, ax, opts) {
1637
1637
1638
1638
if ( ! ax . visible ) return ;
1639
1639
1640
+ // stash selections to avoid DOM queries e.g.
1641
+ // - stash tickLabels selection, so that drawTitle can use it to scoot title
1642
+ ax . _selections = { } ;
1643
+
1640
1644
var transFn = axes . makeTransFn ( ax ) ;
1641
1645
1642
1646
// We remove zero lines, grid lines, and inside ticks if they're within 1px of the end
@@ -1737,12 +1741,6 @@ axes.drawOne = function(gd, ax, opts) {
1737
1741
} ) ;
1738
1742
}
1739
1743
1740
- // stash tickLabels selection, so that drawTitle can use it
1741
- // to scoot title w/o having to query the axis layer again
1742
- //
1743
- // TODO? Stash this per class?
1744
- ax . _tickLabels = null ;
1745
-
1746
1744
var seq = [ ] ;
1747
1745
1748
1746
// tick labels - for now just the main labels.
@@ -2216,6 +2214,7 @@ axes.drawZeroLine = function(gd, ax, opts) {
2216
2214
* - {string} _id
2217
2215
* - {boolean} showticklabels
2218
2216
* - {number} tickangle
2217
+ * - {object (optional)} _selections
2219
2218
* @param {object } opts
2220
2219
* - {array of object} vals (calcTicks output-like)
2221
2220
* - {d3 selection} layer
@@ -2273,8 +2272,6 @@ axes.drawLabels = function(gd, ax, opts) {
2273
2272
2274
2273
tickLabels . exit ( ) . remove ( ) ;
2275
2274
2276
- ax . _tickLabels = tickLabels ;
2277
-
2278
2275
// TODO ??
2279
2276
if ( isAngular ( ax ) ) {
2280
2277
tickLabels . each ( function ( d ) {
@@ -2422,32 +2419,25 @@ axes.drawLabels = function(gd, ax, opts) {
2422
2419
}
2423
2420
}
2424
2421
2422
+ if ( ax . _selections ) {
2423
+ ax . _selections [ cls ] = tickLabels ;
2424
+ }
2425
+
2425
2426
var done = Lib . syncOrAsync ( [ allLabelsReady , fixLabelOverlaps ] ) ;
2426
2427
if ( done && done . then ) gd . _promises . push ( done ) ;
2427
2428
return done ;
2428
2429
} ;
2429
2430
2431
+ function drawTitle ( gd , ax ) {
2430
2432
axes . drawTitle = function ( gd , ax ) {
2431
2433
var fullLayout = gd . _fullLayout ;
2432
- var tickLabels = ax . _tickLabels ;
2433
-
2434
- var avoid = {
2435
- selection : tickLabels ,
2436
- side : ax . side
2437
- } ;
2438
-
2439
2434
var axId = ax . _id ;
2440
2435
var axLetter = axId . charAt ( 0 ) ;
2441
2436
var offsetBase = 1.5 ;
2442
2437
var gs = fullLayout . _size ;
2443
2438
var fontSize = ax . title . font . size ;
2444
2439
2445
2440
var transform , counterAxis , x , y ;
2446
-
2447
- if ( tickLabels && tickLabels . node ( ) && tickLabels . node ( ) . parentNode ) {
2448
- var translation = Drawing . getTranslate ( tickLabels . node ( ) . parentNode ) ;
2449
- avoid . offsetLeft = translation . x ;
2450
- avoid . offsetTop = translation . y ;
2451
2441
}
2452
2442
2453
2443
var titleStandoff = 10 + fontSize * offsetBase +
@@ -2467,8 +2457,6 @@ axes.drawTitle = function(gd, ax) {
2467
2457
fontSize * ( ax . showticklabels ? 1.5 : 0.5 ) ;
2468
2458
}
2469
2459
y += counterAxis . _offset ;
2470
-
2471
- if ( ! avoid . side ) avoid . side = 'bottom' ;
2472
2460
}
2473
2461
else {
2474
2462
counterAxis = ( ax . anchor === 'free' ) ?
@@ -2485,7 +2473,23 @@ axes.drawTitle = function(gd, ax) {
2485
2473
x += counterAxis . _offset ;
2486
2474
2487
2475
transform = { rotate : '-90' , offset : 0 } ;
2488
- if ( ! avoid . side ) avoid . side = 'left' ;
2476
+ }
2477
+
2478
+ var avoid ;
2479
+
2480
+ if ( ax . type !== 'multicategory' ) {
2481
+ var tickLabels = ax . _selections [ ax . _id + 'tick' ] ;
2482
+
2483
+ avoid = {
2484
+ selection : tickLabels ,
2485
+ side : ax . side
2486
+ } ;
2487
+
2488
+ if ( tickLabels && tickLabels . node ( ) && tickLabels . node ( ) . parentNode ) {
2489
+ var translation = Drawing . getTranslate ( tickLabels . node ( ) . parentNode ) ;
2490
+ avoid . offsetLeft = translation . x ;
2491
+ avoid . offsetTop = translation . y ;
2492
+ }
2489
2493
}
2490
2494
2491
2495
Titles . draw ( gd , axId + 'title' , {
0 commit comments