From 2d84a8fba7aa27f36ff3c61e0e07616ab12cfd66 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Tue, 15 May 2018 17:21:31 -0400 Subject: [PATCH 1/2] fix #2633 - make sure we have a grid before attaching it to layoutOut --- src/components/grid/index.js | 4 +++- test/jasmine/tests/plots_test.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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..8e1a2120371 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -908,6 +908,25 @@ 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(); + }) + .catch(failTest) + .then(done); + }); + it('defaults to a coupled layout', function(done) { Plotly.newPlot(gd, // leave some empty rows/columns From 09ee26e0cf5dcf09b53b7dc3ea787c34c57407b2 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Wed, 16 May 2018 10:43:35 -0400 Subject: [PATCH 2/2] test Plotly.validate for bad grids too --- test/jasmine/tests/plots_test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index 8e1a2120371..9fd68668f06 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -922,6 +922,16 @@ describe('grids', function() { }) .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);