Skip to content

Commit 19e114e

Browse files
committed
bar: do not assume initial bar base is zero
1 parent 23bdc82 commit 19e114e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/traces/bar/set_positions.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ function setGroupPositionsInOverlayMode(gd, pa, sa, traces) {
9292
// along with the tops of each bar,
9393
// and store these bar tops in calcdata
9494
var sLetter = getAxisLetter(sa),
95-
fs = function(v) { v[sLetter] = v.s; return v.s; };
95+
fs = function(v) {
96+
var barTop = v.b + v.s;
97+
v[sLetter] = barTop;
98+
return barTop;
99+
};
96100

97101
Axes.expand(sa, trace.map(fs), {tozero: true, padded: true});
98102
}
@@ -122,7 +126,11 @@ function setGroupPositionsInGroupMode(gd, pa, sa, traces) {
122126
// along with the tops of each bar,
123127
// and store these bar tops in calcdata
124128
var sLetter = getAxisLetter(sa),
125-
fs = function(v) { v[sLetter] = v.s; return v.s; };
129+
fs = function(v) {
130+
var barTop = v.b + v.s;
131+
v[sLetter] = barTop;
132+
return barTop;
133+
};
126134

127135
for(var i = 0; i < traces.length; i++) {
128136
Axes.expand(sa, traces[i].map(fs), {tozero: true, padded: true});
@@ -268,7 +276,7 @@ function stackBars(gd, sa, sieve) {
268276
if(!isNumeric(bar.s)) continue;
269277

270278
// stack current bar and get previous sum
271-
var previousSum = sieve.put(bar.p, bar.s);
279+
var previousSum = sieve.put(bar.p, bar.b + bar.s);
272280

273281
// store the bar base and top in each calcdata item
274282
bar.b = previousSum;
@@ -302,7 +310,7 @@ function sieveBars(gd, sa, sieve) {
302310
for(var j = 0; j < trace.length; j++) {
303311
var bar = trace[j];
304312

305-
if(isNumeric(bar.s)) sieve.put(bar.p, bar.s);
313+
if(isNumeric(bar.s)) sieve.put(bar.p, bar.b + bar.s);
306314
}
307315
}
308316
}
@@ -330,7 +338,7 @@ function normalizeBars(gd, sa, sieve) {
330338

331339
if(!isNumeric(bar.s)) continue;
332340

333-
var scale = Math.abs(sTop / sieve.get(bar.p, bar.s));
341+
var scale = Math.abs(sTop / sieve.get(bar.p, bar.b + bar.s));
334342
bar.b *= scale;
335343
bar.s *= scale;
336344
var barEnd = bar.b + bar.s;

0 commit comments

Comments
 (0)