Skip to content

Commit

Permalink
move grid module to components/
Browse files Browse the repository at this point in the history
... so that its attributes are added to the schema
    free of circular deps.
  • Loading branch information
etpinard committed Mar 1, 2018
1 parent f8e7ee4 commit bee37dd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
32 changes: 22 additions & 10 deletions src/plots/grid.js → src/components/grid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

'use strict';

var Lib = require('../lib');
var domainAttrs = require('./domain').attributes;
var counterRegex = require('../lib/regex').counter;
var cartesianIdRegex = require('./cartesian/constants').idRegex;
var Lib = require('../../lib');
var counterRegex = require('../../lib/regex').counter;
var domainAttrs = require('../../plots/domain').attributes;
var cartesianIdRegex = require('../../plots/cartesian/constants').idRegex;


var gridAttrs = exports.attributes = {
var gridAttrs = {
rows: {
valType: 'integer',
min: 1,
Expand Down Expand Up @@ -168,7 +167,7 @@ var gridAttrs = exports.attributes = {

// the shape of the grid - this needs to be done BEFORE supplyDataDefaults
// so that non-subplot traces can place themselves in the grid
exports.sizeDefaults = function(layoutIn, layoutOut) {
function sizeDefaults(layoutIn, layoutOut) {
var gridIn = layoutIn.grid;
if(!gridIn) return;

Expand Down Expand Up @@ -211,7 +210,7 @@ exports.sizeDefaults = function(layoutIn, layoutOut) {
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, dfltGap, len, reversed) {
Expand All @@ -232,7 +231,7 @@ function fillGridPositions(axLetter, coerce, dfltGap, len, reversed) {

// the (cartesian) contents of the grid - this needs to happen AFTER supplyDataDefaults
// so that we know what cartesian subplots are available
exports.contentDefaults = function(layoutIn, layoutOut) {
function contentDefaults(layoutIn, layoutOut) {
var gridOut = layoutOut.grid;
// make sure we got to the end of handleGridSizing
if(!gridOut || !gridOut._domains) return;
Expand Down Expand Up @@ -368,7 +367,7 @@ exports.contentDefaults = function(layoutIn, layoutOut) {
}
}
}
};
}

function fillGridAxes(axesIn, axesAllowed, len, axisMap, axLetter) {
var out = new Array(len);
Expand Down Expand Up @@ -397,3 +396,16 @@ function fillGridAxes(axesIn, axesAllowed, len, axisMap, axLetter) {

return out;
}

module.exports = {
moduleType: 'component',
name: 'grid',

schema: {
layout: {grid: gridAttrs}
},

layoutAttributes: gridAttrs,
sizeDefaults: sizeDefaults,
contentDefaults: contentDefaults
};
3 changes: 2 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ exports.register([
require('./components/updatemenus'),
require('./components/sliders'),
require('./components/rangeslider'),
require('./components/rangeselector')
require('./components/rangeselector'),
require('./components/grid'),
]);

// locales en and en-US are required for default behavior
Expand Down
4 changes: 1 addition & 3 deletions src/plots/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

var fontAttrs = require('./font_attributes');
var colorAttrs = require('../components/color/attributes');
var gridAttrs = require('./grid').attributes;

var globalFont = fontAttrs({
editType: 'calc',
Expand Down Expand Up @@ -196,6 +195,5 @@ module.exports = {
'being treated as immutable, thus any data array with a',
'different identity from its predecessor contains new data.'
].join(' ')
},
grid: gridAttrs
}
};
2 changes: 1 addition & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var axisIDs = require('../plots/cartesian/axis_ids');
var Lib = require('../lib');
var _ = Lib._;
var Color = require('../components/color');
var Grid = require('../components/grid');
var BADNUM = require('../constants/numerical').BADNUM;
var Grid = require('./grid');

var plots = module.exports = {};

Expand Down

0 comments on commit bee37dd

Please sign in to comment.