diff flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java @ 1679:69929c471646

Improved the creation/rendering of annotations (km favorites, mainvalues). flys-artifacts/trunk@2896 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 05 Oct 2011 14:23:53 +0000
parents dd9dfe1e48fa
children bdb05dc9b763
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Wed Oct 05 13:16:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Wed Oct 05 14:23:53 2011 +0000
@@ -1,20 +1,14 @@
 package de.intevation.flys.exports;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.log4j.Logger;
 
 import org.jfree.chart.JFreeChart;
-import org.jfree.chart.LegendItem;
-import org.jfree.chart.LegendItemCollection;
 import org.jfree.chart.axis.NumberAxis;
 import org.jfree.chart.axis.ValueAxis;
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.chart.title.TextTitle;
 import org.jfree.data.Range;
 import org.jfree.data.xy.XYSeries;
-import org.jfree.ui.TextAnchor;
 
 import org.w3c.dom.Document;
 
@@ -28,8 +22,6 @@
 import de.intevation.flys.artifacts.model.WQKms;
 
 import de.intevation.flys.jfree.FLYSAnnotation;
-import de.intevation.flys.jfree.StickyAxisAnnotation;
-import de.intevation.flys.model.Annotation;
 import de.intevation.flys.utils.FLYSUtils;
 
 
@@ -72,13 +64,9 @@
 
     protected boolean inverted;
 
-    /** List of annotations to insert in plot. */
-    protected List<FLYSAnnotation> annotations;
-
 
     public LongitudinalSectionGenerator() {
         super();
-        annotations = new ArrayList<FLYSAnnotation>();
     }
 
 
@@ -108,16 +96,6 @@
         chart.addSubtitle(new TextTitle(subtitle));
     }
 
-    @Override
-    public JFreeChart generateChart() {
-        JFreeChart c = super.generateChart();
-        XYPlot p = (XYPlot) c.getPlot();
-
-        redoAnnotations(p, p.getDomainAxis());
-
-        return c;
-    }
-
 
     protected String getXAxisLabel() {
         FLYSArtifact flys = (FLYSArtifact) master;
@@ -154,67 +132,6 @@
 
 
     /**
-     * Remove all annotations from plot and re-insert them at an approximately
-     * okay position. The followed approach is naive but side-effect free.
-     *
-     * @param plot the plot.
-     * @param axis the value axis.
-     */
-    protected void redoAnnotations(XYPlot plot, ValueAxis axis) {
-        plot.clearAnnotations();
-        // TODO Position calculation could/should be done in
-        // the StickyAxisAnnotation-Implementation itself.
-
-        int idx = 0;
-        ValueAxis yAxis = plot.getRangeAxis(idx);
-
-        if (yAxis == null) {
-            if (plot.getRangeAxisCount() >= 2) {
-                yAxis = plot.getRangeAxis(++idx);
-            }
-        }
-
-        if (yAxis == null) {
-            // XXX There is no y-axis that might be used to add annotations. If
-            // we absolutely want to display annotations, we need to create a
-            // virtual dataset for an axis.
-            return;
-        }
-
-        float posY = 140.f;
-        posY = (float) yAxis.getRange().getLowerBound();
-        // Add some (2%) space between Text and axis.
-        posY += 0.02f * (yAxis.getRange().getUpperBound()
-                - yAxis.getRange().getLowerBound());
-
-        LegendItemCollection lic = plot.getLegendItems();
-
-        // Add all annotations.
-        for (FLYSAnnotation fa: annotations) {
-            lic.add(new LegendItem(fa.getLabel()));
-
-            for (Annotation a: fa.getAnnotations()) {
-                float posX = (float) a.getRange().getA().doubleValue();
-                String text = a.getPosition().getValue();
-
-                StickyAxisAnnotation ta = new StickyAxisAnnotation(
-                    text,
-                    posX,
-                    posY);
-
-                double rotation = 270.0f * (Math.PI / 180.0f);
-                ta.setRotationAngle(rotation);
-                ta.setRotationAnchor(TextAnchor.CENTER_LEFT);
-                ta.setTextAnchor(TextAnchor.CENTER_LEFT);
-                plot.getRenderer(idx).addAnnotation(ta);
-            }
-        }
-
-        plot.setFixedLegendItems(lic);
-    }
-
-
-    /**
      * Create a range that includes 0 (for the Q axis).
      * @param range range with which to look up upper bound.
      * @return range with 0 included.
@@ -299,7 +216,7 @@
 
         // Add all annotations in list o to our annotation pool.
         FLYSAnnotation fa = (FLYSAnnotation) o;
-        annotations.add(fa);
+        addAnnotations(fa);
     }
 
 

http://dive4elements.wald.intevation.org