# HG changeset patch # User Ingo Weinzierl # Date 1271753101 0 # Node ID 9cbc8343a04d187d9cf38f3afdf3966cda5b35c5 # Parent 47578d91c4f0016c8be62e0ce6d59259c2da2e73 Implemented a workaround to avoid an amount of cut axis labels in 2D charts (issue163). gnv-artifacts/trunk@955 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 47578d91c4f0 -r 9cbc8343a04d gnv-artifacts/ChangeLog --- 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 + + 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 Issue235 diff -r 47578d91c4f0 -r 9cbc8343a04d gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java --- 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; } diff -r 47578d91c4f0 -r 9cbc8343a04d gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java --- 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)