Skip to content

Commit f345015

Browse files
committed
Merge pull request #3956 from plotly/plotschema-polishing
Some plot-schema polishing
2 parents 6ec4b1d + 1df29df commit f345015

File tree

5 files changed

+106
-50
lines changed

5 files changed

+106
-50
lines changed

shelly/plotlyjs/static/plotlyjs/src/axes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ axes.layoutAttributes = {
319319
role: 'style',
320320
description: [
321321
'Determines whether or not a line bounding this axis is drawn.'
322-
]
322+
].join(' ')
323323
},
324324
linecolor: {
325325
valType: 'color',

shelly/plotlyjs/static/plotlyjs/src/colorbar.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ var colorbar = module.exports = function(td, id) {
351351

352352
cbAxisOut._pos = xLeft+thickPx +
353353
(opts.outlinewidth||0)/2 - (opts.ticks==='outside' ? 1 : 0);
354-
cbAxisOut.side = opts.orient;
354+
cbAxisOut.side = 'right';
355355

356356
return Plotly.Axes.doTicks(td, cbAxisOut);
357357
}
@@ -525,14 +525,17 @@ var axesAttrs = Plotly.Axes.layoutAttributes,
525525
extendFlat = Plotly.Lib.extendFlat;
526526

527527
colorbar.attributes = {
528-
orient: {
529-
// which side are the labels on (so left and right make vertical bars, etc.)
530-
// TODO: only right is supported currently
531-
valType: 'enumerated',
532-
role: 'info',
533-
values: ['left', 'right', 'top', 'bottom'],
534-
dflt: 'right'
535-
},
528+
// TODO: only right is supported currently
529+
// orient: {
530+
// valType: 'enumerated',
531+
// role: 'info',
532+
// values: ['left', 'right', 'top', 'bottom'],
533+
// dflt: 'right',
534+
// description: [
535+
// 'Determines which side are the labels on',
536+
// '(so left and right make vertical bars, etc.)'
537+
// ].join(' ')
538+
// },
536539
thicknessmode: {
537540
valType: 'enumerated',
538541
values: ['fraction', 'pixels'],
@@ -688,7 +691,11 @@ colorbar.attributes = {
688691
valType: 'enumerated',
689692
values: ['right', 'top', 'bottom'],
690693
role: 'style',
691-
dflt: 'top'
694+
dflt: 'top',
695+
description: [
696+
'Determines the location of the colorbar title',
697+
'with respect to the color bar.'
698+
].join(' ')
692699
}
693700
};
694701

@@ -701,8 +708,6 @@ colorbar.supplyDefaults = function(containerIn, containerOut, layout) {
701708
colorbar.attributes, attr, dflt);
702709
}
703710

704-
coerce('orient');
705-
706711
var thicknessmode = coerce('thicknessmode');
707712
coerce('thickness', thicknessmode === 'fraction' ?
708713
30 / (layout.width - layout.margin.l - layout.margin.r) :

shelly/plotlyjs/static/plotlyjs/src/plotschema.js

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ var extendDeepAll = Plotly.Lib.extendDeepAll;
88

99
var NESTED_MODULE = '_nestedModules',
1010
COMPOSED_MODULE = '_composedModules',
11-
IS_SUBPLOT_OBJ = '_isSubplotObj';
11+
IS_SUBPLOT_OBJ = '_isSubplotObj',
12+
IS_LINKED_TO_ARRAY = '_isLinkedToArray',
13+
DEPRECATED = '_deprecated';
1214

1315
// list of underscore attributes to keep in schema as is
14-
var UNDERSCORE_ATTRS = [
15-
'_isLinkedToArray', '_isSubplotObj', '_deprecated'
16-
];
16+
var UNDERSCORE_ATTRS = [IS_SUBPLOT_OBJ, IS_LINKED_TO_ARRAY, DEPRECATED];
1717

1818
var plotSchema = {
1919
traces: {},
@@ -84,7 +84,6 @@ function getTraceAttributes(type) {
8484
attributes.type = type;
8585

8686
attributes = removeUnderscoreAttrs(attributes);
87-
8887
mergeValTypeAndRole(attributes);
8988
plotSchema.traces[type] = extendFlat({},
9089
meta,
@@ -104,7 +103,6 @@ function getTraceAttributes(type) {
104103

105104
function getLayoutAttributes() {
106105
var globalLayoutAttributes = Plotly.Plots.layoutAttributes,
107-
subplotsRegistry = Plotly.Plots.subplotsRegistry,
108106
layoutAttributes = {};
109107

110108
// layout module attributes (+ nested + composed)
@@ -116,20 +114,14 @@ function getLayoutAttributes() {
116114
layoutAttributes = assignPolarLayoutAttrs(layoutAttributes);
117115

118116
// add IS_SUBPLOT_OBJ attribute
119-
var gl3dRegex = subplotsRegistry.gl3d.attrRegex,
120-
geoRegex = subplotsRegistry.geo.attrRegex,
121-
xaxisRegex = subplotsRegistry.cartesian.attrRegex.x,
122-
yaxisRegex = subplotsRegistry.cartesian.attrRegex.y;
123-
124-
Object.keys(layoutAttributes).forEach(function(k) {
125-
if(gl3dRegex.test(k) || geoRegex.test(k) || xaxisRegex.test(k) || yaxisRegex.test(k)) {
126-
layoutAttributes[k][IS_SUBPLOT_OBJ] = true;
127-
}
128-
});
117+
layoutAttributes = handleSubplotObjs(layoutAttributes);
129118

130119
layoutAttributes = removeUnderscoreAttrs(layoutAttributes);
131-
132120
mergeValTypeAndRole(layoutAttributes);
121+
122+
// generate IS_LINKED_TO_ARRAY structure
123+
layoutAttributes = handleLinkedToArray(layoutAttributes);
124+
133125
plotSchema.layout = { layoutAttributes: layoutAttributes };
134126
}
135127

@@ -268,3 +260,38 @@ function getSubplotRegistry(traceType) {
268260

269261
return subplotsRegistry[subplotType];
270262
}
263+
264+
function handleSubplotObjs(layoutAttributes) {
265+
var subplotsRegistry = Plotly.Plots.subplotsRegistry;
266+
267+
var gl3dRegex = subplotsRegistry.gl3d.attrRegex,
268+
geoRegex = subplotsRegistry.geo.attrRegex,
269+
xaxisRegex = subplotsRegistry.cartesian.attrRegex.x,
270+
yaxisRegex = subplotsRegistry.cartesian.attrRegex.y;
271+
272+
Object.keys(layoutAttributes).forEach(function(k) {
273+
if(gl3dRegex.test(k) || geoRegex.test(k) || xaxisRegex.test(k) || yaxisRegex.test(k)) {
274+
layoutAttributes[k][IS_SUBPLOT_OBJ] = true;
275+
}
276+
});
277+
278+
return layoutAttributes;
279+
}
280+
281+
function handleLinkedToArray(layoutAttributes) {
282+
Object.keys(layoutAttributes).forEach(function(k) {
283+
var attr = extendDeep({}, layoutAttributes[k]);
284+
285+
if(attr[IS_LINKED_TO_ARRAY] !== true) return;
286+
287+
var itemName = k.substr(0, k.length-1); // TODO more robust logic
288+
289+
delete attr[IS_LINKED_TO_ARRAY];
290+
291+
layoutAttributes[k] = { items: {} };
292+
layoutAttributes[k].items[itemName] = attr;
293+
layoutAttributes[k].role = 'object';
294+
});
295+
296+
return layoutAttributes;
297+
}

shelly/plotlyjs/static/plotlyjs/src/shapes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ shapes.layoutAttributes = {
109109
path: {
110110
valType: 'string',
111111
role: 'info',
112-
dflt: [
112+
description: [
113113
'For `type` *path* - a valid SVG path but with the pixel values',
114114
'replaced by data values. There are a few restrictions / quirks',
115115
'only absolute instructions, not relative. So the allowed segments',

shelly/plotlyjs/static/plotlyjs/tests/plotschema_test.js

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ describe('plot schema', function() {
99
var isValObject = Plotly.PlotSchema.isValObject,
1010
isPlainObject = Plotly.Lib.isPlainObject;
1111

12+
var VALTYPES = Object.keys(valObjects),
13+
ROLES = ['info', 'style', 'data'];
14+
1215
function assertPlotSchema(callback) {
1316
var traces = plotSchema.traces;
1417

@@ -20,34 +23,30 @@ describe('plot schema', function() {
2023
}
2124

2225
it('all attributes should have a valid `valType`', function() {
23-
var valTypes = Object.keys(valObjects);
24-
2526
assertPlotSchema(
2627
function(attr) {
2728
if(isValObject(attr)) {
28-
expect(valTypes.indexOf(attr.valType) !== -1).toBe(true);
29+
expect(VALTYPES.indexOf(attr.valType) !== -1).toBe(true);
2930
}
3031
}
3132
);
3233

3334
});
3435

3536
it('all attributes should only have valid `role`', function() {
36-
var roles = ['info', 'style', 'data'];
37-
3837
assertPlotSchema(
3938
function(attr) {
4039
if(isValObject(attr)) {
41-
expect(roles.indexOf(attr.role) !== -1).toBe(true);
40+
expect(ROLES.indexOf(attr.role) !== -1).toBe(true);
4241
}
4342
}
4443
);
4544
});
4645

4746
it('all nested objects should have the *object* `role`', function() {
4847
assertPlotSchema(
49-
function(attr) {
50-
if(!isValObject(attr) && isPlainObject(attr)) {
48+
function(attr, attrName) {
49+
if(!isValObject(attr) && isPlainObject(attr) && attrName!=='items') {
5150
expect(attr.role === 'object').toBe(true);
5251
}
5352
}
@@ -112,25 +111,50 @@ describe('plot schema', function() {
112111
expect(list).toEqual(astrs);
113112
});
114113

115-
it('layout.annotations and layout.shapes should contain _isLinkedToArray', function() {
116-
var IS_LINKED_TO_ARRAY = '_isLinkedToArray',
117-
astrs = ['annotations', 'shapes'],
118-
list = [];
114+
it('layout.annotations and layout.shapes should contain `items`', function() {
115+
var astrs = ['annotations', 'shapes'];
119116

120117
astrs.forEach(function(astr) {
121118
expect(
122-
Plotly.Lib.nestedProperty(
123-
plotSchema.layout.layoutAttributes,
124-
astr + '.' + IS_LINKED_TO_ARRAY
125-
).get()
119+
isPlainObject(
120+
Plotly.Lib.nestedProperty(
121+
plotSchema.layout.layoutAttributes, astr
122+
).get().items
123+
)
126124
).toBe(true);
127125
});
126+
});
128127

128+
it('valObjects descriptions should be strings', function() {
129129
assertPlotSchema(
130-
function(attr, attrName) {
131-
if(attr[IS_LINKED_TO_ARRAY] === true) list.push(attrName);
130+
function(attr) {
131+
var isValid;
132+
133+
if(isValObject(attr)) {
134+
// attribute don't have to have a description (for now)
135+
isValid = (typeof attr.description === 'string') ||
136+
(attr.description === undefined);
137+
138+
expect(isValid).toBe(true);
139+
}
140+
}
141+
);
142+
});
143+
144+
it('deprecated attributes should have a `valType` and `role`', function() {
145+
var DEPRECATED = '_deprecated';
146+
147+
assertPlotSchema(
148+
function(attr) {
149+
if(isPlainObject(attr[DEPRECATED])) {
150+
Object.keys(attr[DEPRECATED]).forEach(function(dAttrName) {
151+
var dAttr = attr[DEPRECATED][dAttrName];
152+
153+
expect(VALTYPES.indexOf(dAttr.valType) !== -1).toBe(true);
154+
expect(ROLES.indexOf(dAttr.role) !== -1).toBe(true);
155+
});
156+
}
132157
}
133158
);
134-
expect(list).toEqual(astrs);
135159
});
136160
});

0 commit comments

Comments
 (0)