@@ -219,20 +219,19 @@ function drawColorBar(g, opts, gd) {
219
219
220
220
// x positioning: do it initially just for left anchor,
221
221
// then fix at the end (since we don't know the width yet)
222
- var xLeft = Math . round ( optsX * gs . w + xpad ) ;
222
+ var uPx = Math . round ( optsX * gs . w + xpad ) ;
223
223
// for dragging... this is getting a little muddled...
224
- var xLeftFrac = optsX - thickFrac * ( { center : 0.5 , right : 1 } [ xanchor ] || 0 ) ;
224
+ var uFrac = optsX - thickFrac * ( { center : 0.5 , right : 1 } [ xanchor ] || 0 ) ;
225
225
226
226
// y positioning we can do correctly from the start
227
- var yBottomFrac = optsY + lenFrac * ( ( { top : - 0.5 , bottom : 0.5 } [ yanchor ] || 0 ) - 0.5 ) ;
228
- var yBottomPx = Math . round ( gs . h * ( 1 - yBottomFrac ) ) ;
229
- var yTopPx = yBottomPx - lenPx ;
227
+ var vFrac = optsY + lenFrac * ( ( { top : - 0.5 , bottom : 0.5 } [ yanchor ] || 0 ) - 0.5 ) ;
228
+ var vPx = Math . round ( gs . h * ( 1 - vFrac ) ) ;
230
229
231
230
// stash a few things for makeEditable
232
231
opts . _lenFrac = lenFrac ;
233
232
opts . _thickFrac = thickFrac ;
234
- opts . _xLeftFrac = xLeftFrac ;
235
- opts . _yBottomFrac = yBottomFrac ;
233
+ opts . _uFrac = uFrac ;
234
+ opts . _vFrac = vFrac ;
236
235
237
236
// stash mocked axis for contour label formatting
238
237
var ax = opts . _axis = mockColorBarAxis ( gd , opts , zrange ) ;
@@ -244,15 +243,15 @@ function drawColorBar(g, opts, gd) {
244
243
if ( [ 'top' , 'bottom' ] . indexOf ( titleSide ) !== - 1 ) {
245
244
ax . title . side = titleSide ;
246
245
ax . titlex = optsX + xpadFrac ;
247
- ax . titley = yBottomFrac + ( title . side === 'top' ? lenFrac - ypadFrac : ypadFrac ) ;
246
+ ax . titley = vFrac + ( title . side === 'top' ? lenFrac - ypadFrac : ypadFrac ) ;
248
247
}
249
248
250
249
if ( line . color && opts . tickmode === 'auto' ) {
251
250
ax . tickmode = 'linear' ;
252
251
ax . tick0 = levelsIn . start ;
253
252
var dtick = levelsIn . size ;
254
253
// expand if too many contours, so we don't get too many ticks
255
- var autoNtick = Lib . constrain ( ( yBottomPx - yTopPx ) / 50 , 4 , 15 ) + 1 ;
254
+ var autoNtick = Lib . constrain ( lenPx / 50 , 4 , 15 ) + 1 ;
256
255
var dtFactor = ( zrange [ 1 ] - zrange [ 0 ] ) / ( ( opts . nticks || autoNtick ) * dtick ) ;
257
256
if ( dtFactor > 1 ) {
258
257
var dtexp = Math . pow ( 10 , Math . floor ( Math . log ( dtFactor ) / Math . LN10 ) ) ;
@@ -270,8 +269,8 @@ function drawColorBar(g, opts, gd) {
270
269
// set domain after init, because we may want to
271
270
// allow it outside [0,1]
272
271
ax . domain = [
273
- yBottomFrac + ypadFrac ,
274
- yBottomFrac + lenFrac - ypadFrac
272
+ vFrac + ypadFrac ,
273
+ vFrac + lenFrac - ypadFrac
275
274
] ;
276
275
277
276
ax . setScale ( ) ;
@@ -317,10 +316,10 @@ function drawColorBar(g, opts, gd) {
317
316
var y ;
318
317
319
318
if ( titleSide === 'top' ) {
320
- y = ( 1 - ( yBottomFrac + lenFrac - ypadFrac ) ) * gs . h +
319
+ y = ( 1 - ( vFrac + lenFrac - ypadFrac ) ) * gs . h +
321
320
gs . t + 3 + fontSize * 0.75 ;
322
321
} else {
323
- y = ( 1 - ( yBottomFrac + ypadFrac ) ) * gs . h +
322
+ y = ( 1 - ( vFrac + ypadFrac ) ) * gs . h +
324
323
gs . t - 3 - fontSize * 0.25 ;
325
324
}
326
325
drawTitle ( ax . _id + 'title' , {
@@ -431,7 +430,7 @@ function drawColorBar(g, opts, gd) {
431
430
// Colorbar cannot currently support opacities so we
432
431
// use an opaque fill even when alpha channels present
433
432
var fillEl = d3 . select ( this ) . attr ( {
434
- x : xLeft ,
433
+ x : uPx ,
435
434
width : Math . max ( thickPx , 2 ) ,
436
435
y : d3 . min ( z ) ,
437
436
height : Math . max ( d3 . max ( z ) - d3 . min ( z ) , 2 ) ,
@@ -455,15 +454,15 @@ function drawColorBar(g, opts, gd) {
455
454
lines . exit ( ) . remove ( ) ;
456
455
lines . each ( function ( d ) {
457
456
d3 . select ( this )
458
- . attr ( 'd' , 'M' + xLeft + ',' +
457
+ . attr ( 'd' , 'M' + uPx + ',' +
459
458
( Math . round ( ax . c2p ( d ) ) + ( line . width / 2 ) % 1 ) + 'h' + thickPx )
460
459
. call ( Drawing . lineGroupStyle , line . width , lineColormap ( d ) , line . dash ) ;
461
460
} ) ;
462
461
463
462
// force full redraw of labels and ticks
464
463
axLayer . selectAll ( 'g.' + ax . _id + 'tick,path' ) . remove ( ) ;
465
464
466
- var shift = xLeft + thickPx +
465
+ var shift = uPx + thickPx +
467
466
( outlinewidth || 0 ) / 2 - ( opts . ticks === 'outside' ? 1 : 0 ) ;
468
467
469
468
var vals = Axes . calcTicks ( ax ) ;
@@ -489,9 +488,9 @@ function drawColorBar(g, opts, gd) {
489
488
// TODO: why are we redrawing multiple times now with this?
490
489
// I guess autoMargin doesn't like being post-promise?
491
490
function positionCB ( ) {
492
- var innerWidth = thickPx + outlinewidth / 2 ;
491
+ var innerThickness = thickPx + outlinewidth / 2 ;
493
492
if ( ax . ticklabelposition . indexOf ( 'inside' ) === - 1 ) {
494
- innerWidth += Drawing . bBox ( axLayer . node ( ) ) . width ;
493
+ innerThickness += Drawing . bBox ( axLayer . node ( ) ) . width ;
495
494
}
496
495
497
496
titleEl = titleCont . select ( 'text' ) ;
@@ -506,29 +505,28 @@ function drawColorBar(g, opts, gd) {
506
505
// (except for top/bottom mathjax, above)
507
506
// but the weird gs.l is because the titleunshift
508
507
// transform gets removed by Drawing.bBox
509
- titleWidth = Drawing . bBox ( titleCont . node ( ) ) . right - xLeft - gs . l ;
508
+ titleWidth = Drawing . bBox ( titleCont . node ( ) ) . right - uPx - gs . l ;
510
509
}
511
- innerWidth = Math . max ( innerWidth , titleWidth ) ;
510
+ innerThickness = Math . max ( innerThickness , titleWidth ) ;
512
511
}
513
512
514
- var outerwidth = 2 * xpad + innerWidth + borderwidth + outlinewidth / 2 ;
515
- var outerheight = yBottomPx - yTopPx ;
513
+ var outerThickness = 2 * xpad + innerThickness + borderwidth + outlinewidth / 2 ;
516
514
517
515
g . select ( '.' + cn . cbbg ) . attr ( {
518
- x : xLeft - xpad - ( borderwidth + outlinewidth ) / 2 ,
519
- y : yTopPx - yExtraPx ,
520
- width : Math . max ( outerwidth , 2 ) ,
521
- height : Math . max ( outerheight + 2 * yExtraPx , 2 )
516
+ x : uPx - xpad - ( borderwidth + outlinewidth ) / 2 ,
517
+ y : vPx - lenPx - yExtraPx ,
518
+ width : Math . max ( outerThickness , 2 ) ,
519
+ height : Math . max ( lenPx + 2 * yExtraPx , 2 )
522
520
} )
523
521
. call ( Color . fill , opts . bgcolor )
524
522
. call ( Color . stroke , opts . bordercolor )
525
523
. style ( 'stroke-width' , borderwidth ) ;
526
524
527
525
g . selectAll ( '.' + cn . cboutline ) . attr ( {
528
- x : xLeft ,
529
- y : yTopPx + ypad + ( titleSide === 'top' ? titleHeight : 0 ) ,
526
+ x : uPx ,
527
+ y : vPx - lenPx + ypad + ( titleSide === 'top' ? titleHeight : 0 ) ,
530
528
width : Math . max ( thickPx , 2 ) ,
531
- height : Math . max ( outerheight - 2 * ypad - titleHeight , 2 )
529
+ height : Math . max ( lenPx - 2 * ypad - titleHeight , 2 )
532
530
} )
533
531
. call ( Color . stroke , opts . outlinecolor )
534
532
. style ( {
@@ -537,7 +535,7 @@ function drawColorBar(g, opts, gd) {
537
535
} ) ;
538
536
539
537
// fix positioning for xanchor!='left'
540
- var xoffset = ( { center : 0.5 , right : 1 } [ xanchor ] || 0 ) * outerwidth ;
538
+ var xoffset = ( { center : 0.5 , right : 1 } [ xanchor ] || 0 ) * outerThickness ;
541
539
g . attr ( 'transform' , strTranslate ( gs . l - xoffset , gs . t ) ) ;
542
540
543
541
// auto margin adjustment
@@ -546,8 +544,8 @@ function drawColorBar(g, opts, gd) {
546
544
var bFrac = FROM_BR [ yanchor ] ;
547
545
if ( lenmode === 'pixels' ) {
548
546
marginOpts . y = optsY ;
549
- marginOpts . t = outerheight * tFrac ;
550
- marginOpts . b = outerheight * bFrac ;
547
+ marginOpts . t = lenPx * tFrac ;
548
+ marginOpts . b = lenPx * bFrac ;
551
549
} else {
552
550
marginOpts . t = marginOpts . b = 0 ;
553
551
marginOpts . yt = optsY + len * tFrac ;
@@ -558,10 +556,10 @@ function drawColorBar(g, opts, gd) {
558
556
var rFrac = FROM_BR [ xanchor ] ;
559
557
if ( thicknessmode === 'pixels' ) {
560
558
marginOpts . x = optsX ;
561
- marginOpts . l = outerwidth * lFrac ;
562
- marginOpts . r = outerwidth * rFrac ;
559
+ marginOpts . l = outerThickness * lFrac ;
560
+ marginOpts . r = outerThickness * rFrac ;
563
561
} else {
564
- var extraThickness = outerwidth - thickPx ;
562
+ var extraThickness = outerThickness - thickPx ;
565
563
marginOpts . l = extraThickness * lFrac ;
566
564
marginOpts . r = extraThickness * rFrac ;
567
565
marginOpts . xl = optsX - thickness * lFrac ;
@@ -596,9 +594,9 @@ function makeEditable(g, opts, gd) {
596
594
moveFn : function ( dx , dy ) {
597
595
g . attr ( 'transform' , t0 + strTranslate ( dx , dy ) ) ;
598
596
599
- xf = dragElement . align ( opts . _xLeftFrac + ( dx / gs . w ) , opts . _thickFrac ,
597
+ xf = dragElement . align ( opts . _uFrac + ( dx / gs . w ) , opts . _thickFrac ,
600
598
0 , 1 , opts . xanchor ) ;
601
- yf = dragElement . align ( opts . _yBottomFrac - ( dy / gs . h ) , opts . _lenFrac ,
599
+ yf = dragElement . align ( opts . _vFrac - ( dy / gs . h ) , opts . _lenFrac ,
602
600
0 , 1 , opts . yanchor ) ;
603
601
604
602
var csr = dragElement . getCursor ( xf , yf , opts . xanchor , opts . yanchor ) ;
0 commit comments