Skip to content

Commit 5a07b46

Browse files
authored
Merge pull request #4304 from plotly/fix4300-handle-bad-plots-domain
do not accept domain ranges where end is not greater than start
2 parents d0cf957 + 74773fb commit 5a07b46

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/plots/domain.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ exports.defaults = function(containerOut, layout, coerce, dfltDomains) {
127127
}
128128
}
129129

130-
coerce('domain.x', dfltX);
131-
coerce('domain.y', dfltY);
130+
var x = coerce('domain.x', dfltX);
131+
var y = coerce('domain.y', dfltY);
132+
133+
// don't accept bad input data
134+
if(!(x[0] < x[1])) containerOut.domain.x = dfltX.slice();
135+
if(!(y[0] < y[1])) containerOut.domain.y = dfltY.slice();
132136
};

test/jasmine/tests/plots_test.js

+21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ describe('Test Plots', function() {
1313
'use strict';
1414

1515
describe('Plots.supplyDefaults', function() {
16+
it('should not accept ranges where the end is not greater than the start', function() {
17+
var gd = {
18+
data: [{
19+
type: 'pie',
20+
domain: {
21+
x: [0.4, 0],
22+
y: [0.5, 0.5]
23+
},
24+
values: [1, 2, 3, 4],
25+
labels: ['a', 'b', 'c', 'd'],
26+
text: ['text', 'should', 'be', 'inside']
27+
}]
28+
};
29+
30+
supplyAllDefaults(gd);
31+
expect(gd._fullData[0].domain.x[0]).toBe(0);
32+
expect(gd._fullData[0].domain.y[1]).toBe(1);
33+
expect(gd._fullData[0].domain.x[0]).toBe(0);
34+
expect(gd._fullData[0].domain.y[1]).toBe(1);
35+
});
36+
1637
it('should not throw an error when gd is a plain object', function() {
1738
var height = 100;
1839
var gd = {

0 commit comments

Comments
 (0)