Skip to content

Commit 8da8a36

Browse files
committed
loops over trace modules to check for supplyLayoutDefaults,
instead of relying an a hard-coded list.
1 parent 0a7222c commit 8da8a36

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/plots/plots.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -656,25 +656,13 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut) {
656656
};
657657

658658
plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData) {
659-
var moduleLayoutDefaults = [
660-
'Axes', 'Annotations', 'Shapes', 'Fx',
661-
'Bar', 'Box', 'Pie', 'Legend'
662-
];
663-
664659
var i, _module;
665660

666-
// don't add a check for 'function in module' as it is better to error out and
667-
// secure the module API then not apply the default function.
668-
for(i = 0; i < moduleLayoutDefaults.length; i++) {
669-
_module = moduleLayoutDefaults[i];
670-
671-
if(Plotly[_module]) {
672-
Plotly[_module].supplyLayoutDefaults(layoutIn, layoutOut, fullData);
673-
}
674-
}
661+
// TODO incorporate into subplotRegistry
662+
Plotly.Axes.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
675663

664+
// plot module layout defaults
676665
var plotTypes = Object.keys(subplotsRegistry);
677-
678666
for(i = 0; i < plotTypes.length; i++) {
679667
_module = subplotsRegistry[plotTypes[i]];
680668

@@ -683,6 +671,27 @@ plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData) {
683671
_module.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
684672
}
685673
}
674+
675+
// trace module layout defaults
676+
var traceTypes = Object.keys(modules);
677+
for(i = 0; i < traceTypes.length; i++) {
678+
_module = modules[allTypes[i]].module;
679+
680+
if(_module.supplyLayoutDefaults) {
681+
_module.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
682+
}
683+
}
684+
685+
// TODO register these
686+
// Legend must come after traces (e.g. it depends on 'barmode')
687+
var moduleLayoutDefaults = ['Fx', 'Annotations', 'Shapes', 'Legend'];
688+
for(i = 0; i < moduleLayoutDefaults.length; i++) {
689+
_module = moduleLayoutDefaults[i];
690+
691+
if(Plotly[_module]) {
692+
Plotly[_module].supplyLayoutDefaults(layoutIn, layoutOut, fullData);
693+
}
694+
}
686695
};
687696

688697
plots.purge = function(gd) {

0 commit comments

Comments
 (0)