@@ -219,11 +219,14 @@ function drawColorBar(g, opts, gd) {
219
219
var lenPx = Math . round ( len * ( lenmode === 'fraction' ? ( isVertical ? gs . h : gs . w ) : 1 ) ) ;
220
220
var lenFrac = lenPx / ( isVertical ? gs . h : gs . w ) ;
221
221
222
+ var posW = isPaperX ? gs . w : gd . _fullLayout . width ;
223
+ var posH = isPaperY ? gs . h : gd . _fullLayout . height ;
224
+
222
225
// x positioning: do it initially just for left anchor,
223
226
// then fix at the end (since we don't know the width yet)
224
227
var uPx = Math . round ( isVertical ?
225
- optsX * gs . w + xpad :
226
- optsY * gs . h + ypad
228
+ optsX * posW + xpad :
229
+ optsY * posH + ypad
227
230
) ;
228
231
229
232
var xRatio = { center : 0.5 , right : 1 } [ xanchor ] || 0 ;
@@ -240,8 +243,8 @@ function drawColorBar(g, opts, gd) {
240
243
optsX - xRatio * lenFrac ;
241
244
242
245
var vPx = Math . round ( isVertical ?
243
- gs . h * ( 1 - vFrac ) :
244
- gs . w * vFrac
246
+ posH * ( 1 - vFrac ) :
247
+ posW * vFrac
245
248
) ;
246
249
247
250
// stash a few things for makeEditable
@@ -385,14 +388,14 @@ function drawColorBar(g, opts, gd) {
385
388
386
389
if ( titleSide === 'right' ) {
387
390
y = mid ;
388
- x = gs . l + gs . w * pos + 10 + titleFontSize * (
391
+ x = gs . l + posW * pos + 10 + titleFontSize * (
389
392
ax . showticklabels ? 1 : 0.5
390
393
) ;
391
394
} else {
392
395
x = mid ;
393
396
394
397
if ( titleSide === 'bottom' ) {
395
- y = gs . t + gs . h * pos + 10 + (
398
+ y = gs . t + posH * pos + 10 + (
396
399
ticklabelposition . indexOf ( 'inside' ) === - 1 ?
397
400
ax . tickfont . size :
398
401
0
@@ -405,7 +408,7 @@ function drawColorBar(g, opts, gd) {
405
408
406
409
if ( titleSide === 'top' ) {
407
410
var nlines = title . text . split ( '<br>' ) . length ;
408
- y = gs . t + gs . h * pos + 10 - thickPx - LINE_SPACING * titleFontSize * nlines ;
411
+ y = gs . t + posH * pos + 10 - thickPx - LINE_SPACING * titleFontSize * nlines ;
409
412
}
410
413
}
411
414
@@ -671,9 +674,13 @@ function drawColorBar(g, opts, gd) {
671
674
672
675
var extraW = borderwidth + outlinewidth ;
673
676
677
+ // TODO - are these the correct positions?
678
+ var lx = ( isVertical ? uPx : vPx ) - extraW / 2 - ( isVertical ? xpad : 0 ) ;
679
+ var ly = ( isVertical ? vPx : uPx ) - ( isVertical ? lenPx : ypad + moveY - hColorbarMoveTitle ) ;
680
+
674
681
g . select ( '.' + cn . cbbg )
675
- . attr ( 'x' , ( isVertical ? uPx : vPx ) - extraW / 2 - ( isVertical ? xpad : 0 ) )
676
- . attr ( 'y' , ( isVertical ? vPx : uPx ) - ( isVertical ? lenPx : ypad + moveY - hColorbarMoveTitle ) )
682
+ . attr ( 'x' , lx )
683
+ . attr ( 'y' , ly )
677
684
. attr ( isVertical ? 'width' : 'height' , Math . max ( outerThickness - hColorbarMoveTitle , 2 ) )
678
685
. attr ( isVertical ? 'height' : 'width' , Math . max ( lenPx + extraW , 2 ) )
679
686
. call ( Color . fill , bgcolor )
@@ -696,9 +703,14 @@ function drawColorBar(g, opts, gd) {
696
703
'stroke-width' : outlinewidth
697
704
} ) ;
698
705
706
+ var xShift = ( ( isVertical ? xRatio * outerThickness : 0 ) ) ;
707
+ var yShift = ( ( isVertical ? 0 : ( 1 - yRatio ) * outerThickness - moveY ) ) ;
708
+ xShift = isPaperX ? gs . l - xShift : - xShift ;
709
+ yShift = isPaperY ? gs . t - yShift : - yShift ;
710
+
699
711
g . attr ( 'transform' , strTranslate (
700
- gs . l - ( isVertical ? xRatio * outerThickness : 0 ) ,
701
- gs . t - ( isVertical ? 0 : ( 1 - yRatio ) * outerThickness - moveY )
712
+ xShift ,
713
+ yShift
702
714
) ) ;
703
715
704
716
if ( ! isVertical && (
@@ -809,18 +821,24 @@ function drawColorBar(g, opts, gd) {
809
821
var sideX = opts . x < 0.5 ? 'l' : 'r' ;
810
822
811
823
gd . _fullLayout . _reservedMargin [ opts . _id ] = { } ;
824
+ var possibleReservedMargins = {
825
+ r : ( fullLayout . width - lx - xShift ) ,
826
+ l : lx + marginOpts . r ,
827
+ b : ( fullLayout . height - ly - yShift ) ,
828
+ t : ly + marginOpts . b
829
+ } ;
812
830
813
831
if ( isPaperX && isPaperY ) {
814
832
Plots . autoMargin ( gd , opts . _id , marginOpts ) ;
815
833
} else if ( isPaperX ) {
816
- gd . _fullLayout . _reservedMargin [ opts . _id ] [ sideY ] = marginOpts [ sideY ] ;
834
+ gd . _fullLayout . _reservedMargin [ opts . _id ] [ sideY ] = possibleReservedMargins [ sideY ] ;
817
835
} else if ( isPaperY ) {
818
- gd . _fullLayout . _reservedMargin [ opts . _id ] [ sideX ] = marginOpts [ sideX ] ;
836
+ gd . _fullLayout . _reservedMargin [ opts . _id ] [ sideX ] = possibleReservedMargins [ sideX ] ;
819
837
} else {
820
838
if ( isVertical ) {
821
- gd . _fullLayout . _reservedMargin [ opts . _id ] [ sideX ] = marginOpts [ sideX ] ;
839
+ gd . _fullLayout . _reservedMargin [ opts . _id ] [ sideX ] = possibleReservedMargins [ sideX ] ;
822
840
} else {
823
- gd . _fullLayout . _reservedMargin [ opts . _id ] [ sideY ] = marginOpts [ sideY ] ;
841
+ gd . _fullLayout . _reservedMargin [ opts . _id ] [ sideY ] = possibleReservedMargins [ sideY ] ;
824
842
}
825
843
}
826
844
}
0 commit comments