changeset 841:9cbc8343a04d

Implemented a workaround to avoid an amount of cut axis labels in 2D charts (issue163). gnv-artifacts/trunk@955 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 20 Apr 2010 08:45:01 +0000
parents 47578d91c4f0
children 31f63a14a2c3
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java
diffstat 3 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Tue Apr 20 07:19:05 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Tue Apr 20 08:45:01 2010 +0000
@@ -1,3 +1,15 @@
+2010-04-20  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	  Issue163: Workaround implemented.
+
+	* src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java:
+	  Added a gap between data area and the plot border to avoid an amount of 
+	  cut axes labels (small labels aren't cut anymore, large labels will still
+	  be cut).
+
+	* src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java: Added some
+	  necessary methods to set the first domain and range axis.
+
 2010-04-20  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	  Issue235
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java	Tue Apr 20 07:19:05 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java	Tue Apr 20 08:45:01 2010 +0000
@@ -31,6 +31,8 @@
 import org.jfree.chart.title.PaintScaleLegend;
 import org.jfree.chart.title.TextTitle;
 
+import org.jfree.data.Range;
+
 import org.jfree.ui.RectangleEdge;
 import org.jfree.ui.RectangleInsets;
 
@@ -146,6 +148,11 @@
         }
     } // class LocalizedLabelGenerator
 
+    public static double MARGIN_TOP    = 0.05d;
+    public static double MARGIN_BOTTOM = 0.05d;
+    public static double MARGIN_LEFT   = 0.05d;
+    public static double MARGIN_RIGHT  = 0.05d;
+
     /**
      * JFreeChart object stored at this place after chart creation.
      */
@@ -309,6 +316,21 @@
 
         chart.addSubtitle(legend);
 
+        // XXX Workaround, because Axes labels are cut at the
+        // left/right/top/bottom edge. The following lines add a white border
+        // between data area and plot border.
+        ValueAxis xAxis = plot.getDomainAxis();
+        Range xRange    = xAxis.getRange();
+        xRange = Range.expand(xRange, MARGIN_LEFT, MARGIN_RIGHT);
+        xAxis.setRange(xRange);
+        plot.setDomainAxis(xAxis);
+
+        ValueAxis yAxis = plot.getRangeAxis();
+        Range yRange    = yAxis.getRange();
+        yRange = Range.expand(yRange, MARGIN_BOTTOM, MARGIN_TOP);
+        yAxis.setRange(yRange);
+        plot.setRangeAxis(yAxis);
+
         return chart;
     }
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java	Tue Apr 20 07:19:05 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java	Tue Apr 20 08:45:01 2010 +0000
@@ -148,6 +148,10 @@
         return getDomainAxis(0);
     }
 
+    public void setDomainAxis(ValueAxis axis) {
+        domainAxes.set(0, axis);
+    }
+
     public ValueAxis getDomainAxis(int index) {
         return index < domainAxes.size()
             ? (ValueAxis)domainAxes.get(index)
@@ -158,6 +162,10 @@
         return getRangeAxis(0);
     }
 
+    public void setRangeAxis(ValueAxis axis) {
+        rangeAxes.set(0, axis);
+    }
+
     public ValueAxis getRangeAxis(int index) {
         return index < rangeAxes.size()
             ? (ValueAxis)rangeAxes.get(index)

http://dive4elements.wald.intevation.org