changeset 719:035c0095b427

Draw correction curve again. flys-artifacts/trunk@2193 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 21 Jun 2011 21:41:49 +0000
parents f3fd8c9b7f51
children d60cc6453d45
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java
diffstat 6 files changed, 77 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jun 21 18:10:49 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jun 21 21:41:49 2011 +0000
@@ -1,3 +1,23 @@
+2011-06-21  Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+    Draw correction curve again.
+
+	* src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java:
+	  Use correction curve to map plot to axes. Not doing so prevented
+	  the correction curve from being drawn!
+	  Smaller code cleanups and simplifications.
+
+	* src/main/java/de/intevation/flys/artifacts/model/WQKms.java,
+	  src/main/java/de/intevation/flys/artifacts/model/WQCKms.java:
+	  Added methods to directly access the components w, q and c
+	  at a given index.
+
+	* src/main/java/de/intevation/flys/exports/ChartGenerator.java:
+	  Attribute access via DOM instead of XPath.
+
+	* src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java:
+	  Code simplification.
+
 2011-06-21  Ingo Weinzierl <ingo@intevation.de>
 
 	  flys/issue157 (Diagramm: Ursprung berechnete Abflusskurve)
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java	Tue Jun 21 18:10:49 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java	Tue Jun 21 21:41:49 2011 +0000
@@ -73,6 +73,10 @@
         return dst;
     }
 
