@@ -75,7 +75,7 @@ function setGroupPositions(gd, pa, sa, calcTraces, opts) {
75
75
76
76
switch ( opts . mode ) {
77
77
case 'overlay' :
78
- setGroupPositionsInOverlayMode ( pa , sa , calcTraces , opts ) ;
78
+ setGroupPositionsInOverlayMode ( gd , pa , sa , calcTraces , opts ) ;
79
79
break ;
80
80
81
81
case 'group' :
@@ -94,7 +94,7 @@ function setGroupPositions(gd, pa, sa, calcTraces, opts) {
94
94
setGroupPositionsInGroupMode ( gd , pa , sa , included , opts ) ;
95
95
}
96
96
if ( excluded . length ) {
97
- setGroupPositionsInOverlayMode ( pa , sa , excluded , opts ) ;
97
+ setGroupPositionsInOverlayMode ( gd , pa , sa , excluded , opts ) ;
98
98
}
99
99
break ;
100
100
@@ -119,7 +119,7 @@ function setGroupPositions(gd, pa, sa, calcTraces, opts) {
119
119
setGroupPositionsInStackOrRelativeMode ( gd , pa , sa , included , opts ) ;
120
120
}
121
121
if ( excluded . length ) {
122
- setGroupPositionsInOverlayMode ( pa , sa , excluded , opts ) ;
122
+ setGroupPositionsInOverlayMode ( gd , pa , sa , excluded , opts ) ;
123
123
}
124
124
break ;
125
125
}
@@ -217,7 +217,7 @@ function initBase(sa, calcTraces) {
217
217
}
218
218
}
219
219
220
- function setGroupPositionsInOverlayMode ( pa , sa , calcTraces , opts ) {
220
+ function setGroupPositionsInOverlayMode ( gd , pa , sa , calcTraces , opts ) {
221
221
// update position axis and set bar offsets and widths
222
222
for ( var i = 0 ; i < calcTraces . length ; i ++ ) {
223
223
var calcTrace = calcTraces [ i ] ;
@@ -229,7 +229,7 @@ function setGroupPositionsInOverlayMode(pa, sa, calcTraces, opts) {
229
229
} ) ;
230
230
231
231
// set bar offsets and widths, and update position axis
232
- setOffsetAndWidth ( pa , sieve , opts ) ;
232
+ setOffsetAndWidth ( gd , pa , sieve , opts ) ;
233
233
234
234
// set bar bases and sizes, and update size axis
235
235
//
@@ -253,7 +253,7 @@ function setGroupPositionsInGroupMode(gd, pa, sa, calcTraces, opts) {
253
253
} ) ;
254
254
255
255
// set bar offsets and widths, and update position axis
256
- setOffsetAndWidthInGroupMode ( gd , pa , sieve , opts ) ;
256
+ setOffsetAndWidth ( gd , pa , sieve , opts ) ;
257
257
258
258
// relative-stack bars within the same trace that would otherwise
259
259
// be hidden
@@ -276,20 +276,20 @@ function setGroupPositionsInStackOrRelativeMode(gd, pa, sa, calcTraces, opts) {
276
276
} ) ;
277
277
278
278
// set bar offsets and widths, and update position axis
279
- setOffsetAndWidth ( pa , sieve , opts ) ;
279
+ setOffsetAndWidth ( gd , pa , sieve , opts ) ;
280
280
281
281
// set bar bases and sizes, and update size axis
282
282
stackBars ( sa , sieve , opts ) ;
283
283
284
284
// flag the outmost bar (for text display purposes)
285
285
for ( var i = 0 ; i < calcTraces . length ; i ++ ) {
286
286
var calcTrace = calcTraces [ i ] ;
287
-
287
+ var offsetIndex = calcTrace [ 0 ] . t . offsetindex ;
288
288
for ( var j = 0 ; j < calcTrace . length ; j ++ ) {
289
289
var bar = calcTrace [ j ] ;
290
290
291
291
if ( bar . s !== BADNUM ) {
292
- var isOutmostBar = ( ( bar . b + bar . s ) === sieve . get ( bar . p , bar . s ) ) ;
292
+ var isOutmostBar = ( ( bar . b + bar . s ) === sieve . get ( bar . p , offsetIndex , bar . s ) ) ;
293
293
if ( isOutmostBar ) bar . _outmost = true ;
294
294
}
295
295
}
@@ -300,43 +300,19 @@ function setGroupPositionsInStackOrRelativeMode(gd, pa, sa, calcTraces, opts) {
300
300
if ( opts . norm ) normalizeBars ( sa , sieve , opts ) ;
301
301
}
302
302
303
- function setOffsetAndWidth ( pa , sieve , opts ) {
304
- var minDiff = sieve . minDiff ;
305
- var calcTraces = sieve . traces ;
306
-
307
- // set bar offsets and widths
308
- var barGroupWidth = minDiff * ( 1 - opts . gap ) ;
309
- var barWidthPlusGap = barGroupWidth ;
310
- var barWidth = barWidthPlusGap * ( 1 - ( opts . groupgap || 0 ) ) ;
311
-
312
- // computer bar group center and bar offset
313
- var offsetFromCenter = - barWidth / 2 ;
314
-
315
- for ( var i = 0 ; i < calcTraces . length ; i ++ ) {
316
- var calcTrace = calcTraces [ i ] ;
317
- var t = calcTrace [ 0 ] . t ;
318
-
319
- // store bar width and offset for this trace
320
- t . barwidth = barWidth ;
321
- t . poffset = offsetFromCenter ;
322
- t . bargroupwidth = barGroupWidth ;
323
- t . bardelta = minDiff ;
324
- }
325
-
326
- // stack bars that only differ by rounding
327
- sieve . binWidth = calcTraces [ 0 ] [ 0 ] . t . barwidth / 100 ;
328
-
329
- // if defined, apply trace offset and width
330
- applyAttributes ( sieve ) ;
331
-
332
- // store the bar center in each calcdata item
333
- setBarCenterAndWidth ( pa , sieve ) ;
334
-
335
- // update position axes
336
- updatePositionAxis ( pa , sieve ) ;
337
- }
338
-
339
- function setOffsetAndWidthInGroupMode ( gd , pa , sieve , opts ) {
303
+ /**
304
+ * Mode group: Traces should be offsetted to other traces at the same position if they have a
305
+ * different offsetgroup or if no offsetgroups are specified.
306
+ * If there are no other traces at the same position, the trace will not be offsetted and it
307
+ * can occupy the whole width.
308
+ * If two traces share an offsetgroup, they should overlap.
309
+ * Mode overlay/stack/relative: Traces should be offseted to other traces at the same position if
310
+ * they have a different offsetgroup.
311
+ * If two traces share an offsetgroup or if no offsetgroups are specified, they should instead
312
+ * overlap/stack.
313
+ * Angular axes (for barpolar type) don't support group offsets.
314
+ */
315
+ function setOffsetAndWidth ( gd , pa , sieve , opts ) {
340
316
var fullLayout = gd . _fullLayout ;
341
317
var positions = sieve . positions ;
342
318
var distinctPositions = sieve . distinctPositions ;
@@ -347,38 +323,48 @@ function setOffsetAndWidthInGroupMode(gd, pa, sieve, opts) {
347
323
// if there aren't any overlapping positions,
348
324
// let them have full width even if mode is group
349
325
var overlap = ( positions . length !== distinctPositions . length ) ;
350
- var barGroupWidth = minDiff * ( 1 - opts . gap ) ;
351
326
352
- var groupId = getAxisGroup ( fullLayout , pa . _id ) + calcTraces [ 0 ] [ 0 ] . trace . orientation ;
353
- var alignmentGroups = fullLayout . _alignmentOpts [ groupId ] || { } ;
327
+ var barGroupWidth = minDiff * ( 1 - opts . gap ) ;
328
+ var barWidthPlusGap ;
329
+ var barWidth ;
330
+ var offsetFromCenter ;
331
+ var alignmentGroups ;
332
+ if ( pa . _id === 'angularaxis' ) {
333
+ barWidthPlusGap = barGroupWidth ;
334
+ barWidth = barWidthPlusGap * ( 1 - ( opts . groupgap || 0 ) ) ;
335
+ offsetFromCenter = - barWidth / 2 ;
336
+ } else { // collect groups and calculate values in loop below
337
+ var groupId = getAxisGroup ( fullLayout , pa . _id ) + calcTraces [ 0 ] [ 0 ] . trace . orientation ;
338
+ alignmentGroups = fullLayout . _alignmentOpts [ groupId ] || { } ;
339
+ }
354
340
355
341
for ( var i = 0 ; i < nTraces ; i ++ ) {
356
342
var calcTrace = calcTraces [ i ] ;
357
343
var trace = calcTrace [ 0 ] . trace ;
344
+ if ( pa . _id !== 'angularaxis' ) {
345
+ var alignmentGroupOpts = alignmentGroups [ trace . alignmentgroup ] || { } ;
346
+ var nOffsetGroups = Object . keys ( alignmentGroupOpts . offsetGroups || { } ) . length ;
358
347
359
- var alignmentGroupOpts = alignmentGroups [ trace . alignmentgroup ] || { } ;
360
- var nOffsetGroups = Object . keys ( alignmentGroupOpts . offsetGroups || { } ) . length ;
361
-
362
- var barWidthPlusGap ;
363
- if ( nOffsetGroups ) {
364
- barWidthPlusGap = barGroupWidth / nOffsetGroups ;
365
- } else {
366
- barWidthPlusGap = overlap ? barGroupWidth / nTraces : barGroupWidth ;
367
- }
348
+ if ( nOffsetGroups ) {
349
+ barWidthPlusGap = barGroupWidth / nOffsetGroups ;
350
+ } else {
351
+ barWidthPlusGap = overlap ? barGroupWidth / nTraces : barGroupWidth ;
352
+ }
368
353
369
- var barWidth = barWidthPlusGap * ( 1 - ( opts . groupgap || 0 ) ) ;
354
+ barWidth = barWidthPlusGap * ( 1 - ( opts . groupgap || 0 ) ) ;
370
355
371
- var offsetFromCenter ;
372
- if ( nOffsetGroups ) {
373
- offsetFromCenter = ( ( 2 * trace . _offsetIndex + 1 - nOffsetGroups ) * barWidthPlusGap - barWidth ) / 2 ;
374
- } else {
375
- offsetFromCenter = overlap ?
376
- ( ( 2 * i + 1 - nTraces ) * barWidthPlusGap - barWidth ) / 2 :
377
- - barWidth / 2 ;
356
+ if ( nOffsetGroups ) {
357
+ offsetFromCenter = ( ( 2 * trace . _offsetIndex + 1 - nOffsetGroups ) * barWidthPlusGap - barWidth ) / 2 ;
358
+ } else {
359
+ offsetFromCenter = overlap ?
360
+ ( ( 2 * i + 1 - nTraces ) * barWidthPlusGap - barWidth ) / 2 :
361
+ - barWidth / 2 ;
362
+ }
378
363
}
379
364
380
365
var t = calcTrace [ 0 ] . t ;
381
366
t . barwidth = barWidth ;
367
+ t . offsetindex = trace . _offsetIndex || 0 ;
382
368
t . poffset = offsetFromCenter ;
383
369
t . bargroupwidth = barGroupWidth ;
384
370
t . bardelta = minDiff ;
@@ -394,7 +380,11 @@ function setOffsetAndWidthInGroupMode(gd, pa, sieve, opts) {
394
380
setBarCenterAndWidth ( pa , sieve ) ;
395
381
396
382
// update position axes
397
- updatePositionAxis ( pa , sieve , overlap ) ;
383
+ if ( pa . _id === 'angularaxis' ) {
384
+ updatePositionAxis ( pa , sieve ) ;
385
+ } else {
386
+ updatePositionAxis ( pa , sieve , overlap ) ;
387
+ }
398
388
}
399
389
400
390
function applyAttributes ( sieve ) {
@@ -592,18 +582,20 @@ function stackBars(sa, sieve, opts) {
592
582
var isFunnel ;
593
583
var i , j ;
594
584
var bar ;
585
+ var offsetIndex ;
595
586
596
587
for ( i = 0 ; i < calcTraces . length ; i ++ ) {
597
588
calcTrace = calcTraces [ i ] ;
598
589
fullTrace = calcTrace [ 0 ] . trace ;
599
590
600
591
if ( fullTrace . type === 'funnel' ) {
592
+ offsetIndex = calcTrace [ 0 ] . t . offsetindex ;
601
593
for ( j = 0 ; j < calcTrace . length ; j ++ ) {
602
594
bar = calcTrace [ j ] ;
603
595
604
596
if ( bar . s !== BADNUM ) {
605
597
// create base of funnels
606
- sieve . put ( bar . p , - 0.5 * bar . s ) ;
598
+ sieve . put ( bar . p , offsetIndex , - 0.5 * bar . s ) ;
607
599
}
608
600
}
609
601
}
@@ -615,6 +607,8 @@ function stackBars(sa, sieve, opts) {
615
607
616
608
isFunnel = ( fullTrace . type === 'funnel' ) ;
617
609
610
+ offsetIndex = fullTrace . type === 'barpolar' ? 0 : calcTrace [ 0 ] . t . offsetindex ;
611
+
618
612
var pts = [ ] ;
619
613
620
614
for ( j = 0 ; j < calcTrace . length ; j ++ ) {
@@ -629,8 +623,7 @@ function stackBars(sa, sieve, opts) {
629
623
value = bar . s + bar . b ;
630
624
}
631
625
632
- var base = sieve . put ( bar . p , value ) ;
633
-
626
+ var base = sieve . put ( bar . p , offsetIndex , value ) ;
634
627
var top = base + value ;
635
628
636
629
// store the bar base and top in each calcdata item
@@ -663,12 +656,12 @@ function sieveBars(sieve) {
663
656
664
657
for ( var i = 0 ; i < calcTraces . length ; i ++ ) {
665
658
var calcTrace = calcTraces [ i ] ;
666
-
659
+ var offsetIndex = calcTrace [ 0 ] . t . offsetindex ;
667
660
for ( var j = 0 ; j < calcTrace . length ; j ++ ) {
668
661
var bar = calcTrace [ j ] ;
669
662
670
663
if ( bar . s !== BADNUM ) {
671
- sieve . put ( bar . p , bar . b + bar . s ) ;
664
+ sieve . put ( bar . p , offsetIndex , bar . b + bar . s ) ;
672
665
}
673
666
}
674
667
}
@@ -680,6 +673,7 @@ function unhideBarsWithinTrace(sieve, pa) {
680
673
for ( var i = 0 ; i < calcTraces . length ; i ++ ) {
681
674
var calcTrace = calcTraces [ i ] ;
682
675
var fullTrace = calcTrace [ 0 ] . trace ;
676
+ var offsetIndex = calcTrace [ 0 ] . t . offsetindex ;
683
677
684
678
if ( fullTrace . base === undefined ) {
685
679
var inTraceSieve = new Sieve ( [ calcTrace ] , {
@@ -693,7 +687,7 @@ function unhideBarsWithinTrace(sieve, pa) {
693
687
694
688
if ( bar . p !== BADNUM ) {
695
689
// stack current bar and get previous sum
696
- var base = inTraceSieve . put ( bar . p , bar . b + bar . s ) ;
690
+ var base = inTraceSieve . put ( bar . p , offsetIndex , bar . b + bar . s ) ;
697
691
698
692
// if previous sum if non-zero, this means:
699
693
// multiple bars have same starting point are potentially hidden,
@@ -726,6 +720,7 @@ function normalizeBars(sa, sieve, opts) {
726
720
727
721
for ( var i = 0 ; i < calcTraces . length ; i ++ ) {
728
722
var calcTrace = calcTraces [ i ] ;
723
+ var offsetIndex = calcTrace [ 0 ] . t . offsetindex ;
729
724
var fullTrace = calcTrace [ 0 ] . trace ;
730
725
var pts = [ ] ;
731
726
var tozero = false ;
@@ -735,7 +730,7 @@ function normalizeBars(sa, sieve, opts) {
735
730
var bar = calcTrace [ j ] ;
736
731
737
732
if ( bar . s !== BADNUM ) {
738
- var scale = Math . abs ( sTop / sieve . get ( bar . p , bar . s ) ) ;
733
+ var scale = Math . abs ( sTop / sieve . get ( bar . p , offsetIndex , bar . s ) ) ;
739
734
bar . b *= scale ;
740
735
bar . s *= scale ;
741
736
0 commit comments