ingo@298: package de.intevation.gnv.chart; ingo@298: ingo@298: import java.util.Collection; ingo@310: import java.util.Iterator; ingo@298: import java.util.Locale; ingo@298: ingo@298: import com.vividsolutions.jts.geom.Point; ingo@298: import com.vividsolutions.jts.io.WKTReader; ingo@298: import com.vividsolutions.jts.io.ParseException; ingo@298: ingo@298: import org.apache.log4j.Logger; ingo@298: ingo@298: import org.jfree.chart.ChartTheme; ingo@298: import org.jfree.chart.plot.PlotOrientation; ingo@298: import org.jfree.data.general.Series; ingo@298: import org.jfree.data.xy.XYSeries; ingo@298: ingo@298: import de.intevation.gnv.geobackend.base.Result; ingo@310: import de.intevation.gnv.timeseries.gap.TimeGap; ingo@298: import de.intevation.gnv.utils.DistanceCalculator; ingo@298: ingo@298: ingo@298: /** ingo@298: * @author Ingo Weinzierl ingo@298: */ ingo@298: public class HorizontalProfileChart ingo@298: extends VerticalProfileChart ingo@298: { ingo@298: private static Logger log = Logger.getLogger(HorizontalProfileChart.class); ingo@298: ingo@298: private static WKTReader wktReader = new WKTReader(); ingo@298: private Point lastPoint; ingo@298: private double distance; ingo@298: ingo@298: ingo@298: public HorizontalProfileChart( ingo@298: ChartLabels labels, ingo@298: ChartTheme theme, ingo@298: Collection parameters, ingo@298: Collection measurements, ingo@310: Collection dates, ingo@298: Collection result, ingo@310: Collection timeGaps, ingo@298: Locale locale ingo@298: ) { ingo@310: super( ingo@310: labels, ingo@310: theme, ingo@310: parameters, ingo@310: measurements, ingo@310: dates, ingo@310: result, ingo@310: timeGaps, ingo@310: locale ingo@310: ); ingo@298: this.PLOT_ORIENTATION = PlotOrientation.VERTICAL; ingo@298: this.distance = 0; ingo@298: } ingo@298: ingo@298: ingo@298: protected void addValue(Result row, Series series) { ingo@298: // TODO look for gaps between two values ingo@298: try { ingo@298: Point point = (Point) wktReader.read(row.getString("SHAPE")); ingo@298: if (lastPoint != null) ingo@298: distance = distance + DistanceCalculator.calculateDistance( ingo@298: lastPoint, point ingo@298: ); ingo@298: lastPoint = point; ingo@298: ingo@298: ((XYSeries) series).add( ingo@298: distance, ingo@298: row.getDouble("YORDINATE") ingo@298: ); ingo@298: } ingo@298: catch(ParseException pe) { ingo@298: log.warn("No data found while parsing."); ingo@298: } ingo@298: } ingo@298: ingo@298: ingo@298: protected void addSeries(Series series, int idx) { ingo@298: super.addSeries(series, idx); ingo@298: ingo@298: // reset values used by current series for next series ingo@298: lastPoint = null; ingo@298: distance = 0; ingo@298: } ingo@298: ingo@298: ingo@298: protected String createSeriesName( ingo@298: String breakPoint1, ingo@298: String breakPoint2, ingo@298: String breakPoint3 ingo@298: ) { ingo@298: log.debug("create seriesname of horizontalprofile chart"); ingo@298: return super.createSeriesName( ingo@298: breakPoint1, ingo@298: breakPoint2, ingo@298: breakPoint3) + ingo@298: " " + ingo@298: findValueTitle(dates, breakPoint3); ingo@298: } ingo@298: } ingo@298: // vim:set ts=4 sw=4 si et sta sts=4 fenc=latin1 :