Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/exports/process/QOutProcessor.java @ 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 | |
children | 35ecfd1a861a |
line wrap: on
line diff
--- /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 :