felix@1151: package de.intevation.flys.exports; felix@1151: felix@1151: import org.apache.log4j.Logger; felix@1151: felix@1151: import org.jfree.chart.JFreeChart; felix@1170: import org.jfree.chart.plot.XYPlot; felix@1151: import org.jfree.chart.title.TextTitle; felix@1151: import org.jfree.data.xy.XYSeries; felix@1653: import org.jfree.data.Range; felix@1151: felix@1151: import org.w3c.dom.Document; felix@1151: felix@1151: import de.intevation.artifacts.Artifact; felix@1151: felix@1151: import de.intevation.artifactdatabase.state.Facet; felix@1151: felix@1151: import de.intevation.flys.artifacts.FLYSArtifact; felix@1151: import de.intevation.flys.artifacts.model.FacetTypes; felix@1151: import de.intevation.flys.artifacts.model.WKms; felix@1151: felix@1162: import de.intevation.flys.utils.DataUtil; felix@1627: felix@1627: import de.intevation.flys.artifacts.model.WQKms; felix@1700: import de.intevation.flys.utils.FLYSUtils; felix@1162: felix@1151: felix@1151: /** felix@1151: * An OutGenerator that generates w differences curves. felix@1151: */ felix@1151: public class WDifferencesCurveGenerator felix@1151: extends LongitudinalSectionGenerator felix@1151: implements FacetTypes felix@1151: { felix@1151: /** The logger that is used in this generator. */ felix@1151: private static Logger logger = felix@1151: Logger.getLogger(WDifferencesCurveGenerator.class); felix@1151: felix@1701: /** Key for internationalized title of WDiff charts. */ felix@1701: public final static String I18N_WDIFF_TITLE = "chart.w_differences.title"; felix@1701: felix@1701: /** Default for internationalized title (when no translation found). */ felix@1701: public final static String I18N_WDIFF_TITLE_DEFAULT = "Differences"; felix@1701: felix@1701: /** Key for internationalized title of WDiff charts. */ felix@1701: public final static String I18N_WDIFF_2YAXIS_LABEL = felix@1701: "chart.w_differences.yaxis.second.label"; felix@1701: felix@1701: /** Default for label for second Y-Axis when no translation found. */ felix@1701: public final static String I18N_WDIFF_2YAXIS_LABEL_DEFAULT = "W [NN + m]"; felix@1701: felix@1701: public final static String I18N_WDIFF_SUBTITLE = felix@1701: "chart.w_differences.subtitle"; felix@1701: felix@1701: public final static String I18N_WDIFF_YAXIS_LABEL = felix@1701: "chart.w_differences.yaxis.label"; felix@1701: felix@1701: public final static String I18N_WDIFF_YAXIS_LABEL_DEFAULT = "m"; felix@1701: felix@1151: felix@1700: /** felix@1700: * Get internationalized title for chart. felix@1700: */ felix@1700: public String getChartTitle() { felix@1701: return msg(I18N_WDIFF_TITLE, I18N_WDIFF_TITLE_DEFAULT); felix@1700: } felix@1151: felix@1151: felix@1151: /** felix@1700: * Get default value for the second Y-Axis' label (if no translation was felix@1700: * found). felix@1151: */ felix@1151: @Override felix@1700: protected String get2YAxisDefaultLabel() { felix@1701: return I18N_WDIFF_2YAXIS_LABEL_DEFAULT; felix@1700: } felix@1700: felix@1700: felix@1700: /** felix@1700: * Gets key to look up internationalized String for the charts subtitle. felix@1700: * @return key to look up translated subtitle. felix@1700: */ felix@1700: @Override felix@1700: protected String getChartSubtitleKey() { felix@1701: return I18N_WDIFF_SUBTITLE; felix@1700: } felix@1700: felix@1700: felix@1700: /** felix@1700: * Get key for internationalization of the second Y-Axis' label. felix@1700: */ felix@1700: @Override felix@1700: protected String get2YAxisLabelKey() { felix@1701: return I18N_WDIFF_2YAXIS_LABEL; felix@1700: } felix@1700: felix@1700: felix@1700: /** felix@1700: * Get internationalized label for the y axis. felix@1700: */ felix@1700: @Override felix@1700: protected String getYAxisLabel() { felix@1700: FLYSArtifact flys = (FLYSArtifact) master; felix@1700: felix@1700: String unit = FLYSUtils.getRiver(flys).getWstUnit().getName(); felix@1700: felix@1700: return msg( felix@1701: I18N_WDIFF_YAXIS_LABEL, felix@1701: I18N_WDIFF_YAXIS_LABEL_DEFAULT, felix@1700: new Object[] { unit }); felix@1151: } felix@1151: felix@1151: felix@1151: /** felix@1151: * Add (themed) data for chart generation. felix@1151: */ ingo@1684: @Override ingo@1684: public void doOut( ingo@1684: Artifact artifact, ingo@1684: Facet facet, ingo@1684: Document attr, ingo@1684: boolean visible ingo@1684: ) { felix@1151: String name = facet.getName(); felix@1151: felix@1151: logger.debug("WDifferencesCurveGenerator.doOut: " + name); felix@1151: felix@1151: if (name == null) { felix@1151: logger.error("No facet name for doOut(). No output generated!"); felix@1151: return; felix@1151: } felix@1151: felix@1151: FLYSArtifact flys = (FLYSArtifact) artifact; felix@1151: Facet f = flys.getNativeFacet(facet); felix@1151: felix@1151: if (f == null) { felix@1151: return; felix@1151: } felix@1151: felix@1151: if (name.equals(W_DIFFERENCES)) { ingo@1684: doWDifferencesOut( ingo@1684: (WKms) f.getData(artifact, context), ingo@1684: f.getDescription(), ingo@1684: attr, ingo@1684: visible); felix@1151: } felix@1627: else if (name.equals(LONGITUDINAL_W)) { felix@1695: doWOut((WQKms) f.getData(artifact, context), attr, visible); felix@1627: } felix@1695: else { felix@1151: logger.warn("Unknown facet name: " + name); felix@1151: return; felix@1151: } felix@1151: } felix@1151: felix@1170: felix@1640: /** felix@1640: * Add the waterlevel-curves (the "absolutes" from which felix@1640: * differences were calculated). felix@1695: * felix@1640: * @param wqkms The wqkms to add to the diagram. felix@1695: * @param theme The theme that contains styling information. felix@1640: */ felix@1695: @Override felix@1695: protected void doWOut(WQKms wqkms, Document theme, boolean visible) { felix@1695: logger.debug("WDifferencesCurveGenerator.doWOut"); felix@1627: felix@1695: XYSeries series = new StyledXYSeries(getSeriesName(wqkms, "W"), theme); felix@1627: felix@1695: int size = wqkms.size(); felix@1695: felix@1695: for (int i = 0; i < size; i++) { felix@1695: series.add(wqkms.getKm(i), wqkms.getW(i)); felix@1627: } felix@1627: felix@1695: // Note: the only difference in the super-implementation felix@1695: // (in LongitudinalSectionGenerator) is here (adds with felix@1695: // addFirstAxisSeries() . felix@1695: addSecondAxisSeries(series, visible); felix@1627: felix@1695: if (needInvertAxis(wqkms)) { felix@1695: setInverted(true); felix@1695: } felix@1695: } felix@1640: felix@1627: felix@1151: /** felix@1151: * Add items to dataseries which describes the differences. felix@1151: */ ingo@1684: protected void doWDifferencesOut( ingo@1684: WKms wkms, ingo@1684: String seriesName, ingo@1684: Document theme, ingo@1684: boolean visible ingo@1684: ) { felix@1151: logger.debug("WDifferencesCurveGenerator.doWDifferencesOut"); felix@1151: if (wkms == null) { felix@1151: logger.warn("No data to add to WDifferencesChart."); felix@1151: return; felix@1162: } felix@1162: felix@1162: int size = wkms.size(); felix@1162: XYSeries series = new StyledXYSeries(seriesName, theme); felix@1162: felix@1162: if (logger.isDebugEnabled()) { felix@1162: if (wkms.size() > 0) { felix@1162: logger.debug("Generate series: " + series.getKey()); felix@1162: logger.debug("Start km: " + wkms.getKm(0)); felix@1162: logger.debug("End km: " + wkms.getKm(size-1)); felix@1162: logger.debug("Values : " + size); felix@1162: } felix@1151: } felix@1151: felix@1162: for (int i = 0; i < size; i++) { felix@1162: series.add(wkms.getKm(i), wkms.getW(i)); felix@1162: } felix@1151: ingo@1684: addFirstAxisSeries(series, visible); sascha@1678: if (DataUtil.guessWaterIncreasing(wkms.allWs())) { felix@1162: setInverted(true); felix@1162: } felix@1151: } felix@1151: felix@1653: /** felix@1653: * Disable Longitudinals behaviour to include "0" in the Q axis. felix@1653: * @param range range with which to look up upper bound. felix@1653: * @return range to be used for "auto-scaling" axis. felix@1653: */ felix@1653: @Override felix@1653: protected Range createSecondAxisRange(Range range) { felix@1653: return new Range(range.getLowerBound(), range.getUpperBound()); felix@1653: } felix@1151: felix@1653: felix@1151: /** felix@1170: * felix@1170: */ felix@1170: @Override felix@1170: public JFreeChart generateChart() { felix@1170: JFreeChart chart = super.generateChart(); felix@1170: if (chart != null && chart.getPlot() != null) { felix@1170: XYPlot plot = (XYPlot) chart.getPlot(); felix@1170: plot.setRangeZeroBaselineVisible(true); felix@1170: } felix@1170: return chart; felix@1170: } felix@1170: felix@1170: /** felix@1151: * Get name of series (displayed in legend). felix@1151: * @return name of the series. felix@1151: */ felix@1151: protected String getSeriesName(WKms wqkms, String mode) { felix@1151: String name = wqkms.getName(); felix@1151: String prefix = (name != null && name.indexOf(mode) >= 0) felix@1151: ? null felix@1151: : mode; felix@1151: felix@1151: return (prefix != null && prefix.length() > 0) felix@1151: ? prefix + "(" + name +")" felix@1151: : name; felix@1151: } felix@1151: } felix@1151: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :