Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions src/plots/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ exports.defaults = function(containerOut, layout, coerce, dfltDomains) {
}
}

coerce('domain.x', dfltX);
coerce('domain.y', dfltY);
var x = coerce('domain.x', dfltX);
var y = coerce('domain.y', dfltY);

// don't accept bad input data
if(!(x[0] < x[1])) containerOut.domain.x = dfltX;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would dfltX.slice() here. I'm sure it ever happens for traces calling plots/domain.js, but we do mutate the domain sometimes (e.g. when applying scaleanchor constraints), so I would keep things on the safe side.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Done in 74773fb

if(!(y[0] < y[1])) containerOut.domain.y = dfltY;
};
21 changes: 21 additions & 0 deletions test/jasmine/tests/plots_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ describe('Test Plots', function() {
'use strict';

describe('Plots.supplyDefaults', function() {
it('should not accept ranges where the end is not greater than the start', function() {
var gd = {
data: [{
type: 'pie',
domain: {
x: [0.4, 0],
y: [0.5, 0.5]
},
values: [1, 2, 3, 4],
labels: ['a', 'b', 'c', 'd'],
text: ['text', 'should', 'be', 'inside']
}]
};

supplyAllDefaults(gd);
expect(gd._fullData[0].domain.x[0]).toBe(0);
expect(gd._fullData[0].domain.y[1]).toBe(1);
expect(gd._fullData[0].domain.x[0]).toBe(0);
expect(gd._fullData[0].domain.y[1]).toBe(1);
});

it('should not throw an error when gd is a plain object', function() {
var height = 100;
var gd = {
Expand Down