@@ -174,6 +174,7 @@ function drawColorBar(g, opts, gd) {
174174 var thicknessmode = opts . thicknessmode ;
175175 var outlinewidth = opts . outlinewidth ;
176176 var borderwidth = opts . borderwidth ;
177+ var bgcolor = opts . bgcolor ;
177178 var xanchor = opts . xanchor ;
178179 var yanchor = opts . yanchor ;
179180 var xpad = opts . xpad ;
@@ -672,7 +673,7 @@ function drawColorBar(g, opts, gd) {
672673 . attr ( 'y' , ( isVertical ? vPx : uPx ) - ( isVertical ? lenPx : ypad + moveY - hColorbarMoveTitle ) )
673674 . attr ( isVertical ? 'width' : 'height' , Math . max ( outerThickness - hColorbarMoveTitle , 2 ) )
674675 . attr ( isVertical ? 'height' : 'width' , Math . max ( lenPx + extraW , 2 ) )
675- . call ( Color . fill , opts . bgcolor )
676+ . call ( Color . fill , bgcolor )
676677 . call ( Color . stroke , opts . bordercolor )
677678 . style ( 'stroke-width' , borderwidth ) ;
678679
@@ -697,6 +698,55 @@ function drawColorBar(g, opts, gd) {
697698 gs . t - ( isVertical ? 0 : ( 1 - yRatio ) * outerThickness - moveY )
698699 ) ) ;
699700
701+ if ( ! isVertical && (
702+ borderwidth || (
703+ tinycolor ( bgcolor ) . getAlpha ( ) &&
704+ ! tinycolor . equals ( fullLayout . plot_bgcolor , bgcolor )
705+ )
706+ ) ) {
707+ // for horizontal colorbars when there is a border line or having different background color
708+ // adjust x positioning for the first/last tick labels if they go outside the border
709+ var border = g . select ( '.' + cn . cbbg ) . node ( ) ;
710+ var oBb = Drawing . bBox ( border ) ;
711+ var oTr = Drawing . getTranslate ( g ) ;
712+
713+ var TEXTPAD = 2 ;
714+
715+ var tickLabels = axLayer . selectAll ( 'text' ) ;
716+ tickLabels . each ( function ( d , i ) {
717+ var first = 0 ;
718+ var last = tickLabels [ 0 ] . length - 1 ;
719+ if ( i === first || i === last ) {
720+ var iBb = Drawing . bBox ( this ) ;
721+ var iTr = Drawing . getTranslate ( this ) ;
722+ var deltaX ;
723+
724+ if ( i === last ) {
725+ var iRight = iBb . right + iTr . x ;
726+ var oRight = oBb . right + oTr . x + vPx - borderwidth - TEXTPAD + optsX ;
727+
728+ deltaX = oRight - iRight ;
729+ if ( deltaX > 0 ) deltaX = 0 ;
730+ }
731+
732+ if ( i === first ) {
733+ var iLeft = iBb . left + iTr . x ;
734+ var oLeft = oBb . left + oTr . x + vPx + borderwidth + TEXTPAD ;
735+
736+ deltaX = oLeft - iLeft ;
737+ if ( deltaX < 0 ) deltaX = 0 ;
738+ }
739+
740+ if ( deltaX ) {
741+ this . setAttribute ( 'transform' ,
742+ 'translate(' + deltaX + ',0) ' +
743+ this . getAttribute ( 'transform' )
744+ ) ;
745+ }
746+ }
747+ } ) ;
748+ }
749+
700750 // auto margin adjustment
701751 var marginOpts = { } ;
702752 var lFrac = FROM_TL [ xanchor ] ;
0 commit comments