# HG changeset patch # User Andre Heinecke # Date 1379687602 -7200 # Node ID 7f600001c8079c18eb9629c84effaa4cdde0a568 # Parent 253d80af5b7f85ffdb15720b0a92acd3d400f6c4 Add LTR inversion code to diagram generator. This code is used in serveral diagrams and as it modifies a whole diagram it should be central. (This should also make maintenance easier). This function can be called by processors to make sure that their data is plotted with an LTR waterflow. diff -r 253d80af5b7f -r 7f600001c807 artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java --- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java Fri Sep 20 16:25:43 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java Fri Sep 20 16:33:22 2013 +0200 @@ -42,6 +42,7 @@ import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.artifactdatabase.state.Facet; import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.model.WKms; import org.dive4elements.river.exports.process.Processor; import org.dive4elements.river.jfree.AxisDataset; import org.dive4elements.river.jfree.AnnotationHelper; @@ -52,6 +53,7 @@ import org.dive4elements.river.jfree.StyledAreaSeriesCollection; import org.dive4elements.river.jfree.StyledXYSeries; import org.dive4elements.river.themes.ThemeDocument; +import org.dive4elements.river.utils.DataUtil; import org.w3c.dom.Element; @@ -1081,6 +1083,37 @@ return diagramAttributes.getAxisName(index); } + /** Guess if the axis should be inverted to ensure ltr diagram water flow. + * + * A processor should decide if it is appropiate to activate this + * handling in a diagram by calling this function. + * + * Merke: In Deutschland fliesst Wasser in Diagrammen immer von + * links nach rechts!!! + */ + public void handleLTRWaterFlowInversion(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("handleLTRWaterFlowInversion: (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("Not inverting because we have just one km"); + } + logger.debug("inv: " + inv); + } + setInverted(inv); + } + /** Add the acutal data to the diagram according to the processors. * For every outable facets, this function is * called and handles the data accordingly. */