@@ -114,6 +114,7 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
114
114
}
115
115
116
116
var isHorizontal = ( trace . orientation === 'h' ) ;
117
+ var withTransition = hasTransition ( opts ) ;
117
118
118
119
var pointGroup = Lib . ensureSingle ( plotGroup , 'g' , 'points' ) ;
119
120
@@ -139,26 +140,35 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
139
140
var y0 = xy [ 1 ] [ 0 ] ;
140
141
var y1 = xy [ 1 ] [ 1 ] ;
141
142
142
- var isBlank = (
143
- x0 === x1 ||
144
- y0 === y1 ||
145
- ! isNumeric ( x0 ) ||
146
- ! isNumeric ( x1 ) ||
147
- ! isNumeric ( y0 ) ||
148
- ! isNumeric ( y1 )
149
- ) ;
143
+ // empty bars
144
+ var isBlank = ( isHorizontal ? x1 - x0 : y1 - y0 ) === 0 ;
150
145
151
146
// display zeros if line.width > 0
152
- if ( isBlank && shouldDisplayZeros && helpers . getLineWidth ( trace , di ) && ( isHorizontal ? x1 - x0 === 0 : y1 - y0 === 0 ) ) {
147
+ if ( isBlank && shouldDisplayZeros && helpers . getLineWidth ( trace , di ) ) {
153
148
isBlank = false ;
154
149
}
155
- di . isBlank = isBlank ;
156
150
157
- if ( isBlank && isHorizontal ) x1 = x0 ;
158
- if ( isBlank && ! isHorizontal ) y1 = y0 ;
151
+ // skip nulls
152
+ if ( ! isBlank ) {
153
+ isBlank = (
154
+ ! isNumeric ( x0 ) ||
155
+ ! isNumeric ( x1 ) ||
156
+ ! isNumeric ( y0 ) ||
157
+ ! isNumeric ( y1 )
158
+ ) ;
159
+ }
160
+
161
+ // record isBlank
162
+ di . isBlank = isBlank ;
159
163
160
- var spansHorizontal = isHorizontal && ( x0 !== x1 ) ;
161
- var spansVertical = ! isHorizontal && ( y0 !== y1 ) ;
164
+ // for blank bars, ensure start and end positions are equal - important for smooth transitions
165
+ if ( isBlank ) {
166
+ if ( isHorizontal ) {
167
+ x1 = x0 ;
168
+ } else {
169
+ y1 = y0 ;
170
+ }
171
+ }
162
172
163
173
// in waterfall mode `between` we need to adjust bar end points to match the connector width
164
174
if ( adjustPixel && ! isBlank ) {
@@ -185,16 +195,24 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
185
195
mc = di . mc || trace . marker . color ;
186
196
}
187
197
188
- var offset = d3 . round ( ( lw / 2 ) % 1 , 2 ) ;
189
-
190
198
function roundWithLine ( v ) {
199
+ var offset = d3 . round ( ( lw / 2 ) % 1 , 2 ) ;
200
+
191
201
// if there are explicit gaps, don't round,
192
202
// it can make the gaps look crappy
193
203
return ( opts . gap === 0 && opts . groupgap === 0 ) ?
194
204
d3 . round ( Math . round ( v ) - offset , 2 ) : v ;
195
205
}
196
206
197
- function expandToVisible ( v , vc ) {
207
+ function expandToVisible ( v , vc , hideZeroSpan ) {
208
+ if ( hideZeroSpan && v === vc ) {
209
+ // should not expand zero span bars
210
+ // when start and end positions are identical
211
+ // i.e. for vertical when y0 === y1
212
+ // and for horizontal when x0 === x1
213
+ return v ;
214
+ }
215
+
198
216
// if it's not in danger of disappearing entirely,
199
217
// round more precisely
200
218
return Math . abs ( v - vc ) >= 2 ? roundWithLine ( v ) :
@@ -215,14 +233,10 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
215
233
var op = Color . opacity ( mc ) ;
216
234
var fixpx = ( op < 1 || lw > 0.01 ) ? roundWithLine : expandToVisible ;
217
235
218
- if ( spansHorizontal ) {
219
- x0 = fixpx ( x0 , x1 ) ;
220
- x1 = fixpx ( x1 , x0 ) ;
221
- }
222
- if ( spansVertical ) {
223
- y0 = fixpx ( y0 , y1 ) ;
224
- y1 = fixpx ( y1 , y0 ) ;
225
- }
236
+ x0 = fixpx ( x0 , x1 , isHorizontal ) ;
237
+ x1 = fixpx ( x1 , x0 , isHorizontal ) ;
238
+ y0 = fixpx ( y0 , y1 , ! isHorizontal ) ;
239
+ y1 = fixpx ( y1 , y0 , ! isHorizontal ) ;
226
240
}
227
241
228
242
var sel = transition ( Lib . ensureSingle ( bar , 'path' ) , fullLayout , opts , makeOnCompleteCallback ) ;
@@ -231,7 +245,7 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
231
245
. attr ( 'd' , 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z' )
232
246
. call ( Drawing . setClipUrl , plotinfo . layerClipId , gd ) ;
233
247
234
- if ( ! fullLayout . uniformtext . mode && hasTransition ( opts ) ) {
248
+ if ( ! fullLayout . uniformtext . mode && withTransition ) {
235
249
var styleFns = Drawing . makePointStyleFns ( trace ) ;
236
250
Drawing . singlePointStyle ( di , sel , trace , styleFns , gd ) ;
237
251
}
0 commit comments