diff flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 2780:772d0c8100d3

Improved 'line-to-curve' rendering. flys-artifacts/trunk@4519 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 25 May 2012 13:34:46 +0000
parents 5543492f2da4
children 55f91fae8a7b
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri May 25 13:33:59 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri May 25 13:34:46 2012 +0000
@@ -181,6 +181,8 @@
     /** Enumerator over existing axes. */
     protected abstract YAxisWalker getYAxisWalker();
 
+    protected static float ANNOTATIONS_AXIS_OFFSET = 0.02f;
+
     public static final int AXIS_SPACE = 5;
 
     /** The logger that is used in this generator. */
@@ -710,6 +712,58 @@
         }
     }
 
+    protected static XYLineAnnotation createGroundStickAnnotation(
+        Area area, float pos, ThemeAccess.LineStyle lineStyle
+    ) {
+        // Style the line.
+        if (lineStyle != null) {
+            return new XYLineAnnotation(
+                pos, area.atGround(),
+                pos, area.ofGround(ANNOTATIONS_AXIS_OFFSET),
+                new BasicStroke(lineStyle.getWidth()),lineStyle.getColor());
+        }
+        else {
+            return new XYLineAnnotation(
+                pos, area.atGround(),
+                pos, area.ofGround(ANNOTATIONS_AXIS_OFFSET));
+        }
+    }
+
+
+    protected static XYLineAnnotation createRightStickAnnotation(
+        Area area, float pos, ThemeAccess.LineStyle lineStyle
+    ) {
+        // Style the line.
+        if (lineStyle != null) {
+            return new XYLineAnnotation(
+                area.ofRight(ANNOTATIONS_AXIS_OFFSET), pos,
+                area.atRight(), pos,
+                new BasicStroke(lineStyle.getWidth()), lineStyle.getColor());
+        }
+        else {
+            return new XYLineAnnotation(
+                area.atRight(), pos,
+                area.ofRight(ANNOTATIONS_AXIS_OFFSET), pos);
+        }
+    }
+
+
+    protected static XYLineAnnotation createLeftStickAnnotation(
+        Area area, float pos, ThemeAccess.LineStyle lineStyle
+    ) {
+        // Style the line.
+        if (lineStyle != null) {
+            return new XYLineAnnotation(
+                area.atLeft(), pos,
+                area.ofLeft(ANNOTATIONS_AXIS_OFFSET), pos,
+                new BasicStroke(lineStyle.getWidth()), lineStyle.getColor());
+        }
+        else {
+            return new XYLineAnnotation(
+                area.atLeft(), pos,
+                area.ofLeft(ANNOTATIONS_AXIS_OFFSET), pos);
+        }
+    }
 
     /**
      * Add a text and a line annotation.
@@ -724,7 +778,6 @@
     ) {
         // OPTIMIZE pre-calculate area-related values
         final float TEXT_OFF = 0.03f;
-        final float LINE_OFF = 0.02f;
 
         XYLineAnnotation lineAnnotation = null;
         XYTextAnnotation textAnnotation = null;
@@ -736,16 +789,8 @@
                 annotation.getText(), annotation.getPos(), area.ofGround(TEXT_OFF));
             // OPTIMIZE externalize the calculation involving PI.
             textAnnotation.setRotationAngle(270f*Math.PI/180f);
-            // Style the line.
-            if (lineStyle != null) {
-                lineAnnotation = new XYLineAnnotation(annotation.getPos(),
-                    area.atGround(), annotation.getPos(), area.ofGround(LINE_OFF),
-                    new BasicStroke(lineStyle.getWidth()),lineStyle.getColor());
-            }
-            else {
-                lineAnnotation = new XYLineAnnotation(annotation.getPos(),
-                    area.atGround(), annotation.getPos(), area.ofGround(LINE_OFF));
-            }
+            lineAnnotation = createGroundStickAnnotation(
+                area, annotation.getPos(), lineStyle);
             textAnnotation.setRotationAnchor(TextAnchor.CENTER_LEFT);
             textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT);
         }
@@ -764,6 +809,7 @@
                 rendererIndex = dataset.getPlotAxisIndex();
             }
 
+            // Stick to the "right" (opposed to left) Y-Axis.
             if (rendererIndex != 0) {
                 // OPTIMIZE: Pass a different area to this function,
                 //           do the adding to renderer outside (let this
@@ -774,16 +820,22 @@
                     annotation.getText(), area2.ofRight(TEXT_OFF), annotation.getPos());
                 textAnnotation.setRotationAnchor(TextAnchor.CENTER_RIGHT);
                 textAnnotation.setTextAnchor(TextAnchor.CENTER_RIGHT);
-                // Style the line.
-                if (lineStyle != null) {
-                    lineAnnotation = new XYLineAnnotation(area2.ofRight(LINE_OFF),
-                        annotation.getPos(), area2.atRight(),
-                        annotation.getPos(), new BasicStroke(lineStyle.getWidth()),
-                        lineStyle.getColor());
-                }
-                else {
-                    lineAnnotation = new XYLineAnnotation(area2.atRight(),
-                        annotation.getPos(), area2.ofRight(LINE_OFF), annotation.getPos());
+                lineAnnotation = createRightStickAnnotation(
+                    area2, annotation.getPos(), lineStyle);
+                // TODO line to curve
+                if (!Float.isNaN(annotation.getHitPoint())) {
+                    // TODO let line be styled and respect X/Y-ness.
+                    // New line annotation to hit curve.
+                    XYLineAnnotation hitLineAnnotation = new XYLineAnnotation(
+                        area2.atRight(), annotation.getPos(),
+                        annotation.getHitPoint(), annotation.getPos());
+                    XYLineAnnotation lineBackAnnotation = new XYLineAnnotation(
+                        annotation.getHitPoint(), annotation.getPos(),
+                        annotation.getHitPoint(), area2.atGround());
+                    plot.getRenderer(rendererIndex).addAnnotation(hitLineAnnotation,
+                        org.jfree.ui.Layer.BACKGROUND);
+                    plot.getRenderer(rendererIndex).addAnnotation(lineBackAnnotation,
+                        org.jfree.ui.Layer.BACKGROUND);
                 }
             }
             else {
@@ -791,16 +843,20 @@
                     annotation.getText(), area.ofLeft(TEXT_OFF), annotation.getPos());
                 textAnnotation.setRotationAnchor(TextAnchor.CENTER_LEFT);
                 textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT);
-                // Style the line.
-                if (lineStyle != null) {
-                    lineAnnotation = new XYLineAnnotation(area.atLeft(),
-                        annotation.getPos(), area.ofLeft(LINE_OFF),
-                        annotation.getPos(), new BasicStroke(lineStyle.getWidth()),
-                        lineStyle.getColor());
-                }
-                else {
-                    lineAnnotation = new XYLineAnnotation(area.atLeft(),
-                        annotation.getPos(), area.ofLeft(LINE_OFF), annotation.getPos());
+                lineAnnotation = createLeftStickAnnotation(area, annotation.getPos(), lineStyle);
+                // TODO line to curve
+                if (!Float.isNaN(annotation.getHitPoint())) {
+                    // TODO let line be styled and respect X/Y-ness.
+                    // New line annotation to hit curve.
+                    XYLineAnnotation hitLineAnnotation = new XYLineAnnotation(area.atLeft(),
+                        annotation.getPos(), annotation.getHitPoint(), annotation.getPos());
+                    XYLineAnnotation lineBackAnnotation = new XYLineAnnotation(
+                        annotation.getHitPoint(), annotation.getPos(),
+                        annotation.getHitPoint(), area.atGround());
+                    plot.getRenderer(rendererIndex).addAnnotation(hitLineAnnotation,
+                        org.jfree.ui.Layer.BACKGROUND);
+                    plot.getRenderer(rendererIndex).addAnnotation(lineBackAnnotation,
+                        org.jfree.ui.Layer.BACKGROUND);
                 }
             }
         }
@@ -813,19 +869,6 @@
         // Add the Annotations to renderer.
         plot.getRenderer(rendererIndex).addAnnotation(textAnnotation,
             org.jfree.ui.Layer.FOREGROUND);
-        if (!Float.isNaN(annotation.getHitPoint())) {
-            // TODO let line be styled and respect X/Y-ness.
-            // New line annotation to hit curve.
-            XYLineAnnotation hitLineAnnotation = new XYLineAnnotation(area.atLeft(),
-                annotation.getPos(), annotation.getHitPoint(), annotation.getPos());
-            XYLineAnnotation lineBackAnnotation = new XYLineAnnotation(
-                annotation.getHitPoint(), annotation.getPos(),
-                annotation.getHitPoint(), area.atGround());
-            plot.getRenderer(rendererIndex).addAnnotation(hitLineAnnotation,
-                org.jfree.ui.Layer.BACKGROUND);
-            plot.getRenderer(rendererIndex).addAnnotation(lineBackAnnotation,
-                org.jfree.ui.Layer.BACKGROUND);
-        }
         plot.getRenderer(rendererIndex).addAnnotation(lineAnnotation,
             org.jfree.ui.Layer.FOREGROUND);
     }

http://dive4elements.wald.intevation.org