Skip to content

Commit 8804311

Browse files
committed
Object.keys -> for in, in plots/plots
1 parent 698561c commit 8804311

File tree

1 file changed

+18
-33
lines changed

1 file changed

+18
-33
lines changed

Diff for: src/plots/plots.js

+18-33
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,8 @@ function emptySubplotLists() {
436436
collectableSubplotTypes = [];
437437

438438
var subplotsRegistry = Registry.subplotsRegistry;
439-
var subplotTypes = Object.keys(subplotsRegistry);
440439

441-
for(i = 0; i < subplotTypes.length; i++) {
442-
var subplotType = subplotTypes[i];
440+
for(var subplotType in subplotsRegistry) {
443441
var subplotModule = subplotsRegistry[subplotType];
444442
var subplotAttr = subplotModule.attr;
445443

@@ -690,9 +688,8 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa
690688
var i, j, id, ax;
691689

692690
// sort subplot lists
693-
var subplotTypes = Object.keys(newSubplotList);
694-
for(i = 0; i < subplotTypes.length; i++) {
695-
newSubplotList[subplotTypes[i]].sort(Lib.subplotSort);
691+
for(var subplotType in newSubplotList) {
692+
newSubplotList[subplotType].sort(Lib.subplotSort);
696693
}
697694

698695
for(i = 0; i < ids.length; i++) {
@@ -1368,16 +1365,16 @@ function calculateReservedMargins(margins) {
13681365
}
13691366

13701367
plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData, transitionData) {
1371-
var components = Object.keys(Registry.componentsRegistry);
1368+
var componentsRegistry = Registry.componentsRegistry;
13721369
var basePlotModules = layoutOut._basePlotModules;
1373-
var i, _module;
1370+
var component, i, _module;
13741371

13751372
var Cartesian = Registry.subplotsRegistry.cartesian;
13761373

13771374
// check if any components need to add more base plot modules
13781375
// that weren't captured by traces
1379-
for(i = 0; i < components.length; i++) {
1380-
_module = Registry.componentsRegistry[components[i]];
1376+
for(component in componentsRegistry) {
1377+
_module = componentsRegistry[component];
13811378

13821379
if(_module.includeBasePlot) {
13831380
_module.includeBasePlot(layoutIn, layoutOut);
@@ -1424,8 +1421,8 @@ plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData, trans
14241421
}
14251422
}
14261423

1427-
for(i = 0; i < components.length; i++) {
1428-
_module = Registry.componentsRegistry[components[i]];
1424+
for(component in componentsRegistry) {
1425+
_module = componentsRegistry[component];
14291426

14301427
if(_module.supplyLayoutDefaults) {
14311428
_module.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
@@ -1609,10 +1606,7 @@ plots.doAutoMargin = function(gd) {
16091606
// now cycle through all the combinations of l and r
16101607
// (and t and b) to find the required margins
16111608

1612-
var pmKeys = Object.keys(pm);
1613-
1614-
for(var i = 0; i < pmKeys.length; i++) {
1615-
var k1 = pmKeys[i];
1609+
for(var k1 in pm) {
16161610

16171611
var pushleft = pm[k1].l || {},
16181612
pushbottom = pm[k1].b || {},
@@ -1621,9 +1615,7 @@ plots.doAutoMargin = function(gd) {
16211615
fb = pushbottom.val,
16221616
pb = pushbottom.size;
16231617

1624-
for(var j = 0; j < pmKeys.length; j++) {
1625-
var k2 = pmKeys[j];
1626-
1618+
for(var k2 in pm) {
16271619
if(isNumeric(pl) && pm[k2].r) {
16281620
var fr = pm[k2].r.val,
16291621
pr = pm[k2].r.size;
@@ -2472,31 +2464,24 @@ plots.generalUpdatePerTraceModule = function(subplot, subplotCalcData, subplotLa
24722464
}
24732465
}
24742466

2475-
var moduleNamesOld = Object.keys(traceHashOld);
2476-
var moduleNames = Object.keys(traceHash);
2477-
24782467
// when a trace gets deleted, make sure that its module's
24792468
// plot method is called so that it is properly
24802469
// removed from the DOM.
2481-
for(i = 0; i < moduleNamesOld.length; i++) {
2482-
var moduleName = moduleNamesOld[i];
2470+
for(var moduleNameOld in traceHashOld) {
24832471

2484-
if(moduleNames.indexOf(moduleName) === -1) {
2485-
var fakeCalcTrace = traceHashOld[moduleName][0],
2472+
if(!traceHash[moduleNameOld]) {
2473+
var fakeCalcTrace = traceHashOld[moduleNameOld][0],
24862474
fakeTrace = fakeCalcTrace[0].trace;
24872475

24882476
fakeTrace.visible = false;
2489-
traceHash[moduleName] = [fakeCalcTrace];
2477+
traceHash[moduleNameOld] = [fakeCalcTrace];
24902478
}
24912479
}
24922480

2493-
// update list of module names to include 'fake' traces added above
2494-
moduleNames = Object.keys(traceHash);
2495-
24962481
// call module plot method
2497-
for(i = 0; i < moduleNames.length; i++) {
2498-
var moduleCalcData = traceHash[moduleNames[i]],
2499-
_module = moduleCalcData[0][0].trace._module;
2482+
for(var moduleName in traceHash) {
2483+
var moduleCalcData = traceHash[moduleName];
2484+
var _module = moduleCalcData[0][0].trace._module;
25002485

25012486
_module.plot(subplot, filterVisible(moduleCalcData), subplotLayout);
25022487
}

0 commit comments

Comments
 (0)