diff --git a/src/components/grid/index.js b/src/components/grid/index.js index d5986fffc76..357700670f6 100644 --- a/src/components/grid/index.js +++ b/src/components/grid/index.js @@ -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); @@ -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 diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index 27f1d08e848..9fd68668f06 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -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