changeset 3438:b9aff8d6ff74

Simplify annotation code flys-artifacts/trunk@5101 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Christian Lins <christian.lins@intevation.de>
date Mon, 23 Jul 2012 09:37:12 +0000
parents e111902834d3
children cb11919cccf9
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDeltaWtGenerator.java
diffstat 2 files changed, 61 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Jul 23 09:09:49 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon Jul 23 09:37:12 2012 +0000
@@ -1,3 +1,8 @@
+2012-07-23	Christian Lins	<christian.lins@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/fixings/FixDeltaWtGenerator.java:
+	  Simplify annotation code.
+
 2012-07-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDeltaWtGenerator.java	Mon Jul 23 09:09:49 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDeltaWtGenerator.java	Mon Jul 23 09:37:12 2012 +0000
@@ -247,18 +247,24 @@
         logger.debug("doAnalysisEventsOut: desc = " + desc);
 
         QWD[] qwds = (QWD[]) data;
+        doQWDEventsOut(qwds, desc, theme, visible);
+    }
+
+
+    protected void doQWDEventsOut(QWD[] qwds, String desc, Document theme, boolean visible)
+    {
         TimeSeriesCollection tsc = new TimeSeriesCollection();
 
         TimeSeries   series = new StyledTimeSeries(desc, theme);
         TimeSeries interpol = new StyledTimeSeries(desc + "interpol", theme);
 
         if (qwds == null) {
-            logger.debug("doAnalysisEventsOut: qwds == null");
+            logger.debug("doQWDEventsOut: qwds == null");
             return;
         }
 
         if (qwds.length == 0) {
-            logger.debug("doAnalysisEventsOut: qwds.length == 0");
+            logger.debug("doQWDEventsOut: qwds.length == 0");
             return;
         }
 
@@ -268,96 +274,7 @@
         int idxRegular = 0;
         for (int i = 0; i < qwds.length; i++) {
             if (qwds[i] == null) {
-                logger.debug("doAnalysisEventsOut: qwds[" + i + "] == null");
-                continue;
-            }
-            RegularTimePeriod rtp = new Day(qwds[i].getDate());
-            double value =  qwds[i].getDeltaW();
-            boolean interpolate = qwds[i].getInterpolated();
-            if (interpolate) {
-                interpol.add(rtp, value);
-                annoIdxMap.put(
-                    i,
-                    new int[]{1, idxInterpol++});
-            }
-            else {
-                series.add(rtp, value);
-                annoIdxMap.put(
-                    i,
-                    new int[]{0, idxRegular++});
-            }
-        }
-        tsc.addSeries(series);
-        tsc.addSeries(interpol);
-        addAxisDataset(tsc, 0, visible);
-        addAttribute(desc + "interpol", "interpolate");
-        addAttribute(desc, "outline");
-
-        if (visible) {
-            doQWDTextAnnotations(annoIdxMap, tsc, qwds, theme, visible);
-        }
-    }
-
-
-    /**
-     * @param annoIdxMap map of index in qwds to series/dataitem indices in tsc.
-     */
-    protected void doQWDTextAnnotations(Map<Integer, int[]> annoIdxMap,
-            TimeSeriesCollection tsc, QWD[] qwds, Document theme,
-            boolean visible) {
-        logger.debug("doQWDTextAnnotation()");
-
-        if (!visible || !ThemeUtil.parseShowPointLabel(theme)) {
-            logger.debug("doQWDTextAnnotation: annotation not visible");
-            return;
-        }
-
-        List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>();
-        Set<Map.Entry<Integer, int[]>> entries = annoIdxMap.entrySet();
-
-        for(Map.Entry<Integer, int[]> entry : entries) {
-            QWD qwd = qwds[entry.getKey()];
-            int[] idxs = entry.getValue();
-            double x = tsc.getXValue(idxs[0], idxs[1]);
-            XYTextAnnotation anno = new CollisionFreeXYTextAnnotation(
-                qwd.getQ() + " m\u00B3/s",
-                x,
-                qwd.getDeltaW());
-            textAnnos.add(anno);
-            logger.debug("annotation: " + x + "/" + qwd.getDeltaW());
-        }
-
-        FLYSAnnotation flysAnno = new FLYSAnnotation(null, null, null, theme);
-        flysAnno.setTextAnnotations(textAnnos);
-        addAnnotations(flysAnno);
-    }
-
-
-    protected void doReferenceEventsOut(
-        FLYSArtifact artifact,
-        Object       data,
-        String       desc,
-        Document     theme,
-        boolean      visible
-    ) {
-        logger.debug("doReferenceEventsOut: desc = " + desc);
-
-        QWD[] qwds = (QWD[]) data;
-        TimeSeriesCollection tsc = new TimeSeriesCollection();
-
-        TimeSeries   series = new StyledTimeSeries(desc, theme);
-        TimeSeries interpol = new StyledTimeSeries(desc + "interpol", theme);
-
-        if (qwds == null) {
-            return;
-        }
-
-        Map<Integer, int[]> annoIdxMap = new HashMap<Integer, int[]>();
-
-        int idxInterpol = 0;
-        int idxRegular = 0;
-        for (int i = 0; i < qwds.length; i++) {
-            if (qwds[i] == null) {
+                logger.debug("doQWDEventsOut: qwds[" + i + "] == null");
                 continue;
             }
             RegularTimePeriod rtp = new Day(qwds[i].getDate());
@@ -382,7 +299,6 @@
         }
         tsc.addSeries(series);
         tsc.addSeries(interpol);
-
         addAxisDataset(tsc, 0, visible);
         addAttribute(desc + "interpol", "interpolate");
         addAttribute(desc, "outline");
@@ -391,6 +307,53 @@
     }
 
 
+    /**
+     * @param annoIdxMap map of index in qwds to series/data item indices in tsc.
+     */
+    protected void doQWDTextAnnotations(Map<Integer, int[]> annoIdxMap,
+            TimeSeriesCollection tsc, QWD[] qwds, Document theme,
+            boolean visible) {
+        logger.debug("doQWDTextAnnotation()");
+
+        if (!visible || !ThemeUtil.parseShowPointLabel(theme)) {
+            logger.debug("doQWDTextAnnotation: annotation not visible");
+            return;
+        }
+
+        List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>();
+        Set<Map.Entry<Integer, int[]>> entries = annoIdxMap.entrySet();
+
+        for(Map.Entry<Integer, int[]> entry : entries) {
+            QWD qwd = qwds[entry.getKey()];
+            int[] idxs = entry.getValue();
+            double x = tsc.getXValue(idxs[0], idxs[1]);
+            XYTextAnnotation anno = new CollisionFreeXYTextAnnotation(
+                qwd.getQ() + " m\u00B3/s",
+                x,
+                qwd.getDeltaW());
+            textAnnos.add(anno);
+        }
+
+        FLYSAnnotation flysAnno = new FLYSAnnotation(null, null, null, theme);
+        flysAnno.setTextAnnotations(textAnnos);
+        addAnnotations(flysAnno);
+    }
+
+
+    protected void doReferenceEventsOut(
+        FLYSArtifact artifact,
+        Object       data,
+        String       desc,
+        Document     theme,
+        boolean      visible
+    ) {
+        logger.debug("doReferenceEventsOut: desc = " + desc);
+
+        QWD[] qwds = (QWD[]) data;
+        doQWDEventsOut(qwds, desc, theme, visible);
+    }
+
+
     protected void doDeviationOut(
         FLYSArtifact artifact,
         Object       data,

http://dive4elements.wald.intevation.org