PhenX / flotr

Automatically exported from code.google.com/p/flotr
0 stars 0 forks source link

Performance for stacked graph #214

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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;

Original issue reported on code.google.com by sebastie...@prologism.fr on 13 May 2013 at 3:54