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
16 changes: 14 additions & 2 deletions src/plot_api/plot_schema.js
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
27 changes: 21 additions & 6 deletions src/plots/plots.js
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,9 +1159,21 @@ 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
Contributor

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
Contributor

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');
coerceUnlessPruned('customdata');
coerceUnlessPruned('ids');

if(Registry.traceIs(traceOut, 'showLegend')) {
traceOut._dfltShowLegend = true;
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 src/traces/carpet/attributes.js
Expand Up @@ -127,4 +127,5 @@ module.exports = {
'Individual pieces can override this.'
].join(' ')
},
transforms: undefined
};
2 changes: 2 additions & 0 deletions src/traces/cone/attributes.js
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 src/traces/contourcarpet/attributes.js
Expand Up @@ -90,7 +90,8 @@ module.exports = extendFlat({
].join(' ')
}),
editType: 'plot'
}
},
transforms: undefined
},

colorscaleAttrs('', {
Expand Down
1 change: 1 addition & 0 deletions src/traces/heatmap/attributes.js
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 src/traces/mesh3d/attributes.js
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 src/traces/parcoords/attributes.js
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 src/traces/pointcloud/attributes.js
Expand Up @@ -141,5 +141,6 @@ module.exports = {
editType: 'calc'
},
editType: 'calc'
}
},
transforms: undefined
};
3 changes: 2 additions & 1 deletion src/traces/sankey/attributes.js
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 src/traces/streamtube/attributes.js
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 src/traces/surface/attributes.js
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 src/traces/table/attributes.js
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 test/jasmine/bundle_tests/plotschema_test.js
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 test/jasmine/tests/parcoords_test.js
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