#1097 Range.combine method with empty datasets

General (896)

When one or more datasets are empty within a plot, the Range.combine method returns incorrect results. The range for an empty dataset will have lower and upper values of NaN, signifying that the range is undetermined. When combining with a range that *is* determined, the NaN values prevail, which is incorrect. NaN values should be explicitly detected and discarded. Currently, determination relies on the Math.min and max methods. When run as so:

System.out.println(Math.min(Double.NaN, 0));
System.out.println(Math.min(0, Double.NaN));
System.out.println(Math.max(Double.NaN, 0));
System.out.println(Math.max(0, Double.NaN));

... the result is always NaN.


  • Matthew Lohbihler

    The following version of the method works for me:

    public static Range combine(Range range1, Range range2) {
    if (range1 == null) {
    return range2;
    else {
    if (range2 == null) {
    return range1;
    else {
    double l;
    if (Double.isNaN(range1.getLowerBound()))
    l = range2.getLowerBound();
    else if (Double.isNaN(range2.getLowerBound()))
    l = range1.getLowerBound();
    l = Math.min(range1.getLowerBound(), range2.getLowerBound());

    double u;
    if (Double.isNaN(range1.getUpperBound()))
    u = range2.getUpperBound();
    else if (Double.isNaN(range2.getUpperBound()))
    u = range1.getUpperBound();
    u = Math.max(range1.getUpperBound(), range2.getUpperBound());

    return new Range(l, u);

  • Martin Höller

    Martin Höller - 2012-09-21

    This problem has arose before. See bug #3445507 for more details and SVN r2461 for changes.
    The problematic code should probably use the new method Range.combineIgnoringNaN() instead of Range.combine().

    Could you please tell us, where/when exactly the problem triggers? Especially what kind of chart?

    - martin

  • Matthew Lohbihler

    Hi Martin,

    Yes, this looks like the same issue. Sorry for the dup. When r2461 and r2462 are both used the issue should be fixed (although i have not yet tested).

    The problem occurs when one or more datasets are empty within a plot. In my case the context is Mango M2M, SCADA software. Charts are all time series. If a given data stream has no values for the chosen time period, the range combine method prevents all data streams - if they have values or not - from rendering.

  • David Gilbert

    David Gilbert - 2012-09-23

    Closing as this issue is already fixed for the upcoming 1.0.15 release.

  • David Gilbert

    David Gilbert - 2012-09-23
    • assigned_to: nobody --> mungady
    • status: open --> closed-duplicate

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks