@@ -189,7 +189,7 @@ function setOffsetAndWidth(gd, pa, sieve) {
189
189
bargroupgap = fullLayout . bargroupgap ,
190
190
minDiff = sieve . minDiff ,
191
191
calcTraces = sieve . traces ,
192
- i , calcTrace , calcTrace0 , fullTrace ,
192
+ i , calcTrace , calcTrace0 ,
193
193
j , calcBar ,
194
194
t ;
195
195
@@ -223,77 +223,7 @@ function setOffsetAndWidth(gd, pa, sieve) {
223
223
sieve . binWidth = calcTraces [ 0 ] [ 0 ] . t . barwidth / 100 ;
224
224
225
225
// if defined, apply trace offset and width
226
- for ( i = 0 ; i < calcTraces . length ; i ++ ) {
227
- calcTrace = calcTraces [ i ] ;
228
- calcTrace0 = calcTrace [ 0 ] ;
229
- fullTrace = calcTrace0 . trace ;
230
- t = calcTrace0 . t ;
231
-
232
- var offset = fullTrace . offset ,
233
- initialPoffset = t . poffset ,
234
- newPoffset ;
235
- if ( Array . isArray ( offset ) ) {
236
- // if offset is an array, then clone it into t.poffset.
237
- newPoffset = offset . slice ( 0 , calcTrace . length ) ;
238
-
239
- // guard against non-numeric items
240
- for ( j = 0 ; j < newPoffset . length ; j ++ ) {
241
- if ( ! isNumeric ( newPoffset [ j ] ) ) newPoffset [ j ] = initialPoffset ;
242
- }
243
-
244
- // if the length of the array is too short,
245
- // then extend it with the initial value of t.poffset
246
- for ( j = newPoffset . length ; j < calcTrace . length ; j ++ ) {
247
- newPoffset . push ( initialPoffset ) ;
248
- }
249
-
250
- t . poffset = newPoffset ;
251
- }
252
- else if ( offset !== undefined ) {
253
- t . poffset = offset ;
254
- }
255
-
256
- var width = fullTrace . width ,
257
- initialBarwidth = t . barwidth ;
258
- if ( Array . isArray ( width ) ) {
259
- // if width is an array, then clone it into t.barwidth.
260
- var newBarwidth = width . slice ( 0 , calcTrace . length ) ;
261
-
262
- // guard against non-numeric items
263
- for ( j = 0 ; j < newBarwidth . length ; j ++ ) {
264
- if ( ! isNumeric ( newBarwidth [ j ] ) ) newBarwidth [ j ] = initialBarwidth ;
265
- }
266
-
267
- // if the length of the array is too short,
268
- // then extend it with the initial value of t.barwidth
269
- for ( j = newBarwidth . length ; j < calcTrace . length ; j ++ ) {
270
- newBarwidth . push ( initialBarwidth ) ;
271
- }
272
-
273
- t . barwidth = newBarwidth ;
274
-
275
- // if user didn't set offset,
276
- // then correct t.poffset to ensure bars remain centered
277
- if ( offset === undefined ) {
278
- newPoffset = [ ] ;
279
- for ( j = 0 ; j < calcTrace . length ; j ++ ) {
280
- newPoffset . push (
281
- initialPoffset + ( initialBarwidth - newBarwidth [ j ] ) / 2
282
- ) ;
283
- }
284
- t . poffset = newPoffset ;
285
- }
286
- }
287
- else if ( width !== undefined ) {
288
- t . barwidth = width ;
289
-
290
- // if user didn't set offset,
291
- // then correct t.poffset to ensure bars remain centered
292
- if ( offset === undefined ) {
293
- t . poffset = initialPoffset + ( initialBarwidth - width ) / 2 ;
294
- }
295
- }
296
- }
226
+ applyAttributes ( sieve ) ;
297
227
298
228
// update position axes
299
229
updatePositionAxis ( gd , pa , sieve ) ;
@@ -309,7 +239,7 @@ function setOffsetAndWidthInGroupMode(gd, pa, sieve) {
309
239
distinctPositions = sieve . distinctPositions ,
310
240
minDiff = sieve . minDiff ,
311
241
calcTraces = sieve . traces ,
312
- i , calcTrace , calcTrace0 , fullTrace ,
242
+ i , calcTrace , calcTrace0 ,
313
243
j , calcBar ,
314
244
t ;
315
245
@@ -349,17 +279,55 @@ function setOffsetAndWidthInGroupMode(gd, pa, sieve) {
349
279
sieve . binWidth = calcTraces [ 0 ] [ 0 ] . t . barwidth / 100 ;
350
280
351
281
// if defined, apply trace width
282
+ applyAttributes ( sieve ) ;
283
+
284
+ // update position axes
285
+ updatePositionAxis ( gd , pa , sieve , overlap ) ;
286
+ }
287
+
288
+
289
+ function applyAttributes ( sieve ) {
290
+ var calcTraces = sieve . traces ,
291
+ i , calcTrace , calcTrace0 , fullTrace ,
292
+ j ,
293
+ t ;
294
+
352
295
for ( i = 0 ; i < calcTraces . length ; i ++ ) {
353
296
calcTrace = calcTraces [ i ] ;
354
297
calcTrace0 = calcTrace [ 0 ] ;
355
298
fullTrace = calcTrace0 . trace ;
299
+ t = calcTrace0 . t ;
356
300
357
- var width = fullTrace . width ;
358
- if ( width === undefined ) continue ;
301
+ var offset = fullTrace . offset ,
302
+ initialPoffset = t . poffset ,
303
+ newPoffset ;
304
+
305
+ if ( Array . isArray ( offset ) ) {
306
+ // if offset is an array, then clone it into t.poffset.
307
+ newPoffset = offset . slice ( 0 , calcTrace . length ) ;
308
+
309
+ // guard against non-numeric items
310
+ for ( j = 0 ; j < newPoffset . length ; j ++ ) {
311
+ if ( ! isNumeric ( newPoffset [ j ] ) ) {
312
+ newPoffset [ j ] = initialPoffset ;
313
+ }
314
+ }
315
+
316
+ // if the length of the array is too short,
317
+ // then extend it with the initial value of t.poffset
318
+ for ( j = newPoffset . length ; j < calcTrace . length ; j ++ ) {
319
+ newPoffset . push ( initialPoffset ) ;
320
+ }
321
+
322
+ t . poffset = newPoffset ;
323
+ }
324
+ else if ( offset !== undefined ) {
325
+ t . poffset = offset ;
326
+ }
327
+
328
+ var width = fullTrace . width ,
329
+ initialBarwidth = t . barwidth ;
359
330
360
- t = calcTrace0 . t ;
361
- var initialBarwidth = t . barwidth ,
362
- initialPoffset = t . poffset ;
363
331
if ( Array . isArray ( width ) ) {
364
332
// if width is an array, then clone it into t.barwidth.
365
333
var newBarwidth = width . slice ( 0 , calcTrace . length ) ;
@@ -377,25 +345,28 @@ function setOffsetAndWidthInGroupMode(gd, pa, sieve) {
377
345
378
346
t . barwidth = newBarwidth ;
379
347
380
- // correct t.poffset to ensure bars remain centered
381
- var newPoffset = [ ] ;
382
- for ( j = 0 ; j < calcTrace . length ; j ++ ) {
383
- newPoffset . push (
384
- initialPoffset + ( initialBarwidth - newBarwidth [ j ] ) / 2
385
- ) ;
348
+ // if user didn't set offset,
349
+ // then correct t.poffset to ensure bars remain centered
350
+ if ( offset === undefined ) {
351
+ newPoffset = [ ] ;
352
+ for ( j = 0 ; j < calcTrace . length ; j ++ ) {
353
+ newPoffset . push (
354
+ initialPoffset + ( initialBarwidth - newBarwidth [ j ] ) / 2
355
+ ) ;
356
+ }
357
+ t . poffset = newPoffset ;
386
358
}
387
- t . poffset = newPoffset ;
388
359
}
389
- else {
360
+ else if ( width !== undefined ) {
390
361
t . barwidth = width ;
391
362
392
- // correct t.poffset to ensure bars remain centered
393
- t . poffset = initialPoffset + ( initialBarwidth - width ) / 2 ;
363
+ // if user didn't set offset,
364
+ // then correct t.poffset to ensure bars remain centered
365
+ if ( offset === undefined ) {
366
+ t . poffset = initialPoffset + ( initialBarwidth - width ) / 2 ;
367
+ }
394
368
}
395
369
}
396
-
397
- // update position axes
398
- updatePositionAxis ( gd , pa , sieve , overlap ) ;
399
370
}
400
371
401
372
0 commit comments