view gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java @ 329:42a5269636eb

Added time gap detection to time series charts. gnv-artifacts/trunk@395 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 02 Dec 2009 15:42:46 +0000
parents 22a6493e8460
children e37930705daa
line wrap: on
line source
package de.intevation.gnv.chart;

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

import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.io.WKTReader;
import com.vividsolutions.jts.io.ParseException;

import org.apache.log4j.Logger;

import org.jfree.chart.ChartTheme;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.general.Series;
import org.jfree.data.xy.XYSeries;

import de.intevation.gnv.geobackend.base.Result;
import de.intevation.gnv.utils.DistanceCalculator;


/**
 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de>
 */
public class HorizontalProfileChart
extends      VerticalProfileChart
{
    private static Logger log = Logger.getLogger(HorizontalProfileChart.class);

    private static WKTReader wktReader = new WKTReader();
    private        Point     lastPoint;
    private        double    distance;


    public HorizontalProfileChart(
        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
        );
        this.PLOT_ORIENTATION = PlotOrientation.VERTICAL;
        this.distance         = 0;
    }


    protected void addValue(Result row, Series series) {
        // TODO look for gaps between two values
        try {
            Point point = (Point) wktReader.read(row.getString("SHAPE"));
            if (lastPoint != null)
                distance = distance + DistanceCalculator.calculateDistance(
                    lastPoint, point
                );
            lastPoint = point;

            ((XYSeries) series).add(
                distance,
                row.getDouble("YORDINATE")
            );
        }
        catch(ParseException pe) {
            log.warn("No data found while parsing.");
        }
    }


    protected void addSeries(Series series, int idx) {
        super.addSeries(series, idx);

        // reset values used by current series for next series
        lastPoint = null;
        distance  = 0;
    }


    protected String createSeriesName(
        String breakPoint1,
        String breakPoint2,
        String breakPoint3
    ) {
        log.debug("create seriesname of horizontalprofile chart");
        return super.createSeriesName(
            breakPoint1,
            breakPoint2,
            breakPoint3) +
            " " +
            findValueTitle(dates, breakPoint3);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org