Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java @ 1695:0c9f7cc2cc11
In WDifferenceCurveGenerator use slightly modified doWOut-implementation of LongitudinalSectionGenerator.
flys-artifacts/trunk@2922 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 10 Oct 2011 10:27:45 +0000 |
parents | bdb05dc9b763 |
children | 13a9ee6cebef |
line wrap: on
line source
package de.intevation.flys.exports; import org.apache.log4j.Logger; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.title.TextTitle; import org.jfree.data.xy.XYSeries; import org.jfree.data.Range; import org.w3c.dom.Document; import de.intevation.artifacts.Artifact; import de.intevation.artifactdatabase.state.Facet; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.WKms; import de.intevation.flys.utils.DataUtil; import de.intevation.flys.artifacts.model.WQKms; /** * An OutGenerator that generates w differences curves. */ public class WDifferencesCurveGenerator extends LongitudinalSectionGenerator implements FacetTypes { /** The logger that is used in this generator. */ private static Logger logger = Logger.getLogger(WDifferencesCurveGenerator.class); public static final String I18N_CHART_TITLE = "chart.w_differences.title"; public static final String I18N_CHART_SUBTITLE = "chart.w_differences.subtitle"; public static final String I18N_YAXIS_LABEL = "chart.w_differences.yaxis.label"; public static final String I18N_2YAXIS_LABEL = "chart.w_differences.yaxis.second.label"; // TODO proper i18n. public static final String I18N_CHART_TITLE_DEFAULT = "W-Differenzen"; public static final String I18N_XAXIS_LABEL_DEFAULT = "km"; public static final String I18N_YAXIS_LABEL_DEFAULT = "W [m]"; public static final String I18N_2YAXIS_LABEL_DEFAULT = "W [NN + m]"; /** * Add a subtitle to Chart. * @param chart Chart to add subtitle to. */ @Override protected void addSubtitles(JFreeChart chart) { String subtitle = msg(I18N_CHART_SUBTITLE, ""); chart.addSubtitle(new TextTitle(subtitle)); } /** * Add (themed) data for chart generation. */ @Override public void doOut( Artifact artifact, Facet facet, Document attr, boolean visible ) { String name = facet.getName(); logger.debug("WDifferencesCurveGenerator.doOut: " + name); if (name == null) { logger.error("No facet name for doOut(). No output generated!"); return; } FLYSArtifact flys = (FLYSArtifact) artifact; Facet f = flys.getNativeFacet(facet); if (f == null) { return; } if (name.equals(W_DIFFERENCES)) { doWDifferencesOut( (WKms) f.getData(artifact, context), f.getDescription(), attr, visible); } else if (name.equals(LONGITUDINAL_W)) { doWOut((WQKms) f.getData(artifact, context), attr, visible); } else { logger.warn("Unknown facet name: " + name); return; } } /** * Add the waterlevel-curves (the "absolutes" from which * differences were calculated). * * @param wqkms The wqkms to add to the diagram. * @param theme The theme that contains styling information. */ @Override protected void doWOut(WQKms wqkms, Document theme, boolean visible) { logger.debug("WDifferencesCurveGenerator.doWOut"); XYSeries series = new StyledXYSeries(getSeriesName(wqkms, "W"), theme); int size = wqkms.size(); for (int i = 0; i < size; i++) { series.add(wqkms.getKm(i), wqkms.getW(i)); } // Note: the only difference in the super-implementation // (in LongitudinalSectionGenerator) is here (adds with // addFirstAxisSeries() . addSecondAxisSeries(series, visible); if (needInvertAxis(wqkms)) { setInverted(true); } } /** * Add items to dataseries which describes the differences. */ protected void doWDifferencesOut( WKms wkms, String seriesName, Document theme, boolean visible ) { logger.debug("WDifferencesCurveGenerator.doWDifferencesOut"); if (wkms == null) { logger.warn("No data to add to WDifferencesChart."); return; } int size = wkms.size(); XYSeries series = new StyledXYSeries(seriesName, theme); if (logger.isDebugEnabled()) { if (wkms.size() > 0) { logger.debug("Generate series: " + series.getKey()); logger.debug("Start km: " + wkms.getKm(0)); logger.debug("End km: " + wkms.getKm(size-1)); logger.debug("Values : " + size); } } for (int i = 0; i < size; i++) { series.add(wkms.getKm(i), wkms.getW(i)); } addFirstAxisSeries(series, visible); if (DataUtil.guessWaterIncreasing(wkms.allWs())) { setInverted(true); } } /** * Disable Longitudinals behaviour to include "0" in the Q axis. * @param range range with which to look up upper bound. * @return range to be used for "auto-scaling" axis. */ @Override protected Range createSecondAxisRange(Range range) { return new Range(range.getLowerBound(), range.getUpperBound()); } /** * */ @Override public JFreeChart generateChart() { JFreeChart chart = super.generateChart(); if (chart != null && chart.getPlot() != null) { XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeZeroBaselineVisible(true); } return chart; } /** * Get name of series (displayed in legend). * @return name of the series. */ protected String getSeriesName(WKms wqkms, String mode) { String name = wqkms.getName(); String prefix = (name != null && name.indexOf(mode) >= 0) ? null : mode; return (prefix != null && prefix.length() > 0) ? prefix + "(" + name +")" : name; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :