Skip to content

Commit b283919

Browse files
committed
better grid.(x|y)side defaults for splom
1 parent f2569c3 commit b283919

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

src/components/grid/index.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ function sizeDefaults(layoutIn, layoutOut) {
185185
var hasSubplotGrid = Array.isArray(gridIn.subplots) && Array.isArray(gridIn.subplots[0]);
186186
var hasXaxes = Array.isArray(xAxes);
187187
var hasYaxes = Array.isArray(yAxes);
188+
var isSplomGenerated = (
189+
hasXaxes && xAxes !== gridIn.xaxes &&
190+
hasYaxes && yAxes !== gridIn.yaxes
191+
);
188192

189193
var dfltRows, dfltColumns;
190194

@@ -217,17 +221,26 @@ function sizeDefaults(layoutIn, layoutOut) {
217221
var rowOrder = coerce('roworder');
218222
var reversed = rowOrder === 'top to bottom';
219223

224+
var dfltGapX = hasSubplotGrid ? 0.2 : 0.1;
225+
var dfltGapY = hasSubplotGrid ? 0.3 : 0.1;
226+
227+
var dfltSideX, dfltSideY;
228+
if(isSplomGenerated) {
229+
dfltSideX = 'bottom';
230+
dfltSideY = 'left';
231+
}
232+
220233
gridOut._domains = {
221-
x: fillGridPositions('x', coerce, hasSubplotGrid ? 0.2 : 0.1, columns),
222-
y: fillGridPositions('y', coerce, hasSubplotGrid ? 0.3 : 0.1, rows, reversed)
234+
x: fillGridPositions('x', coerce, dfltGapX, dfltSideX, columns),
235+
y: fillGridPositions('y', coerce, dfltGapY, dfltSideY, rows, reversed)
223236
};
224237
}
225238

226239
// coerce x or y sizing attributes and return an array of domains for this direction
227-
function fillGridPositions(axLetter, coerce, dfltGap, len, reversed) {
240+
function fillGridPositions(axLetter, coerce, dfltGap, dfltSide, len, reversed) {
228241
var dirGap = coerce(axLetter + 'gap', dfltGap);
229242
var domain = coerce('domain.' + axLetter);
230-
coerce(axLetter + 'side');
243+
coerce(axLetter + 'side', dfltSide);
231244

232245
var out = new Array(len);
233246
var start = domain[0];

test/image/mocks/splom_upper.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,6 @@
694694
"layout": {
695695
"title": "Iris dataset splom",
696696
"width": 600,
697-
"height": 500,
698-
"grid": {
699-
"xside": "bottom",
700-
"yside": "left"
701-
}
697+
"height": 500
702698
}
703699
}

test/jasmine/tests/splom_test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,37 @@ describe('Test splom trace defaults:', function() {
8080
expect(subplots.cartesian).toEqual(['xy', 'xy2', 'x2y', 'x2y2']);
8181
});
8282

83+
it('should use special `grid.xside` and `grid.yside` defaults on splom generated grids', function() {
84+
var gridOut;
85+
86+
_supply({
87+
dimensions: [
88+
{values: [1, 2, 3]},
89+
{values: [2, 1, 2]}
90+
]
91+
});
92+
93+
gridOut = gd._fullLayout.grid;
94+
expect(gridOut.xside).toBe('bottom');
95+
expect(gridOut.yside).toBe('left');
96+
97+
_supply({
98+
dimensions: [
99+
{values: [1, 2, 3]},
100+
{values: [2, 1, 2]}
101+
]
102+
}, {
103+
grid: {
104+
xaxes: ['x', 'x2'],
105+
yaxes: ['y', 'y2']
106+
}
107+
});
108+
109+
gridOut = gd._fullLayout.grid;
110+
expect(gridOut.xside).toBe('bottom plot');
111+
expect(gridOut.yside).toBe('left plot');
112+
});
113+
83114
it('should honor `grid.xaxes` and `grid.yaxes` settings', function() {
84115
_supply({
85116
dimensions: [

0 commit comments

Comments
 (0)