From 06ee3c0e7d7849208d03a7b2ca243e1c7fedded6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= <etienne@plot.ly>
Date: Fri, 6 Sep 2019 18:02:06 -0400
Subject: [PATCH] fix #4137 - adapt default axis ranges to *rangemode*'

... so that even if no `_extremes` stash get filled in,
    ax.rangemode still as an effect.
---
 src/plots/cartesian/set_convert.js |  4 ++++
 test/jasmine/tests/axes_test.js    | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/src/plots/cartesian/set_convert.js b/src/plots/cartesian/set_convert.js
index 5781b4490ad..c1851741389 100644
--- a/src/plots/cartesian/set_convert.js
+++ b/src/plots/cartesian/set_convert.js
@@ -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;
diff --git a/test/jasmine/tests/axes_test.js b/test/jasmine/tests/axes_test.js
index 7507d27ea9e..a95080538e6 100644
--- a/test/jasmine/tests/axes_test.js
+++ b/test/jasmine/tests/axes_test.js
@@ -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() {