Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

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

Merged
merged 11 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 14 additions & 2 deletions 16 src/plot_api/plot_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ exports.get = function() {
* @param {String} attrName name string
* @param {object[]} attrs all the attributes
* @param {Number} level the recursion level, 0 at the root
* @param {String} fullAttrString full attribute name (ie 'marker.line')
* @param {Number} [specifiedLevel]
* The level in the tree, in order to let the callback function detect descend or backtrack,
* typically unsupplied (implied 0), just used by the self-recursive call.
Expand Down Expand Up @@ -460,11 +461,22 @@ function getTraceAttributes(type) {
// make 'type' the first attribute in the object
attributes.type = null;


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

// prune global-level trace attributes that are already defined in a trace
exports.crawl(copyModuleAttributes, function(attr, attrName, attrs, level, fullAttrString) {
Lib.nestedProperty(copyBaseAttributes, fullAttrString).set(undefined);
// Prune undefined attributes
if(attr === undefined) Lib.nestedProperty(copyModuleAttributes, fullAttrString).set(undefined);
});

// 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
23 changes: 19 additions & 4 deletions 23 src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,7 @@ plots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, trac
// we want even invisible traces to make their would-be subplots visible
// so coerce the subplot id(s) now no matter what
var _module = plots.getModule(traceOut);

traceOut._module = _module;
if(_module) {
var basePlotModule = _module.basePlotModule;
Expand Down Expand Up @@ -1158,6 +1159,18 @@ plots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, trac
}
}

function coerceUnlessPruned(attr, dflt, cb) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably don't need this now that customdata and ids are deemed ok. What if we just add a noHover category to handle the fx.supplyDefaults call below. Oh well, @antoinerg already got a 💃 , so I guess I'm a little late to the party.

Copy link
Contributor

@etpinard etpinard Oct 30, 2018

Choose a reason for hiding this comment

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

But really, at the very least we should add a test checks that parcoords traces don't have hoverlabel in their fullData.

Copy link
Collaborator

Choose a reason for hiding this comment

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

customdata and ids are deemed ok

I wouldn't go that far 😏 I just didn't want to hold up the rest of this PR for that fairly minor issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But really, at the very least we should add a test checks that parcoords traces don't have hoverlabel in their fullData.

@etpinard Nice catch! It is addressed in commit da03ceb

Copy link
Contributor

@etpinard etpinard Oct 30, 2018

Choose a reason for hiding this comment

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

I wouldn't go that far I just didn't want to hold up the rest of this PR for that fairly minor issue.

Ok. I wrote up a summary in #3058 (comment), no need to address this now.

That said, I would prefer switching back those coerceUnlessPruned calls to regular coerce calls for customdata and ids as these are never pruned at the moment - which could confuse devs in future iterations.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That’s fine, easy enough to add back later after I convince you to remove those from some types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to see we can meet halfway 😄 ! Commit 55881c6 calls the regular coerce instead of coerceUnlessPruned. @etpinard I left the coerceUnlessPruned function there in case @alexcjohnson convince you later. Let me know if that's OK

if(_module && (attr in _module.attributes) && _module.attributes[attr] === undefined) {
// Pruned
} else {
if(cb && typeof cb === 'function') {
cb();
} else {
coerce(attr, dflt);
}
}
}

if(visible) {
coerce('customdata');
coerce('ids');
Expand All @@ -1171,10 +1184,12 @@ plots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, trac
traceOut._dfltShowLegend = false;
}

Registry.getComponentMethod(
'fx',
'supplyDefaults'
)(traceIn, traceOut, defaultColor, layout);
coerceUnlessPruned('hoverlabel', '', function() {
Registry.getComponentMethod(
'fx',
'supplyDefaults'
)(traceIn, traceOut, defaultColor, layout);
});

// TODO add per-base-plot-module trace defaults step

Expand Down
1 change: 1 addition & 0 deletions 1 src/traces/carpet/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,5 @@ module.exports = {
'Individual pieces can override this.'
].join(' ')
},
transforms: undefined
};
2 changes: 2 additions & 0 deletions 2 src/traces/cone/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,6 @@ attrs.hoverinfo = extendFlat({}, baseAttrs.hoverinfo, {
dflt: 'x+y+z+norm+text+name'
});

attrs.transforms = undefined;

