changeset 2104:bb0dede9294f

Implementation towards areas at other than first axis (flys/issue441). flys-artifacts/trunk@3661 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 12 Jan 2012 12:29:56 +0000
parents b9f7ec9bda18
children e73eaea035ab
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AreaFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/BlackboardDataFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java
diffstat 5 files changed, 131 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AreaFacet.java	Thu Jan 12 12:22:40 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AreaFacet.java	Thu Jan 12 12:29:56 2012 +0000
@@ -57,6 +57,7 @@
         AreaArtifact artifact = (AreaArtifact) art;
         Object lowerData      = null;
         Object upperData      = null;
+        String stemFacetName  = null;
 
         List<DataProvider> providers = context.
             getDataProvider(artifact.getLowerDPKey());
@@ -67,6 +68,9 @@
         else {
             lowerData = providers.get(0).provideData(
                 artifact.getLowerDPKey(), null, context);
+            logger.debug("'Lower' data provider key for area [" + 
+                artifact.getLowerDPKey() + "]");
+            stemFacetName = artifact.getLowerDPKey().split(":")[1];
         }
 
         providers = context.getDataProvider(artifact.getUpperDPKey());
@@ -77,15 +81,19 @@
         else {
             upperData = providers.get(0).provideData(
                 artifact.getUpperDPKey(), null, context);
+            logger.debug("'Upper' data provider key for area [" +
+                artifact.getUpperDPKey() + "]");
+            if (stemFacetName == null) {
+                stemFacetName = artifact.getUpperDPKey().split(":")[1];
+            }
         }
 
         if (upperData == null && lowerData == null) {
             logger.warn("Not given 'upper' and 'lower' for area");
         }
 
-        return new Object[] {lowerData,
-            upperData,
-            Boolean.valueOf(artifact.getPaintBetween())};
+        return new Data(stemFacetName, lowerData, upperData,
+            Boolean.valueOf(artifact.getPaintBetween()));
     }
 
 
@@ -96,5 +104,43 @@
         copy.set(this);
         return copy;
     }
+
+    /** Result data bundle. */
+    public class Data {
+        protected String  rootFacetName;
+        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;
+            this.lowerData      = low;
+            this.upperData      = up;
+            this.doPaintBetween = between;
+        }
+
+        /** 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;
+        }
+
+        /** Get data for 'upper' curve of area. */
+        public Object getUpperData() {
+            return this.upperData;
+        }
+
+        /** Get data for 'lower' curve of area. */
+        public Object getLowerData() {
+            return this.lowerData;
+        }
+
+        /** Whether to fill whole area between (in contrast to 'under'
+         *  or 'over'). */
+        public boolean doPaintBetween() {
+            return this.doPaintBetween;
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/BlackboardDataFacet.java	Thu Jan 12 12:22:40 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/BlackboardDataFacet.java	Thu Jan 12 12:29:56 2012 +0000
@@ -23,10 +23,17 @@
     }
 
 
-    /** Hey, We can ArtifactUUID+FacetIndex (i.e. getData)! */
+    /** Define key to which to respond when asked for 'blackboard'
+     * (DataProvider)- data. */
+    public String areaDataKey(Artifact art) {
+        return art.identifier() + ":" + getName() + ":" + getIndex();
+    }
+
+
+    /** Hey, We can ArtifactUUID+:+FacetName+:+FacetIndex (i.e. getData)! */
     public List getDataProviderKeys(Artifact art) {
         List list = new ArrayList();
-        list.add(art.identifier() + getIndex());
+        list.add(areaDataKey(art));
         return list;
     }
 
@@ -43,13 +50,12 @@
         Object param,
         CallContext context
     ) {
-        if (key.equals(artifact.identifier() + getIndex())) {
+        if (key.equals(areaDataKey(artifact))) {
             return getData(artifact, context);
         }
         else {
             return null;
         }
     }
-
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Thu Jan 12 12:22:40 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Thu Jan 12 12:29:56 2012 +0000
@@ -17,6 +17,19 @@
                 || type.equals(CROSS_SECTION_AREA)
                 || type.equals(LONGITUDINAL_SECTION_AREA);
         }
+        public static boolean W(String type) {
+            return type.equals(LONGITUDINAL_W)
+                || type.equals(DISCHARGE_LONGITUDINAL_W)
+                || type.equals(DURATION_W)
+                || type.equals(STATIC_WKMS)
+                || type.equals(STATIC_WQKMS_W);
+        }
+        public static boolean Q(String type) {
+            return type.equals(LONGITUDINAL_Q)
+                || type.equals(DISCHARGE_LONGITUDINAL_Q)
+                || type.equals(DURATION_Q)
+                || type.equals(STATIC_WQKMS_Q);
+        }
     };
 
     String AREA                   = "area";
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Thu Jan 12 12:22:40 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Thu Jan 12 12:29:56 2012 +0000
@@ -25,7 +25,7 @@
  * An OutGenerator that generates cross section graphs.
  */
 public class CrossSectionGenerator
