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
Merged
Prev Previous commit
Next Next commit
schema: make _isLinkedToArray define name of array container items
- instead of simply removing the trailing 's' of the container
  name
  • Loading branch information
etpinard committed Nov 15, 2016
commit b56bf0c0378c623cd80abdab5848675a46e976d7
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
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
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
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
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
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
6 changes: 3 additions & 3 deletions src/plot_api/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,16 @@ function crawl(objIn, objOut, schema, list, base, path) {
crawl(valIn, valOut, nestedSchema, list, base, p);
}
else if(nestedSchema.items && !isInfoArray && isArray(valIn)) {
var itemName = k.substr(0, k.length - 1),
var items = nestedSchema.items,
_nestedSchema = items[Object.keys(items)[0]],
indexList = [];

var j, _p;

// loop over valOut items while keeping track of their
// corresponding input container index (given by _index)
for(j = 0; j < valOut.length; j++) {
var _nestedSchema = nestedSchema.items[itemName],
_index = valOut[j]._index || j;
var _index = valOut[j]._index || j;

_p = p.slice();
_p.push(_index);
Expand Down
2 changes: 1 addition & 1 deletion src/plots/mapbox/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module.exports = {
},

layers: {
_isLinkedToArray: true,
_isLinkedToArray: 'layer',

sourcetype: {
valType: 'enumerated',
Expand Down