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

prune global-level trace attributes that are already defined in a trace #3158

Merged
merged 11 commits into from
Oct 30, 2018
15 changes: 13 additions & 2 deletions src/plot_api/plot_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,22 @@ function getTraceAttributes(type) {
// make 'type' the first attribute in the object
attributes.type = null;


var copyBaseAttributes = extendDeepAll({}, baseAttributes),
copyModuleAttributes = extendDeepAll({}, _module.attributes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var a = {},
    b = [];

have gone out of style in our codebase. It might be worth adding an eslint rule for this. From

https://eslint.org/docs/rules/one-var#initialized-and-uninitialized

looks like "one-var": { "initialized": "never", "uninitialized": "consecutive" } is exactly what most of the codebase does already.

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 fixed this in f168ddc and opened an issue (#3162) so I don't forget about adding an eslint rule for this.


// prune global-level trace attributes that are already defined in a trace
exports.crawl(copyModuleAttributes, function(attr, attrName, attrs, level, fullAttrString) {
delete copyBaseAttributes[fullAttrString];
Copy link
Contributor

@etpinard etpinard Oct 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fullAttrString might look like 'marker.line.width' in general, so we'll need to use Lib.nestedProperty here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @etpinard! Commit 7999517 fixes this :)

// Prune undefined attributes
if(attr === undefined) delete copyModuleAttributes[fullAttrString];
Copy link
Contributor

@etpinard etpinard Oct 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice touch here, that way we won't have to rely on JSON.stringify to remove keys with undefined values.

});

// base attributes (same for all trace types)
extendDeepAll(attributes, baseAttributes);
extendDeepAll(attributes, copyBaseAttributes);

// module attributes
extendDeepAll(attributes, _module.attributes);
extendDeepAll(attributes, copyModuleAttributes);

// subplot attributes
if(basePlotModule.attributes) {
Expand Down