Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/exports/DurationCurveGenerator.java @ 9312:740d65e4aa14
Q [m³/s] one message
author | gernotbelger |
---|---|
date | Thu, 26 Jul 2018 15:54:20 +0200 |
parents | 1cc7653ca84f |
children | 9b8e8fc1f408 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DurationCurveGenerator.java Thu Jul 26 11:16:06 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/DurationCurveGenerator.java Thu Jul 26 15:54:20 2018 +0200 @@ -8,6 +8,10 @@ package org.dive4elements.river.exports; +import java.awt.Font; +import java.awt.geom.Point2D; + +import org.apache.log4j.Logger; import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.artifacts.model.FacetTypes; @@ -16,77 +20,59 @@ import org.dive4elements.river.jfree.RiverAnnotation; import org.dive4elements.river.jfree.StyledXYSeries; import org.dive4elements.river.themes.ThemeDocument; - -import java.awt.Font; -import java.awt.geom.Point2D; - -import org.apache.log4j.Logger; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.data.Range; import org.jfree.data.xy.XYSeries; - /** * An OutGenerator that generates duration curves. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ -public class DurationCurveGenerator -extends XYChartGenerator -implements FacetTypes -{ +public class DurationCurveGenerator extends XYChartGenerator implements FacetTypes { public static enum YAXIS { - W(0), - Q(1); + W(0), Q(1); public int idx; - private YAXIS(int c) { - idx = c; + + private YAXIS(final int c) { + this.idx = c; } } /** Local log. */ - private static Logger log = - Logger.getLogger(DurationCurveGenerator.class); - - public static final String I18N_CHART_TITLE = - "chart.duration.curve.title"; - - public static final String I18N_CHART_SUBTITLE = - "chart.duration.curve.subtitle"; - - public static final String I18N_XAXIS_LABEL = - "chart.duration.curve.xaxis.label"; + private static Logger log = Logger.getLogger(DurationCurveGenerator.class); - public static final String I18N_YAXIS_LABEL_W = - "chart.duration.curve.yaxis.label.w"; - - public static final String I18N_YAXIS_LABEL_Q = - "chart.duration.curve.yaxis.label.q"; + public static final String I18N_CHART_TITLE = "chart.duration.curve.title"; - public static final String I18N_CHART_TITLE_DEFAULT = - "Dauerlinie"; + public static final String I18N_CHART_SUBTITLE = "chart.duration.curve.subtitle"; - public static final String I18N_XAXIS_LABEL_DEFAULT = - "Unterschreitungsdauer [Tage]"; + public static final String I18N_XAXIS_LABEL = "chart.duration.curve.xaxis.label"; + public static final String I18N_YAXIS_LABEL_W = "chart.duration.curve.yaxis.label.w"; + + public static final String I18N_YAXIS_LABEL_Q = "common.export.csv.header.q"; + + public static final String I18N_CHART_TITLE_DEFAULT = "Dauerlinie"; + + public static final String I18N_XAXIS_LABEL_DEFAULT = "Unterschreitungsdauer [Tage]"; public DurationCurveGenerator() { 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); + protected NumberAxis createYAxis(final int index) { + final Font labelFont = new Font("Tahoma", Font.BOLD, 14); + final String label = getYAxisLabel(index); - NumberAxis axis = createNumberAxis(index, label); + final NumberAxis axis = createNumberAxis(index, label); if (index == YAXIS.W.idx) { axis.setAutoRangeIncludesZero(false); } @@ -94,54 +80,40 @@ return axis; } - @Override protected String getDefaultChartTitle(final CallContext context) { return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); } - @Override protected String getDefaultChartSubtitle(final CallContext context) { - double[] dist = getRange(); + final double[] dist = getRange(); - Object[] args = new Object[] { - getRiverName(), - dist[0] - }; + final Object[] args = new Object[] { getRiverName(), dist[0] }; return msg(I18N_CHART_SUBTITLE, "", args); } - @Override protected String getDefaultXAxisLabel(final CallContext context) { return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); } - @Override - protected String getDefaultYAxisLabel(int index) { + protected String getDefaultYAxisLabel(final int index) { String label = "default"; if (index == YAXIS.W.idx) { label = msg(I18N_YAXIS_LABEL_W, I18N_YAXIS_LABEL_W, new Object[] { getRiverUnit() }); - } - else if (index == YAXIS.Q.idx) { + } else if (index == YAXIS.Q.idx) { label = msg(I18N_YAXIS_LABEL_Q); } return label; } - @Override - protected boolean zoomX( - XYPlot plot, - ValueAxis axis, - Bounds bounds, - Range x - ) { - boolean zoomin = super.zoom(plot, axis, bounds, x); + protected boolean zoomX(final XYPlot plot, final ValueAxis axis, final Bounds bounds, final Range x) { + final boolean zoomin = super.zoom(plot, axis, bounds, x); if (!zoomin) { axis.setLowerBound(0d); @@ -152,23 +124,17 @@ return zoomin; } - /** * This method overrides the method in the parent class to set the lower * bounds of the Q axis to 0. This axis should never display negative * values on its own. */ @Override - protected boolean zoomY( - XYPlot plot, - ValueAxis axis, - Bounds bounds, - Range x - ) { - boolean zoomin = super.zoom(plot, axis, bounds, x); + protected boolean zoomY(final XYPlot plot, final ValueAxis axis, final Bounds bounds, final Range x) { + final boolean zoomin = super.zoom(plot, axis, bounds, x); if (!zoomin && axis instanceof IdentifiableNumberAxis) { - String id = ((IdentifiableNumberAxis) axis).getId(); + final String id = ((IdentifiableNumberAxis) axis).getId(); if (YAXIS.Q.toString().equals(id)) { axis.setLowerBound(0d); @@ -178,14 +144,9 @@ return zoomin; } - @Override - public void doOut( - ArtifactAndFacet artifactFacet, - ThemeDocument attr, - boolean visible - ) { - String name = artifactFacet.getFacetName(); + public void doOut(final ArtifactAndFacet artifactFacet, final ThemeDocument attr, final boolean visible) { + final String name = artifactFacet.getFacetName(); log.debug("DurationCurveGenerator.doOut: " + name); @@ -193,69 +154,41 @@ log.error("No facet given. Cannot create dataset."); return; } - + final CallContext context = getContext(); if (name.equals(DURATION_W)) { - doWOut( - (WQDay) artifactFacet.getData(context), - artifactFacet, - attr, - visible); - } - else if (name.equals(DURATION_Q)) { - doQOut( - (WQDay) artifactFacet.getData(context), - artifactFacet, - attr, - visible); - } - else if (name.equals(MAINVALUES_Q) || name.equals(MAINVALUES_W)) { - doAnnotations( - (RiverAnnotation) artifactFacet.getData(context), - artifactFacet, - attr, - visible); - } - else if (name.equals(RELATIVE_POINT)) { - doPointOut((Point2D) artifactFacet.getData(context), - artifactFacet, - attr, - visible); - } - else if (FacetTypes.IS.MANUALPOINTS(name)) { - doPoints( - artifactFacet.getData(context), - artifactFacet, - attr, visible, YAXIS.W.idx); - } - else { + doWOut((WQDay) artifactFacet.getData(context), artifactFacet, attr, visible); + } else if (name.equals(DURATION_Q)) { + doQOut((WQDay) artifactFacet.getData(context), artifactFacet, attr, visible); + } else if (name.equals(MAINVALUES_Q) || name.equals(MAINVALUES_W)) { + doAnnotations((RiverAnnotation) artifactFacet.getData(context), artifactFacet, attr, visible); + } else if (name.equals(RELATIVE_POINT)) { + doPointOut((Point2D) artifactFacet.getData(context), artifactFacet, attr, visible); + } else if (FacetTypes.IS.MANUALPOINTS(name)) { + doPoints(artifactFacet.getData(context), artifactFacet, attr, visible, YAXIS.W.idx); + } else { log.warn("Unknown facet name: " + name); return; } } - /** * Creates the series for a duration curve's W facet. * - * @param wqdays The WQDay store that contains the Ws. + * @param wqdays + * The WQDay store that contains the Ws. * @param theme */ - protected void doWOut( - WQDay wqdays, - ArtifactAndFacet aaf, - ThemeDocument theme, - boolean visible - ) { + protected void doWOut(final WQDay wqdays, final ArtifactAndFacet aaf, final ThemeDocument theme, final boolean visible) { log.debug("DurationCurveGenerator.doWOut"); - XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme); + final XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme); - int size = wqdays.size(); + final int size = wqdays.size(); for (int i = 0; i < size; i++) { - int day = wqdays.getDay(i); - double w = wqdays.getW(i); + final int day = wqdays.getDay(i); + final double w = wqdays.getW(i); series.add(day, w); } @@ -263,43 +196,32 @@ addAxisSeries(series, YAXIS.W.idx, visible); } - protected void doPointOut( - Point2D point, - ArtifactAndFacet aandf, - ThemeDocument theme, - boolean visible - ){ + protected void doPointOut(final Point2D point, final ArtifactAndFacet aandf, final ThemeDocument theme, final boolean visible) { log.debug("DurationCurveGenerator.doPointOut"); - XYSeries series = - new StyledXYSeries(aandf.getFacetDescription(), theme); + final XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); series.add(point.getX(), point.getY()); addAxisSeries(series, YAXIS.W.idx, visible); } - /** * Creates the series for a duration curve's Q facet. * - * @param wqdays The WQDay store that contains the Qs. + * @param wqdays + * The WQDay store that contains the Qs. * @param theme */ - protected void doQOut( - WQDay wqdays, - ArtifactAndFacet aaf, - ThemeDocument theme, - boolean visible - ) { + protected void doQOut(final WQDay wqdays, final ArtifactAndFacet aaf, final ThemeDocument theme, final boolean visible) { log.debug("DurationCurveGenerator.doQOut"); - XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme); + final XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme); - int size = wqdays.size(); + final int size = wqdays.size(); for (int i = 0; i < size; i++) { - int day = wqdays.getDay(i); - double q = wqdays.getQ(i); + final int day = wqdays.getDay(i); + final double q = wqdays.getQ(i); series.add(day, q); } @@ -307,7 +229,6 @@ addAxisSeries(series, YAXIS.Q.idx, visible); } - @Override protected YAxisWalker getYAxisWalker() { return new YAxisWalker() { @@ -317,8 +238,8 @@ } @Override - public String getId(int idx) { - YAXIS[] yaxes = YAXIS.values(); + public String getId(final int idx) { + final YAXIS[] yaxes = YAXIS.values(); return yaxes[idx].toString(); } };