From d3d8db767efa27433f1c0de7ade29e6b30aca0ea Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 21 Jan 2021 21:37:39 -0500 Subject: [PATCH 1/7] Revert "adapt tests" This reverts commit bd47920f31ac1a5b26b7a9eeac0fe3a58141959a. --- test/jasmine/bundle_tests/plotschema_test.js | 38 +++++++++++++++++--- test/jasmine/tests/plot_api_test.js | 6 ++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/test/jasmine/bundle_tests/plotschema_test.js b/test/jasmine/bundle_tests/plotschema_test.js index 3d749abe160..4ac720049a0 100644 --- a/test/jasmine/bundle_tests/plotschema_test.js +++ b/test/jasmine/bundle_tests/plotschema_test.js @@ -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) { @@ -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) { @@ -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' ]); @@ -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'); }); }); @@ -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( @@ -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); }); } } @@ -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() { @@ -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])) diff --git a/test/jasmine/tests/plot_api_test.js b/test/jasmine/tests/plot_api_test.js index 78383e283f2..071d4dca760 100644 --- a/test/jasmine/tests/plot_api_test.js +++ b/test/jasmine/tests/plot_api_test.js @@ -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}); @@ -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}); From 295c8ed7a1cefb87b61c7954d7d66a083fe9b5f9 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 21 Jan 2021 21:37:52 -0500 Subject: [PATCH 2/7] Revert "more role removal" This reverts commit 65da615ef39fc84389015d2a088df692a54a8c2a. --- src/components/colorbar/attributes.js | 1 + src/plot_api/plot_schema.js | 12 +++++++++--- src/traces/barpolar/attributes.js | 1 + src/traces/streamtube/attributes.js | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/colorbar/attributes.js b/src/components/colorbar/attributes.js index 1bf3c3e72f0..ed075ecd961 100644 --- a/src/components/colorbar/attributes.js +++ b/src/components/colorbar/attributes.js @@ -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: [ diff --git a/src/plot_api/plot_schema.js b/src/plot_api/plot_schema.js index 54e2b5aab29..0e2f542ec26 100644 --- a/src/plot_api/plot_schema.js +++ b/src/plot_api/plot_schema.js @@ -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 @@ -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', @@ -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'; } } @@ -646,6 +651,7 @@ function formatArrayContainers(attrs) { attrs[attrName] = { items: {} }; attrs[attrName].items[itemName] = attr; + attrs[attrName].role = 'object'; } exports.crawl(attrs, callback); diff --git a/src/traces/barpolar/attributes.js b/src/traces/barpolar/attributes.js index bf331cf2bd3..986a048547d 100644 --- a/src/traces/barpolar/attributes.js +++ b/src/traces/barpolar/attributes.js @@ -24,6 +24,7 @@ module.exports = { // orientation: { // valType: 'enumerated', + // role: 'info', // values: ['radial', 'angular'], // editType: 'calc+clearAxisTypes', // description: 'Sets the orientation of the bars.' diff --git a/src/traces/streamtube/attributes.js b/src/traces/streamtube/attributes.js index e031904a6b1..b54857a6195 100644 --- a/src/traces/streamtube/attributes.js +++ b/src/traces/streamtube/attributes.js @@ -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.' From 655508a7309da2bd89265c1ab469bae7034a56a4 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 21 Jan 2021 21:59:01 -0500 Subject: [PATCH 3/7] revert data and layout role to be object --- src/plots/frame_attributes.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plots/frame_attributes.js b/src/plots/frame_attributes.js index fd16d5d59b7..e00c9e6cef1 100644 --- a/src/plots/frame_attributes.js +++ b/src/plots/frame_attributes.js @@ -39,6 +39,7 @@ module.exports = { }, data: { valType: 'any', + role: 'object', description: [ 'A list of traces this frame modifies. The format is identical to the', 'normal trace definition.' @@ -46,6 +47,7 @@ module.exports = { }, layout: { valType: 'any', + role: 'object', description: [ 'Layout properties which this frame modifies. The format is identical', 'to the normal layout definition.' From 4efc5aec1f166ebf5afb09ba9a45d5281a3cef37 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 21 Jan 2021 22:36:49 -0500 Subject: [PATCH 4/7] adjustments to bring object role only --- src/components/colorbar/attributes.js | 1 - src/plot_api/plot_schema.js | 9 ++------- src/traces/barpolar/attributes.js | 1 - src/traces/streamtube/attributes.js | 1 - tasks/compress_attributes.js | 1 + test/jasmine/bundle_tests/plotschema_test.js | 10 +++++----- test/jasmine/tests/plot_api_test.js | 6 ++---- 7 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/components/colorbar/attributes.js b/src/components/colorbar/attributes.js index ed075ecd961..1bf3c3e72f0 100644 --- a/src/components/colorbar/attributes.js +++ b/src/components/colorbar/attributes.js @@ -18,7 +18,6 @@ module.exports = overrideAll({ // TODO: only right is supported currently // orient: { // valType: 'enumerated', -// role: 'info', // values: ['left', 'right', 'top', 'bottom'], // dflt: 'right', // description: [ diff --git a/src/plot_api/plot_schema.js b/src/plot_api/plot_schema.js index 0e2f542ec26..73aca869bc8 100644 --- a/src/plot_api/plot_schema.js +++ b/src/plot_api/plot_schema.js @@ -621,13 +621,8 @@ function mergeValTypeAndRole(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 + if(attr.arrayOk === true || attr.valType === 'data_array') { + // all 'arrayOk' and 'data_array' attrs have a corresponding 'src' attr attrs[attrName + 'src'] = makeSrcAttr(attrName); } } else if(isPlainObject(attr)) { diff --git a/src/traces/barpolar/attributes.js b/src/traces/barpolar/attributes.js index 986a048547d..bf331cf2bd3 100644 --- a/src/traces/barpolar/attributes.js +++ b/src/traces/barpolar/attributes.js @@ -24,7 +24,6 @@ module.exports = { // orientation: { // valType: 'enumerated', - // role: 'info', // values: ['radial', 'angular'], // editType: 'calc+clearAxisTypes', // description: 'Sets the orientation of the bars.' diff --git a/src/traces/streamtube/attributes.js b/src/traces/streamtube/attributes.js index b54857a6195..e031904a6b1 100644 --- a/src/traces/streamtube/attributes.js +++ b/src/traces/streamtube/attributes.js @@ -95,7 +95,6 @@ var attrs = { // valType: 'enumerated', // values: ['scaled', 'absolute', 'fixed'], // dflt: 'scaled', - // role: 'info', // editType: 'calc', // description: [ // 'Sets the mode by which the streamtubes are sized.' diff --git a/tasks/compress_attributes.js b/tasks/compress_attributes.js index b2f43e7e5d4..aa1ae1df7d9 100644 --- a/tasks/compress_attributes.js +++ b/tasks/compress_attributes.js @@ -48,6 +48,7 @@ module.exports = function() { .replace(makeJoinedArrayRegex('description'), '') .replace(makeArrayRegex('requiredOpts'), '') .replace(makeArrayRegex('otherOpts'), '') + .replace(makeStringRegex('role'), '') .replace(makeStringRegex('hrName'), '') ); done(); diff --git a/test/jasmine/bundle_tests/plotschema_test.js b/test/jasmine/bundle_tests/plotschema_test.js index 4ac720049a0..1de21bbcd27 100644 --- a/test/jasmine/bundle_tests/plotschema_test.js +++ b/test/jasmine/bundle_tests/plotschema_test.js @@ -25,7 +25,7 @@ describe('plot schema', function() { var isPlainObject = Lib.isPlainObject; var VALTYPES = Object.keys(valObjects); - var ROLES = ['info', 'style', 'data']; + var deprecatedRoles = ['info', 'style', 'data']; var editType = plotSchema.defs.editType; function assertTraceSchema(callback) { @@ -73,11 +73,11 @@ describe('plot schema', function() { ); }); - it('all attributes should only have valid `role`', function() { + it('all attributes should not have valid a deprecated `role`', function() { assertPlotSchema( function(attr) { if(isValObject(attr)) { - expect(ROLES.indexOf(attr.role) !== -1).toBe(true, attr); + expect(deprecatedRoles.indexOf(attr.role) === -1).toBe(true, attr); } } ); @@ -223,7 +223,7 @@ describe('plot schema', function() { ); }); - it('deprecated attributes should have a `valType` and `role`', function() { + it('deprecated attributes should have a `valType` and not any deprecated roles', function() { var DEPRECATED = '_deprecated'; assertPlotSchema( @@ -234,7 +234,7 @@ describe('plot schema', function() { expect(VALTYPES.indexOf(dAttr.valType) !== -1) .toBe(true, attrString + ': ' + dAttrName); - expect(ROLES.indexOf(dAttr.role) !== -1) + expect(deprecatedRoles.indexOf(dAttr.role) === -1) .toBe(true, attrString + ': ' + dAttrName); }); } diff --git a/test/jasmine/tests/plot_api_test.js b/test/jasmine/tests/plot_api_test.js index 071d4dca760..78383e283f2 100644 --- a/test/jasmine/tests/plot_api_test.js +++ b/test/jasmine/tests/plot_api_test.js @@ -2877,8 +2877,7 @@ describe('plot_api edit_types', function() { editTypes.update(flags, { valType: 'boolean', - dflt: true, - role: 'style' + dflt: true }); expect(flags).toEqual({calc: false, style: true}); @@ -2898,8 +2897,7 @@ describe('plot_api edit_types', function() { editTypes.update(flags, { editType: 'calc+style', valType: 'number', - dflt: 1, - role: 'style' + dflt: 1 }); expect(flags).toEqual({calc: true, legend: true, style: true}); From 9c7bf87f646b52e4a9196f0f2aaddbe7219cf50b Mon Sep 17 00:00:00 2001 From: archmoj Date: Fri, 22 Jan 2021 09:54:28 -0500 Subject: [PATCH 5/7] add tests to ensure deprecated roles are undefined --- test/jasmine/bundle_tests/plotschema_test.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/jasmine/bundle_tests/plotschema_test.js b/test/jasmine/bundle_tests/plotschema_test.js index 1de21bbcd27..5c21bb8816b 100644 --- a/test/jasmine/bundle_tests/plotschema_test.js +++ b/test/jasmine/bundle_tests/plotschema_test.js @@ -78,6 +78,7 @@ describe('plot schema', function() { function(attr) { if(isValObject(attr)) { expect(deprecatedRoles.indexOf(attr.role) === -1).toBe(true, attr); + expect(attr.role).toBeUndefined(attr); } } ); @@ -232,10 +233,10 @@ describe('plot schema', function() { Object.keys(attr[DEPRECATED]).forEach(function(dAttrName) { var dAttr = attr[DEPRECATED][dAttrName]; - expect(VALTYPES.indexOf(dAttr.valType) !== -1) - .toBe(true, attrString + ': ' + dAttrName); - expect(deprecatedRoles.indexOf(dAttr.role) === -1) - .toBe(true, attrString + ': ' + dAttrName); + var msg = attrString + ': ' + dAttrName; + expect(VALTYPES.indexOf(dAttr.valType) !== -1).toBe(true, msg); + expect(deprecatedRoles.indexOf(dAttr.role) === -1).toBe(true, msg); + expect(dAttr.role).toBeUndefined(msg); }); } } From fb07d6670c944f4790f4f8994905cac460f0708b Mon Sep 17 00:00:00 2001 From: archmoj Date: Fri, 22 Jan 2021 10:06:11 -0500 Subject: [PATCH 6/7] use former instead of deprecated for retired v1 roles --- test/jasmine/bundle_tests/plotschema_test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/jasmine/bundle_tests/plotschema_test.js b/test/jasmine/bundle_tests/plotschema_test.js index 5c21bb8816b..59cdf9ca0f1 100644 --- a/test/jasmine/bundle_tests/plotschema_test.js +++ b/test/jasmine/bundle_tests/plotschema_test.js @@ -25,7 +25,7 @@ describe('plot schema', function() { var isPlainObject = Lib.isPlainObject; var VALTYPES = Object.keys(valObjects); - var deprecatedRoles = ['info', 'style', 'data']; + var formerRoles = ['info', 'style', 'data']; var editType = plotSchema.defs.editType; function assertTraceSchema(callback) { @@ -73,11 +73,11 @@ describe('plot schema', function() { ); }); - it('all attributes should not have valid a deprecated `role`', function() { + it('all attributes should not have a former `role`', function() { assertPlotSchema( function(attr) { if(isValObject(attr)) { - expect(deprecatedRoles.indexOf(attr.role) === -1).toBe(true, attr); + expect(formerRoles.indexOf(attr.role) === -1).toBe(true, attr); expect(attr.role).toBeUndefined(attr); } } @@ -224,7 +224,7 @@ describe('plot schema', function() { ); }); - it('deprecated attributes should have a `valType` and not any deprecated roles', function() { + it('deprecated attributes should have a `valType` and not any former roles', function() { var DEPRECATED = '_deprecated'; assertPlotSchema( @@ -235,7 +235,7 @@ describe('plot schema', function() { var msg = attrString + ': ' + dAttrName; expect(VALTYPES.indexOf(dAttr.valType) !== -1).toBe(true, msg); - expect(deprecatedRoles.indexOf(dAttr.role) === -1).toBe(true, msg); + expect(formerRoles.indexOf(dAttr.role) === -1).toBe(true, msg); expect(dAttr.role).toBeUndefined(msg); }); } From a363aecf61ea49d67c3e3f74baa949e7e3e9f458 Mon Sep 17 00:00:00 2001 From: archmoj Date: Fri, 22 Jan 2021 12:26:20 -0500 Subject: [PATCH 7/7] Revert "revert data and layout role to be object" This reverts commit 655508a7309da2bd89265c1ab469bae7034a56a4. --- src/plots/frame_attributes.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/plots/frame_attributes.js b/src/plots/frame_attributes.js index e00c9e6cef1..fd16d5d59b7 100644 --- a/src/plots/frame_attributes.js +++ b/src/plots/frame_attributes.js @@ -39,7 +39,6 @@ module.exports = { }, data: { valType: 'any', - role: 'object', description: [ 'A list of traces this frame modifies. The format is identical to the', 'normal trace definition.' @@ -47,7 +46,6 @@ module.exports = { }, layout: { valType: 'any', - role: 'object', description: [ 'Layout properties which this frame modifies. The format is identical', 'to the normal layout definition.'