Skip to content

Commit

Permalink
perf makeSubplotData
Browse files Browse the repository at this point in the history
- replace Object.keys + for-loop with for-in
- replace slow subplots.indexOf
  • Loading branch information
etpinard committed Mar 13, 2018
1 parent 03950d8 commit d305564
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,29 +347,22 @@ exports.rangePlot = function(gd, plotinfo, cdSubplot) {
};

function makeSubplotData(gd) {
var fullLayout = gd._fullLayout,
subplots = Object.keys(fullLayout._plots);

var subplotData = [],
overlays = [];

for(var i = 0; i < subplots.length; i++) {
var subplot = subplots[i],
plotinfo = fullLayout._plots[subplot];

var xa = plotinfo.xaxis;
var ya = plotinfo.yaxis;
var xa2 = xa._mainAxis;
var ya2 = ya._mainAxis;
var fullLayout = gd._fullLayout;
var subplotData = [];
var overlays = [];

for(var k in fullLayout._plots) {
var plotinfo = fullLayout._plots[k];
var xa2 = plotinfo.xaxis._mainAxis;
var ya2 = plotinfo.yaxis._mainAxis;
var mainplot = xa2._id + ya2._id;
if(mainplot !== subplot && subplots.indexOf(mainplot) !== -1) {

if(mainplot !== k && fullLayout._plots[mainplot]) {
plotinfo.mainplot = mainplot;
plotinfo.mainplotinfo = fullLayout._plots[mainplot];
overlays.push(subplot);
}
else {
subplotData.push(subplot);
overlays.push(k);
} else {
subplotData.push(k);
}
}

Expand Down

0 comments on commit d305564

Please sign in to comment.