changeset 7607:ef99781bcec7

(issue1667) Remove duplicate points in the same series in Diagram CSV export
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 27 Nov 2013 18:50:21 +0100
parents 424c3d84e119
children 974ec4eba152
files artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java
diffstat 1 files changed, 27 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java	Wed Nov 27 18:06:04 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java	Wed Nov 27 18:50:21 2013 +0100
@@ -343,8 +343,28 @@
         int series = data.getSeriesCount();
         for (int i = 0; i < series; i++) {
             int items = data.getItemCount(i);
+            double lastX = java.lang.Double.MAX_VALUE;
+            double lastY = java.lang.Double.MAX_VALUE;
+
             for (int j = 0; j < items; j++) {
-                log.debug("write data: " + data.getX(i, j) + ", " + data.getY(i, j));
+                Number x = data.getX(i, j);
+                Number y = data.getY(i, j);
+                double xVal = data.getXValue(i, j);
+                double yVal = data.getYValue(i, j);
+
+                if (lastX == xVal && lastY == yVal) {
+                    // comparing equality is ok here as we want
+                    // to find data duplicates like they are added
+                    // for example by the StyledSeriesBuilder in
+                    // addStepPointsKmQ
+                    log.debug("removing duplicate point in series");
+                    continue;
+                }
+                lastX = xVal;
+                lastY = yVal;
+
+                log.debug("write data: " + x + ", " + y);
+
 
                 /*
                 // Skip (NaN,NaN) datapoints.
@@ -358,16 +378,16 @@
                 String yString;
 
                 try {
-                    xString = java.lang.Double.isNaN(data.getXValue(i,j))
+                    xString = java.lang.Double.isNaN(xVal)
                         ? ""
-                        : format.format(data.getX(i, j));
-                    yString = java.lang.Double.isNaN(data.getYValue(i, j))
+                        : format.format(x);
+                    yString = java.lang.Double.isNaN(yVal)
                         ? ""
-                        : format.format(data.getY(i, j));
+                        : format.format(y);
                 }
                 catch (NumberFormatException nfe) {
-                    xString = data.getX(i, j).toString();
-                    yString = data.getY(i, j).toString();
+                    xString = x.toString();
+                    yString = y.toString();
                 }
                 writer.writeNext(new String[] {
                     xString,

http://dive4elements.wald.intevation.org