[PATCH] Simplyfy / unify "invert axis" logic
Wald Commits
scm-commit at wald.intevation.org
Fri Sep 20 17:36:14 CEST 2013
# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1379691371 -7200
# Branch generator-refactoring
# Node ID 3c4efd4b2c1938f748135a2311da34f58cc0c36a
# Parent 02a704a3732393236ba3688eb62dca7e4177d52a
Simplyfy / unify "invert axis" logic
- DataUtil now can check if two datasets are in the same direction
- In the case of WKM data a no means that the Water flows Right to Left
- If the water flows from right to left do inversion of diagrams
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/artifacts/model/W.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/W.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/W.java Fri Sep 20 17:36:11 2013 +0200
@@ -109,7 +109,7 @@
}
public boolean guessWaterIncreasing(float factor) {
- return DataUtil.guessWaterIncreasing(ws, factor);
+ return DataUtil.guessDataIncreasing(ws, factor);
}
public int [] longestIncreasingWRangeIndices() {
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKms.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKms.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKms.java Fri Sep 20 17:36:11 2013 +0200
@@ -24,5 +24,10 @@
TDoubleArrayList allWs();
boolean guessWaterIncreasing();
+
+ /** Guess if the Water flows from right to left.
+ *
+ * @return True if km's and ws's both grow in the same direction */
+ boolean guessRTLData();
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsImpl.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsImpl.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsImpl.java Fri Sep 20 17:36:11 2013 +0200
@@ -82,11 +82,16 @@
@Override
public boolean guessWaterIncreasing() {
- return guessWaterIncreasing(0.05f);
+ return guessDataIncreasing(0.05f);
}
- protected boolean guessWaterIncreasing(float factor) {
- return DataUtil.guessWaterIncreasing(ws, factor);
+ protected boolean guessDataIncreasing(float factor) {
+ return DataUtil.guessDataIncreasing(ws, factor);
+ }
+
+ @Override
+ public boolean guessRTLData() {
+ return DataUtil.guessSameDirectionData(ws, allKms());
}
@Override
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQKms.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQKms.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQKms.java Fri Sep 20 17:36:11 2013 +0200
@@ -8,6 +8,7 @@
package org.dive4elements.river.artifacts.model;
+import org.dive4elements.river.utils.DataUtil;
import org.dive4elements.river.utils.DoubleUtil;
import gnu.trove.TDoubleArrayList;
@@ -153,5 +154,10 @@
/* Behold the first km might be larger then the last! */
return new double[] {getKm(0), getKm(size()-1)};
}
+
+ @Override
+ public boolean guessRTLData() {
+ return DataUtil.guessSameDirectionData(ws, allKms());
+ }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java Fri Sep 20 17:36:11 2013 +0200
@@ -1083,37 +1083,6 @@
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. */
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator.java Fri Sep 20 17:36:11 2013 +0200
@@ -427,36 +427,6 @@
/**
- * 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 wkms The data object that stores the x and y values used for this
- * chart.
- */
- public boolean needInvertAxis(WKms wkms) {
- boolean wsUp = wkms.guessWaterIncreasing();
- boolean kmUp = DataUtil.guessWaterIncreasing(wkms.allKms());
- boolean inv = (wsUp && kmUp) || (!wsUp && !kmUp);
-
- int size = wkms.size();
-
- 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);
- logger.debug("inv: " + inv);
- }
-
- return inv;
- }
-
-
- /**
* Get name of series (displayed in legend).
* @return name of the series.
*/
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixLongitudinalSectionGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixLongitudinalSectionGenerator.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixLongitudinalSectionGenerator.java Fri Sep 20 17:36:11 2013 +0200
@@ -147,38 +147,7 @@
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.
- *
- * @param wkms The data object that stores the x and y values used for this
- * chart.
- */
- public boolean needInvertAxis(WKms wkms) {
- boolean wsUp = wkms.guessWaterIncreasing();
- boolean kmUp = DataUtil.guessWaterIncreasing(wkms.allKms());
- boolean inv = (wsUp && kmUp) || (!wsUp && !kmUp);
-
- int size = wkms.size();
-
- 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);
- logger.debug("inv: " + inv);
- }
-
- return inv;
+ setInverted(wqkms.guessRTLData());
}
@SuppressWarnings("unchecked")
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceEpochGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceEpochGenerator.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceEpochGenerator.java Fri Sep 20 17:36:11 2013 +0200
@@ -257,7 +257,7 @@
StyledSeriesBuilder.addPoints(series, wkms);
addAxisSeries(series, YAXIS.D.idx, visible);
- if (DataUtil.guessWaterIncreasing(wkms.allWs())) {
+ if (wkms.guessWaterIncreasing()) {
setInverted(true);
}
}
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceYearGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceYearGenerator.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceYearGenerator.java Fri Sep 20 17:36:11 2013 +0200
@@ -234,7 +234,7 @@
StyledSeriesBuilder.addPoints(series, wkms);
addAxisSeries(series, YAXIS.D.idx, visible);
- if (DataUtil.guessWaterIncreasing(wkms.allWs())) {
+ if (wkms.guessWaterIncreasing()) {
setInverted(true);
}
}
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadLSGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadLSGenerator.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadLSGenerator.java Fri Sep 20 17:36:11 2013 +0200
@@ -355,7 +355,7 @@
StyledSeriesBuilder.addPoints(series, wkms);
addAxisSeries(series, YAXIS.D.idx, visible);
- if (DataUtil.guessWaterIncreasing(wkms.allWs())) {
+ if (wkms.guessWaterIncreasing()) {
setInverted(true);
}
}
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/exports/process/QOutProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/QOutProcessor.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/QOutProcessor.java Fri Sep 20 17:36:11 2013 +0200
@@ -50,7 +50,8 @@
generator.addAxisSeries(series, axisName, visible);
- generator.handleLTRWaterFlowInversion(wqkms);
+ /* Check if the diagram should be inverted*/
+ generator.setInverted(wqkms.guessRTLData());
}
@Override
@@ -70,7 +71,8 @@
generator.addAxisSeries(series, index, visible);
- invertAxis(generator, wqkms);
+ /* Check if the diagram should be inverted*/
+ generator.setInverted(wqkms.guessRTLData());
}
/**
@@ -89,36 +91,5 @@
}
return false;
}
-
- /**
- * 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 :
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/exports/process/WOutProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/WOutProcessor.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/WOutProcessor.java Fri Sep 20 17:36:11 2013 +0200
@@ -72,7 +72,7 @@
bundle.getFacetName().equals(FacetTypes.STATIC_WQKMS_W)) {
/* Only use W values to check if the diagram should be inverted
* see flys/issue1290 for details */
- generator.handleLTRWaterFlowInversion(wkms);
+ generator.setInverted(wkms.guessRTLData());
}
}
@@ -116,7 +116,7 @@
bundle.getFacetName().equals(FacetTypes.STATIC_WQKMS_W)) {
/* Only use W values to check if the diagram should be inverted
* see flys/issue1290 for details */
- invertAxis(generator, wkms);
+ generator.setInverted(wkms.guessRTLData());
}
}
@@ -140,36 +140,5 @@
}
return false;
}
-
- /**
- * 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 wkms The data object that stores the x and y values used for this
- * chart.
- */
- // TODO Remove
- 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 :
diff -r 02a704a37323 -r 3c4efd4b2c19 artifacts/src/main/java/org/dive4elements/river/utils/DataUtil.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/DataUtil.java Fri Sep 20 17:04:37 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/DataUtil.java Fri Sep 20 17:36:11 2013 +0200
@@ -14,11 +14,20 @@
public class DataUtil
{
- public static boolean guessWaterIncreasing(TDoubleArrayList data) {
- return guessWaterIncreasing(data, 0.05f);
+ public static boolean guessDataIncreasing(TDoubleArrayList data) {
+ return guessDataIncreasing(data, 0.05f);
}
- public static boolean guessWaterIncreasing(TDoubleArrayList data, float factor) {
+ /** Guess if data1 and data2 both grow in the same direction */
+ public static boolean guessSameDirectionData(TDoubleArrayList data1,
+ TDoubleArrayList data2) {
+ boolean d1dir = DataUtil.guessDataIncreasing(data1, 0.05f);
+ boolean d2dir = DataUtil.guessDataIncreasing(data2, 0.05f);
+ int size = data1.size();
+ return ((d1dir && d2dir) || (!d1dir && !d2dir)) && size > 1;
+ }
+
+ public static boolean guessDataIncreasing(TDoubleArrayList data, float factor) {
int N = data.size();
if (N < 2) return false;
More information about the Dive4elements-commits
mailing list