Skip to content

Commit e81fcb6

Browse files
committed
cut out duplicate setPositions calls (and loops)
1 parent 2071acb commit e81fcb6

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/plot_api/plot_api.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -237,21 +237,32 @@ Plotly.plot = function(gd, data, layout, config) {
237237
return;
238238
}
239239

240-
var subplots = Plots.getSubplotIds(fullLayout, 'cartesian'),
241-
modules = fullLayout._modules;
240+
var subplots = Plots.getSubplotIds(fullLayout, 'cartesian');
241+
var modules = fullLayout._modules;
242+
var setPositionsArray = [];
243+
var hasSetPositions = false;
242244

243245
// position and range calculations for traces that
244246
// depend on each other ie bars (stacked or grouped)
245247
// and boxes (grouped) push each other out of the way
246248

247-
var subplotInfo, _module;
249+
var subplotInfo, setPositionsFunc, i, j;
248250

249-
for(var i = 0; i < subplots.length; i++) {
250-
subplotInfo = fullLayout._plots[subplots[i]];
251+
for(j = 0; j < modules.length; j++) {
252+
setPositionsFunc = modules[j].setPositions;
253+
if(setPositionsFunc && setPositionsArray.indexOf(setPositionsFunc) === -1) {
254+
setPositionsArray.push(setPositionsFunc);
255+
hasSetPositions = true;
256+
}
257+
}
251258

252-
for(var j = 0; j < modules.length; j++) {
253-
_module = modules[j];
254-
if(_module.setPositions) _module.setPositions(gd, subplotInfo);
259+
if(hasSetPositions) {
260+
for(i = 0; i < subplots.length; i++) {
261+
subplotInfo = fullLayout._plots[subplots[i]];
262+
263+
for(j = 0; j < setPositionsArray.length; j++) {
264+
setPositionsArray[j](gd, subplotInfo);
265+
}
255266
}
256267
}
257268

0 commit comments

Comments
 (0)