@@ -54,8 +54,7 @@ function setGroupPositions(gd, pa, sa, traces) {
54
54
55
55
var fullLayout = gd . _fullLayout ,
56
56
pLetter = pa . _id . charAt ( 0 ) ,
57
- sLetter = sa . _id . charAt ( 0 ) ,
58
- i , j ;
57
+ sLetter = sa . _id . charAt ( 0 ) ;
59
58
60
59
if ( fullLayout . barmode === 'overlay' ) {
61
60
traces . forEach ( function ( trace ) {
@@ -64,6 +63,83 @@ function setGroupPositions(gd, pa, sa, traces) {
64
63
}
65
64
else setOffsetAndWidth ( gd , pa , pLetter , traces ) ;
66
65
66
+ setBaseAndSize ( gd , sa , sLetter , traces ) ;
67
+ }
68
+
69
+
70
+ // bar position offset and width calculation
71
+ // traces is a list of traces (in calcdata) to look at together
72
+ // to find the maximum width bars that won't overlap
73
+ // for stacked or grouped bars, this is all vertical or horizontal
74
+ // bars for overlaid bars, call this individually on each trace.
75
+ function setOffsetAndWidth ( gd , pa , pLetter , traces ) {
76
+ var fullLayout = gd . _fullLayout ,
77
+ i , trace ,
78
+ j , bar ;
79
+
80
+ // make list of bar positions
81
+ var positions = [ ] ;
82
+ for ( i = 0 ; i < traces . length ; i ++ ) {
83
+ trace = traces [ i ] ;
84
+ for ( j = 0 ; j < trace . length ; j ++ ) {
85
+ bar = trace [ j ] ;
86
+ positions . push ( bar . p ) ;
87
+ }
88
+ }
89
+
90
+ var dv = Lib . distinctVals ( positions ) ,
91
+ distinctPositions = dv . vals ,
92
+ minDiff = dv . minDiff ;
93
+
94
+ // check if there are any overlapping positions;
95
+ // if there aren't, let them have full width even if mode is group
96
+ var overlap = false ;
97
+ if ( fullLayout . barmode === 'group' ) {
98
+ overlap = ( positions . length !== distinctPositions . length ) ;
99
+ }
100
+
101
+ // check forced minimum dtick
102
+ Axes . minDtick ( pa , minDiff , distinctPositions [ 0 ] , overlap ) ;
103
+
104
+ // position axis autorange - always tight fitting
105
+ Axes . expand ( pa , distinctPositions , { vpad : minDiff / 2 } ) ;
106
+
107
+ // computer bar widths and position offsets
108
+ var barWidth = minDiff * ( 1 - fullLayout . bargap ) ;
109
+ if ( overlap ) barWidth /= traces . length ;
110
+
111
+ var barWidthMinusGroupGap = barWidth * ( 1 - fullLayout . bargroupgap ) ;
112
+
113
+ for ( i = 0 ; i < traces . length ; i ++ ) {
114
+ trace = traces [ i ] ;
115
+
116
+ // computer bar group center and bar offset
117
+ var offsetFromCenter = (
118
+ ( overlap ? ( 2 * i + 1 - traces . length ) * barWidth : 0 ) -
119
+ barWidthMinusGroupGap
120
+ ) / 2 ,
121
+ barCenter = offsetFromCenter + barWidthMinusGroupGap / 2 ;
122
+
123
+ // store bar width and offset for this trace
124
+ var t = trace [ 0 ] . t ;
125
+ t . barwidth = barWidthMinusGroupGap ;
126
+ t . poffset = offsetFromCenter ;
127
+ t . dbar = minDiff ;
128
+
129
+ // store the bar center in each calcdata item
130
+ for ( j = 0 ; j < trace . length ; j ++ ) {
131
+ bar = trace [ j ] ;
132
+ bar [ pLetter ] = bar . p + barCenter ;
133
+ }
134
+ }
135
+ }
136
+
137
+
138
+ function setBaseAndSize ( gd , sa , sLetter , traces ) {
139
+ var fullLayout = gd . _fullLayout ,
140
+ i , trace ,
141
+ j , bar ;
142
+
67
143
var stack = ( fullLayout . barmode === 'stack' ) ,
68
144
relative = ( fullLayout . barmode === 'relative' ) ,
69
145
norm = fullLayout . barnorm ;
@@ -85,32 +161,32 @@ function setGroupPositions(gd, pa, sa, traces) {
85
161
sv = 0 ,
86
162
padded = true ,
87
163
barEnd ,
88
- ti ,
89
164
scale ;
90
165
91
166
for ( i = 0 ; i < traces . length ; i ++ ) { // trace index
92
- ti = traces [ i ] ;
167
+ trace = traces [ i ] ;
93
168
94
- for ( j = 0 ; j < ti . length ; j ++ ) {
169
+ for ( j = 0 ; j < trace . length ; j ++ ) {
170
+ bar = trace [ j ] ;
95
171
96
172
// skip over bars with no size,
97
173
// so that we don't try to stack them
98
- if ( ! isNumeric ( ti [ j ] . s ) ) continue ;
174
+ if ( ! isNumeric ( bar . s ) ) continue ;
99
175
100
- sv = Math . round ( ti [ j ] . p / sumround ) ;
176
+ sv = Math . round ( bar . p / sumround ) ;
101
177
102
178
// store the negative sum value for p at the same key,
103
179
// with sign flipped using string to ensure -0 !== 0.
104
- if ( relative && ti [ j ] . s < 0 ) sv = '-' + sv ;
180
+ if ( relative && bar . s < 0 ) sv = '-' + sv ;
105
181
106
182
var previousSum = sums [ sv ] || 0 ;
107
- if ( stack || relative ) ti [ j ] . b = previousSum ;
108
- barEnd = ti [ j ] . b + ti [ j ] . s ;
109
- sums [ sv ] = previousSum + ti [ j ] . s ;
183
+ if ( stack || relative ) bar . b = previousSum ;
184
+ barEnd = bar . b + bar . s ;
185
+ sums [ sv ] = previousSum + bar . s ;
110
186
111
187
// store the bar top in each calcdata item
112
188
if ( stack || relative ) {
113
- ti [ j ] [ sLetter ] = barEnd ;
189
+ bar [ sLetter ] = barEnd ;
114
190
if ( ! norm && isNumeric ( sa . c2l ( barEnd ) ) ) {
115
191
sMax = Math . max ( sMax , barEnd ) ;
116
192
sMin = Math . min ( sMin , barEnd ) ;
@@ -129,12 +205,14 @@ function setGroupPositions(gd, pa, sa, traces) {
129
205
sMax = stack ? top : 0 ;
130
206
131
207
for ( i = 0 ; i < traces . length ; i ++ ) { // trace index
132
- ti = traces [ i ] ;
208
+ trace = traces [ i ] ;
133
209
134
- for ( j = 0 ; j < ti . length ; j ++ ) {
135
- relAndNegative = ( relative && ti [ j ] . s < 0 ) ;
210
+ for ( j = 0 ; j < trace . length ; j ++ ) {
211
+ bar = trace [ j ] ;
136
212
137
- sv = Math . round ( ti [ j ] . p / sumround ) ;
213
+ relAndNegative = ( relative && bar . s < 0 ) ;
214
+
215
+ sv = Math . round ( bar . p / sumround ) ;
138
216
139
217
// locate negative sum amount for this p val
140
218
if ( relAndNegative ) sv = '-' + sv ;
@@ -143,10 +221,10 @@ function setGroupPositions(gd, pa, sa, traces) {
143
221
144
222
// preserve sign if negative
145
223
if ( relAndNegative ) scale *= - 1 ;
146
- ti [ j ] . b *= scale ;
147
- ti [ j ] . s *= scale ;
148
- barEnd = ti [ j ] . b + ti [ j ] . s ;
149
- ti [ j ] [ sLetter ] = barEnd ;
224
+ bar . b *= scale ;
225
+ bar . s *= scale ;
226
+ barEnd = bar . b + bar . s ;
227
+ bar [ sLetter ] = barEnd ;
150
228
151
229
if ( isNumeric ( sa . c2l ( barEnd ) ) ) {
152
230
if ( barEnd < sMin - tiny ) {
@@ -175,71 +253,3 @@ function setGroupPositions(gd, pa, sa, traces) {
175
253
}
176
254
}
177
255
}
178
-
179
-
180
- // bar position offset and width calculation
181
- // traces is a list of traces (in calcdata) to look at together
182
- // to find the maximum width bars that won't overlap
183
- // for stacked or grouped bars, this is all vertical or horizontal
184
- // bars for overlaid bars, call this individually on each trace.
185
- function setOffsetAndWidth ( gd , pa , pLetter , traces ) {
186
- var fullLayout = gd . _fullLayout ,
187
- i , trace ,
188
- j , bar ;
189
-
190
- // make list of bar positions
191
- var positions = [ ] ;
192
- for ( i = 0 ; i < traces . length ; i ++ ) {
193
- trace = traces [ i ] ;
194
- for ( j = 0 ; j < trace . length ; j ++ ) {
195
- bar = trace [ j ] ;
196
- positions . push ( bar . p ) ;
197
- }
198
- }
199
-
200
- var dv = Lib . distinctVals ( positions ) ,
201
- distinctPositions = dv . vals ,
202
- minDiff = dv . minDiff ;
203
-
204
- // check if there are any overlapping positions;
205
- // if there aren't, let them have full width even if mode is group
206
- var overlap = false ;
207
- if ( fullLayout . barmode === 'group' ) {
208
- overlap = ( positions . length !== distinctPositions . length ) ;
209
- }
210
-
211
- // check forced minimum dtick
212
- Axes . minDtick ( pa , minDiff , distinctPositions [ 0 ] , overlap ) ;
213
-
214
- // position axis autorange - always tight fitting
215
- Axes . expand ( pa , distinctPositions , { vpad : minDiff / 2 } ) ;
216
-
217
- // computer bar widths and position offsets
218
- var barWidth = minDiff * ( 1 - fullLayout . bargap ) ;
219
- if ( overlap ) barWidth /= traces . length ;
220
-
221
- var barWidthMinusGroupGap = barWidth * ( 1 - fullLayout . bargroupgap ) ;
222
-
223
- for ( i = 0 ; i < traces . length ; i ++ ) {
224
- trace = traces [ i ] ;
225
-
226
- // computer bar group center and bar offset
227
- var offsetFromCenter = (
228
- ( overlap ? ( 2 * i + 1 - traces . length ) * barWidth : 0 ) -
229
- barWidthMinusGroupGap
230
- ) / 2 ,
231
- barCenter = offsetFromCenter + barWidthMinusGroupGap / 2 ;
232
-
233
- // store bar width and offset for this trace
234
- var t = trace [ 0 ] . t ;
235
- t . barwidth = barWidthMinusGroupGap ;
236
- t . poffset = offsetFromCenter ;
237
- t . dbar = minDiff ;
238
-
239
- // store the bar center in each calcdata item
240
- for ( j = 0 ; j < trace . length ; j ++ ) {
241
- bar = trace [ j ] ;
242
- bar [ pLetter ] = bar . p + barCenter ;
243
- }
244
- }
245
- }
0 commit comments