changeset 1034:bf3b3a8d089b

Slightly improved rendering of annotations in LongitudinalSection-plots. flys-artifacts/trunk@2495 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 16 Aug 2011 11:43:47 +0000
parents 821aaceb2776
children 9f69a5f0af98
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java
diffstat 2 files changed, 47 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Aug 15 10:56:58 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Aug 16 11:43:47 2011 +0000
@@ -1,3 +1,11 @@
+2011-08-16  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Slightly improved rendering of annotations.
+
+	* src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java:
+	  Slightly improved rendering of annotations. Still no valid collision
+	  detection. Annotations are drawn every 2 km; first come first serve.
+
 2011-08-15  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	Fix for flys/issue191
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Mon Aug 15 10:56:58 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Tue Aug 16 11:43:47 2011 +0000
@@ -14,6 +14,7 @@
 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;
 
@@ -103,14 +104,8 @@
         JFreeChart c = super.generateChart();
         XYPlot p = (XYPlot) c.getPlot();
 
-        for (Annotation a: annotations) {
-            double pos = a.getRange().getA().doubleValue();
-            XYTextAnnotation ta = new XYTextAnnotation(a.getPosition().getValue(), pos, 140);
-            ta.setRotationAngle(270.0 / (Math.PI * 2.0));
-            p.addAnnotation(ta);
-            XYLineAnnotation la = new XYLineAnnotation(pos, 0, pos, 140);
-            p.addAnnotation(la);
-        }
+        redoAnnotations(p, p.getDomainAxis());
+
         return c;
     }
 
@@ -138,6 +133,42 @@
 
 
     /**
+     * Remove all annotations from plot and re-insert them at an approximately
+     * okay position. The followed approach is naive but side-effect free.
+     */
+    protected void redoAnnotations(XYPlot plot, ValueAxis axis) {
+        plot.clearAnnotations();
+        ValueAxis yAxis = plot.getRangeAxis();
+        float posY = 140.f;
+        if (yAxis != null) {
+            posY = (float) yAxis.getRange().getLowerBound();
+            // Lets add some (1%) space between Text and Axis .
+            posY += 0.1f * (yAxis.getRange().getUpperBound()
+                    - yAxis.getRange().getLowerBound());
+        }
+        double freeFrom = axis.getRange().getLowerBound();
+        //logger.warn("Axis lower Bound: " + freeFrom);
+
+        // Assuming ordered annotations.
+        for (Annotation a: annotations) {
+            float posX = (float) a.getRange().getA().doubleValue();
+            if (posX < freeFrom) { continue; }
+            String text = a.getPosition().getValue();
+
+            XYTextAnnotation ta = new XYTextAnnotation(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().addAnnotation(ta);
+            XYLineAnnotation la = new XYLineAnnotation(posX, 0, posX, posY);
+            plot.getRenderer().addAnnotation(la);
+            freeFrom += 2.0;
+        }
+    }
+
+
+    /**
      * This method overrides the XYChartGenerators zoomY method to include the 0
      * value on the Q axis.
      */

http://dive4elements.wald.intevation.org