Skip to content

Commit 2e50941

Browse files
committed
fix #3058 - prune-out base attrs based on module categories
... during Plotly.PlotSchema.get()
1 parent 08a0e22 commit 2e50941

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/plot_api/plot_schema.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@ function getTraceAttributes(type) {
453453
if(type === 'area') {
454454
_module = { attributes: polarAreaAttrs };
455455
basePlotModule = {};
456-
}
457-
else {
456+
} else {
458457
_module = Registry.modules[type]._module,
459458
basePlotModule = _module.basePlotModule;
460459
}
@@ -464,7 +463,6 @@ function getTraceAttributes(type) {
464463
// make 'type' the first attribute in the object
465464
attributes.type = null;
466465

467-
468466
var copyBaseAttributes = extendDeepAll({}, baseAttributes);
469467
var copyModuleAttributes = extendDeepAll({}, _module.attributes);
470468

@@ -478,6 +476,22 @@ function getTraceAttributes(type) {
478476
// base attributes (same for all trace types)
479477
extendDeepAll(attributes, copyBaseAttributes);
480478

479+
// prune-out base attributes based on trace module categories
480+
if(Registry.traceIs(type, 'noOpacity')) {
481+
delete attributes.opacity;
482+
}
483+
if(!Registry.traceIs(type, 'showLegend')) {
484+
delete attributes.showlegend;
485+
delete attributes.legendgroup;
486+
}
487+
if(Registry.traceIs(type, 'noHover')) {
488+
delete attributes.hoverinfo;
489+
delete attributes.hoverlabel;
490+
}
491+
if(!_module.selectPoints) {
492+
delete attributes.selectedpoints;
493+
}
494+
481495
// module attributes
482496
extendDeepAll(attributes, copyModuleAttributes);
483497

test/jasmine/bundle_tests/plotschema_test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,13 @@ describe('plot schema', function() {
368368
});
369369

370370
it('should prune unsupported global-level trace attributes', function() {
371-
expect(Plotly.PlotSchema.get().traces.sankey.attributes.hoverinfo.flags.length).toBe(0);
371+
var traces = Plotly.PlotSchema.get().traces;
372+
373+
expect(traces.sankey.attributes.hoverinfo.flags.length).toBe(0);
374+
expect(traces.choropleth.attributes.showlegend).toBe(undefined, 'no legend attrs for choropleth (for now)');
375+
expect(traces.table.attributes.opacity).toBe(undefined, 'no opacity attr for table');
376+
expect(traces.parcoords.attributes.hoverinfo).toBe(undefined, 'no hover attrs for parcoords');
377+
expect(traces.scatter3d.attributes.selectedpoints).toBe(undefined, 'no selectedpoints for gl3d traces');
372378
});
373379
});
374380

0 commit comments

Comments
 (0)