changeset 8507:7d0c4e508835

(issue1782) Select index based on km for step generation If we calculate from a larger KM to a smaller KM the larger index refers to the smaller KM so to correctly draw the steps with the assumption that the previous q is drawn together with the current q we have to select the next / prev index accordingly.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 16 Dec 2014 15:29:44 +0100
parents da9365fc2f42
children 5160d5f9c65d
files artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java
diffstat 1 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java	Tue Dec 16 14:27:13 2014 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java	Tue Dec 16 15:29:44 2014 +0100
@@ -267,16 +267,25 @@
         for (int i = 0; i < size; i++) {
             if (i==0) {
                 series.add(wqkms.getKm(i), wqkms.getQ(i), false);
-            }
-            else {
+            } else if (i == size-1) {
+                series.add(wqkms.getKm(i), wqkms.getQ(i), false);
+            } else {
                 //Add two points.
-                double halveX = (wqkms.getKm(i-1) + wqkms.getKm(i)) / 2d;
-                series.add(halveX, wqkms.getQ(i-1), false);
+                double prevX;
+                double prevQ;
+                if (wqkms.getKm(i + 1) < wqkms.getKm(i)) {
+                    /* Depending on the data direction the previous km / q
+                     * might have a larger index when we draw right to left data. */
+                    prevX = wqkms.getKm(i + 1);
+                    prevQ = wqkms.getQ(i + 1);
+                } else {
+                    prevX = wqkms.getKm(i - 1);
+                    prevQ = wqkms.getQ(i - 1);
+                }
+                double halveX = (prevX + wqkms.getKm(i)) / 2d;
+                series.add(halveX, prevQ, false);
                 series.add(halveX, wqkms.getQ(i), false);
             }
-            if (i == size-1) {
-                series.add(wqkms.getKm(i), wqkms.getQ(i), false);
-            }
         }
     }
 

http://dive4elements.wald.intevation.org