Export to GitHub

flotr - issue #214

Performance for stacked graph


Posted on May 13, 2013 by Helpful Ox

What steps will reproduce the problem? 1. Plot large series with the stacked option 2. 3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

0.2.0

Please provide any additional information below.

Here is the inefficient code (function plot) : if(series.bars.stacked) { if(series.bars.horizontal) { $H(ya.values).each(function(pair) { if (pair.key == y) { stackOffsetPos = pair.value.stackPos || 0; stackOffsetNeg = pair.value.stackNeg || 0; if(x > 0) pair.value.stackPos = stackOffsetPos + x; else pair.value.stackNeg = stackOffsetNeg + x; } }); } else { $H(xa.values).each(function(pair) { if (pair.key == x) { stackOffsetPos = pair.value.stackPos || 0; stackOffsetNeg = pair.value.stackNeg || 0; if(y > 0) pair.value.stackPos = stackOffsetPos + y; else pair.value.stackNeg = stackOffsetNeg + y; }
}); ...

At least, we should break the loop within the if (pair.key == y) {.

Anyway, a better algo should be used. For my case, all my series are sorted and have the same number of points. That way, i didn't need to have the loop, so i simply have for vertical series:

stackOffsetPos = xa.values[x].stackPos || 0;
stackOffsetNeg = xa.values[x].stackNeg || 0;
var newValue = $H(xa.values[x]); // to have original behaviour
if(y > 0)
    newValue.stackPos = stackOffsetPos + y;
else
    newValue.stackNeg = stackOffsetNeg + y;
xa.values[x] = newValue;

Status: New

Labels:
Type-Defect Priority-Medium