Mercurial > dive4elements > river
changeset 1933:9e9cfc036a3f
Better use multiple axis feature in chart generators.
flys-artifacts/trunk@3314 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 24 Nov 2011 11:03:33 +0000 |
parents | 17e18948fe5e |
children | e4a516ca2e86 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java |
diffstat | 6 files changed, 101 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Nov 24 10:59:40 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Nov 24 11:03:33 2011 +0000 @@ -1,3 +1,15 @@ +2011-11-24 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Use multiple axis in relevant generators. + + * src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java, + src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java, + src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java, + src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java, + src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java: + (createYAxis): Implemented. + Define and use YAXIS enum for axes. + 2011-11-24 Felix Wolfsteller <felix.wolfsteller@intevation.de> Fix theming and legend items for plot with multiaxis feature.
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Thu Nov 24 10:59:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Thu Nov 24 11:03:33 2011 +0000 @@ -5,11 +5,14 @@ import org.apache.log4j.Logger; +import java.awt.Font; + import org.w3c.dom.Document; import org.jfree.chart.annotations.XYTextAnnotation; import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.title.TextTitle; import org.jfree.data.xy.XYSeries; @@ -144,7 +147,7 @@ XYSeries series = new StyledXYSeries(facet.getDescription(), theme); StyledSeriesBuilder.addPoints(series, data); - addAxisSeries(series, 0, visible); + addAxisSeries(series, YAXIS.W.idx, visible); } /** @@ -161,7 +164,7 @@ XYSeries series = new StyledXYSeries(facet.getDescription(), theme); StyledSeriesBuilder.addPointsQW(series, wqkms); - addAxisSeries(series, 0, visible); + addAxisSeries(series, YAXIS.W.idx, visible); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java Thu Nov 24 10:59:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java Thu Nov 24 11:03:33 2011 +0000 @@ -2,9 +2,12 @@ import org.apache.log4j.Logger; +import java.awt.Font; + import org.w3c.dom.Document; import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.data.Range; @@ -35,6 +38,14 @@ extends XYChartGenerator implements FacetTypes { + public static enum YAXIS { + W(0); + protected int idx; + private YAXIS(int c) { + idx = c; + } + } + /** The logger used in this generator. */ private static Logger logger = Logger.getLogger(DischargeCurveGenerator.class); @@ -56,7 +67,6 @@ public static final String I18N_YAXIS_LABEL_DEFAULT = "W [cm]"; - public DischargeCurveGenerator() { super(); } @@ -75,11 +85,16 @@ } + /** + * i18n-Label for X-Axis. + */ protected String getXAxisLabel() { return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); } - + /** + * i18n-Label for X-Axis (W). + */ protected String getYAxisLabel() { return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); } @@ -96,6 +111,23 @@ return zoomin; } + /** + * Create Y-Axis. + * First Axis: W. + * @return Y-Axis with label. + */ + @Override + protected NumberAxis createYAxis(int index) { + Font labelFont = new Font("Tahoma", Font.BOLD, 14); + String label = "default"; + if (index == YAXIS.W.idx) { + label = getYAxisLabel(); + } + NumberAxis axis = new NumberAxis(label); + axis.setLabelFont(labelFont); + return axis; + } + public void doOut( Artifact artifact, @@ -171,7 +203,7 @@ StyledSeriesBuilder.addPointsQW(series, wqkms); - addAxisSeries(series, 0, visible); + addAxisSeries(series, YAXIS.W.idx, visible); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java Thu Nov 24 10:59:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java Thu Nov 24 11:03:33 2011 +0000 @@ -108,7 +108,7 @@ series.add(wqckms.getKm(i), wqckms.getC(i)); } - addAxisSeries(series, 0, visible); + addAxisSeries(series, YAXIS.W.idx, visible); } if (wqckms.guessWaterIncreasing()) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java Thu Nov 24 10:59:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java Thu Nov 24 11:03:33 2011 +0000 @@ -1,5 +1,7 @@ package de.intevation.flys.exports; +import java.awt.Font; + import org.w3c.dom.Document; import org.apache.log4j.Logger; @@ -33,10 +35,18 @@ extends XYChartGenerator implements FacetTypes { + public static enum YAXIS { + W(0), + Q(1); + protected int idx; + private YAXIS(int c) { + idx = c; + } + } + private static Logger logger = Logger.getLogger(DurationCurveGenerator.class); - public static final String I18N_DURATION_W = "chart.duration.curve.curve.w"; @@ -70,6 +80,27 @@ } + /** + * 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 = "default"; + if (index == YAXIS.W.idx) { + label = getYAxisLabel(); + } + else if (index == YAXIS.Q.idx) { + // TODO i18n for this label + label = "Q [m\u00b3/s]"; + //label = msg(get2YAxisLabelKey(), get2YAxisDefaultLabel()); + } + NumberAxis axis = new NumberAxis(label); + axis.setLabelFont(labelFont); + return axis; + } + protected String getChartTitle() { return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); } @@ -113,15 +144,6 @@ } - protected void adjustAxes(XYPlot plot) { - super.adjustAxes(plot); - - NumberAxis qAxis = new NumberAxis("Q [m\u00b3/s]"); - - plot.setRangeAxis(1, qAxis); - } - - @Override public void doOut( Artifact artifact, @@ -184,7 +206,7 @@ series.add((double) day, w); } - addAxisSeries(series, 0, visible); + addAxisSeries(series, YAXIS.W.idx, visible); } @@ -209,7 +231,7 @@ series.add((double) day, q); } - addAxisSeries(series, 1, visible); + addAxisSeries(series, YAXIS.Q.idx, visible); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java Thu Nov 24 10:59:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java Thu Nov 24 11:03:33 2011 +0000 @@ -2,6 +2,8 @@ import org.apache.log4j.Logger; +import java.awt.Font; + import org.jfree.chart.title.TextTitle; import org.jfree.chart.JFreeChart; @@ -34,6 +36,16 @@ extends LongitudinalSectionGenerator implements FacetTypes { + public static enum YAXIS { + D(0), + W(1), + Q(2); + protected int idx; + private YAXIS(int c) { + idx = c; + } + } + /** The logger that is used in this generator. */ private static Logger logger = Logger.getLogger(WDifferencesCurveGenerator.class); @@ -190,7 +202,7 @@ // Note: the only difference in the super-implementation // (in LongitudinalSectionGenerator) is here (adds with // addFirstAxisSeries() . - addAxisSeries(series, 3, visible); + addAxisSeries(series, YAXIS.W.idx, visible); if (wkms instanceof WQKms) { if (needInvertAxis((WQKms) wkms)) { @@ -246,7 +258,7 @@ StyledSeriesBuilder.addPoints(series, wkms); - addAxisSeries(series, 0, visible); + addAxisSeries(series, YAXIS.D.idx, visible); if (DataUtil.guessWaterIncreasing(wkms.allWs())) { setInverted(true); }