Skip to content

Commit 670bdd5

Browse files
committed
🔪 grid.gap
1 parent 40dd784 commit 670bdd5

File tree

3 files changed

+30
-53
lines changed

3 files changed

+30
-53
lines changed

src/plots/grid.js

+8-21
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,6 @@ var gridAttrs = exports.attributes = {
109109
'then iterating rows according to `roworder`.'
110110
].join(' ')
111111
},
112-
gap: {
113-
valType: 'number',
114-
min: 0,
115-
max: 1,
116-
dflt: 0.1,
117-
role: 'info',
118-
editType: 'calc',
119-
description: [
120-
'Space between grid cells, expressed as a fraction of the total',
121-
'width or height available to one cell. You can also use `xgap`',
122-
'and `ygap` to space x and y differently. Defaults to 0.1 for',
123-
'coupled-axes grids and 0.25 for independent grids.'
124-
].join(' ')
125-
},
126112
xgap: {
127113
valType: 'number',
128114
min: 0,
@@ -131,7 +117,8 @@ var gridAttrs = exports.attributes = {
131117
editType: 'calc',
132118
description: [
133119
'Horizontal space between grid cells, expressed as a fraction',
134-
'of the total width available to one cell.'
120+
'of the total width available to one cell. Defaults to 0.1',
121+
'for coupled-axes grids and 0.2 for independent grids.'
135122
].join(' ')
136123
},
137124
ygap: {
@@ -142,7 +129,8 @@ var gridAttrs = exports.attributes = {
142129
editType: 'calc',
143130
description: [
144131
'Vertical space between grid cells, expressed as a fraction',
145-
'of the total height available to one cell.'
132+
'of the total height available to one cell. Defaults to 0.1',
133+
'for coupled-axes grids and 0.3 for independent grids.'
146134
].join(' ')
147135
},
148136
domain: domainAttrs({name: 'grid', editType: 'calc', noGridCell: true}, {
@@ -218,17 +206,16 @@ exports.sizeDefaults = function(layoutIn, layoutOut) {
218206

219207
var rowOrder = coerce('roworder');
220208
var reversed = rowOrder === 'top to bottom';
221-
var gap = coerce('gap', hasSubplotGrid ? 0.25 : 0.1);
222209

223210
gridOut._domains = {
224-
x: fillGridPositions('x', coerce, gap, columns),
225-
y: fillGridPositions('y', coerce, gap, rows, reversed)
211+
x: fillGridPositions('x', coerce, hasSubplotGrid ? 0.2 : 0.1, columns),
212+
y: fillGridPositions('y', coerce, hasSubplotGrid ? 0.3 : 0.1, rows, reversed)
226213
};
227214
};
228215

229216
// coerce x or y sizing attributes and return an array of domains for this direction
230-
function fillGridPositions(axLetter, coerce, gap, len, reversed) {
231-
var dirGap = coerce(axLetter + 'gap', gap);
217+
function fillGridPositions(axLetter, coerce, dfltGap, len, reversed) {
218+
var dirGap = coerce(axLetter + 'gap', dfltGap);
232219
var domain = coerce('domain.' + axLetter);
233220
coerce(axLetter + 'side');
234221

test/image/mocks/grid_subplot_types.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"yaxis2": {"title": "y2"},
2323
"xaxis3": {"title": "x3"},
2424
"yaxis3": {"title": "y3"},
25-
"grid": {"rows": 3, "columns": 3, "gap": 0.3},
25+
"grid": {"rows": 3, "columns": 3, "xgap": 0.3, "ygap": 0.3},
2626
"scene": {"domain": {"row": 1, "column": 1}},
2727
"ternary": {"domain": {"row": 1, "column": 2}},
2828
"geo": {"domain": {"row": 2, "column": 1}},

test/jasmine/tests/plots_test.js

+21-31
Original file line numberDiff line numberDiff line change
@@ -940,12 +940,12 @@ describe('grids', function() {
940940
)
941941
.then(function() {
942942
_assertDomains({
943-
xaxis2: [1 / 2.75, 1.75 / 2.75],
944-
yaxis2: [2 / 2.75, 1],
945-
xaxis3: [2 / 2.75, 1],
946-
yaxis3: [2 / 2.75, 1],
947-
xaxis4: [0, 0.75 / 2.75],
948-
yaxis4: [1 / 2.75, 1.75 / 2.75]
943+
xaxis2: [1 / 2.8, 1.8 / 2.8],
944+
yaxis2: [2 / 2.7, 1],
945+
xaxis3: [2 / 2.8, 1],
946+
yaxis3: [2 / 2.7, 1],
947+
xaxis4: [0, 0.8 / 2.8],
948+
yaxis4: [1 / 2.7, 1.7 / 2.7]
949949
});
950950
_assertMissing(['xaxis', 'yaxis']);
951951

@@ -955,33 +955,33 @@ describe('grids', function() {
955955
})
956956
.then(function() {
957957
_assertDomains({
958-
xaxis2: [1 / 2.75, 1.75 / 2.75],
959-
yaxis2: [0, 0.75 / 2.75],
960-
xaxis3: [2 / 2.75, 1],
961-
yaxis3: [2 / 2.75, 1],
962-
xaxis4: [0, 0.75 / 2.75],
963-
yaxis4: [2 / 2.75, 1]
958+
xaxis2: [1 / 2.8, 1.8 / 2.8],
959+
yaxis2: [0, 0.7 / 2.7],
960+
xaxis3: [2 / 2.8, 1],
961+
yaxis3: [2 / 2.7, 1],
962+
xaxis4: [0, 0.8 / 2.8],
963+
yaxis4: [2 / 2.7, 1]
964964
});
965965
_assertMissing(['xaxis', 'yaxis']);
966966

967967
return Plotly.relayout(gd, {'grid.roworder': 'bottom to top'});
968968
})
969969
.then(function() {
970970
_assertDomains({
971-
xaxis2: [1 / 2.75, 1.75 / 2.75],
972-
yaxis2: [2 / 2.75, 1],
973-
xaxis3: [2 / 2.75, 1],
974-
yaxis3: [0, 0.75 / 2.75],
975-
xaxis4: [0, 0.75 / 2.75],
976-
yaxis4: [0, 0.75 / 2.75]
971+
xaxis2: [1 / 2.8, 1.8 / 2.8],
972+
yaxis2: [2 / 2.7, 1],
973+
xaxis3: [2 / 2.8, 1],
974+
yaxis3: [0, 0.7 / 2.7],
975+
xaxis4: [0, 0.8 / 2.8],
976+
yaxis4: [0, 0.7 / 2.7]
977977
});
978978
_assertMissing(['xaxis', 'yaxis']);
979979
})
980980
.catch(failTest)
981981
.then(done);
982982
});
983983

984-
it('can set x and y gaps together or separately and change domain', function(done) {
984+
it('can set x and y gaps and change domain', function(done) {
985985
Plotly.newPlot(gd,
986986
// leave some empty rows/columns
987987
makeData(['xy', 'x2y2']),
@@ -995,24 +995,14 @@ describe('grids', function() {
995995
yaxis2: [0, 0.9 / 1.9]
996996
});
997997

998-
return Plotly.relayout(gd, {'grid.gap': 0.4});
999-
})
1000-
.then(function() {
1001-
_assertDomains({
1002-
xaxis: [0, 0.6 / 1.6],
1003-
yaxis: [1 / 1.6, 1],
1004-
xaxis2: [1 / 1.6, 1],
1005-
yaxis2: [0, 0.6 / 1.6]
1006-
});
1007-
1008998
return Plotly.relayout(gd, {'grid.xgap': 0.2});
1009999
})
10101000
.then(function() {
10111001
_assertDomains({
10121002
xaxis: [0, 0.8 / 1.8],
1013-
yaxis: [1 / 1.6, 1],
1003+
yaxis: [1 / 1.9, 1],
10141004
xaxis2: [1 / 1.8, 1],
1015-
yaxis2: [0, 0.6 / 1.6]
1005+
yaxis2: [0, 0.9 / 1.9]
10161006
});
10171007

10181008
return Plotly.relayout(gd, {'grid.ygap': 0.3});

0 commit comments

Comments
 (0)