Skip to content

Commit 5a7cc3e

Browse files
authored
Merge pull request #6796 from plotly/fix6765-range-allowed
Fix range defaults to take into account `minallowed` and `maxallowed` values
2 parents 3368552 + 21148d4 commit 5a7cc3e

File tree

7 files changed

+194
-0
lines changed

7 files changed

+194
-0
lines changed

draftlogs/6796_fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix range defaults to take into account minallowed and maxallowed values [[#6796](https://github.com/plotly/plotly.js/pull/6796)]

src/plots/cartesian/set_convert.js

+17
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,23 @@ module.exports = function setConvert(ax, fullLayout) {
447447

448448
if(minallowed !== undefined && rng[0] < bounds[0]) range[axrev ? 1 : 0] = minallowed;
449449
if(maxallowed !== undefined && rng[1] > bounds[1]) range[axrev ? 0 : 1] = maxallowed;
450+
451+
if(range[0] === range[1]) {
452+
var minL = ax.l2r(minallowed);
453+
var maxL = ax.l2r(maxallowed);
454+
455+
if(minallowed !== undefined) {
456+
var _max = minL + 1;
457+
if(maxallowed !== undefined) _max = Math.min(_max, maxL);
458+
range[axrev ? 1 : 0] = _max;
459+
}
460+
461+
if(maxallowed !== undefined) {
462+
var _min = maxL + 1;
463+
if(minallowed !== undefined) _min = Math.max(_min, minL);
464+
range[axrev ? 0 : 1] = _min;
465+
}
466+
}
450467
};
451468

452469
/*

src/plots/polar/polar.js

+18
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,24 @@ proto.doAutoRange = function(fullLayout, polarLayout) {
390390
radialAxis.r2l(rng[0], null, 'gregorian'),
391391
radialAxis.r2l(rng[1], null, 'gregorian')
392392
];
393+
394+
if(radialAxis.minallowed !== undefined) {
395+
var minallowed = radialAxis.r2l(radialAxis.minallowed);
396+
if(radialAxis._rl[0] > radialAxis._rl[1]) {
397+
radialAxis._rl[1] = Math.max(radialAxis._rl[1], minallowed);
398+
} else {
399+
radialAxis._rl[0] = Math.max(radialAxis._rl[0], minallowed);
400+
}
401+
}
402+
403+
if(radialAxis.maxallowed !== undefined) {
404+
var maxallowed = radialAxis.r2l(radialAxis.maxallowed);
405+
if(radialAxis._rl[0] < radialAxis._rl[1]) {
406+
radialAxis._rl[1] = Math.min(radialAxis._rl[1], maxallowed);
407+
} else {
408+
radialAxis._rl[0] = Math.min(radialAxis._rl[0], maxallowed);
409+
}
410+
}
393411
};
394412

395413
proto.updateRadialAxis = function(fullLayout, polarLayout) {
Loading
90.8 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"data": [
3+
{
4+
"type": "scatter",
5+
"mode": "markers",
6+
"xaxis": "x",
7+
"yaxis": "y",
8+
"x": [0,1,2,3,4,5,6,7,8,9,10],
9+
"y":[0,10,20,30,40,50,60,70,80,90,100]
10+
},
11+
{
12+
"type": "scatter",
13+
"mode": "markers",
14+
"xaxis": "x2",
15+
"yaxis": "y2",
16+
"x": [0,1,2,3,4,5,6,7,8,9,10],
17+
"y":[0,10,20,30,40,50,60,70,80,90,100]
18+
},
19+
{
20+
"type": "scatterpolar",
21+
"mode": "markers",
22+
"subplot": "polar",
23+
"r": [0,1,2,3,4,5,6,7,8,9,10],
24+
"theta":[0,10,20,30,40,50,60,70,80,90,100]
25+
},
26+
{
27+
"type": "scatterpolar",
28+
"mode": "markers",
29+
"subplot": "polar2",
30+
"r": [0,1,2,3,4,5,6,7,8,9,10],
31+
"theta":[0,10,20,30,40,50,60,70,80,90,100]
32+
}
33+
],
34+
"layout": {
35+
"showlegend": false,
36+
"width": 800,
37+
"height": 800,
38+
"xaxis": {
39+
"anchor": "y",
40+
"domain": [0, 0.45],
41+
"maxallowed": 6.2,
42+
"minallowed": 5.8
43+
},
44+
"yaxis": {
45+
"anchor": "x",
46+
"domain": [0, 0.45]
47+
},
48+
"xaxis2": {
49+
"autorange": "reversed",
50+
"anchor": "y2",
51+
"domain": [0, 0.45],
52+
"maxallowed": 6.2,
53+
"minallowed": 5.8
54+
},
55+
"yaxis2": {
56+
"anchor": "x2",
57+
"domain": [0.55, 1]
58+
},
59+
"polar": {
60+
"domain": {
61+
"x": [0.55, 1],
62+
"y": [0, 0.45]
63+
},
64+
"radialaxis": {
65+
"maxallowed": 6.2,
66+
"minallowed": 5.8
67+
}
68+
},
69+
"polar2": {
70+
"domain": {
71+
"x": [0.55, 1],
72+
"y": [0.55, 1]
73+
},
74+
"radialaxis": {
75+
"autorange": "reversed",
76+
"maxallowed": 6.2,
77+
"minallowed": 5.8
78+
}
79+
}
80+
}
81+
}
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"data": [
3+
{
4+
"type": "scatter",
5+
"mode": "markers",
6+
"xaxis": "x",
7+
"yaxis": "y",
8+
"x": [0,1,2,3,4,5,6,7,8,9,10],
9+
"y":[0,10,20,30,40,50,60,70,80,90,100]
10+
},
11+
{
12+
"type": "scatter",
13+
"mode": "markers",
14+
"xaxis": "x2",
15+
"yaxis": "y2",
16+
"x": [0,1,2,3,4,5,6,7,8,9,10],
17+
"y":[0,10,20,30,40,50,60,70,80,90,100]
18+
},
19+
{
20+
"type": "scatterpolar",
21+
"mode": "markers",
22+
"subplot": "polar",
23+
"r": [0,1,2,3,4,5,6,7,8,9,10],
24+
"theta":[0,10,20,30,40,50,60,70,80,90,100]
25+
},
26+
{
27+
"type": "scatterpolar",
28+
"mode": "markers",
29+
"subplot": "polar2",
30+
"r": [0,1,2,3,4,5,6,7,8,9,10],
31+
"theta":[0,10,20,30,40,50,60,70,80,90,100]
32+
}
33+
],
34+
"layout": {
35+
"showlegend": false,
36+
"width": 800,
37+
"height": 800,
38+
"xaxis": {
39+
"anchor": "y",
40+
"domain": [0, 0.45],
41+
"minallowed": 6
42+
},
43+
"yaxis": {
44+
"anchor": "x",
45+
"domain": [0, 0.45]
46+
},
47+
"xaxis2": {
48+
"autorange": "reversed",
49+
"anchor": "y2",
50+
"domain": [0, 0.45],
51+
"minallowed": 6
52+
},
53+
"yaxis2": {
54+
"anchor": "x2",
55+
"domain": [0.55, 1]
56+
},
57+
"polar": {
58+
"domain": {
59+
"x": [0.55, 1],
60+
"y": [0, 0.45]
61+
},
62+
"radialaxis": {
63+
"minallowed": 6
64+
}
65+
},
66+
"polar2": {
67+
"domain": {
68+
"x": [0.55, 1],
69+
"y": [0.55, 1]
70+
},
71+
"radialaxis": {
72+
"autorange": "reversed",
73+
"minallowed": 6
74+
}
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)