diff flys-artifacts/src/main/java/de/intevation/flys/jfree/ShapeRenderer.java @ 3164:6d0567a8387d

Label more points in FixingsKMChartService flys-artifacts/trunk@4776 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 25 Jun 2012 13:15:35 +0000
parents 0d8146989012
children 0cf647fe2a96
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/ShapeRenderer.java	Mon Jun 25 11:55:34 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/ShapeRenderer.java	Mon Jun 25 13:15:35 2012 +0000
@@ -293,50 +293,61 @@
 
         String label = generator.generateLabel(dataset, series, item);
 
-        // get the label position..
-        ItemLabelPosition position = null;
-        if (!negative) {
-            position = getPositiveItemLabelPosition(series, item);
-        }
-        else {
-            position = getNegativeItemLabelPosition(series, item);
-        }
-
-        // work out the label anchor point...
-        Point2D anchorPoint = calculateLabelAnchorPoint(
-            position.getItemLabelAnchor(), x, y, orientation);
-
-        Shape labelShape = TextUtilities.calculateRotatedStringBounds(
-            label, g2,
-            (float)anchorPoint.getX(), (float)anchorPoint.getY(),
-            position.getTextAnchor(), position.getAngle(),
-            position.getRotationAnchor());
-
-        Rectangle2D bbox = labelShape.getBounds2D();
+        ATTEMPS: for (int attempt = 0; attempt < 2; ++attempt) {
+            // get the label position..
+            ItemLabelPosition position = null;
 
-        Point2D shift = shiftBox(bbox);
-
-        bbox = new Rectangle2D.Double(
-            bbox.getX() + shift.getX(),
-            bbox.getY() + shift.getY(),
-            bbox.getWidth(),
-            bbox.getHeight());
+            boolean pos;
+            switch (attempt) {
+                case 0: pos = negative; break;
+                case 1: pos = !negative; break;
+                default: break ATTEMPS;
+            }
 
-        if (labelBoundingBoxes != null) {
-            for (Rectangle2D old: labelBoundingBoxes) {
-                if (old.intersects(bbox)) {
-                    return;
-                }
+            if (pos) {
+                position = getNegativeItemLabelPosition(series, item);
             }
-            labelBoundingBoxes.add(bbox);
-        }
+            else {
+                position = getPositiveItemLabelPosition(series, item);
+            }
 
-        TextUtilities.drawRotatedString(
-            label, g2,
-            (float)(anchorPoint.getX() + shift.getX()),
-            (float)(anchorPoint.getY() + shift.getY()),
-            position.getTextAnchor(), position.getAngle(),
-            position.getRotationAnchor());
+            // work out the label anchor point...
+            Point2D anchorPoint = calculateLabelAnchorPoint(
+                position.getItemLabelAnchor(), x, y, orientation);
+
+            Shape labelShape = TextUtilities.calculateRotatedStringBounds(
+                label, g2,
+                (float)anchorPoint.getX(), (float)anchorPoint.getY(),
+                position.getTextAnchor(), position.getAngle(),
+                position.getRotationAnchor());
+
+            Rectangle2D bbox = labelShape.getBounds2D();
+
+            Point2D shift = shiftBox(bbox);
+
+            bbox = new Rectangle2D.Double(
+                bbox.getX() + shift.getX(),
+                bbox.getY() + shift.getY(),
+                bbox.getWidth(),
+                bbox.getHeight());
+
+            if (labelBoundingBoxes != null) {
+                for (Rectangle2D old: labelBoundingBoxes) {
+                    if (old.intersects(bbox)) {
+                        continue ATTEMPS;
+                    }
+                }
+                labelBoundingBoxes.add(bbox);
+            }
+
+            TextUtilities.drawRotatedString(
+                label, g2,
+                (float)(anchorPoint.getX() + shift.getX()),
+                (float)(anchorPoint.getY() + shift.getY()),
+                position.getTextAnchor(), position.getAngle(),
+                position.getRotationAnchor());
+            break;
+        }
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org