@@ -51,7 +51,28 @@ function getXY(di, xa, ya, isHorizontal) {
51
51
return isHorizontal ? [ s , p ] : [ p , s ] ;
52
52
}
53
53
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 ) {
55
76
var xa = plotinfo . xaxis ;
56
77
var ya = plotinfo . yaxis ;
57
78
var fullLayout = gd . _fullLayout ;
@@ -96,7 +117,6 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts) {
96
117
// clipped xf/yf (2nd arg true): non-positive
97
118
// log values go off-screen by plotwidth
98
119
// so you see them continue if you drag the plot
99
-
100
120
var xy = getXY ( di , xa , ya , isHorizontal ) ;
101
121
102
122
var x0 = xy [ 0 ] [ 0 ] ;
@@ -118,6 +138,9 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts) {
118
138
}
119
139
di . isBlank = isBlank ;
120
140
141
+ if ( isBlank && isHorizontal ) x1 = x0 ;
142
+ if ( isBlank && ! isHorizontal ) y1 = y0 ;
143
+
121
144
// in waterfall mode `between` we need to adjust bar end points to match the connector width
122
145
if ( adjustPixel ) {
123
146
if ( isHorizontal ) {
@@ -178,12 +201,19 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts) {
178
201
y1 = fixpx ( y1 , y0 ) ;
179
202
}
180
203
181
- Lib . ensureSingle ( bar , 'path' )
204
+ var sel = transition ( Lib . ensureSingle ( bar , 'path' ) , opts , makeOnCompleteCallback ) ;
205
+ sel
182
206
. style ( 'vector-effect' , 'non-scaling-stroke' )
183
- . attr ( 'd' , isBlank ? 'M0,0Z' : 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z' )
207
+ . attr ( 'display' , function ( ) { return isBlank ? 'none' : null ; } )
208
+ . attr ( 'd' , 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z' )
184
209
. call ( Drawing . setClipUrl , plotinfo . layerClipId , gd ) ;
185
210
186
- appendBarText ( gd , plotinfo , bar , cd , i , x0 , x1 , y0 , y1 , opts ) ;
211
+ if ( hasTransition ( opts ) ) {
212
+ var styleFns = Drawing . makePointStyleFns ( trace ) ;
213
+ Drawing . singlePointStyle ( di , sel , trace , styleFns , gd ) ;
214
+ }
215
+
216
+ appendBarText ( gd , plotinfo , bar , cd , i , x0 , x1 , y0 , y1 , opts , makeOnCompleteCallback ) ;
187
217
188
218
if ( plotinfo . layerClipId ) {
189
219
Drawing . hideOutsideRangePoint ( di , bar . select ( 'text' ) , xa , ya , trace . xcalendar , trace . ycalendar ) ;
@@ -197,10 +227,10 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts) {
197
227
} ) ;
198
228
199
229
// error bars are on the top
200
- Registry . getComponentMethod ( 'errorbars' , 'plot' ) ( gd , bartraces , plotinfo ) ;
230
+ Registry . getComponentMethod ( 'errorbars' , 'plot' ) ( gd , bartraces , plotinfo , opts ) ;
201
231
}
202
232
203
- function appendBarText ( gd , plotinfo , bar , calcTrace , i , x0 , x1 , y0 , y1 , opts ) {
233
+ function appendBarText ( gd , plotinfo , bar , calcTrace , i , x0 , x1 , y0 , y1 , opts , makeOnCompleteCallback ) {
204
234
var xa = plotinfo . xaxis ;
205
235
var ya = plotinfo . yaxis ;
206
236
@@ -212,7 +242,6 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {
212
242
. text ( text )
213
243
. attr ( {
214
244
'class' : 'bartext bartext-' + textPosition ,
215
- transform : '' ,
216
245
'text-anchor' : 'middle' ,
217
246
// prohibit tex interpretation until we can handle
218
247
// tex and regular text together
@@ -325,9 +354,12 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {
325
354
( textPosition === 'outside' ) ?
326
355
outsideTextFont : insideTextFont ) ;
327
356
357
+ var currentTransform = textSelection . attr ( 'transform' ) ;
358
+ textSelection . attr ( 'transform' , '' ) ;
328
359
textBB = Drawing . bBox ( textSelection . node ( ) ) ,
329
360
textWidth = textBB . width ,
330
361
textHeight = textBB . height ;
362
+ textSelection . attr ( 'transform' , currentTransform ) ;
331
363
332
364
if ( textWidth <= 0 || textHeight <= 0 ) {
333
365
textSelection . remove ( ) ;
@@ -360,7 +392,7 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {
360
392
} ) ) ;
361
393
}
362
394
363
- textSelection . attr ( 'transform' , transform ) ;
395
+ transition ( textSelection , opts , makeOnCompleteCallback ) . attr ( 'transform' , transform ) ;
364
396
}
365
397
366
398
function getRotateFromAngle ( angle ) {
0 commit comments