# HG changeset patch # User Sascha L. Teichmann # Date 1262608936 0 # Node ID bc5901bb4525c95c0988eb554434b32e942fdcc5 # Parent 20a480753ff935458f3548da6218536255019888 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values to Java2D space in polygon plot. gnv-artifacts/trunk@499 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 20a480753ff9 -r bc5901bb4525 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Mon Jan 04 02:49:42 2010 +0000 +++ b/gnv-artifacts/ChangeLog Mon Jan 04 12:42:16 2010 +0000 @@ -1,3 +1,17 @@ +2010-01-04 Sascha L. Teichmann + + * src/main/java/de/intevation/gnv/jfreechart/PolygonRenderer.java: + Uses ValueAxis.valueToJava2D() to transform data values into chart + space. This slower than doing it via the Java2D matrix stack + but its more the JFreeChart way and prevents transforming of + graphical attributes too. TODO: Speed this up again! + + * src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java: + Forward plot to polygon renderer to make domain and range + axis accessible. + + * src/main/java/de/intevation/gnv/math/XYColumn.java: Moved code a bit. + 2010-01-04 Sascha L. Teichmann * src/main/java/de/intevation/gnv/jfreechart/PolygonSeriesLabelGenerator.java: diff -r 20a480753ff9 -r bc5901bb4525 gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java Mon Jan 04 02:49:42 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java Mon Jan 04 12:42:16 2010 +0000 @@ -303,7 +303,7 @@ Rectangle2D area, PlotRenderingInfo info ) { - renderer.drawPolygons(g2, area, dataset); + renderer.drawPolygons(g2, this, area, dataset); } diff -r 20a480753ff9 -r bc5901bb4525 gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonRenderer.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonRenderer.java Mon Jan 04 02:49:42 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonRenderer.java Mon Jan 04 12:42:16 2010 +0000 @@ -13,7 +13,6 @@ import java.awt.geom.GeneralPath; import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D.Double; -import java.awt.geom.AffineTransform; import org.jfree.data.Range; @@ -79,27 +78,10 @@ public void drawPolygons( Graphics2D graphics, - Rectangle2D rectangle, + PolygonPlot plot, + Rectangle2D area, PolygonDataset dataset ) { - Rectangle2D bbox = getBoundingBox(dataset); - - double sx = (double)rectangle.getWidth()/bbox.getWidth(); - double sy = (double)rectangle.getHeight()/bbox.getHeight(); - double tx = rectangle.getMinX(); - double ty = rectangle.getMinY(); - - // XXX: Little hack to draw correctly if data is - // below 0 in y direction. - if (bbox.getMinY() <= 0d && bbox.getMaxY() <= 0d) { - sy = -sy; // mirror - } - - AffineTransform xform = graphics.getTransform(); - - graphics.translate(tx, ty); - graphics.scale(sx, sy); - int seriesCount = dataset.getSeriesCount(); for (int i = 0; i < seriesCount; i++) { PolygonSeries series = dataset.getSeries(i); @@ -108,7 +90,7 @@ if (colorIdx != null) { Paint paint = lookup.getPaint(colorIdx.intValue()); graphics.setPaint(paint != null ? paint : Color.black); - graphics.fill(constructShape(series, true)); + graphics.fill(constructShape(plot, area, series, true)); } else { Number lineWidth = (Number)series.getAttribute("line.width"); @@ -116,11 +98,9 @@ lineWidth != null ? lineWidth.floatValue() : 1f); graphics.setStroke(stroke); graphics.setPaint(Color.black); - graphics.draw(constructShape(series, false)); + graphics.draw(constructShape(plot, area, series, false)); } } - - graphics.setTransform(xform); } public void drawLabels( @@ -188,19 +168,35 @@ } // for all series } - protected Shape constructShape(PolygonSeries series, boolean close) { + protected Shape constructShape( + PolygonPlot plot, + Rectangle2D area, + PolygonSeries series, + boolean close + ) { + ValueAxis da = plot.getDomainAxis(); + ValueAxis ra = plot.getRangeAxis(); + RectangleEdge de = plot.getDomainAxisEdge(); + RectangleEdge re = plot.getRangeAxisEdge(); + CompactXYItems [] rings = series.getRings(); - GeneralPath path = new GeneralPath(); + GeneralPath path = new GeneralPath(); + for (int i = 0; i < rings.length; ++i) { + CompactXYItems ring = rings[i]; + double [] data = ring.getData(); + if (data.length >= 2) { - path.moveTo((float)data[0], (float)data[1]); + path.moveTo( + (float)da.valueToJava2D(data[0], area, de), + (float)ra.valueToJava2D(data[1], area, re)); } for (int j = 2; j < data.length;) { - float x = (float)data[j++]; - float y = (float)data[j++]; - path.lineTo(x, y); + path.lineTo( + (float)da.valueToJava2D(data[j++], area, de), + (float)ra.valueToJava2D(data[j++], area, re)); } if (close) { path.closePath(); diff -r 20a480753ff9 -r bc5901bb4525 gnv-artifacts/src/main/java/de/intevation/gnv/math/XYColumn.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/XYColumn.java Mon Jan 04 02:49:42 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/XYColumn.java Mon Jan 04 12:42:16 2010 +0000 @@ -64,8 +64,8 @@ } public boolean prepare(XYDepth xyDepth) { - int N = values.size(); if (curve == null) { + int N = values.size(); if (N == 0) { log.error("no points for interpolation"); return false;