module.exports = attrs;
3 changes: 2 additions & 1 deletion 3 src/traces/contourcarpet/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ module.exports = extendFlat({
].join(' ')
}),
editType: 'plot'
}
},
transforms: undefined
},

colorscaleAttrs('', {
Expand Down
1 change: 1 addition & 0 deletions 1 src/traces/heatmap/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ module.exports = extendFlat({
'https://github.com/d3/d3-format/blob/master/README.md#locale_format'
].join(' ')
},
transforms: undefined
},
colorscaleAttrs('', {
cLetter: 'z',
Expand Down
1 change: 1 addition & 0 deletions 1 src/traces/mesh3d/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ module.exports = extendFlat({
'Overrides *color* and *vertexcolor*.'
].join(' ')
},
transforms: undefined
},

colorscaleAttrs('', {
Expand Down
2 changes: 2 additions & 0 deletions 2 src/traces/parcoords/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var templatedArray = require('../../plot_api/plot_template').templatedArray;
module.exports = {
domain: domainAttrs({name: 'parcoords', trace: true, editType: 'calc'}),

hoverlabel: undefined,

labelfont: fontAttrs({
editType: 'calc',
description: 'Sets the font for the `dimension` labels.'
Expand Down
3 changes: 2 additions & 1 deletion 3 src/traces/pointcloud/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,6 @@ module.exports = {
editType: 'calc'
},
editType: 'calc'
}
},
transforms: undefined
};
3 changes: 2 additions & 1 deletion 3 src/traces/sankey/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var domainAttrs = require('../../plots/domain').attributes;
var extendFlat = require('../../lib/extend').extendFlat;
var overrideAll = require('../../plot_api/edit_types').overrideAll;

module.exports = overrideAll({
var attrs = module.exports = overrideAll({
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {
flags: [],
arrayOk: false,
Expand Down Expand Up @@ -219,3 +219,4 @@ module.exports = overrideAll({
description: 'The links of the Sankey plot.'
}
}, 'calc', 'nested');
attrs.transforms = undefined;
2 changes: 2 additions & 0 deletions 2 src/traces/streamtube/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,6 @@ attrs.hoverinfo = extendFlat({}, baseAttrs.hoverinfo, {
dflt: 'x+y+z+norm+text+name'
});

attrs.transforms = undefined;

module.exports = attrs;
1 change: 1 addition & 0 deletions 1 src/traces/surface/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,4 @@ colorscaleAttrs('', {
}), 'calc', 'nested');

attrs.x.editType = attrs.y.editType = attrs.z.editType = 'calc+clearAxisTypes';
attrs.transforms = undefined;
3 changes: 2 additions & 1 deletion 3 src/traces/table/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var overrideAll = require('../../plot_api/edit_types').overrideAll;
var fontAttrs = require('../../plots/font_attributes');
var domainAttrs = require('../../plots/domain').attributes;

module.exports = overrideAll({
var attrs = module.exports = overrideAll({
domain: domainAttrs({name: 'table', trace: true}),

columnwidth: {
Expand Down Expand Up @@ -198,3 +198,4 @@ module.exports = overrideAll({
font: extendFlat({}, fontAttrs({arrayOk: true}))
}
}, 'calc', 'from-root');
attrs.transforms = undefined;
5 changes: 5 additions & 0 deletions 5 test/jasmine/bundle_tests/plotschema_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ describe('plot schema', function() {
expect(typeof splomAttrs.yaxes.items.regex).toBe('string');
expect(splomAttrs.yaxes.items.regex).toBe('/^y([2-9]|[1-9][0-9]+)?$/');
});

it('should prune unsupported global-level trace attributes', function() {
expect(Plotly.PlotSchema.get().traces.sankey.attributes.hoverinfo.flags.length).toBe(0);
});

});

describe('getTraceValObject', function() {
Expand Down
8 changes: 8 additions & 0 deletions 8 test/jasmine/tests/parcoords_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ describe('parcoords initialization tests', function() {
expect(gd._fullData[0].tickfont).toEqual(expected);
expect(gd._fullData[0].rangefont).toEqual(expected);
});

it('should not coerce hoverlabel', function() {
var gd = Lib.extendDeep({}, mock1);

supplyAllDefaults(gd);

expect(gd._fullData[0].hoverlabel).toBeUndefined();
});
});

describe('parcoords defaults', function() {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.