Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java @ 2311:b8df8d1476ba
Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
flys-artifacts/trunk@3991 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 09 Feb 2012 10:57:35 +0000 |
parents | 6aeb71517136 |
children | 594885703687 |
line wrap: on
line source
package de.intevation.flys.exports; import java.awt.Color; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.log4j.Logger; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.XYPlot; import org.jfree.data.Range; import org.jfree.data.time.TimeSeriesCollection; import org.jfree.data.general.Series; import org.jfree.data.xy.XYDataset; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public abstract class TimeseriesChartGenerator extends ChartGenerator { /** * Inner class TimeseriesAxisDataset stores TimeSeriesCollection. */ public class TimeseriesAxisDataset implements AxisDataset { protected int axisSymbol; protected List<TimeSeriesCollection> datasets; protected Range range; protected int plotAxisIndex; public TimeseriesAxisDataset(int axisSymbol) { this.axisSymbol = axisSymbol; this.datasets = new ArrayList<TimeSeriesCollection>(); } @Override public void addDataset(XYDataset dataset) { if (!(dataset instanceof TimeSeriesCollection)) { logger.warn("Skip non TimeSeriesCollection dataset."); return; } TimeSeriesCollection tsc = (TimeSeriesCollection) dataset; datasets.add(tsc); mergeRanges(tsc); } @Override public XYDataset[] getDatasets() { return (XYDataset[]) datasets.toArray(new XYDataset[datasets.size()]); } @Override public boolean isEmpty() { return datasets.isEmpty(); } @Override public void setRange(Range range) { this.range = range; } @Override public Range getRange() { return range; } @Override public void setPlotAxisIndex(int plotAxisIndex) { this.plotAxisIndex = plotAxisIndex; } @Override public int getPlotAxisIndex() { return plotAxisIndex; } @Override public boolean isArea(XYDataset dataset) { logger.warn("This AxisDataset doesn't support Areas yet!"); return false; } protected void mergeRanges(TimeSeriesCollection dataset) { logger.debug("Range after merging: " + range); Range[] xyRanges = ChartHelper.getRanges(dataset); range = Range.combine(range, xyRanges[1]); logger.debug("Range after merging: " + range); } } // end of TimeseriesAxisDataset class private static final Logger logger = Logger.getLogger(TimeseriesChartGenerator.class); protected Map<Integer, Range> xRanges; protected Map<Integer, Range> yRanges; /** * The default constructor that initializes internal datastructures. */ public TimeseriesChartGenerator() { super(); xRanges = new HashMap<Integer, Range>(); yRanges = new HashMap<Integer, Range>(); } @Override public JFreeChart generateChart() { logger.info("Generate Timeseries Chart."); JFreeChart chart = ChartFactory.createTimeSeriesChart( getChartTitle(), getXAxisLabel(), getYAxisLabel(0), null, true, false, false); logger.warn("TODO: IMPLEMENT ME!"); XYPlot plot = (XYPlot) chart.getPlot(); chart.setBackgroundPaint(Color.WHITE); plot.setBackgroundPaint(Color.WHITE); addSubtitles(chart); addDatasets(plot); return chart; } @Override protected Series getSeriesOf(XYDataset dataset, int idx) { return ((TimeSeriesCollection) dataset).getSeries(idx); } @Override protected void setXRange(int axis, Range range) { xRanges.put(Integer.valueOf(axis), range); } @Override protected void setYRange(int axis, Range range) { yRanges.put(Integer.valueOf(axis), range); } /** * This method creates new instances of TimeseriesAxisDataset. * * @param idx The symbol for the new TimeseriesAxisDataset. */ @Override protected AxisDataset createAxisDataset(int idx) { logger.debug("Create a new AxisDataset for index: " + idx); return new TimeseriesAxisDataset(idx); } /** * Effect: extend range of x axis to include given limits. * @param range the given ("minimal") range. * @param index index of axis to be merged. */ @Override protected void combineXRanges(Range range, int index) { if (range != null) { Range old = xRanges.get(index); if (old != null) { range = Range.combine(old, range); } xRanges.put(index, range); } } @Override public Range[] getRangesForAxis(int index) { logger.debug("Return ranges for axis at: " + index); Range rx = xRanges.get(Integer.valueOf(0)); Range ry = yRanges.get(Integer.valueOf(index)); if (rx == null) { logger.warn("Range for x axis not set." + " Using default values: 0 - 1."); rx = new Range(0, 1); } if (ry == null) { logger.warn("Range for y" + index + " axis not set. Using default values: 0 - 1."); ry = new Range(0, 1); } logger.debug("X Range is: " + rx); logger.debug("Y Range is: " + ry); return new Range[] {rx, ry}; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :