@@ -57,52 +57,57 @@ function setGroupPositions(gd, pa, sa, calcTraces) {
5757 if ( ! calcTraces . length ) return ;
5858
5959 var barmode = gd . _fullLayout . barmode ;
60- var overlay = ( barmode === 'overlay' ) ;
61- var group = ( barmode === 'group' ) ;
6260 var excluded ;
6361 var included ;
6462 var i , calcTrace , fullTrace ;
6563
6664 initBase ( gd , pa , sa , calcTraces ) ;
6765
68- if ( overlay ) {
69- setGroupPositionsInOverlayMode ( gd , pa , sa , calcTraces ) ;
70- } else if ( group ) {
71- // exclude from the group those traces for which the user set an offset
72- excluded = [ ] ;
73- included = [ ] ;
74- for ( i = 0 ; i < calcTraces . length ; i ++ ) {
75- calcTrace = calcTraces [ i ] ;
76- fullTrace = calcTrace [ 0 ] . trace ;
77-
78- if ( fullTrace . offset === undefined ) included . push ( calcTrace ) ;
79- else excluded . push ( calcTrace ) ;
80- }
66+ switch ( barmode ) {
67+ case 'overlay' :
68+ setGroupPositionsInOverlayMode ( gd , pa , sa , calcTraces ) ;
69+ break ;
70+
71+ case 'group' :
72+ // exclude from the group those traces for which the user set an offset
73+ excluded = [ ] ;
74+ included = [ ] ;
75+ for ( i = 0 ; i < calcTraces . length ; i ++ ) {
76+ calcTrace = calcTraces [ i ] ;
77+ fullTrace = calcTrace [ 0 ] . trace ;
78+
79+ if ( fullTrace . offset === undefined ) included . push ( calcTrace ) ;
80+ else excluded . push ( calcTrace ) ;
81+ }
8182
82- if ( included . length ) {
83- setGroupPositionsInGroupMode ( gd , pa , sa , included ) ;
84- }
85- if ( excluded . length ) {
86- setGroupPositionsInOverlayMode ( gd , pa , sa , excluded ) ;
87- }
88- } else {
89- // exclude from the stack those traces for which the user set a base
90- excluded = [ ] ;
91- included = [ ] ;
92- for ( i = 0 ; i < calcTraces . length ; i ++ ) {
93- calcTrace = calcTraces [ i ] ;
94- fullTrace = calcTrace [ 0 ] . trace ;
95-
96- if ( fullTrace . base === undefined ) included . push ( calcTrace ) ;
97- else excluded . push ( calcTrace ) ;
98- }
83+ if ( included . length ) {
84+ setGroupPositionsInGroupMode ( gd , pa , sa , included ) ;
85+ }
86+ if ( excluded . length ) {
87+ setGroupPositionsInOverlayMode ( gd , pa , sa , excluded ) ;
88+ }
89+ break ;
90+
91+ case 'stack' :
92+ case 'relative' :
93+ // exclude from the stack those traces for which the user set a base
94+ excluded = [ ] ;
95+ included = [ ] ;
96+ for ( i = 0 ; i < calcTraces . length ; i ++ ) {
97+ calcTrace = calcTraces [ i ] ;
98+ fullTrace = calcTrace [ 0 ] . trace ;
99+
100+ if ( fullTrace . base === undefined ) included . push ( calcTrace ) ;
101+ else excluded . push ( calcTrace ) ;
102+ }
99103
100- if ( included . length ) {
101- setGroupPositionsInStackOrRelativeMode ( gd , pa , sa , included ) ;
102- }
103- if ( excluded . length ) {
104- setGroupPositionsInOverlayMode ( gd , pa , sa , excluded ) ;
105- }
104+ if ( included . length ) {
105+ setGroupPositionsInStackOrRelativeMode ( gd , pa , sa , included ) ;
106+ }
107+ if ( excluded . length ) {
108+ setGroupPositionsInOverlayMode ( gd , pa , sa , excluded ) ;
109+ }
110+ break ;
106111 }
107112
108113 collectExtents ( calcTraces , pa ) ;
@@ -154,13 +159,15 @@ function initBase(gd, pa, sa, calcTraces) {
154159
155160function setGroupPositionsInOverlayMode ( gd , pa , sa , calcTraces ) {
156161 var barnorm = gd . _fullLayout . barnorm ;
157- var separateNegativeValues = false ;
158- var dontMergeOverlappingData = ! barnorm ;
159162
160163 // update position axis and set bar offsets and widths
161164 for ( var i = 0 ; i < calcTraces . length ; i ++ ) {
162165 var calcTrace = calcTraces [ i ] ;
163- var sieve = new Sieve ( [ calcTrace ] , separateNegativeValues , dontMergeOverlappingData ) ;
166+
167+ var sieve = new Sieve ( [ calcTrace ] , {
168+ separateNegativeValues : false ,
169+ dontMergeOverlappingData : ! barnorm
170+ } ) ;
164171
165172 // set bar offsets and widths, and update position axis
166173 setOffsetAndWidth ( gd , pa , sieve ) ;
@@ -182,9 +189,11 @@ function setGroupPositionsInOverlayMode(gd, pa, sa, calcTraces) {
182189function setGroupPositionsInGroupMode ( gd , pa , sa , calcTraces ) {
183190 var fullLayout = gd . _fullLayout ;
184191 var barnorm = fullLayout . barnorm ;
185- var separateNegativeValues = false ;
186- var dontMergeOverlappingData = ! barnorm ;
187- var sieve = new Sieve ( calcTraces , separateNegativeValues , dontMergeOverlappingData ) ;
192+
193+ var sieve = new Sieve ( calcTraces , {
194+ separateNegativeValues : false ,
195+ dontMergeOverlappingData : ! barnorm
196+ } ) ;
188197
189198 // set bar offsets and widths, and update position axis
190199 setOffsetAndWidthInGroupMode ( gd , pa , sieve ) ;
@@ -201,12 +210,12 @@ function setGroupPositionsInGroupMode(gd, pa, sa, calcTraces) {
201210function setGroupPositionsInStackOrRelativeMode ( gd , pa , sa , calcTraces ) {
202211 var fullLayout = gd . _fullLayout ;
203212 var barmode = fullLayout . barmode ;
204- var stack = barmode === 'stack' ;
205- var relative = barmode === 'relative' ;
206213 var barnorm = fullLayout . barnorm ;
207- var separateNegativeValues = relative ;
208- var dontMergeOverlappingData = ! ( barnorm || stack || relative ) ;
209- var sieve = new Sieve ( calcTraces , separateNegativeValues , dontMergeOverlappingData ) ;
214+
215+ var sieve = new Sieve ( calcTraces , {
216+ separateNegativeValues : barmode === 'relative' ,
217+ dontMergeOverlappingData : ! ( barnorm || barmode === 'stack' || barmode === 'relative' )
218+ } ) ;
210219
211220 // set bar offsets and widths, and update position axis
212221 setOffsetAndWidth ( gd , pa , sieve ) ;
@@ -562,7 +571,9 @@ function sieveBars(gd, sa, sieve) {
562571 for ( var j = 0 ; j < calcTrace . length ; j ++ ) {
563572 var bar = calcTrace [ j ] ;
564573
565- if ( bar . s !== BADNUM ) sieve . put ( bar . p , bar . b + bar . s ) ;
574+ if ( bar . s !== BADNUM ) {
575+ sieve . put ( bar . p , bar . b + bar . s ) ;
576+ }
566577 }
567578 }
568579}
0 commit comments