changeset 2138:59bb5c895be3

Improved HYK/Zones- handling. flys-artifacts/trunk@3716 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 19 Jan 2012 11:00:27 +0000
parents 04b6b6a4564d
children 923256599afe
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java
diffstat 4 files changed, 179 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Jan 19 10:51:20 2012 +0000
+++ b/flys-artifacts/ChangeLog	Thu Jan 19 11:00:27 2012 +0000
@@ -1,3 +1,18 @@
+2012-01-19	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Somewhat improved HYK handling and rendering.
+
+	* src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java:
+	  Added ability to store 'zones', next to text annotations.
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java:
+	  (getLowestYValue, getUppestYValue, colorForHYKZone),
+	  (addBoxAnnotations): New. Create box annotations from zones.
+
+	* src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java:
+	  (doHYK): New, handle hyk facets by adding zones to annotation
+		   container.
+
 2012-01-19	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	Preparing improved HYK handling.
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Thu Jan 19 10:51:20 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Thu Jan 19 11:00:27 2012 +0000
@@ -8,6 +8,8 @@
 import org.jfree.chart.title.TextTitle;
 import org.jfree.data.xy.XYSeries;
 
+import de.intevation.flys.jfree.FLYSAnnotation;
+
 import org.w3c.dom.Document;
 
 import de.intevation.artifacts.DataProvider;
@@ -19,12 +21,14 @@
 import de.intevation.flys.jfree.StyledXYSeries;
 
 import de.intevation.flys.model.FastCrossSectionLine;
+import de.intevation.flys.artifacts.model.HYKFactory;
+
 
 /**
  * An OutGenerator that generates cross section graphs.
  */
 public class CrossSectionGenerator
-extends      LongitudinalSectionGenerator//XYChartGenerator
+extends      LongitudinalSectionGenerator
 implements   FacetTypes
 {
     /** The logger that is used in this generator. */
@@ -83,13 +87,16 @@
     }
 
 
+    /** Always return default subtitle. */
     @Override
     protected String getChartSubtitle() {
         // XXX NOTE: overriding this method disables ChartSettings subtitle!
+        // TODO clarify XXX NOTE
         return getDefaultChartSubtitle();
     }
 
 
+    /** Get Charts default subtitle. */
     @Override
     protected String getDefaultChartSubtitle() {
         List<DataProvider> providers =
@@ -167,6 +174,12 @@
                 attr,
                 visible);
         }
+        else if (name.equals(HYK)) {
+            doHyk(artifactFacet.getData(context),
+                artifactFacet.getFacetDescription(),
+                attr,
+                visible);
+        }
         else {
             logger.warn("CrossSection.doOut: Unknown facet name: " + name);
             return;
@@ -204,6 +217,29 @@
     }
 
 
