Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java @ 446:f5a041000357
Connected vertical cross section with chart generation.
gnv-artifacts/trunk@494 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 01 Jan 2010 12:08:05 +0000 |
parents | |
children | c7ca2fce041f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java Fri Jan 01 12:08:05 2010 +0000 @@ -0,0 +1,142 @@ +package de.intevation.gnv.chart; + +import java.util.Locale; + +import java.awt.Color; +import java.awt.Paint; + +import de.intevation.gnv.math.AttributedXYColumns; + +import de.intevation.gnv.jfreechart.PolygonDataset; +import de.intevation.gnv.jfreechart.PolygonPlot; +import de.intevation.gnv.jfreechart.PolygonRenderer; + +import de.intevation.gnv.raster.Palette; + +import org.jfree.chart.JFreeChart; + +import org.jfree.chart.plot.PlotOrientation; + +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.SymbolAxis; + +import org.jfree.chart.title.PaintScaleLegend; + +import org.jfree.chart.renderer.LookupPaintScale; + +import org.jfree.ui.RectangleEdge; +import org.jfree.ui.RectangleInsets; + +/** + * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) + * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + */ +public class VerticalCrossSectionChart +implements Chart +{ + public static final class PalettePaintLookup + implements PolygonRenderer.PaintLookup + { + private Palette palette; + + public PalettePaintLookup(Palette palette) { + this.palette = palette; + } + + public Paint getPaint(int index) { + return index < 0 + ? Color.black + : palette.getColor(index); + } + } // class PalettePaintLookup + + protected JFreeChart chart; + + protected AttributedXYColumns columns; + protected Palette palette; + protected Locale locale; + + public VerticalCrossSectionChart() { + } + + public VerticalCrossSectionChart( + AttributedXYColumns columns, + Palette palette, + Locale locale + ) { + this.columns = columns; + this.palette = palette; + this.locale = locale; + } + + protected JFreeChart createChart() { + + String title = "Neues 2D-Diagramm"; + String xAxis = "x-Achse des Diagramms"; + String yAxis = "y-Achse des Diagramms"; + boolean legendB = false; + boolean tooltips = false; + boolean urls = false; + + PlotOrientation po = PlotOrientation.HORIZONTAL; + PolygonDataset data = columns.getPolygonDataset(); + + PolygonRenderer renderer = new PolygonRenderer( + new PalettePaintLookup(palette)); + + ValueAxis domainAxis = new NumberAxis(xAxis); + ValueAxis rangeAxis = new NumberAxis(yAxis); + + PolygonPlot plot = new PolygonPlot( + data, + renderer, + domainAxis, + rangeAxis, + null); + + int colors = palette.getSize(); + LookupPaintScale lookupPaint = + new LookupPaintScale(-0.5d, colors-0.5d, Color.white); + + Color color = null; + + String [] labels = new String[colors]; + for (int i = 0; i < colors; i++) { + color = palette.getColor(colors-1-i); + labels[i] = palette.getEntryByIndex(colors-1-i).getDescription(); + lookupPaint.add(i-0.5d, color); + } + + JFreeChart chart = new JFreeChart( + title, + JFreeChart.DEFAULT_TITLE_FONT, + plot, + legendB); + + chart.removeLegend(); + + SymbolAxis scale = new SymbolAxis("Temperatur", labels); + scale.setRange(-1.5d, colors+0.5d); + scale.setGridBandsVisible(false); + scale.setPlot(plot); + + PaintScaleLegend legend = new PaintScaleLegend( + lookupPaint, scale); + legend.setMargin(new RectangleInsets(3d, 10d, 3d, 10d)); + legend.setPosition(RectangleEdge.LEFT); + legend.setAxisOffset(5d); + + chart.addSubtitle(legend); + + return chart; + } + + public JFreeChart generateChart() { + if (chart == null) { + chart = createChart(); + } + return chart; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :