Skip to content

Refactor PlotSchema #1144

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 11 commits into from
Nov 15, 2016
2 changes: 1 addition & 1 deletion src/components/annotations/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var extendFlat = require('../../lib/extend').extendFlat;


module.exports = {
_isLinkedToArray: true,
_isLinkedToArray: 'annotation',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never been able to figure out quite what _isLinkedToArray actually does. It seems to remove the key and trigger some sort of crawl with a key of length - 1 which seems like the sort of thing that would de-pluralize, but this is just a guess.

Perhaps it's a way of defining, for example, button attrs but using a buttons container?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never been able to figure out quite what _isLinkedToArray

It's essentially the plot schema version of Plots.layoutArrayContainers. With this PR, both are now united.

Giving a name to the items in the array container is (again) only relevant for plotly.py at the moment. Previously, the item names were simply the container name minus the 's'. This PR make item naming more robust / flexible.


visible: {
valType: 'boolean',
Expand Down
30 changes: 9 additions & 21 deletions src/components/annotations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,16 @@

'use strict';

var Plotly = require('../../plotly');

exports.moduleType = 'component';

exports.name = 'annotations';

exports.ARROWPATHS = require('./arrow_paths');

exports.layoutAttributes = require('./attributes');

exports.supplyLayoutDefaults = require('./defaults');

exports.calcAutorange = require('./calc_autorange');

exports.arrowhead = require('./draw_arrow_head');

var drawModule = require('./draw');
exports.draw = drawModule.draw;
exports.drawOne = drawModule.drawOne;

exports.add = function(gd) {
var nextAnn = gd._fullLayout.annotations.length;
module.exports = {
moduleType: 'component',
name: 'annotations',

layoutAttributes: require('./attributes'),
supplyLayoutDefaults: require('./defaults'),

Plotly.relayout(gd, 'annotations[' + nextAnn + ']', 'add');
calcAutorange: require('./calc_autorange'),
draw: drawModule.draw,
drawOne: drawModule.drawOne
};
2 changes: 1 addition & 1 deletion src/components/images/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var cartesianConstants = require('../../plots/cartesian/constants');


module.exports = {
_isLinkedToArray: true,
_isLinkedToArray: 'image',

visible: {
valType: 'boolean',
Expand Down
14 changes: 5 additions & 9 deletions src/components/images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@

'use strict';


var draw = require('./draw');
var supplyLayoutDefaults = require('./defaults');
var attributes = require('./attributes');


module.exports = {
moduleType: 'component',
name: 'images',
draw: draw,
layoutAttributes: attributes,
supplyLayoutDefaults: supplyLayoutDefaults

layoutAttributes: require('./attributes'),
supplyLayoutDefaults: require('./defaults'),

draw: require('./draw')
};
20 changes: 8 additions & 12 deletions src/components/legend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@
'use strict';


var legend = module.exports = {};
module.exports = {
moduleType: 'component',
name: 'legend',

layoutAttributes: require('./attributes'),
supplyLayoutDefaults: require('./defaults'),

legend.moduleType = 'component';

legend.name = 'legend';

legend.layoutAttributes = require('./attributes');

legend.supplyLayoutDefaults = require('./defaults');

legend.draw = require('./draw');

legend.style = require('./style');
draw: require('./draw'),
style: require('./style')
};
3 changes: 2 additions & 1 deletion src/components/rangeselector/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var extendFlat = require('../../lib/extend').extendFlat;
var buttonAttrs = require('./button_attributes');

buttonAttrs = extendFlat(buttonAttrs, {
_isLinkedToArray: true,
_isLinkedToArray: 'button',

description: [
'Sets the specifications for each buttons.',
'By default, a range selector comes with no buttons.'
Expand Down
16 changes: 8 additions & 8 deletions src/components/rangeselector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

'use strict';

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

exports.moduleType = 'component';
layoutNodes: ['xaxis.'],
layoutAttributes: require('./attributes'),
handleDefaults: require('./defaults'),

exports.name = 'rangeselector';

exports.layoutAttributes = require('./attributes');

exports.handleDefaults = require('./defaults');

exports.draw = require('./draw');
draw: require('./draw')
};
3 changes: 3 additions & 0 deletions src/components/rangeslider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
module.exports = {
moduleType: 'component',
name: 'rangeslider',

layoutNodes: ['xaxis.'],
layoutAttributes: require('./attributes'),
handleDefaults: require('./defaults'),

draw: require('./draw')
};
2 changes: 1 addition & 1 deletion src/components/shapes/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var extendFlat = require('../../lib/extend').extendFlat;
var scatterLineAttrs = scatterAttrs.line;

module.exports = {
_isLinkedToArray: true,
_isLinkedToArray: 'shape',

visible: {
valType: 'boolean',
Expand Down
20 changes: 10 additions & 10 deletions src/components/shapes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

'use strict';

exports.moduleType = 'component';

exports.name = 'shapes';

exports.layoutAttributes = require('./attributes');
var drawModule = require('./draw');

exports.supplyLayoutDefaults = require('./defaults');
module.exports = {
moduleType: 'component',
name: 'shapes',

exports.calcAutorange = require('./calc_autorange');
layoutAttributes: require('./attributes'),
supplyLayoutDefaults: require('./defaults'),

var drawModule = require('./draw');
exports.draw = drawModule.draw;
exports.drawOne = drawModule.drawOne;
calcAutorange: require('./calc_autorange'),
draw: drawModule.draw,
drawOne: drawModule.drawOne
};
4 changes: 3 additions & 1 deletion src/components/sliders/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var animationAttrs = require('../../plots/animation_attributes');
var constants = require('./constants');

var stepsAttrs = {
_isLinkedToArray: true,
_isLinkedToArray: 'step',

method: {
valType: 'enumerated',
Expand Down Expand Up @@ -57,6 +57,8 @@ var stepsAttrs = {
};

module.exports = {
_isLinkedToArray: 'slider',

visible: {
valType: 'boolean',
role: 'info',
Expand Down
3 changes: 1 addition & 2 deletions src/components/sliders/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

module.exports = {

// layout attribute names
// layout attribute name
name: 'sliders',
itemName: 'slider',

// class names
containerClassName: 'slider-container',
Expand Down
15 changes: 8 additions & 7 deletions src/components/sliders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

'use strict';

var constants = require('./constants');

exports.moduleType = 'component';
module.exports = {
moduleType: 'component',
name: constants.name,

exports.name = 'sliders';
layoutAttributes: require('./attributes'),
supplyLayoutDefaults: require('./defaults'),

exports.layoutAttributes = require('./attributes');

exports.supplyLayoutDefaults = require('./defaults');

exports.draw = require('./draw');
draw: require('./draw')
};
4 changes: 2 additions & 2 deletions src/components/updatemenus/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var extendFlat = require('../../lib/extend').extendFlat;
var padAttrs = require('../../plots/pad_attributes');

var buttonsAttrs = {
_isLinkedToArray: true,
_isLinkedToArray: 'button',

method: {
valType: 'enumerated',
Expand Down Expand Up @@ -48,7 +48,7 @@ var buttonsAttrs = {
};

module.exports = {
_isLinkedToArray: true,
_isLinkedToArray: 'updatemenu',

visible: {
valType: 'boolean',
Expand Down
3 changes: 1 addition & 2 deletions src/components/updatemenus/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

module.exports = {

// layout attribute names
// layout attribute name
name: 'updatemenus',
itemName: 'updatemenu',

// class names
containerClassName: 'updatemenu-container',
Expand Down
15 changes: 8 additions & 7 deletions src/components/updatemenus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

'use strict';

var constants = require('./constants');

exports.moduleType = 'component';
module.exports = {
moduleType: 'component',
name: constants.name,

exports.name = 'updatemenus';
layoutAttributes: require('./attributes'),
supplyLayoutDefaults: require('./defaults'),

exports.layoutAttributes = require('./attributes');

exports.supplyLayoutDefaults = require('./defaults');

exports.draw = require('./draw');
draw: require('./draw')
};
Loading