Skip to content
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

Bring back roles with value object #5432

Merged
merged 7 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/colorbar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = overrideAll({
// TODO: only right is supported currently
// orient: {
// valType: 'enumerated',
// role: 'info',
// values: ['left', 'right', 'top', 'bottom'],
// dflt: 'right',
// description: [
Expand Down
12 changes: 9 additions & 3 deletions src/plot_api/plot_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ exports.get = function() {
return {
defs: {
valObjects: valObjectMeta,
metaKeys: UNDERSCORE_ATTRS.concat(['description', 'editType', 'impliedEdits']),
metaKeys: UNDERSCORE_ATTRS.concat(['description', 'role', 'editType', 'impliedEdits']),
editType: {
traces: editTypes.traces,
layout: editTypes.layout
Expand Down Expand Up @@ -600,14 +600,14 @@ function getFramesAttributes() {
}

function formatAttributes(attrs) {
mergeValType(attrs);
mergeValTypeAndRole(attrs);
formatArrayContainers(attrs);
stringify(attrs);

return attrs;
}

function mergeValType(attrs) {
function mergeValTypeAndRole(attrs) {
function makeSrcAttr(attrName) {
return {
valType: 'string',
Expand All @@ -622,12 +622,17 @@ function mergeValType(attrs) {
function callback(attr, attrName, attrs) {
if(exports.isValObject(attr)) {
if(attr.valType === 'data_array') {
// all 'data_array' attrs have role 'data'
attr.role = 'data';
// all 'data_array' attrs have a corresponding 'src' attr
attrs[attrName + 'src'] = makeSrcAttr(attrName);
} else if(attr.arrayOk === true) {
// all 'arrayOk' attrs have a corresponding 'src' attr
attrs[attrName + 'src'] = makeSrcAttr(attrName);
}
} else if(isPlainObject(attr)) {
// all attrs container objects get role 'object'
attr.role = 'object';
}
}

Expand All @@ -646,6 +651,7 @@ function formatArrayContainers(attrs) {

attrs[attrName] = { items: {} };
attrs[attrName].items[itemName] = attr;
attrs[attrName].role = 'object';
}

exports.crawl(attrs, callback);
Expand Down
2 changes: 2 additions & 0 deletions src/plots/frame_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ module.exports = {
},
data: {
valType: 'any',
role: 'object',
description: [
'A list of traces this frame modifies. The format is identical to the',
'normal trace definition.'
].join(' ')
},
layout: {
valType: 'any',
role: 'object',
description: [
'Layout properties which this frame modifies. The format is identical',
'to the normal layout definition.'
Expand Down
1 change: 1 addition & 0 deletions src/traces/barpolar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {

// orientation: {
// valType: 'enumerated',
// role: 'info',
// values: ['radial', 'angular'],
// editType: 'calc+clearAxisTypes',
// description: 'Sets the orientation of the bars.'
Expand Down
1 change: 1 addition & 0 deletions src/traces/streamtube/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var attrs = {
// valType: 'enumerated',
// values: ['scaled', 'absolute', 'fixed'],
// dflt: 'scaled',
// role: 'info',
// editType: 'calc',
// description: [
// 'Sets the mode by which the streamtubes are sized.'
Expand Down
38 changes: 34 additions & 4 deletions test/jasmine/bundle_tests/plotschema_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('plot schema', function() {
var isPlainObject = Lib.isPlainObject;

var VALTYPES = Object.keys(valObjects);
var ROLES = ['info', 'style', 'data'];
var editType = plotSchema.defs.editType;

function assertTraceSchema(callback) {
Expand Down Expand Up @@ -72,6 +73,26 @@ describe('plot schema', function() {
);
});

it('all attributes should only have valid `role`', function() {
assertPlotSchema(
function(attr) {
if(isValObject(attr)) {
expect(ROLES.indexOf(attr.role) !== -1).toBe(true, attr);
}
}
);
});

it('all nested objects should have the *object* `role`', function() {
assertPlotSchema(
function(attr, attrName) {
if(!isValObject(attr) && isPlainObject(attr) && attrName !== 'items') {
expect(attr.role === 'object').toBe(true);
}
}
);
});

it('all attributes should have the required options', function() {
assertPlotSchema(
function(attr) {
Expand All @@ -94,7 +115,7 @@ describe('plot schema', function() {
var opts = valObject.requiredOpts
.concat(valObject.otherOpts)
.concat([
'valType', 'description',
'valType', 'description', 'role',
'editType', 'impliedEdits', 'anim',
'_compareAsJSON', '_noTemplating'
]);
Expand Down Expand Up @@ -164,8 +185,13 @@ describe('plot schema', function() {

// N.B. the specs below must be satisfied for plotly.py
expect(isPlainObject(itemsObj)).toBe(true);
expect(itemsObj.role).toBeUndefined();
expect(Object.keys(itemsObj).length).toEqual(1);
expect(isPlainObject(itemObj)).toBe(true);
expect(itemObj.role).toBe('object');

var role = np.get().role;
expect(role).toEqual('object');
});
});

Expand Down Expand Up @@ -197,7 +223,7 @@ describe('plot schema', function() {
);
});

it('deprecated attributes should have a `valType`', function() {
it('deprecated attributes should have a `valType` and `role`', function() {
var DEPRECATED = '_deprecated';

assertPlotSchema(
Expand All @@ -208,6 +234,8 @@ describe('plot schema', function() {

expect(VALTYPES.indexOf(dAttr.valType) !== -1)
.toBe(true, attrString + ': ' + dAttrName);
expect(ROLES.indexOf(dAttr.role) !== -1)
.toBe(true, attrString + ': ' + dAttrName);
});
}
}
Expand Down Expand Up @@ -289,13 +317,15 @@ describe('plot schema', function() {
expect(plotSchema.defs.metaKeys)
.toEqual([
'_isSubplotObj', '_isLinkedToArray', '_arrayAttrRegexps',
'_deprecated', 'description', 'editType', 'impliedEdits'
'_deprecated', 'description', 'role', 'editType', 'impliedEdits'
]);
});

it('should list the correct frame attributes', function() {
expect(plotSchema.frames).toBeDefined();
expect(plotSchema.frames.role).toEqual('object');
expect(plotSchema.frames.items.frames_entry).toBeDefined();
expect(plotSchema.frames.items.frames_entry.role).toEqual('object');
});

it('should list config attributes', function() {
Expand Down Expand Up @@ -439,7 +469,7 @@ describe('getTraceValObject', function() {
// it still returns the attribute itself - but maybe we should only do this
// for valType: any? (or data_array/arrayOk with just an index)
[
'valType', 'dflt', 'description', 'arrayOk',
'valType', 'dflt', 'role', 'description', 'arrayOk',
'editType', 'min', 'max', 'values'
].forEach(function(prop) {
expect(getTraceValObject({}, ['x', prop]))
Expand Down
6 changes: 4 additions & 2 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2877,7 +2877,8 @@ describe('plot_api edit_types', function() {

editTypes.update(flags, {
valType: 'boolean',
dflt: true
dflt: true,
role: 'style'
});

expect(flags).toEqual({calc: false, style: true});
Expand All @@ -2897,7 +2898,8 @@ describe('plot_api edit_types', function() {
editTypes.update(flags, {
editType: 'calc+style',
valType: 'number',
dflt: 1
dflt: 1,
role: 'style'
});

expect(flags).toEqual({calc: true, legend: true, style: true});
Expand Down