Skip to content

Commit

Permalink
Merge pull request #2638 from plotly/grid-mess-fix
Browse files Browse the repository at this point in the history
fix #2633 - make sure we have a grid before attaching it to layoutOut
  • Loading branch information
alexcjohnson authored May 16, 2018
2 parents 42cc18d + 09ee26e commit fb75158
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/grid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ function sizeDefaults(layoutIn, layoutOut) {
if(hasXaxes) dfltColumns = xAxes.length;
}

var gridOut = layoutOut.grid = {};
var gridOut = {};

function coerce(attr, dflt) {
return Lib.coerce(gridIn, gridOut, gridAttrs, attr, dflt);
Expand Down Expand Up @@ -234,6 +234,8 @@ function sizeDefaults(layoutIn, layoutOut) {
x: fillGridPositions('x', coerce, dfltGapX, dfltSideX, columns),
y: fillGridPositions('y', coerce, dfltGapY, dfltSideY, rows, reversed)
};

layoutOut.grid = gridOut;
}

// coerce x or y sizing attributes and return an array of domains for this direction
Expand Down
29 changes: 29 additions & 0 deletions test/jasmine/tests/plots_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,35 @@ describe('grids', function() {
});
}

it('does not barf on invalid grid objects', function(done) {
Plotly.newPlot(gd, makeData(['xy']), {grid: true})
.then(function() {
expect(gd._fullLayout.grid).toBeUndefined();

return Plotly.newPlot(gd, makeData(['xy']), {grid: {}});
})
.then(function() {
expect(gd._fullLayout.grid).toBeUndefined();

return Plotly.newPlot(gd, makeData(['xy']), {grid: {rows: 1, columns: 1}});
})
.then(function() {
expect(gd._fullLayout.grid).toBeUndefined();

// check Plotly.validate on the same grids too
[true, {}, {rows: 1, columns: 1}].forEach(function(gridVal) {
var validation = Plotly.validate([], {grid: gridVal});
expect(validation.length).toBe(1);
expect(validation[0]).toEqual(jasmine.objectContaining({
astr: 'grid',
code: 'unused'
}));
});
})
.catch(failTest)
.then(done);
});

it('defaults to a coupled layout', function(done) {
Plotly.newPlot(gd,
// leave some empty rows/columns
Expand Down

0 comments on commit fb75158

Please sign in to comment.