diff --git a/draftlogs/6796_fix.md b/draftlogs/6796_fix.md new file mode 100644 index 00000000000..dd8aadf0759 --- /dev/null +++ b/draftlogs/6796_fix.md @@ -0,0 +1 @@ + - Fix range defaults to take into account minallowed and maxallowed values [[#6796](https://github.com/plotly/plotly.js/pull/6796)] diff --git a/src/plots/cartesian/set_convert.js b/src/plots/cartesian/set_convert.js index e4e41e2548e..14f17f9c2aa 100644 --- a/src/plots/cartesian/set_convert.js +++ b/src/plots/cartesian/set_convert.js @@ -447,6 +447,23 @@ module.exports = function setConvert(ax, fullLayout) { if(minallowed !== undefined && rng[0] < bounds[0]) range[axrev ? 1 : 0] = minallowed; if(maxallowed !== undefined && rng[1] > bounds[1]) range[axrev ? 0 : 1] = maxallowed; + + if(range[0] === range[1]) { + var minL = ax.l2r(minallowed); + var maxL = ax.l2r(maxallowed); + + if(minallowed !== undefined) { + var _max = minL + 1; + if(maxallowed !== undefined) _max = Math.min(_max, maxL); + range[axrev ? 1 : 0] = _max; + } + + if(maxallowed !== undefined) { + var _min = maxL + 1; + if(minallowed !== undefined) _min = Math.max(_min, minL); + range[axrev ? 0 : 1] = _min; + } + } }; /* diff --git a/src/plots/polar/polar.js b/src/plots/polar/polar.js index fec6113da75..da7da52c1b6 100644 --- a/src/plots/polar/polar.js +++ b/src/plots/polar/polar.js @@ -390,6 +390,24 @@ proto.doAutoRange = function(fullLayout, polarLayout) { radialAxis.r2l(rng[0], null, 'gregorian'), radialAxis.r2l(rng[1], null, 'gregorian') ]; + + if(radialAxis.minallowed !== undefined) { + var minallowed = radialAxis.r2l(radialAxis.minallowed); + if(radialAxis._rl[0] > radialAxis._rl[1]) { + radialAxis._rl[1] = Math.max(radialAxis._rl[1], minallowed); + } else { + radialAxis._rl[0] = Math.max(radialAxis._rl[0], minallowed); + } + } + + if(radialAxis.maxallowed !== undefined) { + var maxallowed = radialAxis.r2l(radialAxis.maxallowed); + if(radialAxis._rl[0] < radialAxis._rl[1]) { + radialAxis._rl[1] = Math.min(radialAxis._rl[1], maxallowed); + } else { + radialAxis._rl[0] = Math.min(radialAxis._rl[0], maxallowed); + } + } }; proto.updateRadialAxis = function(fullLayout, polarLayout) { diff --git a/test/image/baselines/zz-allowed-range-small.png b/test/image/baselines/zz-allowed-range-small.png new file mode 100644 index 00000000000..22e662ea4cd Binary files /dev/null and b/test/image/baselines/zz-allowed-range-small.png differ diff --git a/test/image/baselines/zz-allowed-range.png b/test/image/baselines/zz-allowed-range.png new file mode 100644 index 00000000000..05c73586d37 Binary files /dev/null and b/test/image/baselines/zz-allowed-range.png differ diff --git a/test/image/mocks/zz-allowed-range-small.json b/test/image/mocks/zz-allowed-range-small.json new file mode 100644 index 00000000000..c14383fe438 --- /dev/null +++ b/test/image/mocks/zz-allowed-range-small.json @@ -0,0 +1,81 @@ +{ + "data": [ + { + "type": "scatter", + "mode": "markers", + "xaxis": "x", + "yaxis": "y", + "x": [0,1,2,3,4,5,6,7,8,9,10], + "y":[0,10,20,30,40,50,60,70,80,90,100] + }, + { + "type": "scatter", + "mode": "markers", + "xaxis": "x2", + "yaxis": "y2", + "x": [0,1,2,3,4,5,6,7,8,9,10], + "y":[0,10,20,30,40,50,60,70,80,90,100] + }, + { + "type": "scatterpolar", + "mode": "markers", + "subplot": "polar", + "r": [0,1,2,3,4,5,6,7,8,9,10], + "theta":[0,10,20,30,40,50,60,70,80,90,100] + }, + { + "type": "scatterpolar", + "mode": "markers", + "subplot": "polar2", + "r": [0,1,2,3,4,5,6,7,8,9,10], + "theta":[0,10,20,30,40,50,60,70,80,90,100] + } + ], + "layout": { + "showlegend": false, + "width": 800, + "height": 800, + "xaxis": { + "anchor": "y", + "domain": [0, 0.45], + "maxallowed": 6.2, + "minallowed": 5.8 + }, + "yaxis": { + "anchor": "x", + "domain": [0, 0.45] + }, + "xaxis2": { + "autorange": "reversed", + "anchor": "y2", + "domain": [0, 0.45], + "maxallowed": 6.2, + "minallowed": 5.8 + }, + "yaxis2": { + "anchor": "x2", + "domain": [0.55, 1] + }, + "polar": { + "domain": { + "x": [0.55, 1], + "y": [0, 0.45] + }, + "radialaxis": { + "maxallowed": 6.2, + "minallowed": 5.8 + } + }, + "polar2": { + "domain": { + "x": [0.55, 1], + "y": [0.55, 1] + }, + "radialaxis": { + "autorange": "reversed", + "maxallowed": 6.2, + "minallowed": 5.8 + } + } + } +} diff --git a/test/image/mocks/zz-allowed-range.json b/test/image/mocks/zz-allowed-range.json new file mode 100644 index 00000000000..ff3c3762819 --- /dev/null +++ b/test/image/mocks/zz-allowed-range.json @@ -0,0 +1,77 @@ +{ + "data": [ + { + "type": "scatter", + "mode": "markers", + "xaxis": "x", + "yaxis": "y", + "x": [0,1,2,3,4,5,6,7,8,9,10], + "y":[0,10,20,30,40,50,60,70,80,90,100] + }, + { + "type": "scatter", + "mode": "markers", + "xaxis": "x2", + "yaxis": "y2", + "x": [0,1,2,3,4,5,6,7,8,9,10], + "y":[0,10,20,30,40,50,60,70,80,90,100] + }, + { + "type": "scatterpolar", + "mode": "markers", + "subplot": "polar", + "r": [0,1,2,3,4,5,6,7,8,9,10], + "theta":[0,10,20,30,40,50,60,70,80,90,100] + }, + { + "type": "scatterpolar", + "mode": "markers", + "subplot": "polar2", + "r": [0,1,2,3,4,5,6,7,8,9,10], + "theta":[0,10,20,30,40,50,60,70,80,90,100] + } + ], + "layout": { + "showlegend": false, + "width": 800, + "height": 800, + "xaxis": { + "anchor": "y", + "domain": [0, 0.45], + "minallowed": 6 + }, + "yaxis": { + "anchor": "x", + "domain": [0, 0.45] + }, + "xaxis2": { + "autorange": "reversed", + "anchor": "y2", + "domain": [0, 0.45], + "minallowed": 6 + }, + "yaxis2": { + "anchor": "x2", + "domain": [0.55, 1] + }, + "polar": { + "domain": { + "x": [0.55, 1], + "y": [0, 0.45] + }, + "radialaxis": { + "minallowed": 6 + } + }, + "polar2": { + "domain": { + "x": [0.55, 1], + "y": [0.55, 1] + }, + "radialaxis": { + "autorange": "reversed", + "minallowed": 6 + } + } + } +}