Skip to content

Commit

Permalink
Merge pull request #4171 from plotly/dflt-range-under-rangemode
Browse files Browse the repository at this point in the history
Adapt default axis ranges to rangemode
  • Loading branch information
etpinard authored Sep 11, 2019
2 parents c727dd1 + 06ee3c0 commit 6c2babd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ module.exports = function setConvert(ax, fullLayout) {
// make sure we don't later mutate the defaults
dflt = dflt.slice();

if(ax.rangemode === 'tozero' || ax.rangemode === 'nonnegative') {
dflt[0] = 0;
}

if(!range || range.length !== 2) {
Lib.nestedProperty(ax, rangeAttr).set(dflt);
return;
Expand Down
19 changes: 19 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,25 @@ describe('Test axes', function() {
_assertMatchingAxes(['xaxis3', 'yaxis3'], true, [-1, 6]);
_assertMatchingAxes(['xaxis4', 'yaxis4'], false, [-1, 3]);
});

it('should adapt default axis ranges to *rangemode*', function() {
layoutIn = {
xaxis: {rangemode: 'tozero'},
yaxis: {rangemode: 'nonnegative'},
xaxis2: {rangemode: 'nonnegative'},
yaxis2: {rangemode: 'tozero'}
};
layoutOut._subplots.cartesian.push('x2y2');
layoutOut._subplots.xaxis.push('x2');
layoutOut._subplots.yaxis.push('y2');

supplyLayoutDefaults(layoutIn, layoutOut, fullData);

expect(layoutOut.xaxis.range).withContext('xaxis range').toEqual([0, 6]);
expect(layoutOut.xaxis2.range).withContext('xaxis2 range').toEqual([0, 6]);
expect(layoutOut.yaxis.range).withContext('yaxis range').toEqual([0, 4]);
expect(layoutOut.yaxis2.range).withContext('yaxis2 range').toEqual([0, 4]);
});
});

describe('constraints relayout', function() {
Expand Down

0 comments on commit 6c2babd

Please sign in to comment.