[PATCH] (issue1574) Add area handling for correction curves

Wald Commits scm-commit at wald.intevation.org
Fri Dec 20 12:40:13 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1387539608 -3600
# Node ID 0ee6aa11649b9b1642f8f1fb3326a7899f2458d9
# Parent  dfe3f78fd3e50f67bfc8caa2af3463a7cae5f86e
(issue1574) Add area handling for correction curves

diff -r dfe3f78fd3e5 -r 0ee6aa11649b artifacts/src/main/java/org/dive4elements/river/artifacts/model/AreaFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/AreaFacet.java	Thu Dec 19 18:36:00 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/AreaFacet.java	Fri Dec 20 12:40:08 2013 +0100
@@ -64,7 +64,8 @@
         AreaArtifact artifact = (AreaArtifact) art;
         Object lowerData      = null;
         Object upperData      = null;
-        String stemFacetName  = null;
+        String lowerFacetName = null;
+        String upperFacetName = null;
 
         List<DataProvider> providers = context.
             getDataProvider(artifact.getLowerDPKey());
@@ -77,7 +78,7 @@
                 artifact.getLowerDPKey(), null, context);
             logger.debug("'Lower' data provider key for area [" +
                 artifact.getLowerDPKey() + "]");
-            stemFacetName = artifact.getLowerDPKey().split(":")[1];
+            lowerFacetName = artifact.getLowerDPKey().split(":")[1];
         }
 
         providers = context.getDataProvider(artifact.getUpperDPKey());
@@ -90,16 +91,14 @@
                 artifact.getUpperDPKey(), null, context);
             logger.debug("'Upper' data provider key for area [" +
                 artifact.getUpperDPKey() + "]");
-            if (stemFacetName == null) {
-                stemFacetName = artifact.getUpperDPKey().split(":")[1];
-            }
+            upperFacetName = artifact.getUpperDPKey().split(":")[1];
         }
 
         if (upperData == null && lowerData == null) {
             logger.warn("Not given 'upper' and 'lower' for area");
         }
 
-        return new Data(stemFacetName, lowerData, upperData,
+        return new Data(upperFacetName, lowerFacetName, lowerData, upperData,
             Boolean.valueOf(artifact.getPaintBetween()));
     }
 
@@ -113,24 +112,28 @@
     }
 
     /** Result data bundle. */
