Linuxkey007 / achartengine

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

XYSeries.add runs into endless loop #357

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Add to different x/y-pairs with the same big x-value (e.g. using a  long 
representing the current timestamp).

What is the expected output? What do you see instead?
The second call to XYSeries.add(x,y) leads to an endless loop.

Please provide a source code snippet that we can use to replicate the issue.

What version of the product binary library are you using?
1.1.0

Please provide any additional information below.
See also 
http://stackoverflow.com/questions/17466522/adding-new-values-in-achartengine-ch
arts/18967760#18967760 

Original issue reported on code.google.com by Edgar.Bo...@googlemail.com on 24 Sep 2013 at 6:48

GoogleCodeExporter commented 9 years ago
Sorry, for the typo: I meant of course "Add two different x/y-pairs...."

Original comment by Edgar.Bo...@googlemail.com on 24 Sep 2013 at 6:52

GoogleCodeExporter commented 9 years ago
Just found a new method in Math, which I was not aware of so far, and which 
would solve the problem very easily:

  public synchronized void add(double x, double y) {
    while (mXY.get(x) != null) {
      // add a very small value to x such as data points sharing the same x will
      // still be added. Math.ulp delivers the smallest value which still
      // leads to a change of x.
      x += Math.ulp(x);
    }
    mXY.put(x, y);
    updateRange(x, y);
  }

Same should be done of course in the other add-method, which takes an 
additional index as parameter.

BTW: The updateMaxDifference in IndexXYMap will not work correctly, when 
put(int index, K key, V value) is used, as it compares only the last two 
entries. But the index could point anywhere. I am however not sure about the 
consequences, as I did not check when and why this value is used.

Original comment by Edgar.Bo...@googlemail.com on 28 Sep 2013 at 4:52

GoogleCodeExporter commented 9 years ago
Thanks for reporting this.

Original comment by dandrome...@gmail.com on 31 Oct 2013 at 9:05