Mercurial > dive4elements > river
changeset 8748:36d7bda0b47a
(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.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 08 Jun 2015 16:53:54 +0200 (2015-06-08) |
parents | e9d912c97fa8 |
children | c4654863108d |
files | artifacts/src/main/java/org/dive4elements/river/jfree/StableXYDifferenceRenderer.java |
diffstat | 1 files changed, 65 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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<XYDataset> splitByNaNsTwoSeries( XYDataset dataset ) { @@ -628,6 +653,11 @@ List<XYDataset> datasets = new ArrayList<XYDataset>(); + 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<XYDataset> splitByNaNs(XYDataset dataset) { switch (dataset.getSeriesCount()) {