Skip to content

Commit 876ce4b

Browse files
committed
attach has (plot type) method to fullLayout,
- as a replacement for _hasCartesian, _hasGeo, _hadGL3D, etc.
1 parent 525e3c7 commit 876ce4b

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/plots/plots.js

+21-8
Original file line numberDiff line numberDiff line change
@@ -471,20 +471,16 @@ plots.supplyDefaults = function(gd) {
471471
var fullTrace = plots.supplyDataDefaults(newData[i], i, newFullLayout);
472472
newFullData.push(fullTrace);
473473

474-
// detect plot type
475-
if(plots.traceIs(fullTrace, 'cartesian')) newFullLayout._hasCartesian = true;
476-
else if(plots.traceIs(fullTrace, 'gl3d')) newFullLayout._hasGL3D = true;
477-
else if(plots.traceIs(fullTrace, 'geo')) newFullLayout._hasGeo = true;
478-
else if(plots.traceIs(fullTrace, 'pie')) newFullLayout._hasPie = true;
479-
else if(plots.traceIs(fullTrace, 'gl2d')) newFullLayout._hasGL2D = true;
480-
else if(plots.traceIs(fullTrace, 'ternary')) newFullLayout._hasTernary = true;
481-
else if('r' in fullTrace) newFullLayout._hasPolar = true;
474+
// detect polar
475+
if('r' in fullTrace) newFullLayout._hasPolar = true;
482476

483477
// fill in modules list
484478
_module = fullTrace._module;
485479
if(_module && modules.indexOf(_module) === -1) modules.push(_module);
486480
}
487481

482+
// attach helper method
483+
newFullLayout._has = hasPlotType.bind(newFullLayout);
488484
// special cases that introduce interactions between traces
489485
for(i = 0; i < modules.length; i++) {
490486
_module = modules[i];
@@ -526,6 +522,23 @@ plots.supplyDefaults = function(gd) {
526522
}
527523
};
528524

525+
// helper function to be bound to fullLayout to check
526+
// whether a certain plot type or layout categories is present on plot
527+
function hasPlotType(category) {
528+
var modules = this._modules || [];
529+
530+
for(var i = 0; i < modules.length; i++) {
531+
var _module = modules[i];
532+
533+
if(_module.basePlotModule.name === category) return true;
534+
535+
var layoutCategories = _module.layoutCategories || [];
536+
if(layoutCategories.indexOf(category) !== -1) return true;
537+
}
538+
539+
return false;
540+
}
541+
529542
plots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
530543
var i, j;
531544

0 commit comments

Comments
 (0)