-    public class Data {
-        protected String  rootFacetName;
+    public static class Data {
+        protected String  upperFacetName;
+        protected String  lowerFacetName;
         protected Object  upperData;
         protected Object  lowerData;
         protected boolean doPaintBetween;
 
         /** Create a new result data bundle. */
-        public Data(String rootName, Object low, Object up, boolean between) {
-            this.rootFacetName  = rootName;
+        public Data(String upperFacetName, String lowerFacetName, Object low, Object up, boolean between) {
             this.lowerData      = low;
             this.upperData      = up;
             this.doPaintBetween = between;
+            this.lowerFacetName = lowerFacetName;
+            this.upperFacetName = upperFacetName;
         }
 
-        /** Get name of a facet that is involved in area generation
-         * to induce type (e.g. longitudinal_section.w -> "W over km"). */
-        public String getRootFacetName() {
-            return this.rootFacetName;
+        public String getLowerFacetName() {
+            return this.lowerFacetName;
+        }
+
+        public String getUpperFacetName() {
+            return this.upperFacetName;
         }
 
         /** Get data for 'upper' curve of area. */
diff -r dfe3f78fd3e5 -r 0ee6aa11649b artifacts/src/main/java/org/dive4elements/river/exports/process/AreaProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/AreaProcessor.java	Thu Dec 19 18:36:00 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/AreaProcessor.java	Fri Dec 20 12:40:08 2013 +0100
@@ -18,6 +18,7 @@
 import org.dive4elements.river.artifacts.geom.Lines;
 import org.dive4elements.river.artifacts.model.WKms;
 import org.dive4elements.river.artifacts.model.WQKms;
+import org.dive4elements.river.artifacts.model.WQCKms;
 import org.dive4elements.river.artifacts.model.AreaFacet;
 import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.exports.DiagramGenerator;
@@ -32,6 +33,45 @@
 
     private static final Logger logger = Logger.getLogger(AreaProcessor.class);
 
+    protected XYSeries getSeries(String seriesName, Object data, String facetType,
+            ThemeDocument theme) {
+        if (data == null || facetType == null) {
+            return null;
+        }
+
+        XYSeries series = new StyledXYSeries(seriesName, false, theme);
+
+        if (facetType.equals(FacetTypes.DISCHARGE_LONGITUDINAL_C)) {
+            WQCKms wqckms = (WQCKms) data;
+            int size = wqckms.size();
+            for (int i = 0; i < size; i++) {
+                series.add(wqckms.getKm(i), wqckms.getC(i), false);
+            }
+        } else if (data instanceof WQKms) {
+            if (FacetTypes.IS.Q(facetType)) {
+                StyledSeriesBuilder.addPointsKmQ(series, (WQKms) data);
+            }
+            else {
+                StyledSeriesBuilder.addPoints(series, (WKms) data);
+            }
+        }
+        else if (data instanceof double[][]) {
+            StyledSeriesBuilder.addPoints(series, (double [][]) data, false);
+        }
+        else if (data instanceof WKms) {
+            StyledSeriesBuilder.addPoints(series, (WKms) data);
+        }
+        else if (data instanceof Lines.LineData) {
+            StyledSeriesBuilder.addPoints(series, ((Lines.LineData) data).points, false);
+        }
+        else {
+            logger.error("Do not know how to deal with (up) area info from: "
+                    + data);
+        }
+        return series;
+    }
+
+
     @Override
     public void doOut(
             DiagramGenerator generator,
@@ -46,63 +86,15 @@
 
         AreaFacet.Data data = (AreaFacet.Data) bundle.getData(context);
 
-        XYSeries up   = null;
-        XYSeries down = null;
+        String lowerFacetName = data.getLowerFacetName();
+        String upperFacetName = data.getUpperFacetName();
 
-        if (data.getUpperData() != null) {
-            up = new StyledXYSeries(seriesName, false, theme);
-            if (data.getUpperData() instanceof WQKms) {
-                if (FacetTypes.IS.Q(data.getRootFacetName())) {
-                    StyledSeriesBuilder.addPointsKmQ(up, (WQKms) data.getUpperData());
-                }
-                else {
-                    StyledSeriesBuilder.addPoints(up, (WKms) data.getUpperData());
-                }
-            }
-            else if (data.getUpperData() instanceof double[][]) {
-                StyledSeriesBuilder.addPoints(up, (double [][]) data.getUpperData(), false);
-            }
-            else if (data.getUpperData() instanceof WKms) {
-                StyledSeriesBuilder.addPoints(up, (WKms) data.getUpperData());
-            }
-            else if (data.getUpperData() instanceof Lines.LineData) {
-                StyledSeriesBuilder.addPoints(up, ((Lines.LineData) data.getUpperData()).points, false);
-            }
-            else {
-                logger.error("Do not know how to deal with (up) area info from: "
-                        + data.getUpperData());
-            }
-        }
+        XYSeries up   = getSeries(seriesName, data.getUpperData(), upperFacetName, theme);
+        XYSeries down = getSeries(seriesName + " ", data.getLowerData(), lowerFacetName, theme);
+
 
         // TODO Depending on style, the area (e.g. 20m^2) should be added as annotation.
 
-        if (data.getLowerData() != null) {
-            // TODO: Sort this out: when the two series have the same name,
-            // the renderer (or anything in between) will not work correctly.
-            down = new StyledXYSeries(seriesName + " ", false, theme);
-            if (data.getLowerData() instanceof WQKms) {
-                if (FacetTypes.IS.Q(data.getRootFacetName())) {
-                    StyledSeriesBuilder.addPointsKmQ(down, (WQKms) data.getLowerData());
-                }
-                else {
-                    StyledSeriesBuilder.addPoints(down, (WQKms) data.getLowerData());
-                }
-            }
-            else if (data.getLowerData() instanceof double[][]) {
-                StyledSeriesBuilder.addPoints(down, (double[][]) data.getLowerData(), false);
-            }
-            else if (data.getLowerData() instanceof WKms) {
-                StyledSeriesBuilder.addPoints(down, (WKms) data.getLowerData());
-            }
-            else if (data.getLowerData() instanceof Lines.LineData) {
-                StyledSeriesBuilder.addPoints(down, ((Lines.LineData) data.getLowerData()).points, false);
-            }
-            else {
-                logger.error("Do not know how to deal with (down) area info from: "
-                        + data.getLowerData());
-            }
-        }
-
         if (up == null && down != null) {
             area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE);
             down.setKey(seriesName);
@@ -125,9 +117,12 @@
             area.addSeries(down);
         }
 
+        String facetNameForAxis = lowerFacetName == null
+            ? upperFacetName
+            : lowerFacetName;
         /* Decide axis name based on facet name */
         generator.addAreaSeries(area,
-                axisNameForFacet(data.getRootFacetName()), visible);
+                axisNameForFacet(facetNameForAxis), visible);
     }
 
     /** Look up the axis identifier for a given facet type. */
@@ -135,7 +130,8 @@
         if (FacetTypes.W_DIFFERENCES.equals(facetName)) {
             return "diffW";
         }
-        if (FacetTypes.IS.W(facetName)) {
+        if (FacetTypes.IS.W(facetName) ||
+            FacetTypes.DISCHARGE_LONGITUDINAL_C.equals(facetName)) {
             return "W";
         }
         if (FacetTypes.IS.Q(facetName)) {


More information about the Dive4elements-commits mailing list