Skip to content

Commit 1819584

Browse files
authored
Merge pull request #3158 from plotly/3058-prune-unsupported-globals
prune global-level trace attributes that are already defined in a trace
2 parents ec0ddd8 + 55881c6 commit 1819584

File tree

15 files changed

+64
-10
lines changed

15 files changed

+64
-10
lines changed

src/plot_api/plot_schema.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ exports.get = function() {
112112
* @param {String} attrName name string
113113
* @param {object[]} attrs all the attributes
114114
* @param {Number} level the recursion level, 0 at the root
115+
* @param {String} fullAttrString full attribute name (ie 'marker.line')
115116
* @param {Number} [specifiedLevel]
116117
* The level in the tree, in order to let the callback function detect descend or backtrack,
117118
* typically unsupplied (implied 0), just used by the self-recursive call.
@@ -460,11 +461,22 @@ function getTraceAttributes(type) {
460461
// make 'type' the first attribute in the object
461462
attributes.type = null;
462463

464+
465+
var copyBaseAttributes = extendDeepAll({}, baseAttributes);
466+
var copyModuleAttributes = extendDeepAll({}, _module.attributes);
467+
468+
// prune global-level trace attributes that are already defined in a trace
469+
exports.crawl(copyModuleAttributes, function(attr, attrName, attrs, level, fullAttrString) {
470+
Lib.nestedProperty(copyBaseAttributes, fullAttrString).set(undefined);
471+
// Prune undefined attributes
472+
if(attr === undefined) Lib.nestedProperty(copyModuleAttributes, fullAttrString).set(undefined);
473+
});
474+
463475
// base attributes (same for all trace types)
464-
extendDeepAll(attributes, baseAttributes);
476+
extendDeepAll(attributes, copyBaseAttributes);
465477

466478
// module attributes
467-
extendDeepAll(attributes, _module.attributes);
479+
extendDeepAll(attributes, copyModuleAttributes);
468480

469481
// subplot attributes
470482
if(basePlotModule.attributes) {

src/plots/plots.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ plots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, trac
11251125
// we want even invisible traces to make their would-be subplots visible
11261126
// so coerce the subplot id(s) now no matter what
11271127
var _module = plots.getModule(traceOut);
1128+
11281129
traceOut._module = _module;
11291130
if(_module) {
11301131
var basePlotModule = _module.basePlotModule;
@@ -1158,6 +1159,18 @@ plots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, trac
11581159
}
11591160
}
11601161

1162+
function coerceUnlessPruned(attr, dflt, cb) {
1163+
if(_module && (attr in _module.attributes) && _module.attributes[attr] === undefined) {
1164+
// Pruned
1165+
} else {
1166+
if(cb && typeof cb === 'function') {
1167+
cb();
1168+
} else {
1169+
coerce(attr, dflt);
1170+
}
1171+
}
1172+
}
1173+
11611174
if(visible) {
11621175
coerce('customdata');
11631176
coerce('ids');
@@ -1171,10 +1184,12 @@ plots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, trac
11711184
traceOut._dfltShowLegend = false;
11721185
}
11731186

1174-
Registry.getComponentMethod(
1175-
'fx',
1176-
'supplyDefaults'
1177-
)(traceIn, traceOut, defaultColor, layout);
1187+
coerceUnlessPruned('hoverlabel', '', function() {
1188+
Registry.getComponentMethod(
1189+
'fx',
1190+
'supplyDefaults'
1191+
)(traceIn, traceOut, defaultColor, layout);
1192+
});
11781193

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

src/traces/carpet/attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,5 @@ module.exports = {
127127
'Individual pieces can override this.'
128128
].join(' ')
129129
},
130+
transforms: undefined
130131
};

src/traces/cone/attributes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,6 @@ attrs.hoverinfo = extendFlat({}, baseAttrs.hoverinfo, {
180180
dflt: 'x+y+z+norm+text+name'
181181
});
182182

183+
attrs.transforms = undefined;
184+
183185
module.exports = attrs;

src/traces/contourcarpet/attributes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ module.exports = extendFlat({
9090
].join(' ')
9191
}),
9292
editType: 'plot'
93-
}
93+
},
94+
transforms: undefined
9495
},
9596

9697
colorscaleAttrs('', {

src/traces/heatmap/attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ module.exports = extendFlat({
111111
'https://github.com/d3/d3-format/blob/master/README.md#locale_format'
112112
].join(' ')
113113
},
114+
transforms: undefined
114115
},
115116
colorscaleAttrs('', {
116117
cLetter: 'z',

src/traces/mesh3d/attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ module.exports = extendFlat({
165165
'Overrides *color* and *vertexcolor*.'
166166
].join(' ')
167167
},
168+
transforms: undefined
168169
},
169170

170171
colorscaleAttrs('', {

src/traces/parcoords/attributes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ var templatedArray = require('../../plot_api/plot_template').templatedArray;
2020
module.exports = {
2121
domain: domainAttrs({name: 'parcoords', trace: true, editType: 'calc'}),
2222

23+
hoverlabel: undefined,
24+
2325
labelfont: fontAttrs({
2426
editType: 'calc',
2527
description: 'Sets the font for the `dimension` labels.'

src/traces/pointcloud/attributes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,6 @@ module.exports = {
141141
editType: 'calc'
142142
},
143143
editType: 'calc'
144-
}
144+
},
145+
transforms: undefined
145146
};

src/traces/sankey/attributes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var domainAttrs = require('../../plots/domain').attributes;
1717
var extendFlat = require('../../lib/extend').extendFlat;
1818
var overrideAll = require('../../plot_api/edit_types').overrideAll;
1919

20-
module.exports = overrideAll({
20+
var attrs = module.exports = overrideAll({
2121
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {
2222
flags: [],
2323
arrayOk: false,
@@ -219,3 +219,4 @@ module.exports = overrideAll({
219219
description: 'The links of the Sankey plot.'
220220
}
221221
}, 'calc', 'nested');
222+
attrs.transforms = undefined;

0 commit comments

Comments
 (0)