Skip to content

Commit

Permalink
fix #3031 - don't set tozero:true when all bar bases are above zero
Browse files Browse the repository at this point in the history
  • Loading branch information
etpinard committed Jan 21, 2019
1 parent b18669d commit 7e0a228
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/traces/bar/cross_trace_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ function setBaseAndTop(gd, sa, sieve) {
var calcTrace = calcTraces[i];
var fullTrace = calcTrace[0].trace;
var pts = [];
var allBarBaseAboveZero = true;

for(var j = 0; j < calcTrace.length; j++) {
var bar = calcTrace[j];
Expand All @@ -480,10 +481,14 @@ function setBaseAndTop(gd, sa, sieve) {
bar[sLetter] = barTop;
pts.push(barTop);
if(bar.hasB) pts.push(barBase);

if(!bar.hasB || !(bar.b > 0 && bar.s > 0)) {
allBarBaseAboveZero = false;
}
}

fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {
tozero: true,
tozero: !allBarBaseAboveZero,
padded: true
});
}
Expand Down Expand Up @@ -522,6 +527,8 @@ function stackBars(gd, sa, sieve) {
// if barnorm is set, let normalizeBars update the axis range
if(!barnorm) {
fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {
// N.B. we don't stack base with 'base',
// so set tozero:true always!
tozero: true,
padded: true
});
Expand Down Expand Up @@ -567,6 +574,7 @@ function normalizeBars(gd, sa, sieve) {
var calcTrace = calcTraces[i];
var fullTrace = calcTrace[0].trace;
var pts = [];
var allBarBaseAboveZero = true;
var padded = false;

for(var j = 0; j < calcTrace.length; j++) {
Expand All @@ -588,11 +596,15 @@ function normalizeBars(gd, sa, sieve) {
pts.push(barBase);
padded = padded || needsPadding(barBase);
}

if(!bar.hasB || !(bar.b > 0 && bar.s > 0)) {
allBarBaseAboveZero = false;
}
}
}

fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {
tozero: true,
tozero: !allBarBaseAboveZero,
padded: padded
});
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/bar_autorange-above-zero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/image/mocks/bar_autorange-above-zero-normalized.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"data": [
{
"y": [1, 2, 3],
"base": [3, 4, 5],
"type": "bar"
},
{
"y": [1, 2, 3],
"base": [3, 4, 5],
"type": "bar"
}
],
"layout": {
"barnorm": "percent",
"width": 400,
"height": 400
}
}
18 changes: 18 additions & 0 deletions test/image/mocks/bar_autorange-above-zero.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"data": [
{
"y": [1, 2, 3],
"base": [3, 4, 5],
"type": "bar"
},
{
"y": [1, 2, 3],
"base": [3, 4, 5],
"type": "bar"
}
],
"layout": {
"width": 400,
"height": 400
}
}

0 comments on commit 7e0a228

Please sign in to comment.