Skip to content

Commit fb75158

Browse files
authored
Merge pull request #2638 from plotly/grid-mess-fix
fix #2633 - make sure we have a grid before attaching it to layoutOut
2 parents 42cc18d + 09ee26e commit fb75158

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/components/grid/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function sizeDefaults(layoutIn, layoutOut) {
201201
if(hasXaxes) dfltColumns = xAxes.length;
202202
}
203203

204-
var gridOut = layoutOut.grid = {};
204+
var gridOut = {};
205205

206206
function coerce(attr, dflt) {
207207
return Lib.coerce(gridIn, gridOut, gridAttrs, attr, dflt);
@@ -234,6 +234,8 @@ function sizeDefaults(layoutIn, layoutOut) {
234234
x: fillGridPositions('x', coerce, dfltGapX, dfltSideX, columns),
235235
y: fillGridPositions('y', coerce, dfltGapY, dfltSideY, rows, reversed)
236236
};
237+
238+
layoutOut.grid = gridOut;
237239
}
238240

239241
// coerce x or y sizing attributes and return an array of domains for this direction

test/jasmine/tests/plots_test.js

+29
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,35 @@ describe('grids', function() {
908908
});
909909
}
910910

911+
it('does not barf on invalid grid objects', function(done) {
912+
Plotly.newPlot(gd, makeData(['xy']), {grid: true})
913+
.then(function() {
914+
expect(gd._fullLayout.grid).toBeUndefined();
915+
916+
return Plotly.newPlot(gd, makeData(['xy']), {grid: {}});
917+
})
918+
.then(function() {
919+
expect(gd._fullLayout.grid).toBeUndefined();
920+
921+
return Plotly.newPlot(gd, makeData(['xy']), {grid: {rows: 1, columns: 1}});
922+
})
923+
.then(function() {
924+
expect(gd._fullLayout.grid).toBeUndefined();
925+
926+
// check Plotly.validate on the same grids too
927+
[true, {}, {rows: 1, columns: 1}].forEach(function(gridVal) {
928+
var validation = Plotly.validate([], {grid: gridVal});
929+
expect(validation.length).toBe(1);
930+
expect(validation[0]).toEqual(jasmine.objectContaining({
931+
astr: 'grid',
932+
code: 'unused'
933+
}));
934+
});
935+
})
936+
.catch(failTest)
937+
.then(done);
938+
});
939+
911940
it('defaults to a coupled layout', function(done) {
912941
Plotly.newPlot(gd,
913942
// leave some empty rows/columns

0 commit comments

Comments
 (0)