# HG changeset patch # User Andre Heinecke # Date 1433775234 -7200 # Node ID 36d7bda0b47ab7ff847195ed1d758dbb77f14221 # Parent e9d912c97fa850d388c2273c179497cd53b20e08 (issue1788) Fix area split if there are no NaN's in the data The split algorithmn splits in a way that it always creates at least two datasets. One before the NaN, one after the NaN. This is broken in case the dataset does not contain any NaN value as it resulted in two identical datasets. This changed the display and resulted in a broken area calculation. I've also added some commented out debug code that was helpful tracking down this problem. diff -r e9d912c97fa8 -r 36d7bda0b47a artifacts/src/main/java/org/dive4elements/river/jfree/StableXYDifferenceRenderer.java --- a/artifacts/src/main/java/org/dive4elements/river/jfree/StableXYDifferenceRenderer.java Fri Jun 05 16:56:47 2015 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/jfree/StableXYDifferenceRenderer.java Mon Jun 08 16:53:54 2015 +0200 @@ -621,6 +621,31 @@ return false; } + protected static boolean hasNaN(XYDataset dataset) { + int N = dataset.getItemCount(0); + int M = dataset.getItemCount(1); + + int i = 0, j = 0; + boolean haveNaN = false; + for (; i < N; ++i) { + double x = dataset.getXValue(0, i); + double y = dataset.getYValue(0, i); + if (Double.isNaN(x) || Double.isNaN(y)) { + return true; + } + } + + for (; j < M; ++j) { + double x = dataset.getXValue(1, j); + double y = dataset.getYValue(1, j); + if (Double.isNaN(x) || Double.isNaN(y)) { + return true; + } + } + return false; + } + + protected static List splitByNaNsTwoSeries( XYDataset dataset ) { @@ -628,6 +653,11 @@ List datasets = new ArrayList(); + if (!hasNaN(dataset)) { + datasets.add(dataset); + return datasets; + } + int N = dataset.getItemCount(0); int M = dataset.getItemCount(1); @@ -846,9 +876,44 @@ log.debug("datasets after split: " + datasets.size()); } + /* + log.debug("Begin dump datasets: "); + log.debug("Original"); + i=0; + dumpDataset(dataset, "Original" ); + for (XYDataset set: datasets) { + dumpDataset(dataset, "New: " + i++); + } + log.debug("End dump datasets: "); + */ + return datasets; } + /* + public static void dumpDataset(XYDataset dataset, String msg) { + log.debug("Begin dump Dataset: " + msg); + + int N = dataset.getItemCount(0); + int M = dataset.getItemCount(1); + + int i = 0, j = 0; + for (; i < N; ++i) { + double x = dataset.getXValue(0, i); + double y = dataset.getYValue(0, i); + log.debug("0 " + i + " X: "+ x + "Y: "+ y); + } + + for (; j < M; ++j) { + double x = dataset.getXValue(1, j); + double y = dataset.getYValue(1, j); + log.debug("1 " + i + " X: "+ x + "Y: "+ y); + } + log.debug("End dump Dataset: " + msg); + } + */ + + public static List splitByNaNs(XYDataset dataset) { switch (dataset.getSeriesCount()) {