Mercurial > dive4elements > gnv-client
changeset 767:79401c871da4
Added and repaired javadoc in de.intevation.gnv.chart package.
gnv-artifacts/trunk@823 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/ChangeLog Wed Mar 24 14:48:55 2010 +0000 @@ -1,3 +1,24 @@ +2010-03-24 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * src/main/java/de/intevation/gnv/chart/Chart.java, + src/main/java/de/intevation/gnv/chart/DefaultHistogram.java, + src/main/java/de/intevation/gnv/chart/XMLChartTheme.java, + src/main/java/de/intevation/gnv/chart/HorizontalCrossProfileChart.java, + src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java, + src/main/java/de/intevation/gnv/chart/exception/TechnicalChartException.java, + src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java, + src/main/java/de/intevation/gnv/chart/AbstractHistogram.java, + src/main/java/de/intevation/gnv/chart/ChartLabels.java, + src/main/java/de/intevation/gnv/chart/AbstractChart.java, + src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java, + src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java, + src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java: Added + and repaired javadoc in chart package. + + * src/main/java/de/intevation/gnv/chart/Insets.java, + src/main/java/de/intevation/gnv/chart/ChartStyle.java: Removed these + classes, because they aren't used anymore. + 2010-03-23 Tim Englich <tim.englich@intevation.de> * src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_07_feed.xml,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java Wed Mar 24 14:48:55 2010 +0000 @@ -7,25 +7,76 @@ import org.jfree.chart.ChartTheme; /** - * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) + * Abstract chart class to define the basic fields used for chart creation. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public abstract class AbstractChart implements Chart { + /** + * JFreeChart object. Created after {@link #generateChart()} is called. + */ protected JFreeChart chart; + + /** + * Field storing the visibility of lines in the chart plot. + */ protected boolean linesVisible; + + /** + * Field storing the visibility of points in the chart plot. + */ protected boolean shapesVisible; + /** + * Locale object used for i18n support. + */ protected Locale locale; + /** + * ChartLabels + */ protected ChartLabels labels; + + /** + * ChartTheme + */ protected ChartTheme theme; + + /** + * Collection which contains a bunch of parameters. + */ protected Collection parameters; + + /** + * Collection which contains a bunch of measurements. + */ protected Collection measurements; + + /** + * Collection which contains all data objects used to be displayed in the + * chart. It contains different series and different datasets which is not + * very elegant. + */ protected Collection resultSet; + + /** + * Collection which contains a bunch of date objects. + */ protected Collection dates; + + /** + * Collection which contains a bunch of time gap definitions used to + * detect gaps in timeseries charts. + */ protected Collection timeGaps; + /** + * Abstract method which needs to be implemented by concrete subclasses. + * This method triggers the JFreeChart creation process. After calling this + * method {@link #chart} should be a valid <code>JFreeChart</code> object. + */ public abstract JFreeChart generateChart(); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractHistogram.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractHistogram.java Wed Mar 24 14:48:55 2010 +0000 @@ -14,21 +14,52 @@ import org.jfree.chart.renderer.xy.XYBarRenderer; /** - * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) + * This abstract class defines some methods to adjust chart settings after its + * creation. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public abstract class AbstractHistogram implements Chart { + /** + * Logger used for logging with Apache log4j. + */ private Logger logger = Logger.getLogger(AbstractHistogram.class); + /** + * JFreeChart chart stored at this place after chart creation. + */ protected JFreeChart chart; + + /** + * Labels used for chart title, subtitle, axis description. + */ protected ChartLabels labels; + + /** + * Theme which is used to adjust the styling of this chart. + */ protected ChartTheme theme; + + /** + * Raw data which should be displayed in the chart. + */ protected Object[] data; + /** + * Locale object used for i18n support. + */ protected Locale locale; + /** + * Constructor for creating histogram charts. + * + * @param labels See {@link #labels} + * @param data See {@link #data} + * @param theme See {@link #theme} + */ public AbstractHistogram( ChartLabels labels, Object[] data, ChartTheme theme ) { @@ -38,6 +69,9 @@ } + /** + * @see de.intevation.gnv.chart.Chart#generateChart() + */ public JFreeChart generateChart() { if (chart != null) @@ -62,6 +96,9 @@ } + /** + * Method to do some changes in plot settings. + */ protected void adjustPlot() { XYPlot plot = (XYPlot) chart.getPlot(); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); @@ -71,6 +108,11 @@ } + /** + * This method needs to be implemented by subclasses and should add valid + * <code>HistogramDataset</code> objects to the created chart. It is called + * by {@link #generateChart} after chart creation. + */ protected abstract void applyDatasets(); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Wed Mar 24 14:48:55 2010 +0000 @@ -29,36 +29,107 @@ /** - * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> + * This abstract class defines some methods to adjust chart settings after its + * creation. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public abstract class AbstractXYLineChart extends AbstractChart { + /** + * Constant field used to expand the area between data and chart border. Its + * value is {@value}.<br> + * A value of 0.05 equals 5 percent. + */ public static final double LOWER_MARGIN = 0.05D; + + /** + * Constant field used to expand the area between data and chart border. Its + * value is {@value}.<br> + * A value of 0.05 equals 5 percent. + */ public static final double UPPER_MARGIN = 0.05D; + /** + * Logger used to log with log4j. + */ private static Logger log = Logger.getLogger(AbstractXYLineChart.class); + /** + * Field of supported colors used for lines and data points in charts. + * Colors are: {@value}. + */ protected static Color[] COLOR = { Color.black, Color.red, Color.green, Color.blue, Color.yellow, Color.gray, Color.orange, Color.pink, Color.cyan }; + /** + * Static field to remember the index of the previously used color. + */ protected static int nextColor = 0; + /** + * Default <code>PlotOrientation</code>. Its value is {@value}. + */ protected PlotOrientation PLOT_ORIENTATION = PlotOrientation.VERTICAL; - /** Map to store datasets for each parameter */ + /** + * Map to store datasets for each parameter. + */ protected Map datasets; - /** Map to store max ranges of each parameter (axis.setAutoRange(true) + /** + * Map to store max ranges of each parameter (axis.setAutoRange(true) * doesn't seem to work */ protected Map ranges; + /** + * This method is called by <code>Chart</code> to bring the data into the + * right form fitting to JFreeChart objects. + */ protected abstract void initData(); + + /** + * Add a value of <code>row</code> to <code>series</code>. + * + * @param row <code>Result</code> Object returned from database. Contains + * a value used to add to <code>series</code> + * @param series A JFreeChart Series object. + */ protected abstract void addValue(Result row, Series series); + + /** + * Add <code>series</code> to JFreeChart's Dataset object currently which is + * processing. + * + * @param series Series to add. + * @param label Label used show in legend. + * @param idx Currently not used. + */ protected abstract void addSeries(Series series, String label, int idx); + + /** + * Abstract method which is called by <code>Chart</code> interface after + * chart creation. It turns an axis' label into a locale specific format. + * + * @param axis Axis to adjust. + * @param local java.util.Locale object used specify the format. + */ protected abstract void localizeDomainAxis(Axis axis, Locale locale); + + /** + * Abstract method to create a label for a series of parameters. + * + * @param breakPoint1 Identifier returned from database. These identifier + * are used to identify the results from database which are all stored in + * one big java.util.Collection. + * @param breakPoint2 Identifier returned from database. + * @param breakPoint3 Identifier returned from database. + * + * @return Concatinated string of parameter name and measurement. + */ protected abstract String createSeriesName( String breakPoint1, String breakPoint2, @@ -66,6 +137,9 @@ ); + /** + * @see de.intevation.gnv.chart.Chart#generateChart() + */ public JFreeChart generateChart() { log.debug("generate XYLineChart"); nextColor = 0; @@ -86,6 +160,9 @@ } + /** + * @see de.intevation.gnv.chart.AbstractChart#initChart() + */ protected void initChart() { chart = ChartFactory.createXYLineChart( labels.getTitle(), @@ -100,6 +177,18 @@ } + /** + * Method used to adjust the axes after chart generation. Methods for i18n + * support ({@link #localizeDomainAxis and {@link #localizeRangeAxis) are + * called and axes of this series are expanded ({@link org.jfree.data.Range#expand( + * Range, double, double}). + * + * @param seriesKey Identifier of an axis which have to be adjusted. + * @param idx Set the axis identified by <code>seriesKey</code> to position + * <code>idx</code>. + * + * @see org.jfree.data.Range#expand(Range, double, double) + */ protected void prepareAxis(String seriesKey, int idx) { log.debug("prepare axis of xychart"); @@ -138,6 +227,16 @@ } + /** + * Method to adjust the rendering of a series in a chart. Line color and + * symbols of vertices are configured here. + * + * @param idx Position of the renderer. + * @param seriesCount Maximum number of series in this chart. + * @param renderLines Lines are displayed if true, otherwise they are not. + * @param renderShapes Vertices are displayed if true, otherwise they are + * not. + */ protected void adjustRenderer( int idx, int seriesCount, @@ -169,12 +268,27 @@ } + /** + * Method to adjust the plot rendering. Disable horizontal grid lines if + * <code>plot</code> contains only a single y-axis. + * + * @param plot JFreeChart Plot object to be adjusted. + */ protected void adjustPlot(XYPlot plot) { if (plot.getRangeAxisCount() > 1) plot.setRangeGridlinesVisible(false); } + /** + * Abstract method which is called after chart creation. It turns an + * axis' label into a locale specific format. + * + * @param axis Axis to adjust. + * @param local java.util.Locale object used specify the format. + * + * @param axis + */ protected void localizeRangeAxis(Axis axis, Locale locale) { if (locale == null) return; @@ -189,6 +303,13 @@ } + /** + * Return the maximum y-range of <code>dataset</code>. + * + * @param dataset Dataset to be scaned. + * + * @return JFreeChart Range object containing min and max y-value. + */ public Range getMaxRangeOfDataset(XYDataset dataset) { int seriesCount = dataset.getSeriesCount(); double upper = Double.NEGATIVE_INFINITY; @@ -212,6 +333,15 @@ } + /** + * Return the maximum y-range of <code>dataset</code> with a margin of + * <code>percent</code> percent. + * + * @param dataset Dataset to be scaned. + * + * @return JFreeChart Range object containing min and max y-value with a + * margin. + */ public Range getMaxRangeOfDatasetWithMargin( XYDataset dataset, double percent @@ -225,6 +355,13 @@ } + /** + * Method to find a parameter specified by its value. + * + * @param label Search string. + * + * @return Value of a parameter with the given label. + */ protected String findParameter(String label) { Iterator iter = parameters.iterator(); @@ -240,6 +377,14 @@ } + /** + * Method to find a description of a given collection of values. + * + * @param values Collection to be scaned. + * @param id Identifier and search string of the searched value. + * + * @return title + */ protected String findValueTitle(Collection values, String id) { log.debug("find description of dataset"); @@ -256,6 +401,15 @@ } + /** + * Method to store the maximum range. Since we need to adjust the range of + * each range axis, we have to memorize its range - each parameter uses an + * own range axis. + * + * @param ranges Map where ranges of each axis will be stored in. + * @param value A given value on an axis. + * @param parameter Parameter name which belongs to <code>value</code>. + */ protected void storeMaxRange(Map ranges, double value, String parameter) { Range range = null;
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/Chart.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/Chart.java Wed Mar 24 14:48:55 2010 +0000 @@ -6,10 +6,19 @@ /** - * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> + * The <code>Chart</code> interface should be implemented by each type of chart. + * The class must implement a method <code>generateChart</code> which returns a + * JFreeChart object. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public interface Chart extends Serializable { + /** + * This method is used to create a JFreeChart of this object. + * + * @return JFreeChart object. + */ public JFreeChart generateChart(); }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartLabels.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartLabels.java Wed Mar 24 14:48:55 2010 +0000 @@ -14,12 +14,12 @@ /** * @author drewnak - * @author Tim Englich <tim.englich@intevation.de> Changes and codecleanup - * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> + * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> Changes and codecleanup + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class ChartLabels { /** - * + * */ private String title; @@ -47,13 +47,22 @@ /** * Constructor * - * @param title - * @param domainAxisLabel + * @param title Title + * @param subtitle Subtitle + * @param domainAxisLabel X-axis label */ public ChartLabels(String title, String subtitle, String domainAxisLabel) { this(title, subtitle, domainAxisLabel, null); } + /** + * Constructor + * + * @param title Title + * @param subtitle Subtitle + * @param domainAxisLabel X-axis label + * @param rangeAxisLabel Y-axis label + */ public ChartLabels( String title, String subtitle, @@ -64,6 +73,15 @@ } + /** + * Constructor + * + * @param title Title + * @param subtitle Subtitle + * @param domainAxisLabel X-axis label + * @param rangeAxisLabel Y-axis label + * @param parameterName Name of a given parameter in the chart. + */ public ChartLabels( String title, String subtitle, @@ -101,11 +119,17 @@ } + /** + * @return the y-axis label + */ public String getRangeAxisLabel() { return this.rangeAxisLabel; } + /** + * @return the parameter name + */ public String getParameterName() { return this.parameterName; }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartStyle.java Tue Mar 23 14:11:51 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,170 +0,0 @@ -/* Copyright (C) 2007 con terra GmbH (http://www.conterra.de) - * All rights reserved - * - * $Id: ChartStyle.java,v 1.2 2007/12/21 12:31:15 blume Exp $ - * - * created by: drewnak - * created at : 10.12.2007 - * created at : 13:07:44 - * - * modified by: $Author: blume $ - * modified at: $Date: 2007/12/21 12:31:15 $ - */ -package de.intevation.gnv.chart; - -import java.awt.Color; -import java.awt.Dimension; - -/** - * @author drewnak - */ -public class ChartStyle { - - private Color mCanvasColor; - private Color mPlotBackgroundColor; - private Color mDomainGridlineColor; - private Color mRangeGridlineColor; - private boolean mDomainCrosshairVisible; - private boolean mRangeCrosshairVisible; - private Insets mAxisOffset; - private boolean mOverrideDefaultChartWidth = false; - private Dimension mChartSize; - - private boolean mUseUpperDataLevel = false; - private boolean mUseLowerDataLevel = false; - private int mUpperLevel; - private int mLowerLevel; - - /** - * @param pCanvasColor - * @param pPlotBackgroundColor - * @param pDomainGridlineColor - * @param pRangeGridlineColor - * @param pDomainCrosshairVisible - * @param pRangeCrosshairVisible - * @param pAxisOffset - */ - public ChartStyle(Color pCanvasColor, Color pPlotBackgroundColor, - Color pDomainGridlineColor, Color pRangeGridlineColor, - boolean pDomainCrosshairVisible, - boolean pRangeCrosshairVisible, Insets pAxisOffset, - Dimension pChartSize) { - super(); - mCanvasColor = pCanvasColor; - mPlotBackgroundColor = pPlotBackgroundColor; - mDomainGridlineColor = pDomainGridlineColor; - mRangeGridlineColor = pRangeGridlineColor; - mDomainCrosshairVisible = pDomainCrosshairVisible; - mRangeCrosshairVisible = pRangeCrosshairVisible; - mAxisOffset = pAxisOffset; - mChartSize = pChartSize; - } - - public Color getCanvasColor() { - return mCanvasColor; - } - - public void setCanvasColor(Color pCanvasColor) { - mCanvasColor = pCanvasColor; - } - - public Color getDomainGridlineColor() { - return mDomainGridlineColor; - } - - public void setDomainGridlineColor(Color pDomainGridlineColor) { - mDomainGridlineColor = pDomainGridlineColor; - } - - public Color getRangeGridlineColor() { - return mRangeGridlineColor; - } - - public void setRangeGridlineColor(Color pRangeGridlineColor) { - mRangeGridlineColor = pRangeGridlineColor; - } - - public boolean isDomainCrosshairVisible() { - return mDomainCrosshairVisible; - } - - public void setDomainCrosshairVisible(boolean pDomainCrosshairVisible) { - mDomainCrosshairVisible = pDomainCrosshairVisible; - } - - public boolean isRangeCrosshairVisible() { - return mRangeCrosshairVisible; - } - - public void setRangeCrosshairVisible(boolean pRangeCrosshairVisible) { - mRangeCrosshairVisible = pRangeCrosshairVisible; - } - - public Insets getAxisOffset() { - return mAxisOffset; - } - - public void setAxisOffset(Insets pAxisOffset) { - mAxisOffset = pAxisOffset; - } - - public Color getPlotBackgroundColor() { - return mPlotBackgroundColor; - } - - public void setPlotBackgroundColor(Color pPlotBackgroundColor) { - mPlotBackgroundColor = pPlotBackgroundColor; - } - - public Dimension getChartSize() { - return mChartSize; - } - - public void setChartSize(Dimension pChartSize) { - mChartSize = pChartSize; - } - - public boolean isOverrideDefaultChartWidth() { - return mOverrideDefaultChartWidth; - } - - public void setOverrideDefaultChartWidth(boolean pOverrideDefaultChartWidth) { - mOverrideDefaultChartWidth = pOverrideDefaultChartWidth; - } - - public void setNewChartWidth(int pNewChartWidth) { - mChartSize.setSize(pNewChartWidth, mChartSize.getHeight()); - } - - public boolean isUseUpperDataLevel() { - return mUseUpperDataLevel; - } - - public void setUseUpperDataLevel(boolean pUseUpperDataLevel) { - mUseUpperDataLevel = pUseUpperDataLevel; - } - - public boolean isUseLowerDataLevel() { - return mUseLowerDataLevel; - } - - public void setUseLowerDataLevel(boolean pUseLowerDataLevel) { - mUseLowerDataLevel = pUseLowerDataLevel; - } - - public int getUpperLevel() { - return mUpperLevel; - } - - public void setUpperLevel(int pUpperLevel) { - mUpperLevel = pUpperLevel; - } - - public int getLowerLevel() { - return mLowerLevel; - } - - public void setLowerLevel(int pLowerLevel) { - mLowerLevel = pLowerLevel; - } -}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/DefaultHistogram.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/DefaultHistogram.java Wed Mar 24 14:48:55 2010 +0000 @@ -14,25 +14,73 @@ import org.jfree.data.statistics.HistogramDataset; /** - * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) + * Default implementation of {@link de.intevation.gnv.chart.AbstractHistogram}. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class DefaultHistogram extends AbstractHistogram { - // TODO take a better default value + /** + * Default bin count. + * TODO find a better default value + */ public static final int DEFAULT_BINS = 15; + + /** + * Constant field for limitating the number of bin in a single histogram. + */ public static final int MAXIMAL_BINS = 20; + + /** + * Default key to retrieve the number of bins from {@link + * #requestParameter}. + */ public static final String REQUEST_KEY_BIN_COUNT = "bincount"; + + /** + * Default key to retrieve the width of a single bin from {@link + * #requestParameter}. + */ public static final String REQUEST_KEY_BIN_WIDTH = "binwidth"; + + /** + * Default key to retrieve the chart width from {@link #requestParameter}. + */ public static final String REQUEST_KEY_CHART_WIDTH = "width"; + + /** + * Default key to retrieve the <code>Locale</code> object from {@link + * #requestParameter} used for i18n support. + */ public static final String REQUEST_KEY_LOCALE = "locale"; + + /** + * Default key to retrieve the object from {@link #requestParameter}. It + * defines which value this chart has to be used for bin calculation. You + * can either adjust the number of bins or the width of a single bin. + */ public static final String REQUEST_KEY_BIN_CHOICE = "bintype"; + /** + * Logger used for logging with log4j. + */ private static Logger logger = Logger.getLogger(DefaultHistogram.class); + /** + * Object storing some further parameter used for chart settings. + */ protected Map requestParameter; + /** + * Constructor to create DefaultHistogram objects. + * + * @param labels Labels to decorate this chart. + * @param data Raw data to be displayed in histogram. + * @param theme Theme used to adjust the chart look. + * @param requestParameter Object which serves some further settings. + */ public DefaultHistogram( ChartLabels labels, Object[] data, ChartTheme theme, Map requestParameter ) { @@ -41,6 +89,10 @@ } + /** + * @see de.intevation.gnv.chart.AbstractHistogram#applyDatasets() + */ + @Override protected void applyDatasets() { XYPlot plot = (XYPlot) chart.getPlot(); @@ -56,6 +108,15 @@ } + /** + * Method which scans the hole bunch of values and returns an array with + * contains min and max value. Min value is stored at position 0, max value + * is stored at position 1 in that array. + * + * @param values Array which contains all values + * + * @return Array which contains min and max value + */ protected double[] getMinMax(double[] values) { double[] minmax = new double[2]; minmax[0] = Double.MAX_VALUE; @@ -71,6 +132,13 @@ } + /** + * Turn a Double[] into a double[]. + * + * @param array Doube[] + * + * @return double[] + */ protected double[] toDouble(Double[] array) { int length = array.length; double[] values = new double[length]; @@ -83,6 +151,16 @@ } + /** + * Method to calculate the number of bins this chart should be parted into. + * The real calculation takes place in {@link #getBinCountByNumber} and + * {@link #getBinCountByWidth}. This method switches between these methods + * depending on the object stored in {@link #requestParameter}. + * + * @param values All values used in this histogram + * + * @return Number of bins + */ protected int getBinCount(double[] values) { String param = (String) requestParameter.get(REQUEST_KEY_BIN_CHOICE); @@ -95,6 +173,16 @@ } + /** + * Method to retrieve the number of bins. If {@link #requestParameter} + * contains a valid <code>Integer</code> at + * <code>REQUEST_KEY_BIN_COUNT</code> and this is smaller than or equal + * {@link #MAXIMAL_BINS}, this value is used. If no valid + * <code>Integer</code> is given or if the value in {@link #requestParameter} + * is bigger than {@link #MAXIMAL_BINS}, {@link #DEFAULT_BINS} is used. + * + * @return Number of bins + */ protected int getBinCountByNumber() { int bins = -1; String param = (String) requestParameter.get(REQUEST_KEY_BIN_COUNT); @@ -115,6 +203,14 @@ } + /** + * Serves the number of bins depending on a given width for each bin, but + * maximum bin count is limited by {@link MAXIMAL_BINS}. + * + * @param values All values in this histogram + * + * @return Number of bins + */ protected int getBinCountByWidth(double[] values) { int bins = -1; String param = (String) requestParameter.get(REQUEST_KEY_BIN_WIDTH);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalCrossProfileChart.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalCrossProfileChart.java Wed Mar 24 14:48:55 2010 +0000 @@ -12,13 +12,34 @@ import org.jfree.data.general.Series; /** - * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> + * Implementation to create a special type of horizontal profile charts. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class HorizontalCrossProfileChart extends HorizontalProfileChart { + /** + * Logger used for logging with log4j. + */ private static Logger log = Logger.getLogger(HorizontalCrossProfileChart.class); + /** + * Constructor to create HorizontalCrossProfileChart objects. + * + * @param labels Labels used to be displayed in title, subtitle and so on. + * @param theme ChartTheme used to adjust the rendering of this chart. + * @param parameters Collection containing a bunch of parameters. + * @param measurements Collection containing a bunch of measurements. + * @param dates Collection containing a bunch of date objects. + * @param result Collection containing a bunch of <code>Result</code> + * objects which contain the actual data items to be displayed. + * @param timeGaps Collection with timegap definitions. + * @param locale Locale used to specify the format of labels, numbers, ... + * @param linesVisible Render lines between data points if true, otherwise + * not. + * @param shapesVisible Render vertices as points if true, otherwise not. + */ public HorizontalCrossProfileChart( ChartLabels labels, ChartTheme theme, @@ -46,6 +67,13 @@ } + /** + * Method for gap detection. Nothing is done here, because in this type of + * chart no gap detection takes place. + * + * @see de.intevation.gnv.chart.HorizontalProfileChart#gapDetection(Result[], + * Series, int, int) + */ @Override protected void gapDetection( Result[] results,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Wed Mar 24 14:48:55 2010 +0000 @@ -20,16 +20,45 @@ /** - * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> + * This class is used to create xy-charts of horizontal profiles. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class HorizontalProfileChart extends VerticalProfileChart { + /** + * Logger used for logging with log4j. + */ private static Logger log = Logger.getLogger(HorizontalProfileChart.class); + /** + * <code>WKTReader</code> used to turn wkt strings into geometries. + */ private static WKTReader wktReader = new WKTReader(); + + /** + * The first point in a HorizontalProfileChart. It is used to calculate the + * distance between the currently processed point an the start. + */ private Point firstPoint; + /** + * Constructor used to create horizontal profile charts. + * + * @param labels Labels used to be displayed in title, subtitle and so on. + * @param theme ChartTheme used to adjust the rendering of this chart. + * @param parameters Collection containing a bunch of parameters. + * @param measurements Collection containing a bunch of measurements. + * @param dates Collection containing a bunch of date objects. + * @param result Collection containing a bunch of <code>Result</code> + * objects which contain the actual data items to be displayed. + * @param timeGaps Collection with timegap definitions. + * @param locale Locale used to specify the format of labels, numbers, ... + * @param linesVisible Render lines between data points if true, otherwise + * not. + * @param shapesVisible Render vertices as points if true, otherwise not. + */ public HorizontalProfileChart( ChartLabels labels, ChartTheme theme, @@ -58,6 +87,9 @@ } + /** + * @see de.intevation.gnv.chart.VerticalProfileChart#getValue(Result) + */ @Override protected Object getValue(Result row) { try { @@ -70,6 +102,11 @@ } + /** + * @see de.intevation.gnv.chart.VerticalProfileChart#gapDetection(Result, + * Series, int, int) + */ + @Override protected void gapDetection( Result[] results, Series series, @@ -103,6 +140,10 @@ } + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart(Result, Series) + */ + @Override protected void addValue(Result row, Series series) { double distance = 0; @@ -128,6 +169,12 @@ } + + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart#addSeries(Series, + * String, int) + */ + @Override protected void addSeries(Series series, String label, int idx) { super.addSeries(series, label, idx); @@ -136,6 +183,10 @@ } + /** + * @see de.intevation.gnv.chart.VerticalProfileChart#prepareRangeAxis(String, + * int) + */ @Override protected void prepareRangeAxis(String seriesKey, int idx) { return; @@ -143,6 +194,10 @@ } + /** + * @see de.intevation.gnv.chart.VerticalProfileChart#storeMaxValue(Map, + * Object, String) + */ @Override protected void storeMaxValue(Map values, Object value, String parameter) { return; @@ -150,6 +205,11 @@ } + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart#createSeriesName(String, + * String, String) + */ + @Override protected String createSeriesName( String breakPoint1, String breakPoint2, @@ -165,6 +225,11 @@ } + /** + * @see de.intevation.gnv.chart.VerticalProfileChart#addGapsOnGrid(Result[], + * Series, int, int) + */ + @Override protected void addGapsOnGrid( Result[] results, Series series, @@ -226,6 +291,17 @@ } + /** + * Method to add gaps between two data points. The real detection is done by + * {@link #simpleDetection} and {@link #specialDetection}. + * + * @param results All data points in this dataset. + * @param series Series to be processed. + * @param startValue <code>Point</code> where the scan for gaps should begin. + * @param endValue <code>Point</code> where the scan should end. + * @param startPos Start position of this series in <code>results</code>. + * @param endPos End position of a series in <code>results</code> + */ protected void addGaps( Result[] results, Series series, @@ -276,6 +352,21 @@ } + /** + * Simple method to detect gaps. A gap is detected if the delta between two + * data points (current, last) is bigger than <code>PERCENTAGE</code> percent + * of delta of start and end. + * <br> + * (smallDelta > delta / 100 * PERCENTAGE) + * + * @param start First data point in a series + * @param end Last data point in a series + * @param last Left point + * @param current Right point + * + * @return true, if a gap is detected between last and current - otherwise + * false. + */ protected boolean simpleDetection( Point start, Point end, @@ -289,6 +380,22 @@ } + /** + * Method to detect gaps between two data points. Following formula is used + * for detection:<br> + * smallDelta > (3.0 / (count - 1) * delta)<br> + * smallDelta = distance between <code>current</code> and <code>last</code> + * <br> + * delta = distance between <code>start</code> and <code>end</code> + * + * @param start First data point in a series + * @param end Last data point in a series + * @param last Left point + * @param current Right point + * + * @return true, if a gap is detected between last and current - otherwise + * false. + */ protected boolean specialDetection( Point start, Point end, @@ -306,6 +413,10 @@ return (smallDelta > (3.0 / (count - 1) * delta)); } + /** + * @see de.intevation.gnv.chart.VerticalProfileChart#getDependendAxisName(Result, + * Result) + */ @Override protected String getDependendAxisName(Result first, Result second) { if (first.getInteger("IPOSITION") == second.getInteger("IPOSITION")) @@ -314,6 +425,15 @@ return "IPOSITION"; } + /** + * This method returns a point from a given wkt string stored in + * <code>result</code>. + * + * @param result <code>Result</code> object which contains the wkt string. + * The wkt string needs to be available under the key SHAPE. + * + * @return Point representation of wkt string. + */ private Point getPoint(Result result) throws ParseException {
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/Insets.java Tue Mar 23 14:11:51 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -/* Copyright (C) 2007 con terra GmbH (http://www.conterra.de) - * All rights reserved - * - * $Id: Insets.java,v 1.1 2007/12/10 13:57:13 drewnak Exp $ - * - * created by: drewnak - * created at : 10.12.2007 - * created at : 13:31:12 - * - * modified by: $Author: drewnak $ - * modified at: $Date: 2007/12/10 13:57:13 $ - */ -package de.intevation.gnv.chart; - -public class Insets { - public double mUpper; - public double mLower; - public double mLeft; - public double mRight; - - /** - * @param pUpper - * @param pLower - * @param pLeft - * @param pRight - */ - public Insets(double pUpper, double pLeft, double pLower, double pRight) { - super(); - mUpper = pUpper; - mLower = pLower; - mLeft = pLeft; - mRight = pRight; - } -} \ No newline at end of file
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java Wed Mar 24 14:48:55 2010 +0000 @@ -41,22 +41,54 @@ import org.jfree.data.time.TimeSeriesCollection; /** - * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) + * This class is used to create timeseries charts. The domain axis contains + * multiple date/time objects. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class TimeSeriesChart extends AbstractXYLineChart { - private static final String DATE_FORMAT = "chart.timeseries.date.format"; - + /** + * Constant format which can be useful to format date items. Value is + * {@value}. + */ public static final String DEFAULT_DATE_FORMAT = "dd-MMM-yyyy"; + /** + * Constant field used if no gap detection should be done here. This field + * is used in @see #getTimeGapValue. Value is {@value}. + */ public static final long NO_TIME_GAP = Long.MAX_VALUE - 1000; + + /** + * Percentage used for gap detection. Its value is {@value}. + */ public static final int GAP_SIZE = 5; // in percent + /** + * Logger used for logging with log4j. + */ private static Logger log = Logger.getLogger(TimeSeriesChart.class); + /** + * Constructor used to create <code>TimeSeries</code> charts. + * + * @param labels Labels used to be displayed in title, subtitle and so on. + * @param theme ChartTheme used to adjust the rendering of this chart. + * @param parameters Collection containing a bunch of parameters. + * @param measurements Collection containing a bunch of measurements. + * @param dates Collection containing a bunch of date objects. + * @param result Collection containing a bunch of <code>Result</code> + * objects which contain the actual data items to be displayed. + * @param timeGaps Collection with timegap definitions. + * @param locale Locale used to specify the format of labels, numbers, ... + * @param linesVisible Render lines between data points if true, otherwise + * not. + * @param shapesVisible Render vertices as points if true, otherwise not. + */ public TimeSeriesChart( ChartLabels labels, ChartTheme theme, @@ -85,6 +117,9 @@ } + /** + * see de.intevation.gnv.chart.AbstractXYLineChart#initChart() + */ protected void initChart() { chart = ChartFactory.createTimeSeriesChart( labels.getTitle(), @@ -102,6 +137,9 @@ } + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart#initData() + */ protected void initData() { log.debug("init data for timeseries chart"); @@ -177,6 +215,9 @@ } + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart#addValue(Result, Series) + */ protected void addValue(Result row, Series series) { ((TimeSeries) series).addOrUpdate( new Minute(row.getDate("XORDINATE")), @@ -185,6 +226,10 @@ } + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart#addSeries(Series, + * String, int) + */ protected void addSeries(Series series, String parameter, int idx) { log.debug("add series (" + parameter + ")to timeseries chart"); @@ -205,6 +250,10 @@ } + /** + * Method to add processed datasets to plot. Each dataset is adjusted using + * <code>prepareAxis</code> and <code>adjustRenderer</code> methods. + */ protected void addDatasets() { Iterator iter = parameters.iterator(); XYPlot plot = chart.getXYPlot(); @@ -233,6 +282,10 @@ } + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart#localizeDomainAxis(Axis, + * Locale) + */ protected void localizeDomainAxis(Axis axis, Locale locale) { ((ValueAxis)axis).setStandardTickUnits(createStandardDateTickUnits( TimeZone.getDefault(), @@ -240,6 +293,10 @@ } + /** + * @see org.jfree.chart.axis.DateAxis#createStandardDateTickUnits(TimeZone, + * Locale) + */ public static TickUnitSource createStandardDateTickUnits( TimeZone zone, Locale locale) @@ -370,11 +427,23 @@ } + /** + * Method to get a message from resource bundle. + * + * @param Locale Locale used to specify the resource bundle. + * @param def Key to specify the required message. + * + * @return Message + */ protected String getMessage(Locale locale, String key, String def) { return RessourceFactory.getInstance().getRessource(locale, key, def); } + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart#createSeriesName(String, + * String, String) + */ protected String createSeriesName( String breakPoint1, String breakPoint2, @@ -388,6 +457,17 @@ } + /** + * Method to add gaps between two data points. The max valid space between + * two data points is calculated by <code>calculateGapSize</code>. + * + * @param results All data points in this dataset. + * @param series Series to be processed. + * @param startDate Date item where the scan for gaps should begin. + * @param endDate Date item where the scan should end. + * @param startPos Start position of this series in <code>results</code>. + * @param endPos End position of a series in <code>results</code> + */ protected void addGaps( Result[] results, Series series, @@ -435,6 +515,19 @@ } + /** + * Method to calculate the max space between two data points. + * + * @param start First date + * @param end Last date + * @param startPos Start position of the current series in the collection + * containing the bunch of series. + * @param endPos End position of the current series in the collection + * containing the bunch of series. + * @param gapID Gap id used to specify the time intervals. + * + * @return Min size of a gap. + */ protected long calculateGapSize( Date start, Date end, @@ -452,6 +545,19 @@ } + /** + * Determine the interval size between two data points. + * + * @param dStart Start date + * @param dEnd End date + * @param pStart Index of start point in series used to specify the total + * amount of date items. + * @param pEnd Index of end point in series used to specify the total amount + * of date items. + * @param gapID Gap id used to determine gaps configured in a xml document. + * + * @return Interval size between two data points. + */ protected long getTimeGapValue( Date dStart, Date dEnd,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java Wed Mar 24 14:48:55 2010 +0000 @@ -35,22 +35,45 @@ import org.jfree.ui.RectangleInsets; /** - * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) - * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> */ public class VerticalCrossSectionChart implements Chart { + /** + * Lookup class for retrieving a color which corresponds to a specific + * integer value. + */ public static final class PalettePaintLookup implements PolygonRenderer.PaintLookup { + /** + * Object storing information about value ranges and its coresponding + * colors and descriptions. + */ private Palette palette; + + /** + * Map containing some special <code>Paint</code> like ground fillcolor. + */ private Map<Integer, Paint> special; + /** + * Constructor + * + * @param palette See {@link #palette} + */ public PalettePaintLookup(Palette palette) { this(palette, null); } + /** + * Constructor + * + * @param palette See {@link #palette} + * @param special See {@link #special} + */ public PalettePaintLookup( Palette palette, Map<Integer, Paint> special @@ -59,6 +82,11 @@ this.special = special; } + /** + * @param index Index of a <code>Paint</code> + * + * @return <code>Paint</code> object for a given index. + */ public Paint getPaint(int index) { if (special != null) { Paint paint = special.get(index); @@ -72,18 +100,43 @@ } } // class PalettePaintLookup + /** + * This class is used to turn labels which represent a number into a + * specific format. + */ public static class LocalizedLabelGenerator extends PolygonRenderer.DefaultLabelGenerator { + /** + * <code>NumberFormat</code> which is used to turn a number into a + * specific format. + */ protected NumberFormat format; + /** + * Constructor + */ public LocalizedLabelGenerator() { } + /** + * Constructor + * + * @param format See {@link #format} + */ public LocalizedLabelGenerator(NumberFormat format) { this.format = format; } + /** + * If label is a <code>Number</code>, it is turned into a format + * specified by {@link #format}. + * + * @param label Label to format. + * + * @return String representation of label. + */ + @Override protected String toString(Object label) { return label instanceof Number ? format.format(((Number)label).doubleValue()) @@ -91,17 +144,51 @@ } } // class LocalizedLabelGenerator + /** + * JFreeChart object stored at this place after chart creation. + */ protected JFreeChart chart; + /** + * Stores {@link de.intevation.gnv.jfreechart.PolygonDataset} which is used + * to create a vertical cross chart. + */ protected AttributedXYColumns columns; + + /** + * Map which contains colors to fill polygons draw by this chart. + */ protected Map<Integer, Paint> special; + + /** + * Object used to map value intervals to specific colors and descriptions. + */ protected Palette palette; + + /** + * Locale object used for i18n support. + */ protected Locale locale; + + /** + * Labels for decorating the chart. + */ protected ChartLabels labels; + /** + * Default Constructor + */ public VerticalCrossSectionChart() { } + /** + * Constructor for VerticalCrossSectionChart creation. + * + * @param columns See {@link #columns} + * @param palette See {@link #palette} + * @param locale See {@link #locale} + * @param labels See {@link #labels} + */ public VerticalCrossSectionChart( AttributedXYColumns columns, Palette palette, @@ -111,6 +198,15 @@ this(columns, palette, null, locale, labels); } + /** + * Constructor for VerticalCrossSectionChart creation. + * + * @param columns See {@link #columns} + * @param palette See {@link #palette} + * @param special See {@link #special} + * @param locale See {@link #locale} + * @param labels See {@link #labels} + */ public VerticalCrossSectionChart( AttributedXYColumns columns, Palette palette, @@ -125,6 +221,12 @@ this.labels = labels; } + /** + * This method is used to create a JFreeChart from this object. A 2D plot is + * drawn and a legend panel is created containing each value range. + * + * @return JFreeChart object + */ protected JFreeChart createChart() { boolean legendB = false; @@ -208,6 +310,9 @@ return chart; } + /** + * @see de.intevation.gnv.chart.Chart#generateChart() + */ public JFreeChart generateChart() { if (chart == null) { chart = createChart(); @@ -216,6 +321,9 @@ return chart; } + /** + * Set the background paint of {@link #chart}. + */ public void setBackgroundPaint(Paint paint) { chart.setBackgroundPaint(paint); }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java Wed Mar 24 14:48:55 2010 +0000 @@ -23,24 +23,64 @@ /** - * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> + * This class is used to create xy charts of vertical profiles. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class VerticalProfileChart extends AbstractXYLineChart { + /** + * Default axis identifier which is used if @see #getDependendAxisName does + * not return a value. The value of this field is {@value}. + */ public static final String DEFAULT_AXIS = "KPOSITION"; + /** + * Logger used for logging with log4j. + */ private static Logger log = Logger.getLogger(VerticalProfileChart.class); + /** + * Constant used for gap detection. Its value is {@value}. + */ protected final double PERCENTAGE = 5.0; + + /** + * Constnat used for gap detection in @see #gridDetection. Its value is + * {@value}. + */ protected final double GAP_MAX_LEVEL = Math.sqrt(2.0); + + /** + * Constant used for gap detection in @see #addGaps. Its value is {@value}. + */ protected final int GAP_MAX_VALUES = 60; - /** Map to store max ranges of each parameter (axis.setAutoRange(true) - * doesn't seem to work properly. */ + /** + * Map to store max ranges of each parameter + * (org.jfree.chart.axis.Axis.setAutoRange(true) doesn't seem to work + * properly. + */ protected Map values; + /** + * Constructor used to create xy-charts. + * + * @param labels Labels used to be displayed in title, subtitle and so on. + * @param theme ChartTheme used to adjust the rendering of this chart. + * @param parameters Collection containing a bunch of parameters. + * @param measurements Collection containing a bunch of measurements. + * @param dates Collection containing a bunch of date objects. + * @param result Collection containing a bunch of <code>Result</code> + * objects which contain the actual data items to be displayed. + * @param timeGaps Collection with timegap definitions. + * @param locale Locale used to specify the format of labels, numbers, ... + * @param linesVisible Render lines between data points if true, otherwise + * not. + * @param shapesVisible Render vertices as points if true, otherwise not. + */ public VerticalProfileChart( ChartLabels labels, ChartTheme theme, @@ -70,6 +110,10 @@ } + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart#initData() + */ + @Override protected void initData() { log.debug("init data for VerticalProfileChart"); @@ -145,11 +189,32 @@ } + /** + * Extract the important value from <code>Result</code> object. + * + * @param row <code>Result</code> object which contains a required value. + * + * @return X-ordinate + */ protected Object getValue(Result row) { return row.getDouble("XORDINATE"); } + /** + * General method to start a gap detection. The switch between standard gap + * detection method <code>addGaps</code> and a specialized method + * <code>addGapsOnGrid</code> is done by a parameter <code>DATEID</code> + * which is stored a each <code>Result</code> object. Specialized method is + * used if <code>DATEID</code> equals 2, otherwise the standard method is + * used. + * + * @param results Array of <code>Result</code> objects storing data of + * this chart. + * @param series Series used to add gaps. + * @param startPos Index of first element of series in results. + * @param endPos Index of last element of series in results. + */ protected void gapDetection( Result[] results, Series series, @@ -165,6 +230,15 @@ } + /** + * Method to expand max range of a range axis identified by seriesKey. + * <code>LOWER_MARGIN</code> and <code>UPPER_MARGIN</code> are used to + * expand the range. + * + * @param seriesKey Key to identify the series stored at the current + * Dataset. + * @param idx Currently not used. + */ protected void prepareRangeAxis(String seriesKey, int idx) { XYPlot plot = chart.getXYPlot(); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); @@ -175,6 +249,10 @@ } + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart#addValue(Result, Series) + */ + @Override protected void addValue(Result row, Series series) { ((XYSeries) series).add( row.getDouble("XORDINATE"), @@ -183,6 +261,11 @@ } + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart#addSeries(Series, String, + * int) + */ + @Override protected void addSeries(Series series, String parameter, int idx) { log.debug("add series (" + parameter + ")to chart"); @@ -203,6 +286,10 @@ } + /** + * Method to add processed datasets to plot. Each dataset is adjusted using + * <code>prepareAxis</code> and <code>adjustRenderer</code> methods. + */ protected void addDatasets() { Iterator iter = parameters.iterator(); XYPlot plot = chart.getXYPlot(); @@ -232,6 +319,13 @@ } + /** + * Method used to store the max y-range of each parameter in this chart. + * + * @param values Map to store max values for each parameter. + * @param val Value used to be a Double. + * @param parameter Title used to identify a range object stored in values. + */ protected void storeMaxValue(Map values, Object val, String parameter) { double value = ((Double) val).doubleValue(); Range range = null; @@ -250,12 +344,22 @@ } + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart#localizeDomainAxis(Axis, + * Locale) + */ + @Override protected void localizeDomainAxis(Axis axis, Locale locale) { // call localizeRangeAxis from superclass which formats NumberAxis super.localizeRangeAxis(axis, locale); } + /** + * @see de.intevation.gnv.chart.AbstractXYLineChart#createSeriesName(String, + * String, String) + */ + @Override protected String createSeriesName( String breakPoint1, String breakPoint2, @@ -269,6 +373,18 @@ } + /** + * Method used to add gaps between data points on grids. The real detection + * is done in <code>gridDetection</code>. + * + * @param results Array of <code>Result</code> objects storing the relevant + * values. + * @param series Series object where the gaps are added to. + * @param startPos Index of first element which should be used in gap + * detection. Other series are stored in results as well. + * @param endPos Index of last element which should be used in gap + * detection. + */ protected void addGapsOnGrid( Result[] results, Series series, @@ -307,6 +423,24 @@ } + /** + * Standarad method to add gaps. There are two different methods to detect + * gaps. <code>simpleDetection</code> is used if the number of data points + * in this chart is lower than <code>GAP_MAX_VALUES</code>. Otherwise + * <code>specialDetection</code> is used. A data point with + * <code>null</code> value is added where a gap should be. This lets + * JFreeChart break the current graph. + * + * @param results Array of <code>Result</code> objects storing the relevant + * values. + * @param series Series object where the gaps are added to. + * @param startValue First data point value in series. + * @param endValue Last data point value in series. + * @param startPos Index of first data point in results which contains all + * data points of all series. + * @param endPos Index of last data point in results which contains all data + * points of all series. + */ protected void addGaps( Result[] results, Series series, @@ -347,6 +481,21 @@ } + /** + * Simple method to detect gaps. A gap is detected if the delta between two + * data points (current, last) is bigger than <code>PERCENTAGE</code> percent + * of delta of start and end. + * <br> + * (smallDelta > delta / 100 * PERCENTAGE) + * + * @param start First data point value in a series. + * @param end Last data point value in a series. + * @param last Left value + * @param current Right value + * + * @return true, if a gap is detected between last and current - otherwise + * false. + */ protected boolean simpleDetection( double start, double end, @@ -360,6 +509,21 @@ } + /** + * Method to detect gaps between two data points. Following formula is used + * for detection:<br> + * smallDelta > (3.0 / (count - 1) * delta)<br> + * smallDelta = current - last<br> + * delta = end - start + * + * @param start First data point value in a series. + * @param end Last data point value in a series. + * @param last Left value + * @param current Right value + * + * @return true, if a gap is detected between last and current - otherwise + * false. + */ protected boolean specialDetection( double start, double end, @@ -374,6 +538,16 @@ } + /** + * Method used to detect gaps between two data points grids. If the delta + * between current and last is bigger than <code>GAP_MAX_LEVEL</code>, a gap + * is detected. + * + * @param last Left value + * @param current Right value + * + * @return True, if a gap was detected - otherwise false. + */ protected boolean gridDetection(double last, double current) { if (log.isDebugEnabled()) { log.debug("######################################################"); @@ -387,6 +561,15 @@ } + /** + * This method returns the key which is used to retrieve the y-value served + * by a <code>Result</code> object. + * + * @param first <code>Result</code> object - not used in this class. + * @param second <code>Result</code> object - not used in this class. + * + * @return the string "KPOSITION" + */ protected String getDependendAxisName(Result first, Result second) { return "KPOSITION"; }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/XMLChartTheme.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/XMLChartTheme.java Wed Mar 24 14:48:55 2010 +0000 @@ -22,61 +22,138 @@ import de.intevation.artifactdatabase.Config; /** - * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> + * Implementation of JFreeChart's default implementation + * <code>StandardChartTheme</code>. This class takes an xml document with a + * bunch of parameters and turns it into a <code>ChartTheme</code> to change + * the appearance of charts. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class XMLChartTheme extends StandardChartTheme { + /** + * Default color. + */ private static final Color DEFAULT_COLOR = Color.BLACK; + /** + * Logger used for logging with log4j. + */ private Logger log = Logger.getLogger(XMLChartTheme.class); + /** + * Field storing the visibility of the domain crosshair + */ protected boolean domainCrosshairVisible; + + /** + * Field storing the visibility of the range crosshair + */ protected boolean rangeCrosshairVisible; + + /** + * Field storing the visiblity of lines. + */ protected boolean renderLines; + + /** + * Field storing the visibility of data points + */ protected boolean renderShapes; + /** + * Field storing the width of a data point + */ protected int pointWidth; + + /** + * Field storing the height of a data point. + */ protected int pointHeight; + /** + * Field storing the base color of a bin in a histogram chart + */ protected Paint histogramBasePaint; + /** + * Constructor + * + * @param name Name for this theme. + */ public XMLChartTheme(String name) { super(name); } + /** + * Setter method for the visibility of the domain crosshair. + * + * @param visible True, if domain crosshair should be visible + */ public void setDomainCrosshairVisible(boolean visible) { this.domainCrosshairVisible = visible; } + /** + * Getter method for retrieving the visibility of the domain crosshair. + * + * @return Visibility of the domain crosshair. + */ public boolean getDomainCrosshairVisible() { return domainCrosshairVisible; } + /** + * Getter method for retrieving the visibility of the range crosshair. + * + * @return Visibility of the range crosshair. + */ public boolean getRangeCrosshairVisible() { return rangeCrosshairVisible; } + /** + * Setter method for the visibility of the range crosshair. + * + * @param visible True, if range crosshair should be visible + */ public void setRangeCrosshairVisible(boolean visible) { this.rangeCrosshairVisible = visible; } + /** + * Method to set the bin color of histograms. + * + * @param c Bin color + */ public void setHistogramBasePaint(Color c) { this.histogramBasePaint = c; } + /** + * Getter method for retrieving the bin color. + * + * @return Bin color + */ public Paint getHistogramBasePaint() { return histogramBasePaint; } + /** + * Take a given xml document and read the configuration of a chart + * appearance. + * + * @param document XML document + */ public void applyXMLConfiguration(Document document) { log.debug("create XMLChartTheme"); @@ -84,6 +161,11 @@ } + /** + * Start parsing the different settings from <code>document</code>. + * + * @param document XML document + */ private void init(Document document) { log.debug("init XMLChartTheme parameters"); @@ -98,6 +180,11 @@ } + /** + * Read parameters configuring the title of a chart. + * + * @param document XML document + */ private void initTitleParameters(Document document) { log.debug("init title parameters."); @@ -114,6 +201,11 @@ } + /** + * Read parameters configuring the subtitle of a chart. + * + * @param document XML document + */ private void initSubtitleParameters(Document document) { log.debug("init title parameters."); @@ -128,6 +220,11 @@ } + /** + * Read parameters configuring the background color of a chart. + * + * @param document XML document + */ private void initChartParameters(Document document) { log.debug("init chart parameters."); @@ -138,6 +235,11 @@ } + /** + * Read parameters configuring the plot of a chart. + * + * @param document XML document + */ private void initPlotParameters(Document document) { log.debug("init plot parameters."); @@ -181,6 +283,11 @@ } + /** + * Read parameters configuring the axes of a plot. + * + * @param document XML document + */ private void initAxisParameters(Document document) { log.debug("init axis parameters."); @@ -197,6 +304,11 @@ } + /** + * Read parameters configuring the legend of a chart. + * + * @param document XML document + */ private void initLegendParameters(Document document) { log.debug("init legend parameters."); @@ -213,6 +325,11 @@ } + /** + * Read parameters configuring the renderer of a plot. + * + * @param document XML document + */ private void initRenderer(Document document) { log.debug("init renderer parameters."); @@ -229,6 +346,11 @@ } + /** + * Read base color of bins in histogram charts. + * + * @param document XML document + */ private void initHistogramColor(Document document) { log.debug("init histogram color"); String tmp = getString(document, "theme/histogram/bar/color/@value"); @@ -239,11 +361,28 @@ } + /** + * Read a xpath expression and return the matched string. + * + * @param document Document + * @param xpath XPath expression + * + * @return Matched string + */ private static String getString(Document document, String xpath) { return Config.getStringXPath(document, xpath); } + /** + * Read a xpath and turn it into an integer. + * + * @param document Document + * @param xpath XPath expression + * + * @return Matched string as integer representation. Return 0 if no integer + * have been found at <code>xpath</code>. + */ private static int getInt(Document document, String xpath) { String tmp = getString(document, xpath); @@ -254,6 +393,15 @@ } + /** + * Read a xpath and turn it into a boolean. + * + * @param document Document + * @param xpath XPath expression + * + * @return Matched string as boolean representation. Return false if no + * boolean have been found at <code>xpath</code>. + */ private static boolean getBool(Document document, String xpath) { String tmp = getString(document, xpath); @@ -264,6 +412,13 @@ } + /** + * Turns a string into a color using {@link java.awt.Color}. + * + * @param Color as string + * + * @return Color + */ protected Color decodeColor(String color) { try { if (color == null) @@ -279,6 +434,15 @@ } + /** + * Create a font with the given parameters. + * + * @param type Font type + * @param size Font size + * @param bold Font weight + * + * @return Font + */ protected Font createFont(String type, int size, boolean bold) { Font font = null; if (bold) @@ -290,6 +454,12 @@ } + /** + * Apply settings of this <code>ChartTheme</code> to the given + * <code>XYPlot</code>. + * + * @param plot XYPlot + */ protected void applyToXYPlot(XYPlot plot) { log.debug("apply theme parameter to XYPlot"); @@ -308,6 +478,12 @@ } + /** + * Apply settings of this <code>ChartTheme</code> to the + * <code>XYLineAndShapeRenderer</code> of the given <code>XYPlot</code>. + * + * @param plot XYPlot + */ protected void applyToXYLineAndShapeRenderer(XYPlot plot) { if (plot == null) return; @@ -327,6 +503,12 @@ } + /** + * Apply settings of this <code>ChartTheme</code> to the + * <code>XYBarRenderer</code> of the given <code>XYPlot</code>. + * + * @param plot XYPlot + */ protected void applyToXYBarRenderer(XYPlot plot) { if (plot == null) return;
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/exception/TechnicalChartException.java Tue Mar 23 14:11:51 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/exception/TechnicalChartException.java Wed Mar 24 14:48:55 2010 +0000 @@ -1,10 +1,7 @@ -/** - * - */ package de.intevation.gnv.chart.exception; /** - * @author Tim Englich <tim.englich@intevation.de> + * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> * */ public class TechnicalChartException extends Exception {