changeset 2998:4b6fb6d91192

issue417: duration curve main values as line(s) to curve. flys-artifacts/trunk@4553 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 29 May 2012 14:59:04 +0000
parents 60f13d966ee3
children 703be13ffa74
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 2 files changed, 76 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue May 29 08:38:39 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue May 29 14:59:04 2012 +0000
@@ -1,3 +1,11 @@
+2012-05-29	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	solve issue417: duration curve annotations as line to curve.
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java
+	  (createStickyLineAnnotation): New.
+	  Resolved todos, use the line style.
+
 2012-05-29	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Tue May 29 08:38:39 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Tue May 29 14:59:04 2012 +0000
@@ -787,6 +787,54 @@
 
 
     /**
+     * Create a line from a axis to a given point.
+     * @param axis   The "simple" axis.
+     * @param fromD1 from-location in first dimension.
+     * @param toD2   to-location in second dimension.
+     * @param area   helper to calculate offsets.
+     * @param lineStyle optional line style.
+     */
+    protected static XYLineAnnotation createStickyLineAnnotation(
+        StickyAxisAnnotation.SimpleAxis axis, float fromD1, float toD2,
+        Area area, ThemeAccess.LineStyle lineStyle
+    ) {
+        double anchorX1 = 0d, anchorX2 = 0d, anchorY1 = 0d, anchorY2 = 0d;
+        switch(axis) {
+            case X_AXIS:
+                anchorX1 = fromD1;
+                anchorX2 = fromD1;
+                anchorY1 = area.atGround();
+                anchorY2 = toD2;
+                break;
+            case Y_AXIS:
+                anchorX1 = area.atLeft();
+                anchorX2 = toD2;
+                anchorY1 = fromD1;
+                anchorY2 = fromD1;
+                break;
+            case Y_AXIS2:
+                anchorX1 = area.atRight();
+                anchorX2 = toD2;
+                anchorY1 = fromD1;
+                anchorY2 = fromD1;
+                break;
+        }
+        // Style the line.
+        if (lineStyle != null) {
+            return new XYLineAnnotation(
+                anchorX1, anchorY1,
+                anchorX2, anchorY2,
+                new BasicStroke(lineStyle.getWidth()), lineStyle.getColor());
+        }
+        else {
+            return new XYLineAnnotation(
+                anchorX1, anchorY1,
+                anchorX2, anchorY2);
+        }
+    }
+
+
+    /**
      * Add a text and a line annotation.
      * @param area convenience to determine positions in plot.
      * @param theme (optional) theme document
@@ -845,23 +893,23 @@
                 textAnnotation.setTextAnchor(TextAnchor.CENTER_RIGHT);
                 lineAnnotation = createRightStickAnnotation(
                     area2, annotation.getPos(), lineStyle);
-                // TODO line to curve
                 if (!Float.isNaN(annotation.getHitPoint()) && theme != null) {
                     // New line annotation to hit curve.
-                    // TODO include more style information
                     if (ThemeUtil.parseShowVerticalLine(theme)) {
-                        // createRightStickAnnotaiton .... 
-                        XYLineAnnotation hitLineAnnotation = new XYLineAnnotation(
-                            area2.atRight(), annotation.getPos(),
-                            annotation.getHitPoint(), annotation.getPos());
+                        XYLineAnnotation hitLineAnnotation =
+                            createStickyLineAnnotation(
+                                StickyAxisAnnotation.SimpleAxis.X_AXIS,
+                                annotation.getPos(), annotation.getHitPoint(),
+                                area, lineStyle);
                         plot.getRenderer(rendererIndex).addAnnotation(hitLineAnnotation,
                             org.jfree.ui.Layer.BACKGROUND);
                     }
                     if (ThemeUtil.parseShowHorizontalLine(theme)) {
-                        // createGroundStickAnnotation
-                        XYLineAnnotation lineBackAnnotation = new XYLineAnnotation(
-                            annotation.getHitPoint(), annotation.getPos(),
-                            annotation.getHitPoint(), area2.atGround());
+                        XYLineAnnotation lineBackAnnotation =
+                            createStickyLineAnnotation(
+                                StickyAxisAnnotation.SimpleAxis.Y_AXIS2,
+                                annotation.getPos(), annotation.getHitPoint(),
+                                area, lineStyle);
                         plot.getRenderer(rendererIndex).addAnnotation(lineBackAnnotation,
                             org.jfree.ui.Layer.BACKGROUND);
                     }
@@ -874,20 +922,22 @@
                 textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT);
                 lineAnnotation = createLeftStickAnnotation(area, annotation.getPos(), lineStyle);
                 if (!Float.isNaN(annotation.getHitPoint()) && theme != null) {
-                    // TODO include more style information
                     // New line annotation to hit curve.
                     if (ThemeUtil.parseShowHorizontalLine(theme)) {
-                        // createLeftStickAnnotaiton
-                        XYLineAnnotation hitLineAnnotation = new XYLineAnnotation(area.atLeft(),
-                            annotation.getPos(), annotation.getHitPoint(), annotation.getPos());
+                        XYLineAnnotation hitLineAnnotation =
+                            createStickyLineAnnotation(
+                                StickyAxisAnnotation.SimpleAxis.Y_AXIS,
+                                annotation.getPos(), annotation.getHitPoint(),
+                                area, lineStyle);
                         plot.getRenderer(rendererIndex).addAnnotation(hitLineAnnotation,
                             org.jfree.ui.Layer.BACKGROUND);
                     }
                     if (ThemeUtil.parseShowVerticalLine(theme)) {
-                        // createGroundStickAnnotation
-                        XYLineAnnotation lineBackAnnotation = new XYLineAnnotation(
-                            annotation.getHitPoint(), annotation.getPos(),
-                            annotation.getHitPoint(), area.atGround());
+                        XYLineAnnotation lineBackAnnotation =
+                            createStickyLineAnnotation(
+                                StickyAxisAnnotation.SimpleAxis.X_AXIS,
+                                annotation.getHitPoint(), annotation.getPos(), 
+                                area, lineStyle);
                         plot.getRenderer(rendererIndex).addAnnotation(lineBackAnnotation,
                             org.jfree.ui.Layer.BACKGROUND);
                     }

http://dive4elements.wald.intevation.org