Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6c2babd

Browse filesBrowse files
authored
Merge pull request plotly#4171 from plotly/dflt-range-under-rangemode
Adapt default axis ranges to rangemode
2 parents c727dd1 + 06ee3c0 commit 6c2babd
Copy full SHA for 6c2babd

File tree

Expand file treeCollapse file tree

2 files changed

+23
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-0
lines changed

‎src/plots/cartesian/set_convert.js

Copy file name to clipboardExpand all lines: src/plots/cartesian/set_convert.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ module.exports = function setConvert(ax, fullLayout) {
398398
// make sure we don't later mutate the defaults
399399
dflt = dflt.slice();
400400

401+
if(ax.rangemode === 'tozero' || ax.rangemode === 'nonnegative') {
402+
dflt[0] = 0;
403+
}
404+
401405
if(!range || range.length !== 2) {
402406
Lib.nestedProperty(ax, rangeAttr).set(dflt);
403407
return;

‎test/jasmine/tests/axes_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/axes_test.js
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,25 @@ describe('Test axes', function() {
870870
_assertMatchingAxes(['xaxis3', 'yaxis3'], true, [-1, 6]);
871871
_assertMatchingAxes(['xaxis4', 'yaxis4'], false, [-1, 3]);
872872
});
873+
874+
it('should adapt default axis ranges to *rangemode*', function() {
875+
layoutIn = {
876+
xaxis: {rangemode: 'tozero'},
877+
yaxis: {rangemode: 'nonnegative'},
878+
xaxis2: {rangemode: 'nonnegative'},
879+
yaxis2: {rangemode: 'tozero'}
880+
};
881+
layoutOut._subplots.cartesian.push('x2y2');
882+
layoutOut._subplots.xaxis.push('x2');
883+
layoutOut._subplots.yaxis.push('y2');
884+
885+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
886+
887+
expect(layoutOut.xaxis.range).withContext('xaxis range').toEqual([0, 6]);
888+
expect(layoutOut.xaxis2.range).withContext('xaxis2 range').toEqual([0, 6]);
889+
expect(layoutOut.yaxis.range).withContext('yaxis range').toEqual([0, 4]);
890+
expect(layoutOut.yaxis2.range).withContext('yaxis2 range').toEqual([0, 4]);
891+
});
873892
});
874893

875894
describe('constraints relayout', function() {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.