view gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileVectorChart.java @ 1089:1dc08501a1be

Implemented necessary classes (artifact, output state) used for a new product 'Achsenparalleler Vertikalschnitt. gnv-artifacts/trunk@1203 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Sat, 12 Jun 2010 12:59:48 +0000
parents ec512e7992c6
children f953c9a559d8
line wrap: on
line source
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