-extends      XYChartGenerator
+extends      LongitudinalSectionGenerator//XYChartGenerator
 implements   FacetTypes
 {
     /** The logger that is used in this generator. */
@@ -76,7 +76,7 @@
      * Get localized chart title.
      */
     @Override
-    protected String getDefaultChartTitle() {
+    public String getDefaultChartTitle() {
         Object[] i18n_msg_args = new Object[] {
             getRiverName()
         };
@@ -175,55 +175,10 @@
     }
 
 
-    /**
-     * Do Area out.
-     */
-    protected void doArea(
-        Object     o,
-        String     seriesName,
-        Document   theme,
-        boolean    visible
-    ) {
-        logger.debug("CrossSectionGenerator.doArea");
-        StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme);
-
-        // TODO make this more stable.
-        Object[] doubles = (Object[]) o;
-        XYSeries up   = null;
-        XYSeries down = null;
-
-        if (doubles[1] != null) {
-            up = new StyledXYSeries(seriesName, false, theme);
-            StyledSeriesBuilder.addPoints(up, (double [][]) doubles[1]);
-        }
-
-        if (doubles[0] != 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);
-            StyledSeriesBuilder.addPoints(down, (double [][]) doubles[0]);
-        }
-
-        if (up == null && down != null) {
-            area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE);
-            down.setKey(seriesName);
-            area.addSeries(down);
-        }
-        else if (up != null && down == null) {
-            area.setMode(StyledAreaSeriesCollection.FILL_MODE.UNDER);
-            area.addSeries(up);
-        }
-        else if (up != null && down != null) {
-            if (doubles[2] != null && ((Boolean)doubles[2]).booleanValue()) {
-                area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN);
-            }
-            else {
-                area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE);
-            }
-            area.addSeries(up);
-            area.addSeries(down);
-        }
-        addAreaSeries(area, 0, visible);
+    /** Look up the axis identifier for a given facet type. */
+    public int axisIdxForFacet(String facetName) {
+        // TODO Where to add thid axis too.
+        return 0;
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Thu Jan 12 12:22:40 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Thu Jan 12 12:29:56 2012 +0000
@@ -17,6 +17,7 @@
 
 import de.intevation.flys.artifacts.FLYSArtifact;
 
+import de.intevation.flys.artifacts.model.AreaFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.WKms;
 import de.intevation.flys.artifacts.model.WQKms;
@@ -282,7 +283,6 @@
      * @param xaxis The domain axis.
      */
     protected void invertXAxis(ValueAxis xaxis) {
-
         if (inverted) {
             logger.debug("X-Axis.setInverted(true)");
             xaxis.setInverted(true);
@@ -330,6 +330,12 @@
                 || name.equals(STATIC_WQKMS)) {
             doWOut((WKms) artifactAndFacet.getData(context), facet, attr, visible);
         }
+        else if (name.equals(STATIC_WQKMS_W)) {
+            doWOut((WQKms) artifactAndFacet.getData(context), facet, attr, visible);
+        }
+        else if (name.equals(STATIC_WQKMS_Q)) {
+            doQOut((WQKms) artifactAndFacet.getData(context), facet, attr, visible);
+        }
         else if (name.equals(W_DIFFERENCES)) {
             doWDifferencesOut(
                 (WKms) artifactAndFacet.getData(context),
@@ -493,6 +499,20 @@
     }
 
 
+    /** Look up the axis identifier for a given facet type. */
+    public int axisIdxForFacet(String facetName) {
+        if (FacetTypes.IS.W(facetName)) {
+            return YAXIS.W.idx;
+        }
+        else if (FacetTypes.IS.Q(facetName)) {
+            return YAXIS.Q.idx;
+        }
+        else {
+            logger.warn("Could not find axis for facet " + facetName);
+            return YAXIS.W.idx;
+        }
+    }
+
     /**
      * Do Area out.
      */
@@ -505,40 +525,49 @@
         logger.debug("LongitudinalSectionGenerator.doArea");
         StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme);
 
-        // TODO make this more stable.
-        Object[] doubles = (Object[]) o;
+        AreaFacet.Data data = (AreaFacet.Data) o;
+
         XYSeries up   = null;
         XYSeries down = null;
 
-        if (doubles[1] != null) {
+        if (data.getUpperData() != null) {
             up = new StyledXYSeries(seriesName, false, theme);
-            if (doubles[1] instanceof WKms) {
-                StyledSeriesBuilder.addPoints(up, (WKms) doubles[1]);
+            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 (doubles[1] instanceof double[][]) {
-                StyledSeriesBuilder.addPoints(up, (double [][]) doubles[1]);
+            else if (data.getUpperData() instanceof double[][]) {
+                StyledSeriesBuilder.addPoints(up, (double [][]) data.getUpperData());
             }
             else {
                 logger.error("Do not know how to deal with (up) area info from: "
-                    + doubles[1]);
+                    + data.getUpperData());
             }
         }
 
-        if (doubles[0] != null) {
+        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 (doubles[0] instanceof WQKms) {
-                StyledSeriesBuilder.addPoints(down, (WKms) doubles[0]);
+            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 (doubles[0] instanceof double[][]) {
-                StyledSeriesBuilder.addPoints(down, (double[][]) doubles[0]);
+            else if (data.getLowerData() instanceof double[][]) {
+                StyledSeriesBuilder.addPoints(down, (double[][]) data.getLowerData());
             }
             else {
                 logger.error("Do not know how to deal with (down) area info from: "
-                    + doubles[0]);
+                    + data.getLowerData());
             }
-
         }
 
         if (up == null && down != null) {
@@ -551,11 +580,17 @@
             area.addSeries(up);
         }
         else if (up != null && down != null) {
-            area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN);
+            if (data.doPaintBetween()) {
+                area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN);
+            }
+            else {
+                area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE);
+            }
             area.addSeries(up);
             area.addSeries(down);
         }
-        addAreaSeries(area, 0, visible);
+        // Add area to the respective axis.
+        addAreaSeries(area, axisIdxForFacet(data.getRootFacetName()), visible);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org