Skip to content

Commit

Permalink
Merge pull request #3158 from plotly/3058-prune-unsupported-globals
Browse files Browse the repository at this point in the history
prune global-level trace attributes that are already defined in a trace
  • Loading branch information
antoinerg authored Oct 30, 2018
2 parents ec0ddd8 + 55881c6 commit 1819584
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 10 deletions.
16 changes: 14 additions & 2 deletions 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 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) {
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 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 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 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 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 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 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 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 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 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 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 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 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 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

0 comments on commit 1819584

Please sign in to comment.