@@ -249,17 +249,12 @@ function setBaseAndSize(gd, sa, sieve) {
249
249
// so we don't have to redo this later
250
250
var sMax = sa . l2c ( sa . c2l ( 0 ) ) ,
251
251
sMin = sMax ,
252
- sums = { } ,
252
+ barEnd ;
253
253
254
- // make sure if p is different only by rounding,
255
- // we still stack
256
- sumround = traces [ 0 ] [ 0 ] . t . barwidth / 100 ,
257
- sv = 0 ,
258
- padded = true ,
259
- barEnd ,
260
- scale ;
254
+ // stack bars that only differ by rounding
255
+ sieve . binWidth = traces [ 0 ] [ 0 ] . t . barwidth / 100 ;
261
256
262
- for ( i = 0 ; i < traces . length ; i ++ ) { // trace index
257
+ for ( i = 0 ; i < traces . length ; i ++ ) {
263
258
trace = traces [ i ] ;
264
259
265
260
for ( j = 0 ; j < trace . length ; j ++ ) {
@@ -269,16 +264,11 @@ function setBaseAndSize(gd, sa, sieve) {
269
264
// so that we don't try to stack them
270
265
if ( ! isNumeric ( bar . s ) ) continue ;
271
266
272
- sv = Math . round ( bar . p / sumround ) ;
273
-
274
- // store the negative sum value for p at the same key,
275
- // with sign flipped using string to ensure -0 !== 0.
276
- if ( relative && bar . s < 0 ) sv = '-' + sv ;
267
+ // stack current bar and get previous sum
268
+ var previousSum = sieve . put ( bar . p , bar . s ) ;
277
269
278
- var previousSum = sums [ sv ] || 0 ;
279
270
if ( stack || relative ) bar . b = previousSum ;
280
271
barEnd = bar . b + bar . s ;
281
- sums [ sv ] = previousSum + bar . s ;
282
272
283
273
// store the bar top in each calcdata item
284
274
if ( stack || relative ) {
@@ -291,43 +281,36 @@ function setBaseAndSize(gd, sa, sieve) {
291
281
}
292
282
}
293
283
294
- if ( norm ) {
295
- var top = norm === 'fraction' ? 1 : 100 ,
296
- relAndNegative = false ,
297
- tiny = top / 1e9 ; // in case of rounding error in sum
284
+ var padded = true ;
298
285
286
+ if ( norm ) {
299
287
padded = false ;
288
+
289
+ var sTop = ( norm === 'fraction' ) ? 1 : 100 ,
290
+ sTiny = sTop / 1e9 ; // in case of rounding error in sum
291
+
300
292
sMin = 0 ;
301
- sMax = stack ? top : 0 ;
293
+ sMax = ( stack ) ? sTop : 0 ;
302
294
303
- for ( i = 0 ; i < traces . length ; i ++ ) { // trace index
295
+ for ( i = 0 ; i < traces . length ; i ++ ) {
304
296
trace = traces [ i ] ;
305
297
306
298
for ( j = 0 ; j < trace . length ; j ++ ) {
307
299
bar = trace [ j ] ;
308
300
309
- relAndNegative = ( relative && bar . s < 0 ) ;
310
-
311
- sv = Math . round ( bar . p / sumround ) ;
312
-
313
- // locate negative sum amount for this p val
314
- if ( relAndNegative ) sv = '-' + sv ;
315
-
316
- scale = top / sums [ sv ] ;
301
+ var scale = Math . abs ( sTop / sieve . get ( bar . p , bar . s ) ) ;
317
302
318
- // preserve sign if negative
319
- if ( relAndNegative ) scale *= - 1 ;
320
303
bar . b *= scale ;
321
304
bar . s *= scale ;
322
305
barEnd = bar . b + bar . s ;
323
306
bar [ sLetter ] = barEnd ;
324
307
325
308
if ( isNumeric ( sa . c2l ( barEnd ) ) ) {
326
- if ( barEnd < sMin - tiny ) {
309
+ if ( barEnd < sMin - sTiny ) {
327
310
padded = true ;
328
311
sMin = barEnd ;
329
312
}
330
- if ( barEnd > sMax + tiny ) {
313
+ if ( barEnd > sMax + sTiny ) {
331
314
padded = true ;
332
315
sMax = barEnd ;
333
316
}
0 commit comments