Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonRenderer.java @ 451:bc5901bb4525
Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
to Java2D space in polygon plot.
gnv-artifacts/trunk@499 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 04 Jan 2010 12:42:16 +0000 |
parents | 20a480753ff9 |
children | 9a828e5a2390 |
line wrap: on
line diff
--- 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();