changeset 6880:8a4e344b309a

issue1378: Preparing DischargeProcessor to be able to draw W/Q points, code borrowed from FixWQGenerator.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 20 Aug 2013 15:05:07 +0200
parents 1186fa8a0bb9
children 32af7e5cb00f
files artifacts/src/main/java/org/dive4elements/river/exports/process/DischargeProcessor.java
diffstat 1 files changed, 56 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/DischargeProcessor.java	Tue Aug 20 14:35:48 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/DischargeProcessor.java	Tue Aug 20 15:05:07 2013 +0200
@@ -8,6 +8,9 @@
 
 package org.dive4elements.river.exports.process;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.log4j.Logger;
 import org.jfree.data.xy.XYSeries;
 import org.w3c.dom.Document;
@@ -18,7 +21,12 @@
 import org.dive4elements.river.artifacts.model.WQKms;
 import org.dive4elements.river.exports.StyledSeriesBuilder;
 import org.dive4elements.river.exports.XYChartGenerator;
+import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation;
+import org.dive4elements.river.jfree.RiverAnnotation;
 import org.dive4elements.river.jfree.StyledXYSeries;
+import org.dive4elements.river.utils.ThemeUtil;
+
+import org.jfree.chart.annotations.XYTextAnnotation;
 
 
 /** Helper for data handling in discharge diagrams. */
@@ -28,6 +36,23 @@
     private final static Logger logger =
             Logger.getLogger(DischargeProcessor.class);
 
+    /** Station for which the diagram is shown. */
+    private double km;
+
+    /** Tolerance for comparison of kilometers. */
+    public static final double KM_EPSILON = 0.001d;
+
+
+    /** This processor needs to be constructed with a given km. */
+    private DischargeProcessor() {
+        km = Double.NaN;
+    }
+
+
+    public DischargeProcessor(double km) {
+        this.km = km;
+    }
+
 
     /** Process data, add it to plot. */
     @Override
@@ -41,7 +66,8 @@
         CallContext context = generator.getCallContext();
         Object data = aandf.getData(context);
         if (data instanceof WQKms) {
-            // TODO: Fetch point
+            doWQKmsPointOut(
+                generator, (WQKms) data, aandf, theme, visible, index);
             return;
         }
         logger.error("Can't process " + data.getClass().getName() + " objects");
@@ -51,24 +77,44 @@
     /** True if this processor knows how to deal with facetType. */
     @Override
     public boolean canHandle(String facetType) {
-        return BED_DIFFERENCE_HEIGHT_YEAR.equals(facetType);
+        return STATIC_WQKMS_W.equals(facetType);
     }
 
 
-    /** TODO Handle WQKms point data. */
+    /** Handle WQKms data by finding w/q values at given km. */
     protected void doWQKmsPointOut(XYChartGenerator generator,
-        WQKms data,
+        WQKms wqkms,
         ArtifactAndFacet aandf,
         Document theme,
         boolean visible,
-        int axidx) {
+        int axidx
+    ) {
+        String title = aandf.getFacetDescription();
+        XYSeries series = new StyledXYSeries(
+            title,
+            theme);
 
-        /*
-        XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
-        StyledSeriesBuilder.addPoints(series, data.getHeightPerYearData(), false, GAP_TOLERANCE);
+        double[] kms = wqkms.getKms();
 
-        generator.addAxisSeries(series, axidx, visible);
-        */
+        for (int i = 0 ; i< kms.length; i++) {
+            if (Math.abs(kms[i] - km) <= KM_EPSILON) {
+                series.add(wqkms.getQ(i), wqkms.getW(i));
+                generator.addAxisSeries(series, axidx, visible);
+                if(visible && ThemeUtil.parseShowPointLabel(theme)) {
+                    List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>();
+                    XYTextAnnotation anno = new CollisionFreeXYTextAnnotation(
+                            title,
+                            wqkms.getQ(i),
+                            // TODO add a percentage to the extend of W axis
+                            wqkms.getW(i));
+                    textAnnos.add(anno);
+                    RiverAnnotation flysAnno = new RiverAnnotation(null, null, null, theme);
+                    flysAnno.setTextAnnotations(textAnnos);
+                    generator.addAnnotations(flysAnno);
+                }
+                return;
+            }
+        }
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org