view gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileVectorChart.java @ 1145:dfe1ac687c7f tip

added tags
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:16:15 +0200
parents f953c9a559d8
children
line wrap: on
line source
/*
 * Copyright (c) 2010 by Intevation GmbH
 *
 * This program is free software under the LGPL (>=v2.1)
 * Read the file LGPL.txt coming with the software for details
 * or visit http://www.gnu.org/licenses/ if it does not exist.
 */

package de.intevation.gnv.chart;

import de.intevation.gnv.geobackend.base.Result;
import de.intevation.gnv.geobackend.base.ResultDescriptor;

import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;

import org.apache.log4j.Logger;

import org.jfree.chart.ChartTheme;

import org.jfree.chart.plot.XYPlot;

import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 * This class is used to create xy charts of vertical profiles.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class VerticalProfileVectorChart
extends      VerticalProfileChart
{
    private static Logger logger =
        Logger.getLogger(VerticalProfileVectorChart.class);

    public VerticalProfileVectorChart(
        ChartLabels labels,
        ChartTheme  theme,
        Collection  parameters,
        Collection  measurements,
        Collection  dates,
        Collection  result,
        Collection  timeGaps,
        Locale      locale,
        boolean     linesVisible,
        boolean     shapesVisible
    ) {
        super(labels, theme, parameters, measurements, dates, result,
              timeGaps, locale, linesVisible, shapesVisible);
    }


    @Override
    protected void initData() {
        logger.debug("init data for verticalprofile chart with vector data.");

        int items = resultSet.size();
        logger.debug("Found " + items + " items for this chart.");

        Iterator iter         = resultSet.iterator();
        Result     row        = null;
        String     seriesName = null;
        XYSeries   series     = null;

        int  idx       = 0;
        int  startPos  = 0;
        int  endPos    = 0;

        double startValue = 0;
        double endValue   = 0;

        ResultDescriptor rd = null;
        int idxSeries       = -1;
        int idxX            = -1;
        int idxY            = -1;

        Result[] results =
            (Result[]) resultSet.toArray(new Result[resultSet.size()]);

        while (iter.hasNext()) {
            row = (Result) iter.next();

            if (rd == null) {
                rd        = row.getResultDescriptor();
                idxSeries = rd.getColumnIndex("SERIES");
                idxX      = rd.getColumnIndex("XORDINATE");
                idxY      = rd.getColumnIndex("YORDINATE");
            }

            if (!row.getString(idxSeries).equals(seriesName)) {
                logger.debug("prepare data/plot for next dataset.");

                if (series != null) {
                    if (startPos >= 0 && endPos < items) {
                        gapDetection(results, series, startPos, endPos);
                    }

                    addSeries(series, seriesName, idx);

                    startPos = endPos + 1;
                }

                seriesName = row.getString(idxSeries);

                logger.debug("next data is '" + seriesName + "'");
                series = new XYSeries(seriesName);
            }

            addValue(row, series);
            Object x = getValue(row);
            Double y = row.getDouble(idxY);
            if (x != null && y != null) {
                storeMaxRange(ranges, y, seriesName);
                storeMaxValue(values, x, seriesName);
            }

            endPos++;
        }

        if (results.length == 0)
            return;

        if (startPos >= 0 && endPos < items) {
            gapDetection(results, series, startPos, endPos);
        }
        addSeries(series, seriesName, idx);

        addDatasets();
    }


    @Override
    protected void addDatasets() {
        XYPlot     plot = chart.getXYPlot();
        int        idx  = 0;

        XYSeriesCollection sc  = null;
        Iterator           iter = datasets.keySet().iterator();

        while (iter.hasNext()) {
            String key = (String) iter.next();
            sc  = (XYSeriesCollection)datasets.get(key);
            plot.setDataset(idx, sc );
            logger.debug("Added " + key + " parameter to plot.");
            prepareAxis(key, idx);
            adjustRenderer(
                idx++,
                sc.getSeriesCount(),
                linesVisible,
                shapesVisible
            );
        }

        prepareRangeAxis(null, -1);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org