Skip to content

Commit 7e0a228

Browse files
committed
fix #3031 - don't set tozero:true when all bar bases are above zero
1 parent b18669d commit 7e0a228

5 files changed

+51
-2
lines changed

src/traces/bar/cross_trace_calc.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ function setBaseAndTop(gd, sa, sieve) {
471471
var calcTrace = calcTraces[i];
472472
var fullTrace = calcTrace[0].trace;
473473
var pts = [];
474+
var allBarBaseAboveZero = true;
474475

475476
for(var j = 0; j < calcTrace.length; j++) {
476477
var bar = calcTrace[j];
@@ -480,10 +481,14 @@ function setBaseAndTop(gd, sa, sieve) {
480481
bar[sLetter] = barTop;
481482
pts.push(barTop);
482483
if(bar.hasB) pts.push(barBase);
484+
485+
if(!bar.hasB || !(bar.b > 0 && bar.s > 0)) {
486+
allBarBaseAboveZero = false;
487+
}
483488
}
484489

485490
fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {
486-
tozero: true,
491+
tozero: !allBarBaseAboveZero,
487492
padded: true
488493
});
489494
}
@@ -522,6 +527,8 @@ function stackBars(gd, sa, sieve) {
522527
// if barnorm is set, let normalizeBars update the axis range
523528
if(!barnorm) {
524529
fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {
530+
// N.B. we don't stack base with 'base',
531+
// so set tozero:true always!
525532
tozero: true,
526533
padded: true
527534
});
@@ -567,6 +574,7 @@ function normalizeBars(gd, sa, sieve) {
567574
var calcTrace = calcTraces[i];
568575
var fullTrace = calcTrace[0].trace;
569576
var pts = [];
577+
var allBarBaseAboveZero = true;
570578
var padded = false;
571579

572580
for(var j = 0; j < calcTrace.length; j++) {
@@ -588,11 +596,15 @@ function normalizeBars(gd, sa, sieve) {
588596
pts.push(barBase);
589597
padded = padded || needsPadding(barBase);
590598
}
599+
600+
if(!bar.hasB || !(bar.b > 0 && bar.s > 0)) {
601+
allBarBaseAboveZero = false;
602+
}
591603
}
592604
}
593605

594606
fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {
595-
tozero: true,
607+
tozero: !allBarBaseAboveZero,
596608
padded: padded
597609
});
598610
}
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"data": [
3+
{
4+
"y": [1, 2, 3],
5+
"base": [3, 4, 5],
6+
"type": "bar"
7+
},
8+
{
9+
"y": [1, 2, 3],
10+
"base": [3, 4, 5],
11+
"type": "bar"
12+
}
13+
],
14+
"layout": {
15+
"barnorm": "percent",
16+
"width": 400,
17+
"height": 400
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"data": [
3+
{
4+
"y": [1, 2, 3],
5+
"base": [3, 4, 5],
6+
"type": "bar"
7+
},
8+
{
9+
"y": [1, 2, 3],
10+
"base": [3, 4, 5],
11+
"type": "bar"
12+
}
13+
],
14+
"layout": {
15+
"width": 400,
16+
"height": 400
17+
}
18+
}

0 commit comments

Comments
 (0)