Mercurial > dive4elements > river
changeset 2277:3f3e4f94171b
Added generator for "Reduzierte Bezugslinie".
flys-artifacts/trunk@3936 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 06 Feb 2012 15:42:27 +0000 |
parents | 2966787b5188 |
children | 08bb95e1fc41 |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ReferenceCurveState.java flys-artifacts/src/main/java/de/intevation/flys/exports/NormalizedReferenceCurveGenerator.java |
diffstat | 5 files changed, 267 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Feb 06 15:37:54 2012 +0000 +++ b/flys-artifacts/ChangeLog Mon Feb 06 15:42:27 2012 +0000 @@ -13,6 +13,19 @@ 2012-02-06 Sascha L. Teichmann <sascha.teichmann@intevation.de> + * doc/conf/conf.xml: Registered generator for normalized reference curves. + + * src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java: + Added "reference_curve_normalized". + + * src/main/java/de/intevation/flys/artifacts/states/ReferenceCurveState.java: + Added facets for normalized reference curves. + + * src/main/java/de/intevation/flys/exports/NormalizedReferenceCurveGenerator.java: + Generator for normalized reference curves. + +2012-02-06 Sascha L. Teichmann <sascha.teichmann@intevation.de> + * doc/conf/artifacts/winfo.xml: Added config for "reduzierte Bezugslinie". 2012-02-06 Sascha L. Teichmann <sascha.teichmann@intevation.de>
--- a/flys-artifacts/doc/conf/conf.xml Mon Feb 06 15:37:54 2012 +0000 +++ b/flys-artifacts/doc/conf/conf.xml Mon Feb 06 15:42:27 2012 +0000 @@ -182,6 +182,7 @@ <output-generator name="floodmap">de.intevation.flys.exports.MapGenerator</output-generator> <output-generator name="map">de.intevation.flys.exports.MapGenerator</output-generator> <output-generator name="reference_curve">de.intevation.flys.exports.ReferenceCurveGenerator</output-generator> + <output-generator name="reference_curve_normalized">de.intevation.flys.exports.NormalizedReferenceCurveGenerator</output-generator> <output-generator name="reference_curve_chartinfo">de.intevation.flys.exports.ReferenceCurveInfoGenerator</output-generator> <output-generator name="reference_curve_export">de.intevation.flys.exports.ReferenceCurveExporter</output-generator> <output-generator name="historical_discharge">de.intevation.flys.exports.HistoricalDischargeCurveGenerator</output-generator> @@ -194,6 +195,7 @@ <output-generator name="durationcurve_report">de.intevation.flys.exports.ReportGenerator</output-generator> <output-generator name="wsplgen_report">de.intevation.flys.exports.ReportGenerator</output-generator> <output-generator name="historical_discharge_report">de.intevation.flys.exports.ReportGenerator</output-generator> + <output-generator name="reference_curve_report">de.intevation.flys.exports.ReportGenerator</output-generator> <!-- AT exporter. --> <output-generator name="computed_dischargecurve_at_export">de.intevation.flys.exports.ATExporter</output-generator> </output-generators>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java Mon Feb 06 15:37:54 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java Mon Feb 06 15:42:27 2012 +0000 @@ -124,5 +124,6 @@ String HISTORICAL_DISCHARGE_Q = "historical_discharge.historicalq"; String REFERENCE_CURVE = "reference_curve"; + String REFERENCE_CURVE_NORMALIZED = "reference_curve_normalized"; } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ReferenceCurveState.java Mon Feb 06 15:37:54 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ReferenceCurveState.java Mon Feb 06 15:42:27 2012 +0000 @@ -60,6 +60,11 @@ facets.add(new ReferenceCurveFacet(i, REFERENCE_CURVE, Resources.getMsg(context.getMeta(), REFERENCE_CURVE, REFERENCE_CURVE))); + facets.add(new ReferenceCurveFacet(i, + REFERENCE_CURVE_NORMALIZED, + Resources.getMsg( + context.getMeta(), + REFERENCE_CURVE_NORMALIZED, REFERENCE_CURVE_NORMALIZED))); } if (wws.length > 0) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/NormalizedReferenceCurveGenerator.java Mon Feb 06 15:42:27 2012 +0000 @@ -0,0 +1,246 @@ +package de.intevation.flys.exports; + +import org.w3c.dom.Document; + +import java.awt.Font; + +import org.apache.log4j.Logger; + +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.title.TextTitle; + +import org.jfree.data.xy.XYSeries; + +import de.intevation.artifactdatabase.state.ArtifactAndFacet; + +import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.WW; +import de.intevation.flys.artifacts.model.WW.ApplyFunctionIterator; +import de.intevation.flys.artifacts.model.WWAxisTypes; + +import de.intevation.flys.jfree.StyledXYSeries; + + +/** + * An OutGenerator that generates reference curves. + */ +public class NormalizedReferenceCurveGenerator +extends XYChartGenerator +implements FacetTypes +{ + public static enum YAXIS { + W_M(0), + W_CM(1); + + public int idx; + private YAXIS(int c) { + idx = c; + } + } + + /** House logger. */ + private static Logger logger = + Logger.getLogger(NormalizedReferenceCurveGenerator.class); + + public static final String I18N_CHART_TITLE = + "chart.reference.curve.title"; + + public static final String I18N_CHART_SUBTITLE = + "chart.reference.curve.subtitle"; + + public static final String W_CM_DEFAULT = + "chart.reference.curve.wcm"; + + public static final String W_NNM_DEFAULT = + "chart.reference.curve.wnn"; + + public static final String START_GAUGE = + "chart.reference.curve.start_at_gauge"; + + public static final String START_FREE = + "chart.reference.curve.start_free"; + + /* + + public static final String I18N_XAXIS_LABEL = + "chart.reference.curve.xaxis.label"; + + public static final String I18N_YAXIS_LABEL = + "chart.reference.curve.yaxis.label"; +*/ +/* + public static final String I18N_XAXIS_LABEL_DEFAULT = + "W [NN + m]"; + + public static final String I18N_YAXIS_LABEL_DEFAULT = + "W [NN + m]"; + */ + + + public static final String I18N_CHART_TITLE_DEFAULT = + "Bezugslinie"; + + + public NormalizedReferenceCurveGenerator() { + super(); + } + + + /** + * Create Axis for given index. + * @return axis with according internationalized label. + */ + @Override + protected NumberAxis createYAxis(int index) { + Font labelFont = new Font("Tahoma", Font.BOLD, 14); + String label = getYAxisLabel(index); + + NumberAxis axis = createNumberAxis(index, label); + // TODO aspect-ratio settings. + if (index == YAXIS.W_M.idx) { + axis.setAutoRangeIncludesZero(false); + } + axis.setLabelFont(labelFont); + return axis; + } + + + /** Get default chart title. */ + @Override + protected String getDefaultChartTitle() { + return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); + } + + @Override + protected String getDefaultChartSubtitle() { + Object[] args = new Object[] { + getRiverName(), + }; + + return msg(I18N_CHART_SUBTITLE, "", args); + } + + + @Override + protected void addSubtitles(JFreeChart chart) { + String subtitle = getChartSubtitle(); + + if (subtitle != null && subtitle.length() > 0) { + chart.addSubtitle(new TextTitle(subtitle)); + } + } + + + /** Get Label for X-axis (W). */ + @Override + protected String getDefaultXAxisLabel() { + // TODO i18nreturn msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); + // at_gauge + w_cm + return "W am Bezugsort- oder Pegel."; + } + + + /** + * Get Label for primary and other Y Axes. + * @param index Axis-Index (0-based). + */ + @Override + protected String getDefaultYAxisLabel(int index) { + String label = "default"; + if (index == YAXIS.W_M.idx) { + //label = msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); + //TODO i18n + return "W am Zielort"; + } + else if (index == YAXIS.W_CM.idx) { + return "W am Zielpegel"; + } + + return label; + } + + + /** + * Called for each facet/them in the out mapped to this generator. + * @param artifactFacet artifact and facet for this theme. + * @param theme styling info. + * @param visible Whether or not the theme is visible. + */ + @Override + public void doOut( + ArtifactAndFacet artifactFacet, + Document theme, + boolean visible + ) { + String name = artifactFacet.getFacetName(); + + logger.debug("NormalizedReferenceCurveGenerator.doOut: " + name); + + if (name == null || name.length() == 0) { + logger.error("No facet given. Cannot create dataset."); + return; + } + + if (name.equals(REFERENCE_CURVE_NORMALIZED)) { + doReferenceOut(artifactFacet.getData(context), theme, visible); + } + else { + logger.warn("Unknown facet name: " + name); + return; + } + } + + + /** Register DataSeries with (maybe transformed) points. */ + public void doReferenceOut( + Object data, + Document theme, + boolean visible + ) { + WW ww = (WW)data; + + // TODO: Fetch from black board instead! + WWAxisTypes wwat = new WWAxisTypes(ww); + + ApplyFunctionIterator iter = wwat.transform(ww); + + XYSeries series = new StyledXYSeries( + ww.getName(), false, theme); + + double [] values = new double[2]; + + while (iter.hasNext()) { + iter.next(values); + series.add(values[0], values[1], false); + } + + if (ww.endAtGauge()) { + addAxisSeries(series, YAXIS.W_M.idx, visible); + } + else { + addAxisSeries(series, YAXIS.W_CM.idx, visible); + } + } + + + /** Get Walker to iterate over all axes. */ + @Override + protected YAxisWalker getYAxisWalker() { + return new YAxisWalker() { + /** Get number of items. */ + @Override + public int length() { + return YAXIS.values().length; + } + + /** Get identifier for this index. */ + @Override + public String getId(int idx) { + YAXIS[] yaxes = YAXIS.values(); + return yaxes[idx].toString(); + } + }; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :