Skip to content

Bar axis autorange fix #2050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/traces/bar/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,23 @@ module.exports = function calc(gd, trace) {
if(Array.isArray(base)) {
for(i = 0; i < Math.min(base.length, cd.length); i++) {
b = sa.d2c(base[i], 0, scalendar);
cd[i].b = (isNumeric(b)) ? b : 0;
if(isNumeric(b)) {
cd[i].b = +b;
cd[i].hasB = 1;
}
else cd[i].b = 0;
}
for(; i < cd.length; i++) {
cd[i].b = 0;
}
}
else {
b = sa.d2c(base, 0, scalendar);
b = (isNumeric(b)) ? b : 0;
var hasBase = isNumeric(b);
b = hasBase ? b : 0;
for(i = 0; i < cd.length; i++) {
cd[i].b = b;
if(hasBase) cd[i].hasB = 1;
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/traces/bar/set_positions.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,7 @@ function setBaseAndTop(gd, sa, sieve) {
// along with the bases and tops of each bar.
var traces = sieve.traces,
sLetter = getAxisLetter(sa),
s0 = sa.l2c(sa.c2l(0)),
sRange = [s0, s0];
sRange = [null, null];

for(var i = 0; i < traces.length; i++) {
var trace = traces[i];
Expand All @@ -481,7 +480,7 @@ function setBaseAndTop(gd, sa, sieve) {
bar[sLetter] = barTop;

if(isNumeric(sa.c2l(barTop))) expandRange(sRange, barTop);
if(isNumeric(sa.c2l(barBase))) expandRange(sRange, barBase);
if(bar.hasB && isNumeric(sa.c2l(barBase))) expandRange(sRange, barBase);
}
}

Expand All @@ -497,8 +496,7 @@ function stackBars(gd, sa, sieve) {
i, trace,
j, bar;

var s0 = sa.l2c(sa.c2l(0)),
sRange = [s0, s0];
var sRange = [null, null];

for(i = 0; i < traces.length; i++) {
trace = traces[i];
Expand All @@ -518,7 +516,7 @@ function stackBars(gd, sa, sieve) {

if(!barnorm) {
if(isNumeric(sa.c2l(barTop))) expandRange(sRange, barTop);
if(isNumeric(sa.c2l(barBase))) expandRange(sRange, barBase);
if(bar.hasB && isNumeric(sa.c2l(barBase))) expandRange(sRange, barBase);
}
}
}
Expand Down Expand Up @@ -584,7 +582,7 @@ function normalizeBars(gd, sa, sieve) {
bar[sLetter] = barTop;

maybeExpand(barTop);
maybeExpand(barBase);
if(bar.hasB) maybeExpand(barBase);
}
}

Expand Down
28 changes: 28 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,34 @@ describe('Bar.setPositions', function() {
expect(Axes.getAutoRange(ya)).toBeCloseToArray([-1.11, 1.11], undefined, '(ya.range)');
});

it('should include explicit base in size axis range', function() {
var barmodes = ['stack', 'group', 'overlay'];
barmodes.forEach(function(barmode) {
var gd = mockBarPlot([
{y: [3, 4, -5], base: [-1, -2, 7]}
], {
barmode: barmode
});

var ya = gd._fullLayout.yaxis;
expect(Axes.getAutoRange(ya)).toBeCloseToArray([-2.5, 7.5]);
});
});

it('should not include date zero (1970) in date axis range', function() {
var barmodes = ['stack', 'group', 'overlay'];
barmodes.forEach(function(barmode) {
var gd = mockBarPlot([
{y: ['2017-01-01', '2017-01-03', '2017-01-19']}
], {
barmode: barmode
});

var ya = gd._fullLayout.yaxis;
expect(Axes.getAutoRange(ya)).toEqual(['2016-12-31', '2017-01-20']);
});
});

it('works with log axes (grouped bars)', function() {
var gd = mockBarPlot([
{y: [1, 10, 1e10, -1]},
Expand Down