Mercurial > dive4elements > gnv-client
changeset 297:3f43392df3f6
Interface and abstract classes for chart creation implemented.
gnv-artifacts/trunk@351 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 19 Nov 2009 15:24:45 +0000 |
parents | da1499a464b9 |
children | 80f7c5dc09c6 |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/Chart.java |
diffstat | 4 files changed, 206 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Thu Nov 19 15:13:11 2009 +0000 +++ b/gnv-artifacts/ChangeLog Thu Nov 19 15:24:45 2009 +0000 @@ -1,3 +1,19 @@ +2009-11-19 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * src/main/java/de/intevation/gnv/chart/Chart.java: Interface, which + declares basic method to create charts and export it in different formats. + + * src/main/java/de/intevation/gnv/chart/AbstractChart.java, + src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java: Abstract + chart classes which declare basic methods for chart creation and implement + general methods used by subclasses. + +2009-11-19 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * src/main/java/de/intevation/gnv/utils/DistanceCalculator.java: Declared a + method as static, which can be used without instantiating an object of its + class. + 2009-11-17 Ingo Weinzierl <ingo.weinzierl@intevation.de> * pom.xml: Changed version of JFreeChart from 1.0.12 to 1.0.13 and added
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java Thu Nov 19 15:24:45 2009 +0000 @@ -0,0 +1,52 @@ +package de.intevation.gnv.chart; + +import java.util.Collection; +import java.util.Iterator; +import java.util.Date; +import java.util.Locale; +import java.awt.Transparency; +import java.awt.image.BufferedImage; + +import org.apache.log4j.Logger; + +import org.jfree.chart.JFreeChart; +import org.jfree.chart.ChartTheme; +import org.jfree.data.time.TimeSeriesCollection; + +/** + * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> + */ +public abstract class AbstractChart +implements Chart +{ + private static Logger log = Logger.getLogger(AbstractChart.class); + + protected JFreeChart chart; + + protected Locale locale; + + protected ChartLabels labels; + protected ChartTheme theme; + protected Collection parameters; + protected Collection measurements; + protected Collection resultSet; + protected Collection dates; + + public abstract JFreeChart generateChart(); + + public BufferedImage exportPNG(int width, int height) { + log.info("export chart as png"); + + return chart.createBufferedImage( + width, height, Transparency.BITMASK, null); + } + + public void exportSVG() { + log.info("export chart as svg (not implemented yet)"); + } + + public void exportPDF() { + log.info("export chart as pdf (not implemented yet)"); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=latin1 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Thu Nov 19 15:24:45 2009 +0000 @@ -0,0 +1,116 @@ +package de.intevation.gnv.chart; + +import java.awt.Color; +import java.util.Collection; +import java.util.Iterator; +import java.util.Locale; + +import org.apache.log4j.Logger; + +import org.jfree.chart.JFreeChart; +import org.jfree.chart.ChartTheme; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.NumberTickUnit; +import org.jfree.chart.axis.AxisLocation; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.StandardXYItemRenderer; +import org.jfree.data.general.Series; +import org.jfree.data.time.TimeSeriesCollection; +import org.jfree.data.time.Minute; +import org.jfree.data.xy.XYDataset; + +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.transition.describedata.KeyValueDescibeData; + +/** + * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> + */ +public abstract class AbstractXYLineChart +extends AbstractChart +{ + private static Logger log = Logger.getLogger(AbstractXYLineChart.class); + + protected static Color[] COLOR = { + Color.black, Color.red, Color.green, Color.blue + }; + + protected PlotOrientation PLOT_ORIENTATION = PlotOrientation.VERTICAL; + + protected abstract void initData(); + protected abstract void addValue(Result row, Series series); + protected abstract void addSeries(Series series, int idx); + protected abstract String createSeriesName( + String breakPoint1, + String breakPoint2, + String breakPoint3 + ); + + + public JFreeChart generateChart() { + log.debug("generate XYLineChart"); + + if (chart != null) + return chart; + + chart = ChartFactory.createXYLineChart( + labels.getTitle(), + labels.getDomainAxisLabel(), + null, + null, + PLOT_ORIENTATION, + true, + false, + false + ); + + initData(); + return chart; + } + + + protected void prepareAxis(String seriesKey, int idx) { + log.debug("prepare axis of xychart"); + XYPlot plot = chart.getXYPlot(); + NumberAxis axis = new NumberAxis(seriesKey); + + if (seriesKey.contains("richtung")) { + axis.setTickUnit(new NumberTickUnit(30.0)); + axis.setUpperBound(360.0); + axis.setLowerBound(0.0); + plot.setRangeAxis(idx, axis); + } + else { + axis.setFixedDimension(10.0); + axis.setAutoRangeIncludesZero(false); + plot.setRangeAxis(idx, axis); + axis.configure(); + } + + if (idx % 2 != 0) + plot.setRangeAxisLocation(idx, AxisLocation.BOTTOM_OR_RIGHT); + else + plot.setRangeAxisLocation(idx, AxisLocation.BOTTOM_OR_LEFT); + plot.mapDatasetToRangeAxis(idx, idx); + + StandardXYItemRenderer renderer = new StandardXYItemRenderer(); + renderer.setSeriesPaint(idx, COLOR[idx%COLOR.length]); + plot.setRenderer(idx, renderer); + } + + + protected String findValueTitle(Collection values, String id) { + log.debug("find description of dataset"); + + Iterator it = values.iterator(); + while (it.hasNext()) { + KeyValueDescibeData data = (KeyValueDescibeData) it.next(); + + if (id.equals(data.getKey())) + return data.getValue(); + } + return ""; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=latin1 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/Chart.java Thu Nov 19 15:24:45 2009 +0000 @@ -0,0 +1,22 @@ +package de.intevation.gnv.chart; + +import java.io.IOException; +import java.awt.image.BufferedImage; + +import org.jfree.chart.JFreeChart; + + +/** + * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> + */ +public interface Chart { + + public JFreeChart generateChart(); + + public BufferedImage exportPNG(int width, int height) + throws IOException; + + public void exportSVG(); //TODO Change return value + + public void exportPDF(); //TODO Change return value +}