+    /** Add HYK-Annotations (colorize and label some areas, draw lines. */
+    protected void doHyk(
+        Object     o,
+        String     seriesName,
+        Document   theme,
+        boolean    visible
+    ) {
+        logger.debug("CrossSectionGenerator.doHyk");
+
+        // TODO there is some style information for the text at least.
+
+        List<HYKFactory.Zone> zones = (List<HYKFactory.Zone>) o;
+
+        if (zones.size() == 0) {
+            logger.debug("CrossSectionGenerator.doHYK: empty zone list received.");
+        }
+
+        //TODO handle visible
+
+        addAnnotations(new FLYSAnnotation("HYK Zones", null, zones), true);
+    }
+
+
     /**
      * Do cross sections out.
      *
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Thu Jan 19 10:51:20 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Thu Jan 19 11:00:27 2012 +0000
@@ -30,6 +30,7 @@
 import org.jfree.chart.JFreeChart;
 import org.jfree.chart.LegendItem;
 import org.jfree.chart.LegendItemCollection;
+import org.jfree.chart.annotations.XYBoxAnnotation;
 import org.jfree.chart.annotations.XYTextAnnotation;
 import org.jfree.chart.axis.NumberAxis;
 import org.jfree.chart.axis.ValueAxis;
@@ -60,6 +61,8 @@
 
 import de.intevation.flys.utils.ThemeAccess;
 
+import de.intevation.flys.artifacts.model.HYKFactory;
+
 /**
  * An abstract base class for creating XY charts.
  *
@@ -512,6 +515,9 @@
         adjustAxes(plot);
         autoZoom(plot);
 
+        // These have to go after the autozoom.
+        addBoxAnnotations(plot);
+
         return chart;
     }
 
@@ -998,7 +1004,7 @@
 
             lic.add(li);
 
-            for (XYTextAnnotation ta: fa.getAnnotations()) {
+            for (XYTextAnnotation ta: fa.getTextAnnotations()) {
                 if(ta instanceof StickyAxisAnnotation) {
                     StickyAxisAnnotation sta = (StickyAxisAnnotation)ta;
                     sta.applyTheme(themeAccess);
@@ -1023,6 +1029,94 @@
         plot.setFixedLegendItems(old);
     }
 
+    /**
+     * Get "lowest" Y Value for first axis. This value is exactly at the
+     * border of the plot.
+     */
+    protected double getLowestYValue(XYPlot plot) {
+        ValueAxis yaxis = plot.getRangeAxis(0);
+        if (yaxis == null) {
+            logger.warn("No first Y-Axis to find lowest value for.");
+        }
+        return yaxis.getRange().getLowerBound();
+    }
+
+
+    /**
+     * Get "lowest" Y Value for first axis. This value is exactly at the
+     * border of the plot.
+     */
+    protected double getUppestYValue(XYPlot plot) {
+        ValueAxis yaxis = plot.getRangeAxis(0);
+        if (yaxis == null) {
+            logger.warn("No first Y-Axis to find uppest value for.");
+        }
+        return yaxis.getRange().getUpperBound();
+    }
+
+
+    /** Get color for hyk zones by their type (which is the name). */
+    public Paint colorForHYKZone(String zoneName) {
+        if (zoneName.startsWith("R")) {
+            // Brownish.
+            return new Color(153, 60, 0);
+        }
+        else if (zoneName.startsWith("V")) {
+            // Greenish.
+            return new Color(0, 255, 0);
+        }
+        else if (zoneName.startsWith("B")) {
+            // Grayish.
+            return new Color(128, 128, 128);
+        }
+        else if (zoneName.startsWith("H")) {
+            // Blueish.
+            return new Color(0, 0, 255);
+        }
+        else {
+            // Default.
+            logger.debug("Unknown zone type found.");
+            return new Color(255, 0, 0);
+        }
+    }
+
+
+    /** Add box annotations (currently, only hyk zones). */
+    public void addBoxAnnotations(XYPlot plot) {
+        logger.debug("XYChartGenerator.addBoxAnnotations");
+
+        Stroke basicStroke = new BasicStroke(1.0f);
+
+        Paint linePaint = new Color(255,0,0,60);
+        Paint fillPaint = new Color(0,255,0,60);
+        Paint tranPaint = new Color(0,0,0,0);
+
+        double fillPercent = 0.05;
+        double low = getLowestYValue(plot);
+        double up  = getUppestYValue(plot);
+        double upb = low + (up - low) * fillPercent;
+        double upt = low + (up - low) * fillPercent/2.0d;
+
+        for (FLYSAnnotation fa: annotations) {
+            for (HYKFactory.Zone zone: fa.getBoxes()) {
+                fillPaint = colorForHYKZone(zone.getName());
+
+                XYBoxAnnotation boxA = new XYBoxAnnotation(zone.getFrom(), low,
+                    zone.getTo(), upb, basicStroke, tranPaint, fillPaint);
+                XYBoxAnnotation boxB = new XYBoxAnnotation(zone.getFrom(), low,
+                    zone.getTo(), up, basicStroke, fillPaint, tranPaint);
+
+                // TODO style text
+                XYTextAnnotation tex = new XYTextAnnotation(zone.getName(),
+                    zone.getFrom() + (zone.getTo() - zone.getFrom()) / 2.0d,
+                    upt);
+
+                plot.getRenderer().addAnnotation(boxA);
+                plot.getRenderer().addAnnotation(boxB);
+                plot.getRenderer().addAnnotation(tex);
+            }
+        }
+    }
 
     /**
      * Adjusts the axes of a plot. This method sets the <i>labelFont</i> of the
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java	Thu Jan 19 10:51:20 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java	Thu Jan 19 11:00:27 2012 +0000
@@ -1,26 +1,48 @@
 package de.intevation.flys.jfree;
 
+import java.util.Collections;
 import java.util.List;
 
 import org.w3c.dom.Document;
 
 import org.jfree.chart.annotations.XYTextAnnotation;
 
+import de.intevation.flys.artifacts.model.HYKFactory;
+
+
 /**
- * List of Annotations with name and theme.
+ * List of Text- Annotations with name and theme.
  */
 public class FLYSAnnotation {
 
-    protected List<XYTextAnnotation> annotations;
+    protected List<XYTextAnnotation> textAnnotations;
+
+    protected List<HYKFactory.Zone> boxes;
 
     protected Document theme;
 
     protected String label;
 
 
+    /** Create annotations, parameter might be null. */
+    public FLYSAnnotation(String label, List<XYTextAnnotation> annotations,
+        List<HYKFactory.Zone> bAnnotations
+    ) {
+        this.label           = label;
+        this.textAnnotations = (annotations != null)
+                               ? annotations
+                               : Collections.<XYTextAnnotation>emptyList();
+        this.boxes  = (bAnnotations != null)
+                               ? bAnnotations
+                               : Collections.<HYKFactory.Zone>emptyList();
+    }
+
     public FLYSAnnotation(String label, List<XYTextAnnotation> annotations) {
-        this.label       = label;
-        this.annotations = annotations;
+        this.label           = label;
+        this.textAnnotations = (annotations != null)
+                               ? annotations
+                               : Collections.<XYTextAnnotation>emptyList();
+        this.boxes           = Collections.<HYKFactory.Zone>emptyList();
     }
 
     public void setLabel(String label) {
@@ -31,8 +53,12 @@
         return label;
     }
 
-    public List<XYTextAnnotation> getAnnotations() {
-        return annotations;
+    public List<XYTextAnnotation> getTextAnnotations() {
+        return textAnnotations;
+    }
+
+    public List<HYKFactory.Zone> getBoxes() {
+        return boxes;
     }
 
     public void setTheme(Document theme) {

http://dive4elements.wald.intevation.org