+    public double getC(int idx) {
+        return cw.getQuick(idx);
+    }
+
 
     /**
      * Returns the double array of corrected W values.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java	Tue Jun 21 18:10:49 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java	Tue Jun 21 21:41:49 2011 +0000
@@ -140,6 +140,13 @@
         return kms.getQuick(idx);
     }
 
+    public double getW(int idx) {
+        return w.getQuick(idx);
+    }
+
+    public double getQ(int idx) {
+        return q.getQuick(idx);
+    }
 
     public double[] getKms() {
         return kms.toNativeArray();
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Tue Jun 21 18:10:49 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Tue Jun 21 21:41:49 2011 +0000
@@ -8,7 +8,7 @@
 import org.apache.log4j.Logger;
 
 import org.w3c.dom.Document;
-import org.w3c.dom.Node;
+import org.w3c.dom.Element;
 
 import org.jfree.data.Range;
 
@@ -117,20 +117,19 @@
     protected int[] getSize() {
         int[] size = new int[2];
 
-        Node sizeEl = (Node) XMLUtils.xpath(
+        Element sizeEl = (Element)XMLUtils.xpath(
             request,
             XPATH_CHART_SIZE,
             XPathConstants.NODE,
             ArtifactNamespaceContext.INSTANCE);
 
         if (sizeEl != null) {
-            String w = XMLUtils.xpathString(
-                sizeEl, "@art:width", ArtifactNamespaceContext.INSTANCE);
+            String uri = ArtifactNamespaceContext.NAMESPACE_URI;
 
-            String h = XMLUtils.xpathString(
-                sizeEl, "@art:height", ArtifactNamespaceContext.INSTANCE);
+            String w = sizeEl.getAttributeNS(uri, "width");
+            String h = sizeEl.getAttributeNS(uri, "height");
 
-            if (w != null && w.length() > 0 && h != null && h.length() > 0) {
+            if (w.length() > 0 && h.length() > 0) {
                 try {
                     size[0] = Integer.parseInt(w);
                     size[1] = Integer.parseInt(h);
@@ -146,7 +145,7 @@
 
 
     protected Range getDomainAxisRange() {
-        Node xrange = (Node) XMLUtils.xpath(
+        Element xrange = (Element)XMLUtils.xpath(
             request,
             XPATH_CHART_X_RANGE,
             XPathConstants.NODE,
@@ -156,15 +155,14 @@
             return null;
         }
 
-        String lower = XMLUtils.xpathString(
-            xrange, "@art:from", ArtifactNamespaceContext.INSTANCE);
+        String uri = ArtifactNamespaceContext.NAMESPACE_URI;
 
-        String upper = XMLUtils.xpathString(
-            xrange, "@art:to", ArtifactNamespaceContext.INSTANCE);
+        String lower = xrange.getAttributeNS(uri, "from");
+        String upper = xrange.getAttributeNS(uri, "to");
 
         logger.debug("FOUND X RANGE: " + lower + " -> " + upper);
 
-        if (lower != null && upper != null) {
+        if (lower.length() > 0 && upper.length() > 0) {
             try {
                 double from = Double.parseDouble(lower);
                 double to   = Double.parseDouble(upper);
@@ -192,7 +190,7 @@
 
 
     protected Range getValueAxisRange() {
-        Node yrange = (Node) XMLUtils.xpath(
+        Element yrange = (Element)XMLUtils.xpath(
             request,
             XPATH_CHART_Y_RANGE,
             XPathConstants.NODE,
@@ -202,13 +200,12 @@
             return null;
         }
 
-        String lower = XMLUtils.xpathString(
-            yrange, "@art:from", ArtifactNamespaceContext.INSTANCE);
+        String uri = ArtifactNamespaceContext.NAMESPACE_URI;
 
-        String upper = XMLUtils.xpathString(
-            yrange, "@art:to", ArtifactNamespaceContext.INSTANCE);
+        String lower = yrange.getAttributeNS(uri, "from");
+        String upper = yrange.getAttributeNS(uri, "to");
 
-        if (lower != null && upper != null) {
+        if (lower.length() > 0 && upper.length() > 0) {
             try {
                 double from = Double.parseDouble(lower);
                 double to   = Double.parseDouble(upper);
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java	Tue Jun 21 18:10:49 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java	Tue Jun 21 21:41:49 2011 +0000
@@ -44,6 +44,7 @@
     }
 
 
+    @Override
     public void addDatasets(JFreeChart chart) {
         super.addDatasets(chart);
 
@@ -53,6 +54,7 @@
     }
 
 
+    @Override
     protected void adjustPlot(XYPlot plot) {
         super.adjustPlot(plot);
 
@@ -81,7 +83,7 @@
     protected void adjustAxes(XYPlot plot) {
         super.adjustAxes(plot);
 
-        plot.mapDatasetToRangeAxis(2, 1);
+        plot.mapDatasetToRangeAxis(2, 0);
     }
 
 
@@ -90,23 +92,30 @@
     public void doOut(Artifact artifact, Facet facet, Document attr) {
         logger.debug("DischargeLongitudinalSectionGenerator.doOut");
 
-        String name = facet != null ? facet.getName() : null;
+        if (facet == null) {
+            return;
+        }
+
+        String name = facet.getName();
+
+        if (name == null) {
+            return;
+        }
 
         FLYSArtifact flys = (FLYSArtifact) artifact;
         Facet        f    = flys.getNativeFacet(facet);
 
-        if (name != null && name.equals(DISCHARGE_LONGITUDINAL_W)) {
+        if (name.equals(DISCHARGE_LONGITUDINAL_W)) {
             doWOut((WQKms) f.getData(artifact, context));
         }
-        else if (name != null && name.equals(DISCHARGE_LONGITUDINAL_Q)) {
+        else if (name.equals(DISCHARGE_LONGITUDINAL_Q)) {
             doQOut((WQKms) f.getData(artifact, context));
         }
-        else if (name != null && name.equals(DISCHARGE_LONGITUDINAL_C)) {
+        else if (name.equals(DISCHARGE_LONGITUDINAL_C)) {
             doCorrectedWOut((WQCKms) f.getData(artifact, context));
         }
         else {
             logger.warn("Unknown facet name: " + name);
-            return;
         }
     }
 
@@ -119,18 +128,13 @@
     protected void doCorrectedWOut(WQCKms wqckms) {
         logger.debug("DischargeLongitudinalSectionGenerator.doCorrectedWOut");
 
-        XYSeries series = new XYSeries(getSeriesNameForCorrected(wqckms, "W"));
-
-        double[] target = new double[4];
-        int      size   = wqckms.size();
+        int size = wqckms.size();
 
-        for (int i = 0; i < size; i++) {
-            target = wqckms.get(i, target);
-
-            series.add(target[2], target[3]);
-        }
-
-        if (series.getItemCount() > 0) {
+        if (size > 0) {
+            XYSeries series = new XYSeries(getSeriesNameForCorrected(wqckms, "W"));
+            for (int i = 0; i < size; i++) {
+                series.add(wqckms.getKms(i), wqckms.getC(i));
+            }
             cw.addSeries(series);
         }
     }
@@ -140,13 +144,13 @@
         String name = wqkms.getName();
 
         name = name.replace(
-            "Benutzerdefiniert",
-            "Benutzerdefiniert [korrigiert]");
+            "benutzerdefiniert",
+            "benutzerdefiniert [korrigiert]");
 
-        String prefix = name != null && name.indexOf(mode) >= 0 ? null : mode;
+        String prefix = name.indexOf(mode) >= 0 ? null : mode;
 
         return prefix != null && prefix.length() > 0
-            ? prefix + "(" + name +")"
+            ? prefix + "(" + name + ")"
             : name;
     }
 }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Tue Jun 21 18:10:49 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Tue Jun 21 21:41:49 2011 +0000
@@ -40,13 +40,6 @@
     private static Logger logger =
         Logger.getLogger(LongitudinalSectionGenerator.class);
 
-
-    public static final String LONGITUDINAL_SECTION_W =
-        "longitudinal_section.w";
-
-    public static final String LONGITUDINAL_SECTION_Q =
-        "longitudinal_section.q";
-
     public static final String I18N_CHART_TITLE =
         "chart.longitudinal.section.title";
 
@@ -112,6 +105,7 @@
     }
 
 
+    @Override
     protected void addDatasets(JFreeChart chart) {
         XYPlot plot = (XYPlot) chart.getPlot();
 
@@ -224,8 +218,7 @@
 
         XYSeries series = new XYSeries(getSeriesName(wqkms, "W"));
 
-        double[] target = new double[3];
-        int      size   = wqkms.size();
+        int size = wqkms.size();
 
         if (logger.isDebugEnabled()) {
             if (wqkms.size() > 0) {
@@ -237,9 +230,7 @@
         }
 
         for (int i = 0; i < size; i++) {
-            target = wqkms.get(i, target);
-
-            series.add(target[2], target[0]);
+            series.add(wqkms.getKms(i), wqkms.getW(i));
         }
 
         w.addSeries(series);
@@ -256,8 +247,7 @@
 
         XYSeries series = new XYSeries(getSeriesName(wqkms, "Q"));
 
-        double[] target = new double[3];
-        int      size   = wqkms.size();
+        int size = wqkms.size();
 
         if (logger.isDebugEnabled()) {
             if (wqkms.size() > 0) {
@@ -269,10 +259,7 @@
         }
 
         for (int i = 0; i < size; i++) {
-            target = wqkms.get(i, target);
-
-            //logger.debug("++ Q Tuple: " + target[2] + " -> " + target[1]);
-            series.add(target[2], target[1]);
+            series.add(wqkms.getKms(i), wqkms.getQ(i));
         }
 
         q.addSeries(series);

http://dive4elements.wald.intevation.org