Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/chart/DefaultHistogram.java @ 767:79401c871da4
Added and repaired javadoc in de.intevation.gnv.chart package.
gnv-artifacts/trunk@823 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 24 Mar 2010 14:48:55 +0000 |
parents | d08b9ba148c5 |
children | 9a828e5a2390 |
line wrap: on
line diff
--- 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);