@@ -167,6 +167,19 @@ function makeColorBarData(gd) {
167
167
}
168
168
169
169
function drawColorBar ( g , opts , gd ) {
170
+ var len = opts . len ;
171
+ var lenmode = opts . lenmode ;
172
+ var thickness = opts . thickness ;
173
+ var thicknessmode = opts . thicknessmode ;
174
+ var outlinewidth = opts . outlinewidth ;
175
+ var borderwidth = opts . borderwidth ;
176
+ var xanchor = opts . xanchor ;
177
+ var yanchor = opts . yanchor ;
178
+ var xpad = opts . xpad ;
179
+ var ypad = opts . ypad ;
180
+ var optsX = opts . x ;
181
+ var optsY = opts . y ;
182
+
170
183
var fullLayout = gd . _fullLayout ;
171
184
var gs = fullLayout . _size ;
172
185
@@ -196,22 +209,22 @@ function drawColorBar(g, opts, gd) {
196
209
// when the colorbar itself is pushing the margins.
197
210
// but then the fractional size is calculated based on the
198
211
// actual graph size, so that the axes will size correctly.
199
- var thickPx = Math . round ( opts . thickness * ( opts . thicknessmode === 'fraction' ? gs . w : 1 ) ) ;
212
+ var thickPx = Math . round ( thickness * ( thicknessmode === 'fraction' ? gs . w : 1 ) ) ;
200
213
var thickFrac = thickPx / gs . w ;
201
- var lenPx = Math . round ( opts . len * ( opts . lenmode === 'fraction' ? gs . h : 1 ) ) ;
214
+ var lenPx = Math . round ( len * ( lenmode === 'fraction' ? gs . h : 1 ) ) ;
202
215
var lenFrac = lenPx / gs . h ;
203
- var xpadFrac = opts . xpad / gs . w ;
204
- var yExtraPx = ( opts . borderwidth + opts . outlinewidth ) / 2 ;
205
- var ypadFrac = opts . ypad / gs . h ;
216
+ var xpadFrac = xpad / gs . w ;
217
+ var yExtraPx = ( borderwidth + outlinewidth ) / 2 ;
218
+ var ypadFrac = ypad / gs . h ;
206
219
207
220
// x positioning: do it initially just for left anchor,
208
221
// then fix at the end (since we don't know the width yet)
209
- var xLeft = Math . round ( opts . x * gs . w + opts . xpad ) ;
222
+ var xLeft = Math . round ( optsX * gs . w + xpad ) ;
210
223
// for dragging... this is getting a little muddled...
211
- var xLeftFrac = opts . x - thickFrac * ( { center : 0.5 , right : 1 } [ opts . xanchor ] || 0 ) ;
224
+ var xLeftFrac = optsX - thickFrac * ( { center : 0.5 , right : 1 } [ xanchor ] || 0 ) ;
212
225
213
226
// y positioning we can do correctly from the start
214
- var yBottomFrac = opts . y + lenFrac * ( ( { top : - 0.5 , bottom : 0.5 } [ opts . yanchor ] || 0 ) - 0.5 ) ;
227
+ var yBottomFrac = optsY + lenFrac * ( ( { top : - 0.5 , bottom : 0.5 } [ yanchor ] || 0 ) - 0.5 ) ;
215
228
var yBottomPx = Math . round ( gs . h * ( 1 - yBottomFrac ) ) ;
216
229
var yTopPx = yBottomPx - lenPx ;
217
230
@@ -226,11 +239,11 @@ function drawColorBar(g, opts, gd) {
226
239
227
240
// position can't go in through supplyDefaults
228
241
// because that restricts it to [0,1]
229
- ax . position = opts . x + xpadFrac + thickFrac ;
242
+ ax . position = optsX + xpadFrac + thickFrac ;
230
243
231
244
if ( [ 'top' , 'bottom' ] . indexOf ( titleSide ) !== - 1 ) {
232
245
ax . title . side = titleSide ;
233
- ax . titlex = opts . x + xpadFrac ;
246
+ ax . titlex = optsX + xpadFrac ;
234
247
ax . titley = yBottomFrac + ( title . side === 'top' ? lenFrac - ypadFrac : ypadFrac ) ;
235
248
}
236
249
@@ -299,7 +312,7 @@ function drawColorBar(g, opts, gd) {
299
312
// draw the title so we know how much room it needs
300
313
// when we squish the axis. This one only applies to
301
314
// top or bottom titles, not right side.
302
- var x = gs . l + ( opts . x + xpadFrac ) * gs . w ;
315
+ var x = gs . l + ( optsX + xpadFrac ) * gs . w ;
303
316
var fontSize = ax . title . font . size ;
304
317
var y ;
305
318
@@ -346,7 +359,7 @@ function drawColorBar(g, opts, gd) {
346
359
// squish the axis top to make room for the title
347
360
var titleGroup = g . select ( '.' + cn . cbtitle ) ;
348
361
var titleText = titleGroup . select ( 'text' ) ;
349
- var titleTrans = [ - opts . outlinewidth / 2 , opts . outlinewidth / 2 ] ;
362
+ var titleTrans = [ - outlinewidth / 2 , outlinewidth / 2 ] ;
350
363
var mathJaxNode = titleGroup
351
364
. select ( '.h' + ax . _id + 'title-math-group' )
352
365
. node ( ) ;
@@ -451,7 +464,7 @@ function drawColorBar(g, opts, gd) {
451
464
axLayer . selectAll ( 'g.' + ax . _id + 'tick,path' ) . remove ( ) ;
452
465
453
466
var shift = xLeft + thickPx +
454
- ( opts . outlinewidth || 0 ) / 2 - ( opts . ticks === 'outside' ? 1 : 0 ) ;
467
+ ( outlinewidth || 0 ) / 2 - ( opts . ticks === 'outside' ? 1 : 0 ) ;
455
468
456
469
var vals = Axes . calcTicks ( ax ) ;
457
470
var tickSign = Axes . getTickSigns ( ax ) [ 2 ] ;
@@ -476,7 +489,7 @@ function drawColorBar(g, opts, gd) {
476
489
// TODO: why are we redrawing multiple times now with this?
477
490
// I guess autoMargin doesn't like being post-promise?
478
491
function positionCB ( ) {
479
- var innerWidth = thickPx + opts . outlinewidth / 2 ;
492
+ var innerWidth = thickPx + outlinewidth / 2 ;
480
493
if ( ax . ticklabelposition . indexOf ( 'inside' ) === - 1 ) {
481
494
innerWidth += Drawing . bBox ( axLayer . node ( ) ) . width ;
482
495
}
@@ -498,61 +511,61 @@ function drawColorBar(g, opts, gd) {
498
511
innerWidth = Math . max ( innerWidth , titleWidth ) ;
499
512
}
500
513
501
- var outerwidth = 2 * opts . xpad + innerWidth + opts . borderwidth + opts . outlinewidth / 2 ;
514
+ var outerwidth = 2 * xpad + innerWidth + borderwidth + outlinewidth / 2 ;
502
515
var outerheight = yBottomPx - yTopPx ;
503
516
504
517
g . select ( '.' + cn . cbbg ) . attr ( {
505
- x : xLeft - opts . xpad - ( opts . borderwidth + opts . outlinewidth ) / 2 ,
518
+ x : xLeft - xpad - ( borderwidth + outlinewidth ) / 2 ,
506
519
y : yTopPx - yExtraPx ,
507
520
width : Math . max ( outerwidth , 2 ) ,
508
521
height : Math . max ( outerheight + 2 * yExtraPx , 2 )
509
522
} )
510
523
. call ( Color . fill , opts . bgcolor )
511
524
. call ( Color . stroke , opts . bordercolor )
512
- . style ( 'stroke-width' , opts . borderwidth ) ;
525
+ . style ( 'stroke-width' , borderwidth ) ;
513
526
514
527
g . selectAll ( '.' + cn . cboutline ) . attr ( {
515
528
x : xLeft ,
516
- y : yTopPx + opts . ypad + ( titleSide === 'top' ? titleHeight : 0 ) ,
529
+ y : yTopPx + ypad + ( titleSide === 'top' ? titleHeight : 0 ) ,
517
530
width : Math . max ( thickPx , 2 ) ,
518
- height : Math . max ( outerheight - 2 * opts . ypad - titleHeight , 2 )
531
+ height : Math . max ( outerheight - 2 * ypad - titleHeight , 2 )
519
532
} )
520
533
. call ( Color . stroke , opts . outlinecolor )
521
534
. style ( {
522
535
fill : 'none' ,
523
- 'stroke-width' : opts . outlinewidth
536
+ 'stroke-width' : outlinewidth
524
537
} ) ;
525
538
526
539
// fix positioning for xanchor!='left'
527
- var xoffset = ( { center : 0.5 , right : 1 } [ opts . xanchor ] || 0 ) * outerwidth ;
540
+ var xoffset = ( { center : 0.5 , right : 1 } [ xanchor ] || 0 ) * outerwidth ;
528
541
g . attr ( 'transform' , strTranslate ( gs . l - xoffset , gs . t ) ) ;
529
542
530
543
// auto margin adjustment
531
544
var marginOpts = { } ;
532
- var tFrac = FROM_TL [ opts . yanchor ] ;
533
- var bFrac = FROM_BR [ opts . yanchor ] ;
534
- if ( opts . lenmode === 'pixels' ) {
535
- marginOpts . y = opts . y ;
545
+ var tFrac = FROM_TL [ yanchor ] ;
546
+ var bFrac = FROM_BR [ yanchor ] ;
547
+ if ( lenmode === 'pixels' ) {
548
+ marginOpts . y = optsY ;
536
549
marginOpts . t = outerheight * tFrac ;
537
550
marginOpts . b = outerheight * bFrac ;
538
551
} else {
539
552
marginOpts . t = marginOpts . b = 0 ;
540
- marginOpts . yt = opts . y + opts . len * tFrac ;
541
- marginOpts . yb = opts . y - opts . len * bFrac ;
553
+ marginOpts . yt = optsY + len * tFrac ;
554
+ marginOpts . yb = optsY - len * bFrac ;
542
555
}
543
556
544
- var lFrac = FROM_TL [ opts . xanchor ] ;
545
- var rFrac = FROM_BR [ opts . xanchor ] ;
546
- if ( opts . thicknessmode === 'pixels' ) {
547
- marginOpts . x = opts . x ;
557
+ var lFrac = FROM_TL [ xanchor ] ;
558
+ var rFrac = FROM_BR [ xanchor ] ;
559
+ if ( thicknessmode === 'pixels' ) {
560
+ marginOpts . x = optsX ;
548
561
marginOpts . l = outerwidth * lFrac ;
549
562
marginOpts . r = outerwidth * rFrac ;
550
563
} else {
551
564
var extraThickness = outerwidth - thickPx ;
552
565
marginOpts . l = extraThickness * lFrac ;
553
566
marginOpts . r = extraThickness * rFrac ;
554
- marginOpts . xl = opts . x - opts . thickness * lFrac ;
555
- marginOpts . xr = opts . x + opts . thickness * rFrac ;
567
+ marginOpts . xl = optsX - thickness * lFrac ;
568
+ marginOpts . xr = optsX + thickness * rFrac ;
556
569
}
557
570
558
571
Plots . autoMargin ( gd , opts . _id , marginOpts ) ;
0 commit comments