@@ -51,7 +51,28 @@ function getXY(di, xa, ya, isHorizontal) {
5151 return isHorizontal ? [ s , p ] : [ p , s ] ;
5252}
5353
54- function plot ( gd , plotinfo , cdModule , traceLayer , opts ) {
54+ function transition ( selection , opts , makeOnCompleteCallback ) {
55+ if ( hasTransition ( opts ) ) {
56+ var onComplete ;
57+ if ( makeOnCompleteCallback ) {
58+ onComplete = makeOnCompleteCallback ( ) ;
59+ }
60+ return selection
61+ . transition ( )
62+ . duration ( opts . duration )
63+ . ease ( opts . easing )
64+ . each ( 'end' , function ( ) { onComplete && onComplete ( ) ; } )
65+ . each ( 'interrupt' , function ( ) { onComplete && onComplete ( ) ; } ) ;
66+ } else {
67+ return selection ;
68+ }
69+ }
70+
71+ function hasTransition ( transitionOpts ) {
72+ return transitionOpts && transitionOpts . duration > 0 ;
73+ }
74+
75+ function plot ( gd , plotinfo , cdModule , traceLayer , opts , makeOnCompleteCallback ) {
5576 var xa = plotinfo . xaxis ;
5677 var ya = plotinfo . yaxis ;
5778 var fullLayout = gd . _fullLayout ;
@@ -96,7 +117,6 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts) {
96117 // clipped xf/yf (2nd arg true): non-positive
97118 // log values go off-screen by plotwidth
98119 // so you see them continue if you drag the plot
99-
100120 var xy = getXY ( di , xa , ya , isHorizontal ) ;
101121
102122 var x0 = xy [ 0 ] [ 0 ] ;
@@ -118,8 +138,11 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts) {
118138 }
119139 di . isBlank = isBlank ;
120140
141+ if ( isBlank && isHorizontal ) x1 = x0 ;
142+ if ( isBlank && ! isHorizontal ) y1 = y0 ;
143+
121144 // in waterfall mode `between` we need to adjust bar end points to match the connector width
122- if ( adjustPixel ) {
145+ if ( adjustPixel && ! isBlank ) {
123146 if ( isHorizontal ) {
124147 x0 -= dirSign ( x0 , x1 ) * adjustPixel ;
125148 x1 += dirSign ( x0 , x1 ) * adjustPixel ;
@@ -178,12 +201,18 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts) {
178201 y1 = fixpx ( y1 , y0 ) ;
179202 }
180203
181- Lib . ensureSingle ( bar , 'path' )
204+ var sel = transition ( Lib . ensureSingle ( bar , 'path' ) , opts , makeOnCompleteCallback ) ;
205+ sel
182206 . style ( 'vector-effect' , 'non-scaling-stroke' )
183- . attr ( 'd' , isBlank ? 'M0,0Z' : 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z' )
207+ . attr ( 'd' , 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z' )
184208 . call ( Drawing . setClipUrl , plotinfo . layerClipId , gd ) ;
185209
186- appendBarText ( gd , plotinfo , bar , cd , i , x0 , x1 , y0 , y1 , opts ) ;
210+ if ( hasTransition ( opts ) ) {
211+ var styleFns = Drawing . makePointStyleFns ( trace ) ;
212+ Drawing . singlePointStyle ( di , sel , trace , styleFns , gd ) ;
213+ }
214+
215+ appendBarText ( gd , plotinfo , bar , cd , i , x0 , x1 , y0 , y1 , opts , makeOnCompleteCallback ) ;
187216
188217 if ( plotinfo . layerClipId ) {
189218 Drawing . hideOutsideRangePoint ( di , bar . select ( 'text' ) , xa , ya , trace . xcalendar , trace . ycalendar ) ;
@@ -197,10 +226,10 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts) {
197226 } ) ;
198227
199228 // error bars are on the top
200- Registry . getComponentMethod ( 'errorbars' , 'plot' ) ( gd , bartraces , plotinfo ) ;
229+ Registry . getComponentMethod ( 'errorbars' , 'plot' ) ( gd , bartraces , plotinfo , opts ) ;
201230}
202231
203- function appendBarText ( gd , plotinfo , bar , calcTrace , i , x0 , x1 , y0 , y1 , opts ) {
232+ function appendBarText ( gd , plotinfo , bar , calcTrace , i , x0 , x1 , y0 , y1 , opts , makeOnCompleteCallback ) {
204233 var xa = plotinfo . xaxis ;
205234 var ya = plotinfo . yaxis ;
206235
@@ -212,7 +241,6 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {
212241 . text ( text )
213242 . attr ( {
214243 'class' : 'bartext bartext-' + textPosition ,
215- transform : '' ,
216244 'text-anchor' : 'middle' ,
217245 // prohibit tex interpretation until we can handle
218246 // tex and regular text together
@@ -325,9 +353,12 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {
325353 ( textPosition === 'outside' ) ?
326354 outsideTextFont : insideTextFont ) ;
327355
356+ var currentTransform = textSelection . attr ( 'transform' ) ;
357+ textSelection . attr ( 'transform' , '' ) ;
328358 textBB = Drawing . bBox ( textSelection . node ( ) ) ,
329359 textWidth = textBB . width ,
330360 textHeight = textBB . height ;
361+ textSelection . attr ( 'transform' , currentTransform ) ;
331362
332363 if ( textWidth <= 0 || textHeight <= 0 ) {
333364 textSelection . remove ( ) ;
@@ -360,7 +391,7 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {
360391 } ) ) ;
361392 }
362393
363- textSelection . attr ( 'transform' , transform ) ;
394+ transition ( textSelection , opts , makeOnCompleteCallback ) . attr ( 'transform' , transform ) ;
364395}
365396
366397function getRotateFromAngle ( angle ) {
0 commit comments