Mercurial > dive4elements > river
changeset 6927:0288db5e90d5
issue1455: Extract QOutProcessor, use it
in MiddleBedHeightGenerator and LongitudinalSectionGenerator.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 27 Aug 2013 12:46:11 +0200 |
parents | bf191baa37e7 |
children | 2119f13f95ab |
files | artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator.java artifacts/src/main/java/org/dive4elements/river/exports/MiddleBedHeightGenerator.java artifacts/src/main/java/org/dive4elements/river/exports/process/QOutProcessor.java |
diffstat | 3 files changed, 144 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator.java Tue Aug 27 11:35:37 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator.java Tue Aug 27 12:46:11 2013 +0200 @@ -21,6 +21,7 @@ import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor; import org.dive4elements.river.exports.process.BedDiffYearProcessor; import org.dive4elements.river.exports.process.BedheightProcessor; +import org.dive4elements.river.exports.process.QOutProcessor; import org.dive4elements.river.exports.process.WOutProcessor; import org.dive4elements.river.jfree.RiverAnnotation; @@ -340,6 +341,7 @@ } WOutProcessor wProcessor = new WOutProcessor(); + QOutProcessor qProcessor = new QOutProcessor(); Processor bedp = new BedheightProcessor(); Processor bdyProcessor = new BedDiffYearProcessor(); Processor bdhyProcessor = new BedDiffHeightYearProcessor(); @@ -347,6 +349,9 @@ if (wProcessor.canHandle(name)) { wProcessor.doOut(this, artifactAndFacet, attr, visible, YAXIS.W.idx); } + if (qProcessor.canHandle(name)) { + qProcessor.doOut(this, artifactAndFacet, attr, visible, YAXIS.Q.idx); + } else if (bedp.canHandle(name)) { bedp.doOut(this, artifactAndFacet, attr, visible, YAXIS.W.idx); } @@ -356,13 +361,6 @@ else if (bdhyProcessor.canHandle(name)) { bdhyProcessor.doOut(this, artifactAndFacet, attr, visible, YAXIS.W.idx); } - else if (name.equals(LONGITUDINAL_Q)) { - doQOut( - (WQKms) artifactAndFacet.getData(context), - artifactAndFacet, - attr, - visible); - } else if (name.equals(LONGITUDINAL_ANNOTATION)) { doAnnotations( (RiverAnnotation) artifactAndFacet.getData(context), @@ -370,13 +368,6 @@ attr, visible); } - else if (name.equals(STATIC_WQKMS_Q)) { - doQOut( - (WQKms) artifactAndFacet.getData(context), - artifactAndFacet, - attr, - visible); - } else if (name.equals(W_DIFFERENCES)) { doWDifferencesOut( (WKms) artifactAndFacet.getData(context), @@ -441,35 +432,6 @@ /** - * Process the output for Q facets in a longitudinal section curve. - * - * @param wqkms An array of WQKms values. - * @param aandf The facet and artifact. This facet does NOT support any data objects. Use - * D4EArtifact.getNativeFacet() instead to retrieve a Facet which supports - * data. - * @param theme The theme that contains styling information. - * @param visible The visibility of the curve. - */ - protected void doQOut( - WQKms wqkms, - ArtifactAndFacet aandf, - ThemeDocument theme, - boolean visible - ) { - logger.debug("LongitudinalSectionGenerator.doQOut"); - - XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); - - StyledSeriesBuilder.addStepPointsKmQ(series, wqkms); - - addAxisSeries(series, YAXIS.Q.idx, visible); - - if (needInvertAxis(wqkms)) { - setInverted(true); - } - } - - /** * This method determines - taking JFreeCharts auto x value ordering into * account - if the x axis need to be inverted. Waterlines in these charts * should decrease.
--- a/artifacts/src/main/java/org/dive4elements/river/exports/MiddleBedHeightGenerator.java Tue Aug 27 11:35:37 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/MiddleBedHeightGenerator.java Tue Aug 27 12:46:11 2013 +0200 @@ -18,6 +18,7 @@ import org.dive4elements.river.exports.process.BedheightProcessor; import org.dive4elements.river.exports.process.Processor; +import org.dive4elements.river.exports.process.QOutProcessor; import org.dive4elements.river.exports.process.WOutProcessor; import org.dive4elements.river.jfree.RiverAnnotation; import org.dive4elements.river.jfree.StyledXYSeries; @@ -145,7 +146,7 @@ else if (index == YAXIS.P.idx) { label = msg(I18N_P_YAXIS_LABEL, I18N_P_YAXIS_LABEL_DEFAULT); } - else if (index = YAXIS.Q.idx) { + else if (index == YAXIS.Q.idx) { label = msg(I18N_Q_YAXIS_LABEL, I18N_Q_YAXIS_LABEL_DEFAULT); } @@ -195,11 +196,14 @@ Processor woutp = new WOutProcessor(); Processor bedp = new BedheightProcessor(); - WOutProcessor processor = new WOutProcessor(); - if (processor.canHandle(name)) { - processor.doOut(this, artifactAndFacet, attr, visible, YAXIS.W.idx); + Processor qoutp = new QOutProcessor(); + if (woutp.canHandle(name)) { + woutp.doOut(this, artifactAndFacet, attr, visible, YAXIS.W.idx); } - if (name.equals(MIDDLE_BED_HEIGHT_SINGLE) || name.equals(MIDDLE_BED_HEIGHT_EPOCH)) { + else if (qoutp.canHandle(name)) { + qoutp.doOut(this, artifactAndFacet, attr, visible, YAXIS.Q.idx); + } + else if (name.equals(MIDDLE_BED_HEIGHT_SINGLE) || name.equals(MIDDLE_BED_HEIGHT_EPOCH)) { doHeightOut( (MiddleBedHeightData) artifactAndFacet.getData(context), artifactAndFacet,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/QOutProcessor.java Tue Aug 27 12:46:11 2013 +0200 @@ -0,0 +1,130 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.exports.process; + +import org.apache.log4j.Logger; +import org.jfree.data.xy.XYSeries; + +import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; +import org.dive4elements.artifacts.CallContext; +import org.dive4elements.river.artifacts.model.FacetTypes; +import org.dive4elements.river.artifacts.model.WKms; +import org.dive4elements.river.artifacts.model.WQKms; + +import org.dive4elements.river.exports.StyledSeriesBuilder; +import org.dive4elements.river.exports.XYChartGenerator; +import org.dive4elements.river.jfree.StyledXYSeries; +import org.dive4elements.river.themes.ThemeDocument; +import org.dive4elements.river.utils.DataUtil; + +/** + * Add data to chart/generator. + * + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class QOutProcessor implements Processor { + + /** Private logger. */ + private static final Logger logger = + Logger.getLogger(QOutProcessor.class); + + @Override + public void doOut( + XYChartGenerator generator, + ArtifactAndFacet aaf, + ThemeDocument theme, + boolean visible, + int index) + { + CallContext context = generator.getCallContext(); + WQKms wqkms = (WQKms) aaf.getData(context); + + doQOut(generator, wqkms, aaf, theme, visible, index); + } + + /** + * Returns true if facettype is q-type. + */ + @Override + public boolean canHandle(String facetType) { + if (facetType == null) { + return false; + } + + if (facetType.equals(FacetTypes.STATIC_WQKMS_Q) + || facetType.equals(FacetTypes.LONGITUDINAL_Q)) { + return true; + } + return false; + } + + + /** + * Process the output for Q facets in a longitudinal section curve. + * + * @param generator Generator to use. + * @param wqkms An array of WQKms values. + * @param aandf The facet and artifact. This facet does NOT support any data objects. Use + * D4EArtifact.getNativeFacet() instead to retrieve a Facet which supports + * data. + * @param theme The theme that contains styling information. + * @param visible The visibility of the curve. + * @param index Axis index to add data to. + */ + protected void doQOut( + XYChartGenerator generator, + WQKms wqkms, + ArtifactAndFacet aaf, + ThemeDocument theme, + boolean visible, + int index + ) { + logger.debug("QProcessor.doOut"); + + XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme); + + StyledSeriesBuilder.addStepPointsKmQ(series, wqkms); + + generator.addAxisSeries(series, index, visible); + + invertAxis(generator, wqkms); + } + + /** + * This method determines - taking JFreeCharts auto x value ordering into + * account - if the x axis need to be inverted. Waterlines in these charts + * should decrease. + * + * @param generator the generator to invert the axis or not. + * @param wkms The data object that stores the x and y values used for this + * chart. + */ + public void invertAxis(XYChartGenerator generator, WKms wkms) { + boolean wsUp = wkms.guessWaterIncreasing(); + boolean kmUp = DataUtil.guessWaterIncreasing(wkms.allKms()); + int size = wkms.size(); + boolean inv = ((wsUp && kmUp) || (!wsUp && !kmUp)) && size > 1; + + if (logger.isDebugEnabled()) { + logger.debug("(Wkms)Values : " + size); + if (size > 0) { + logger.debug("Start km: " + wkms.getKm(0)); + logger.debug("End km: " + wkms.getKm(size-1)); + } + logger.debug("wsUp: " + wsUp); + logger.debug("kmUp: " + kmUp); + if (size == 1) { + logger.debug("InvertAxis not inverting because we have just one km"); + } + logger.debug("inv: " + inv); + } + generator.setInverted(inv); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :