@@ -148,8 +148,11 @@ module.exports = function setPositions(gd, plotinfo) {
148
148
if ( ! isNumeric ( ti [ j ] . s ) ) continue ;
149
149
150
150
sv = Math . round ( ti [ j ] . p / sumround ) ;
151
- // store the negative sum value for p at the same key, with sign flipped
152
- if ( relative && ti [ j ] . s < 0 ) sv = '-' + sv ; // use string to ensure -0 !== 0
151
+
152
+ // store the negative sum value for p at the same key,
153
+ // with sign flipped using string to ensure -0 !== 0.
154
+ if ( relative && ti [ j ] . s < 0 ) sv = '-' + sv ;
155
+
153
156
var previousSum = sums [ sv ] || 0 ;
154
157
if ( stack || relative ) ti [ j ] . b = previousSum ;
155
158
barEnd = ti [ j ] . b + ti [ j ] . s ;
@@ -167,20 +170,29 @@ module.exports = function setPositions(gd, plotinfo) {
167
170
}
168
171
169
172
if ( norm ) {
170
- padded = false ;
171
173
var top = norm === 'fraction' ? 1 : 100 ,
172
174
relAndNegative = false ,
173
175
tiny = top / 1e9 ; // in case of rounding error in sum
176
+
177
+ padded = false ;
174
178
sMin = 0 ;
175
179
sMax = stack ? top : 0 ;
180
+
176
181
for ( i = 0 ; i < bl . length ; i ++ ) { // trace index
177
182
ti = gd . calcdata [ bl [ i ] ] ;
183
+
178
184
for ( j = 0 ; j < ti . length ; j ++ ) {
179
- relAndNegative = relative && ti [ j ] . s < 0 ;
185
+ relAndNegative = ( relative && ti [ j ] . s < 0 ) ;
186
+
180
187
sv = Math . round ( ti [ j ] . p / sumround ) ;
181
- if ( relAndNegative ) sv = '-' + sv ; // locate negative sum amount for this p val
188
+
189
+ // locate negative sum amount for this p val
190
+ if ( relAndNegative ) sv = '-' + sv ;
191
+
182
192
scale = top / sums [ sv ] ;
183
- if ( relAndNegative ) scale *= - 1 ; // preserve sign if negative
193
+
194
+ // preserve sign if negative
195
+ if ( relAndNegative ) scale *= - 1 ;
184
196
ti [ j ] . b *= scale ;
185
197
ti [ j ] . s *= scale ;
186
198
barEnd = ti [ j ] . b + ti [ j ] . s ;
0 commit comments