Mercurial > dive4elements > river
changeset 1791:e0e5a5b51a40
Added new StyledSeriesBuilder class and use it when adding points to XYSeries (in diagram generation).
flys-artifacts/trunk@3114 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 28 Oct 2011 13:39:37 +0000 |
parents | d3a0d55dff63 |
children | 49ad801076e4 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java |
diffstat | 5 files changed, 94 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Oct 28 12:41:10 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Oct 28 13:39:37 2011 +0000 @@ -1,3 +1,16 @@ +2011-10-28 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Refactored, added StyledSeriesBuilder to unify adding points to + XYSeries. + + * src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java: + New class to help with adding points to XYSeries. + + * src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java, + src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java, + src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java: + Use StyledSeriesBuilder to add points to series. + 2011-10-28 Felix Wolfsteller <felix.wolfsteller@intevation.de> Added DC-conf, such that static data can be loaded from w-difference
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Fri Oct 28 12:41:10 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Fri Oct 28 13:39:37 2011 +0000 @@ -192,12 +192,8 @@ // DO NOT SORT DATA! This destroys the gaps indicated by NaNs XYSeries series = new StyledXYSeries(seriesName, false, theme); - double [][] a = (double [][]) o; - double [] pxs = a[0]; - double [] pys = a[1]; - for (int i = 0; i < pxs.length; i++) { - series.add(pxs[i], pys[i]); - } + StyledSeriesBuilder.addPoints(series, (double [][]) o); + addFirstAxisSeries(series, visible); } @@ -218,12 +214,8 @@ XYSeries series = new StyledXYSeries(seriesName, theme); - double [][] a = (double [][]) o; - double [] xs = a[0]; - double [] ys = a[1]; - for (int i = 0; i < xs.length; i++) { - series.add (xs[i], ys[i], false); - } + StyledSeriesBuilder.addPoints(series, (double [][]) o); + addFirstAxisSeries(series, visible); } }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Fri Oct 28 12:41:10 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Fri Oct 28 13:39:37 2011 +0000 @@ -343,11 +343,7 @@ XYSeries series = new StyledXYSeries(facet.getDescription(), theme); - int size = wkms.size(); - - for (int i = 0; i < size; i++) { - series.add(wkms.getKm(i), wkms.getW(i), false); - } + StyledSeriesBuilder.addPoints(series, wkms); addFirstAxisSeries(series, visible); @@ -374,21 +370,18 @@ return; } - int size = wkms.size(); XYSeries series = new StyledXYSeries(facet.getDescription(), 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); + logger.debug("End km: " + wkms.getKm(wkms.size() - 1)); + logger.debug("Values : " + wkms.size()); } } - for (int i = 0; i < size; i++) { - series.add(wkms.getKm(i), wkms.getW(i)); - } + StyledSeriesBuilder.addPoints(series, wkms); addSecondAxisSeries(series, visible); if (DataUtil.guessWaterIncreasing(wkms.allWs())) { @@ -418,11 +411,7 @@ XYSeries series = new StyledXYSeries(facet.getDescription(), theme); - int size = wqkms.size(); - - for (int i = 0; i < size; i++) { - series.add(wqkms.getKm(i), wqkms.getQ(i), false); - } + StyledSeriesBuilder.addPoints(series, wqkms); addSecondAxisSeries(series, visible);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java Fri Oct 28 13:39:37 2011 +0000 @@ -0,0 +1,68 @@ +package de.intevation.flys.exports; + +import org.apache.log4j.Logger; + +import org.jfree.data.xy.XYSeries; + +import de.intevation.flys.artifacts.model.WKms; +import de.intevation.flys.artifacts.model.WQKms; + +/** + * Helper to create and modify StyledXYSeries. + */ +public class StyledSeriesBuilder { + + private static final Logger logger = Logger.getLogger(StyledSeriesBuilder.class); + + + /** + * Trivial, hidden constructor. + */ + private StyledSeriesBuilder() {;} + + + /** + * Add points to series. + * + * @param series Series to add points to. + * @param points Points to add to series, points[0] to 1st dim, points[1] + * to 2nd dim. + */ + public static void addPoints(XYSeries series, double[][] points) { + double [] xPoints = points[0]; + double [] yPoints = points[1]; + for (int i = 0; i < xPoints.length; i++) { + series.add(xPoints[i], yPoints[i], false); + } + } + + + /** + * Add points to series (km to 1st dim, w to 2nd dim). + * + * @param series Series to add points to. + * @param points Points to add to series. + */ + public static void addPoints(XYSeries series, WKms wkms) { + int size = wkms.size(); + + for (int i = 0; i < size; i++) { + series.add(wkms.getKm(i), wkms.getW(i), false); + } + } + + /** + * Add points to series (w to 1st dim, km to 2nd dim). + * + * @param series Series to add points to. + * @param points Points to add to series. + */ + public static void addPointsKmQ(XYSeries series, WQKms wqkms) { + int size = wqkms.size(); + + for (int i = 0; i < size; i++) { + series.add(wqkms.getKm(i), wqkms.getQ(i), false); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java Fri Oct 28 12:41:10 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java Fri Oct 28 13:39:37 2011 +0000 @@ -182,11 +182,7 @@ XYSeries series = new StyledXYSeries(facet.getDescription(), theme); - int size = wkms.size(); - - for (int i = 0; i < size; i++) { - series.add(wkms.getKm(i), wkms.getW(i)); - } + StyledSeriesBuilder.addPoints(series, wkms); // Note: the only difference in the super-implementation // (in LongitudinalSectionGenerator) is here (adds with @@ -234,21 +230,18 @@ return; } - int size = wkms.size(); XYSeries series = new StyledXYSeries(facet.getDescription(), 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); + logger.debug("End km: " + wkms.getKm(wkms.size()-1)); + logger.debug("Values : " + wkms.size()); } } - for (int i = 0; i < size; i++) { - series.add(wkms.getKm(i), wkms.getW(i)); - } + StyledSeriesBuilder.addPoints(series, wkms); addFirstAxisSeries(series, visible); if (DataUtil.guessWaterIncreasing(wkms.allWs())) {