Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,23 +445,25 @@ module.exports = function setConvert(ax, fullLayout) {

var bounds = Lib.simpleMap([minallowed, maxallowed], ax.r2l);

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 && rng[0] < bounds[0]) {
range[axrev ? 1 : 0] = minallowed;
rng[0] = bounds[0];
}
if(maxallowed !== undefined && rng[1] > bounds[1]) {
range[axrev ? 0 : 1] = maxallowed;
rng[1] = bounds[1];
}

// If clamping collapsed or inverted the range, extend the opposite end
// so we preserve the original orientation. Otherwise a default range
// entirely below minallowed (or above maxallowed) would flip the axis.
if(rng[0] >= rng[1]) {
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;
var _max = bounds[0] + 1;
if(maxallowed !== undefined) _max = Math.min(_max, bounds[1]);
range[axrev ? 0 : 1] = ax.l2r(_max);
} else if(maxallowed !== undefined) {
range[axrev ? 1 : 0] = ax.l2r(bounds[1] - 1);
}
}
};
Expand Down
Binary file modified test/image/baselines/allowed-range-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/allowed-range.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,65 @@ describe('Test axes', function() {
});
});

describe('minallowed / maxallowed', function() {
// regression test for https://github.com/plotly/plotly.js/issues/7717
var gd;

beforeEach(function() { gd = createGraphDiv(); });
afterEach(destroyGraphDiv);

function expectForward(done, minallowed) {
Plotly.newPlot(gd, [{
x: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
y: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}], {
xaxis: { minallowed: minallowed }
}).then(function() {
var r = gd._fullLayout.xaxis.range;
expect(r[0]).toBeLessThan(r[1], 'axis should not be reversed for minallowed=' + minallowed);
expect(r[0]).toBe(minallowed, 'axis min should be pinned at minallowed');
}).then(done, done.fail);
}

it('does not reverse axis when minallowed exceeds default range max', function(done) {
expectForward(done, 7);
});

it('does not reverse axis when minallowed equals default range max', function(done) {
expectForward(done, 6);
});

it('does not reverse axis when minallowed is well above default range max', function(done) {
expectForward(done, 100);
});

it('keeps explicit autorange:reversed even when minallowed is set', function(done) {
Plotly.newPlot(gd, [{
x: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
y: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}], {
xaxis: { autorange: 'reversed', minallowed: 7 }
}).then(function() {
var r = gd._fullLayout.xaxis.range;
expect(r[0]).toBeGreaterThan(r[1], 'axis should remain reversed');
expect(r[1]).toBe(7, 'min slot (range[1] when reversed) should be minallowed');
}).then(done, done.fail);
});

it('does not reverse axis when maxallowed is below default range min', function(done) {
Plotly.newPlot(gd, [{
x: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
y: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}], {
xaxis: { maxallowed: -2 }
}).then(function() {
var r = gd._fullLayout.xaxis.range;
expect(r[0]).toBeLessThan(r[1], 'axis should not be reversed');
expect(r[1]).toBe(-2, 'axis max should be pinned at maxallowed');
}).then(done, done.fail);
});
});

describe('constraints relayout', function() {
var gd;

Expand Down
Loading