Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java @ 1072:80aecb01d79a
Let MainValuesArtifact have a state, outputmode and facet.
flys-artifacts/trunk@2556 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 24 Aug 2011 12:07:33 +0000 |
parents | b1ed0ec0236f |
children | e0243627ba62 |
line wrap: on
line source
package de.intevation.flys.exports; import java.util.Date; import java.util.List; import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.data.Range; import org.jfree.data.xy.XYSeries; import de.intevation.artifacts.Artifact; import de.intevation.artifactdatabase.state.Facet; import de.intevation.flys.model.DischargeTable; import de.intevation.flys.model.Gauge; import de.intevation.flys.model.River; import de.intevation.flys.model.TimeInterval; import de.intevation.flys.artifacts.WINFOArtifact; import de.intevation.flys.artifacts.model.WQKms; /** * An OutGenerator that generates discharge curves. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class DischargeCurveGenerator extends XYChartGenerator { /** The logger used in this generator. */ private static Logger logger = Logger.getLogger(DischargeCurveGenerator.class); public static final String I18N_CHART_TITLE = "chart.discharge.curve.title"; public static final String I18N_CHART_SUBTITLE = "chart.discharge.curve.subtitle"; public static final String I18N_XAXIS_LABEL = "chart.discharge.curve.xaxis.label"; public static final String I18N_YAXIS_LABEL = "chart.discharge.curve.yaxis.label"; public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurven"; public static final String I18N_XAXIS_LABEL_DEFAULT = "Q [m\u00b3/s]"; public static final String I18N_YAXIS_LABEL_DEFAULT = "W [cm]"; public DischargeCurveGenerator() { super(); } protected String getChartTitle() { return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); } @Override protected void addSubtitles(JFreeChart chart) { } protected String getXAxisLabel() { return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); } protected String getYAxisLabel() { return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); } @Override protected boolean zoomX(XYPlot plot, ValueAxis axis, Range range, Range x) { boolean zoomin = super.zoom(plot, axis, range, x); if (!zoomin) { axis.setLowerBound(0d); } return zoomin; } public void doOut(Artifact artifact, Facet facet, Document attr) { logger.debug("DischargeCurveGenerator.doOut: " + facet.getName()); if (!(artifact instanceof WINFOArtifact)) { logger.debug("Artifact is no instance of WINFOArtifact."); return; } WINFOArtifact flysArtifact = (WINFOArtifact) artifact; facet = flysArtifact.getNativeFacet(facet); if (facet == null) { logger.debug("no facet found"); return; } WQKms wqkms = (WQKms)facet.getData(flysArtifact, context); String gaugeName = wqkms.getName(); River river = flysArtifact.getRiver(); if (river == null) { logger.debug("no river found"); return; } Gauge gauge = river.determineGaugeByName(gaugeName); if (gauge == null) { logger.debug("no gauge found"); return; } String seriesName = getSeriesName(gauge); double [][] values = new double [][] { wqkms.getQs(), wqkms.getWs() }; int size = values != null ? values[0].length : 0; XYSeries series = new StyledXYSeries(seriesName, attr); for (int i = 0; i < size; i++) { series.add(values[0][i], values[1][i]); } addFirstAxisSeries(series); } protected String getSeriesName(Gauge gauge) { // XXX The following code stops the artifact server accepting new HTTP // requests. It needs more analysis! Is loading the discharge table a // memory problem? Or is the time interval the problem? //List<DischargeTable> dts = gauge.getDischargeTables(); //for (DischargeTable dt: dts) { // if (dt.getKind() == 0) { // TimeInterval ti = dt.getTimeInterval(); // Date start = ti.getStartTime(); // Date end = ti.getStopTime(); // String name = gauge.getName(); // if (end == null) { // Object[] args = new Object[] { name, start }; // return msg( // "chart.discharge.curve.curve.valid.from", // "", // args); // } // else { // Object[] args = new Object[] { name, start, end }; // return msg( // "chart.discharge.curve.curve.valid.range", // "", // args); // } // } //} return gauge.getName(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :