Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java @ 4255:670e98f5a441
Fixed leak while merging facets.
The ThemeList that is used by OutputHelper to sort the
Facets for an Output now uses a list to store the ManagedFacets.
The correct order is made up by sorting the List using
Collections.sort() function of the Java JDK. Therfore, the
ManagedFacet class implements the Comparable interface. The
return value of its compareTo(other) method depends on the
value of the 'position' field.
author | Ingo Weinzierl <weinzierl.ingo@googlemail.com> |
---|---|
date | Thu, 25 Oct 2012 14:01:46 +0200 |
parents | 3dc26ec2558d |
children | 0bb57e72b8ea |
line wrap: on
line source
package de.intevation.flys.exports; import de.intevation.artifactdatabase.state.ArtifactAndFacet; import de.intevation.artifactdatabase.state.Facet; import de.intevation.flys.artifacts.StaticWKmsArtifact; import de.intevation.flys.artifacts.WINFOArtifact; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.WKms; import de.intevation.flys.artifacts.model.WQKms; import de.intevation.flys.jfree.FLYSAnnotation; import de.intevation.flys.jfree.StickyAxisAnnotation; import de.intevation.flys.jfree.StyledXYSeries; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import org.jfree.data.xy.XYSeries; import org.w3c.dom.Document; /** * An OutGenerator that generates discharge curves. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class ComputedDischargeCurveGenerator extends DischargeCurveGenerator implements FacetTypes { /** The logger used in this generator. */ private static Logger logger = Logger.getLogger(ComputedDischargeCurveGenerator.class); public static final String I18N_CHART_TITLE = "chart.computed.discharge.curve.title"; public static final String I18N_CHART_SUBTITLE = "chart.computed.discharge.curve.subtitle"; public static final String I18N_YAXIS_LABEL = "chart.computed.discharge.curve.yaxis.label"; public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve"; public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; public static final String I18N_MAINVALUES_Q_LABEL = "Q (Haupt- und Extremwerte)"; public static final String I18N_MAINVALUES_W_LABEL = "W (Haupt- und Extremwerte)"; /** Trivial Constructor. */ public ComputedDischargeCurveGenerator () { super(); } @Override protected String getDefaultChartTitle() { return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); } @Override protected String getDefaultChartSubtitle() { double[] dist = getRange(); Object[] args = new Object[] { getRiverName(), dist[0] }; return msg(I18N_CHART_SUBTITLE, "", args); } @Override protected String getDefaultYAxisLabel(int pos) { return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); } /** * Process data, build up plot. */ @Override public void doOut( ArtifactAndFacet artifactFacet, Document attr, boolean visible ) { String name = artifactFacet.getFacetName(); logger.debug("ComputedDischargeCurveGenerator.doOut: " + name); if (name == null) { logger.warn("Broken facet in computed discharge out generation."); return; } //XXX DEAD CODE // Facet facet = artifactFacet.getFacet(); if (name.equals(COMPUTED_DISCHARGE_Q)) { doQOut((WQKms) artifactFacet.getData(context), artifactFacet, attr, visible); } else if (name.equals(STATIC_WQ)) { doWQOut(artifactFacet.getData(context), artifactFacet, attr, visible); } else if (name.equals(STATIC_WQ_ANNOTATIONS)) { doWQAnnotations( artifactFacet.getData(context), artifactFacet, attr, visible); } else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q) || name.equals(MAINVALUES_Q) || name.equals(COMPUTED_DISCHARGE_MAINVALUES_W) || name.equals(MAINVALUES_W) ) { doAnnotations((FLYSAnnotation) artifactFacet.getData(context), artifactFacet, attr, visible); } else if (name.equals(STATIC_WKMS_INTERPOL) || name.equals(HEIGHTMARKS_POINTS)) { doWAnnotations( artifactFacet.getData(context), artifactFacet, attr, visible); } else if (name.equals(STATIC_WKMS)) { doWAnnotations( artifactFacet.getData(context), artifactFacet, attr, visible); } else if (FacetTypes.IS.MANUALPOINTS(name)) { doPoints(artifactFacet.getData(context), artifactFacet, attr, visible, YAXIS.W.idx); } else if (name.equals(DISCHARGE_CURVE)) { doDischargeOut( (WINFOArtifact) artifactFacet.getArtifact(), artifactFacet.getData(context), artifactFacet.getFacetDescription(), attr, visible); } else { logger.warn("Unknown facet type for computed discharge: " + name); return; } } /** * Add WQ Data to plot. * @param wqkms data as double[][] */ protected void doWQOut( Object wqkms, ArtifactAndFacet aaf, Document theme, boolean visible ) { logger.debug("ComputedDischargeCurveGenerator: doWQOut"); double [][] data = (double [][]) wqkms; XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme); StyledSeriesBuilder.addPoints(series, data, true); addAxisSeries(series, YAXIS.W.idx, visible); } /** * Add Q-Series to plot. * @param wqkms actual data * @param theme theme to use. */ protected void doQOut( WQKms wqkms, ArtifactAndFacet aaf, Document theme, boolean visible ) { logger.debug("ComputedDischargeCurveGenerator: doWQOut"); XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme); StyledSeriesBuilder.addPointsQW(series, wqkms); addAxisSeries(series, YAXIS.W.idx, visible); } /** * Add WQ-Annotations to plot. * @param wqkms actual data * @param theme theme to use. */ protected void doWQAnnotations( Object wqkms, ArtifactAndFacet aandf, Document theme, boolean visible ) { List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); double [][] data = (double [][]) wqkms; for (int i = 0; i< data[0].length; i++) { // TODO we need linear interpolation? xy.add(new StickyAxisAnnotation(aandf.getFacetDescription(), (float) data[0][i], StickyAxisAnnotation.SimpleAxis.X_AXIS)); xy.add(new StickyAxisAnnotation(aandf.getFacetDescription(), (float) data[1][i], StickyAxisAnnotation.SimpleAxis.Y_AXIS)); } doAnnotations(new FLYSAnnotation(aandf.getFacetDescription(), xy), aandf, theme, visible); } /** * Add W-Annotations to plot. * @param wqkms actual data (double[][]). * @param theme theme to use. */ protected void doWAnnotations( Object wqkms, ArtifactAndFacet aandf, Document theme, boolean visible ) { Facet facet = aandf.getFacet(); List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); // Try to find them as WKms as well... if (wqkms instanceof double[][]) { logger.debug("its double[][] time, baby"); double [][] data = (double [][]) wqkms; // TODO Do we need interpolation? for (int i = 0; i< data[0].length; i++) { xy.add(new StickyAxisAnnotation(aandf.getFacetDescription(), (float) data[1][i], StickyAxisAnnotation.SimpleAxis.Y_AXIS)); } doAnnotations(new FLYSAnnotation(facet.getDescription(), xy), aandf, theme, visible); } else { logger.debug("its wkms time, baby"); WKms data = (WKms) wqkms; // Assume its WKms. // XXX DEAD CODE // double location = getRange()[0]; double w = StaticWKmsArtifact.getWAtKmLin(data, getRange()[0]); xy.add(new StickyAxisAnnotation(aandf.getFacetDescription(), (float) w, StickyAxisAnnotation.SimpleAxis.Y_AXIS)); doAnnotations(new FLYSAnnotation(facet.getDescription(), xy), aandf, theme, visible); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :