Skip to content

Commit f8f08cf

Browse files
authored
Merge pull request #5432 from plotly/bring-back-object-role
Bring back roles with value object
2 parents e53a3f6 + a363aec commit f8f08cf

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

Diff for: src/plot_api/plot_schema.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ exports.get = function() {
6363
return {
6464
defs: {
6565
valObjects: valObjectMeta,
66-
metaKeys: UNDERSCORE_ATTRS.concat(['description', 'editType', 'impliedEdits']),
66+
metaKeys: UNDERSCORE_ATTRS.concat(['description', 'role', 'editType', 'impliedEdits']),
6767
editType: {
6868
traces: editTypes.traces,
6969
layout: editTypes.layout
@@ -600,14 +600,14 @@ function getFramesAttributes() {
600600
}
601601

602602
function formatAttributes(attrs) {
603-
mergeValType(attrs);
603+
mergeValTypeAndRole(attrs);
604604
formatArrayContainers(attrs);
605605
stringify(attrs);
606606

607607
return attrs;
608608
}
609609

610-
function mergeValType(attrs) {
610+
function mergeValTypeAndRole(attrs) {
611611
function makeSrcAttr(attrName) {
612612
return {
613613
valType: 'string',
@@ -621,13 +621,13 @@ function mergeValType(attrs) {
621621

622622
function callback(attr, attrName, attrs) {
623623
if(exports.isValObject(attr)) {
624-
if(attr.valType === 'data_array') {
625-
// all 'data_array' attrs have a corresponding 'src' attr
626-
attrs[attrName + 'src'] = makeSrcAttr(attrName);
627-
} else if(attr.arrayOk === true) {
628-
// all 'arrayOk' attrs have a corresponding 'src' attr
624+
if(attr.arrayOk === true || attr.valType === 'data_array') {
625+
// all 'arrayOk' and 'data_array' attrs have a corresponding 'src' attr
629626
attrs[attrName + 'src'] = makeSrcAttr(attrName);
630627
}
628+
} else if(isPlainObject(attr)) {
629+
// all attrs container objects get role 'object'
630+
attr.role = 'object';
631631
}
632632
}
633633

@@ -646,6 +646,7 @@ function formatArrayContainers(attrs) {
646646

647647
attrs[attrName] = { items: {} };
648648
attrs[attrName].items[itemName] = attr;
649+
attrs[attrName].role = 'object';
649650
}
650651

651652
exports.crawl(attrs, callback);

Diff for: tasks/compress_attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = function() {
4848
.replace(makeJoinedArrayRegex('description'), '')
4949
.replace(makeArrayRegex('requiredOpts'), '')
5050
.replace(makeArrayRegex('otherOpts'), '')
51+
.replace(makeStringRegex('role'), '')
5152
.replace(makeStringRegex('hrName'), '')
5253
);
5354
done();

Diff for: test/jasmine/bundle_tests/plotschema_test.js

+37-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('plot schema', function() {
2525
var isPlainObject = Lib.isPlainObject;
2626

2727
var VALTYPES = Object.keys(valObjects);
28+
var formerRoles = ['info', 'style', 'data'];
2829
var editType = plotSchema.defs.editType;
2930

3031
function assertTraceSchema(callback) {
@@ -72,6 +73,27 @@ describe('plot schema', function() {
7273
);
7374
});
7475

76+
it('all attributes should not have a former `role`', function() {
77+
assertPlotSchema(
78+
function(attr) {
79+
if(isValObject(attr)) {
80+
expect(formerRoles.indexOf(attr.role) === -1).toBe(true, attr);
81+
expect(attr.role).toBeUndefined(attr);
82+
}
83+
}
84+
);
85+
});
86+
87+
it('all nested objects should have the *object* `role`', function() {
88+
assertPlotSchema(
89+
function(attr, attrName) {
90+
if(!isValObject(attr) && isPlainObject(attr) && attrName !== 'items') {
91+
expect(attr.role === 'object').toBe(true);
92+
}
93+
}
94+
);
95+
});
96+
7597
it('all attributes should have the required options', function() {
7698
assertPlotSchema(
7799
function(attr) {
@@ -94,7 +116,7 @@ describe('plot schema', function() {
94116
var opts = valObject.requiredOpts
95117
.concat(valObject.otherOpts)
96118
.concat([
97-
'valType', 'description',
119+
'valType', 'description', 'role',
98120
'editType', 'impliedEdits', 'anim',
99121
'_compareAsJSON', '_noTemplating'
100122
]);
@@ -164,8 +186,13 @@ describe('plot schema', function() {
164186

165187
// N.B. the specs below must be satisfied for plotly.py
166188
expect(isPlainObject(itemsObj)).toBe(true);
189+
expect(itemsObj.role).toBeUndefined();
167190
expect(Object.keys(itemsObj).length).toEqual(1);
168191
expect(isPlainObject(itemObj)).toBe(true);
192+
expect(itemObj.role).toBe('object');
193+
194+
var role = np.get().role;
195+
expect(role).toEqual('object');
169196
});
170197
});
171198

@@ -197,7 +224,7 @@ describe('plot schema', function() {
197224
);
198225
});
199226

200-
it('deprecated attributes should have a `valType`', function() {
227+
it('deprecated attributes should have a `valType` and not any former roles', function() {
201228
var DEPRECATED = '_deprecated';
202229

203230
assertPlotSchema(
@@ -206,8 +233,10 @@ describe('plot schema', function() {
206233
Object.keys(attr[DEPRECATED]).forEach(function(dAttrName) {
207234
var dAttr = attr[DEPRECATED][dAttrName];
208235

209-
expect(VALTYPES.indexOf(dAttr.valType) !== -1)
210-
.toBe(true, attrString + ': ' + dAttrName);
236+
var msg = attrString + ': ' + dAttrName;
237+
expect(VALTYPES.indexOf(dAttr.valType) !== -1).toBe(true, msg);
238+
expect(formerRoles.indexOf(dAttr.role) === -1).toBe(true, msg);
239+
expect(dAttr.role).toBeUndefined(msg);
211240
});
212241
}
213242
}
@@ -289,13 +318,15 @@ describe('plot schema', function() {
289318
expect(plotSchema.defs.metaKeys)
290319
.toEqual([
291320
'_isSubplotObj', '_isLinkedToArray', '_arrayAttrRegexps',
292-
'_deprecated', 'description', 'editType', 'impliedEdits'
321+
'_deprecated', 'description', 'role', 'editType', 'impliedEdits'
293322
]);
294323
});
295324

296325
it('should list the correct frame attributes', function() {
297326
expect(plotSchema.frames).toBeDefined();
327+
expect(plotSchema.frames.role).toEqual('object');
298328
expect(plotSchema.frames.items.frames_entry).toBeDefined();
329+
expect(plotSchema.frames.items.frames_entry.role).toEqual('object');
299330
});
300331

301332
it('should list config attributes', function() {
@@ -439,7 +470,7 @@ describe('getTraceValObject', function() {
439470
// it still returns the attribute itself - but maybe we should only do this
440471
// for valType: any? (or data_array/arrayOk with just an index)
441472
[
442-
'valType', 'dflt', 'description', 'arrayOk',
473+
'valType', 'dflt', 'role', 'description', 'arrayOk',
443474
'editType', 'min', 'max', 'values'
444475
].forEach(function(prop) {
445476
expect(getTraceValObject({}, ['x', prop]))

0 commit comments

Comments
 (0)