Skip to content

Layout grids #2399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🔪 grid.gap
  • Loading branch information
alexcjohnson committed Feb 25, 2018
commit 670bdd59bb696fb5ef6bf0d785a183632451ba8c
29 changes: 8 additions & 21 deletions src/plots/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,6 @@ var gridAttrs = exports.attributes = {
'then iterating rows according to `roworder`.'
].join(' ')
},
gap: {
valType: 'number',
min: 0,
max: 1,
dflt: 0.1,
role: 'info',
editType: 'calc',
description: [
'Space between grid cells, expressed as a fraction of the total',
'width or height available to one cell. You can also use `xgap`',
'and `ygap` to space x and y differently. Defaults to 0.1 for',
'coupled-axes grids and 0.25 for independent grids.'
].join(' ')
},
xgap: {
valType: 'number',
min: 0,
Expand All @@ -131,7 +117,8 @@ var gridAttrs = exports.attributes = {
editType: 'calc',
description: [
'Horizontal space between grid cells, expressed as a fraction',
'of the total width available to one cell.'
'of the total width available to one cell. Defaults to 0.1',
'for coupled-axes grids and 0.2 for independent grids.'
].join(' ')
},
ygap: {
Expand All @@ -142,7 +129,8 @@ var gridAttrs = exports.attributes = {
editType: 'calc',
description: [
'Vertical space between grid cells, expressed as a fraction',
'of the total height available to one cell.'
'of the total height available to one cell. Defaults to 0.1',
'for coupled-axes grids and 0.3 for independent grids.'
].join(' ')
},
domain: domainAttrs({name: 'grid', editType: 'calc', noGridCell: true}, {
Expand Down Expand Up @@ -218,17 +206,16 @@ exports.sizeDefaults = function(layoutIn, layoutOut) {

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

gridOut._domains = {
x: fillGridPositions('x', coerce, gap, columns),
y: fillGridPositions('y', coerce, gap, rows, reversed)
x: fillGridPositions('x', coerce, hasSubplotGrid ? 0.2 : 0.1, columns),
y: fillGridPositions('y', coerce, hasSubplotGrid ? 0.3 : 0.1, rows, reversed)
};
};

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

Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/grid_subplot_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"yaxis2": {"title": "y2"},
"xaxis3": {"title": "x3"},
"yaxis3": {"title": "y3"},
"grid": {"rows": 3, "columns": 3, "gap": 0.3},
"grid": {"rows": 3, "columns": 3, "xgap": 0.3, "ygap": 0.3},
"scene": {"domain": {"row": 1, "column": 1}},
"ternary": {"domain": {"row": 1, "column": 2}},
"geo": {"domain": {"row": 2, "column": 1}},
Expand Down
52 changes: 21 additions & 31 deletions test/jasmine/tests/plots_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,12 +940,12 @@ describe('grids', function() {
)
.then(function() {
_assertDomains({
xaxis2: [1 / 2.75, 1.75 / 2.75],
yaxis2: [2 / 2.75, 1],
xaxis3: [2 / 2.75, 1],
yaxis3: [2 / 2.75, 1],
xaxis4: [0, 0.75 / 2.75],
yaxis4: [1 / 2.75, 1.75 / 2.75]
xaxis2: [1 / 2.8, 1.8 / 2.8],
yaxis2: [2 / 2.7, 1],
xaxis3: [2 / 2.8, 1],
yaxis3: [2 / 2.7, 1],
xaxis4: [0, 0.8 / 2.8],
yaxis4: [1 / 2.7, 1.7 / 2.7]
});
_assertMissing(['xaxis', 'yaxis']);

Expand All @@ -955,33 +955,33 @@ describe('grids', function() {
})
.then(function() {
_assertDomains({
xaxis2: [1 / 2.75, 1.75 / 2.75],
yaxis2: [0, 0.75 / 2.75],
xaxis3: [2 / 2.75, 1],
yaxis3: [2 / 2.75, 1],
xaxis4: [0, 0.75 / 2.75],
yaxis4: [2 / 2.75, 1]
xaxis2: [1 / 2.8, 1.8 / 2.8],
yaxis2: [0, 0.7 / 2.7],
xaxis3: [2 / 2.8, 1],
yaxis3: [2 / 2.7, 1],
xaxis4: [0, 0.8 / 2.8],
yaxis4: [2 / 2.7, 1]
});
_assertMissing(['xaxis', 'yaxis']);

return Plotly.relayout(gd, {'grid.roworder': 'bottom to top'});
})
.then(function() {
_assertDomains({
xaxis2: [1 / 2.75, 1.75 / 2.75],
yaxis2: [2 / 2.75, 1],
xaxis3: [2 / 2.75, 1],
yaxis3: [0, 0.75 / 2.75],
xaxis4: [0, 0.75 / 2.75],
yaxis4: [0, 0.75 / 2.75]
xaxis2: [1 / 2.8, 1.8 / 2.8],
yaxis2: [2 / 2.7, 1],
xaxis3: [2 / 2.8, 1],
yaxis3: [0, 0.7 / 2.7],
xaxis4: [0, 0.8 / 2.8],
yaxis4: [0, 0.7 / 2.7]
});
_assertMissing(['xaxis', 'yaxis']);
})
.catch(failTest)
.then(done);
});

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

return Plotly.relayout(gd, {'grid.gap': 0.4});
})
.then(function() {
_assertDomains({
xaxis: [0, 0.6 / 1.6],
yaxis: [1 / 1.6, 1],
xaxis2: [1 / 1.6, 1],
yaxis2: [0, 0.6 / 1.6]
});

return Plotly.relayout(gd, {'grid.xgap': 0.2});
})
.then(function() {
_assertDomains({
xaxis: [0, 0.8 / 1.8],
yaxis: [1 / 1.6, 1],
yaxis: [1 / 1.9, 1],
xaxis2: [1 / 1.8, 1],
yaxis2: [0, 0.6 / 1.6]
yaxis2: [0, 0.9 / 1.9]
});

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