changeset 6465:126c76184c3e

StyledSeriesBuilder: More convenience methods to scale and translate values while adding.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 27 Jun 2013 10:41:36 +0200
parents 2e850d56ae87
children cf514239d290
files artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java
diffstat 1 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java	Thu Jun 27 10:40:50 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java	Thu Jun 27 10:41:36 2013 +0200
@@ -78,6 +78,37 @@
      * @param points Points to add to series, points[0] to 1st dim, points[1]
      *               to 2nd dim.
      * @param skipNANs if true, skip NAN values in points parameter.
+     * @param transY translate y-values by this value (before scale).
+     * @param factorY scale y-values by this value (after translation).
+     */
+    public static void addPoints(XYSeries series, double[][] points,
+        boolean skipNANs, double transY, double factorY) {
+        if (transY == 0d && factorY == 1d) {
+            addPoints(series, points, skipNANs);
+            return;
+        }
+        if (points == null || points.length <= 1) {
+            return;
+        }
+        double [] xPoints = points[0];
+        double [] yPoints = points[1];
+        for (int i = 0; i < xPoints.length; i++) {
+            if (skipNANs &&
+                (Double.isNaN(xPoints[i]) || Double.isNaN(yPoints[i]))) {
+                logger.warn ("Skipping NaN in StyledSeriesBuilder.");
+                continue;
+            }
+            series.add(xPoints[i], factorY * (transY+yPoints[i]), false);
+        }
+    }
+
+    /**
+     * 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.
+     * @param skipNANs if true, skip NAN values in points parameter.
      */
     public static void addPoints(XYSeries series, double[][] points, boolean skipNANs) {
         if (points == null || points.length <= 1) {
@@ -254,6 +285,28 @@
         }
     }
 
+    /**
+     * Add points to series (q to 1st dim, w to 2nd dim), with
+     * scaling and translation.
+     *
+     * @param series Series to add points to.
+     * @param qs the Qs to add, assumed same length than ws.
+     * @param ws the Ws to add, assumed same length than qs.
+     */
+    public static void addPointsQW(XYSeries series, double[] qs, double ws[],
+        double wTrans, double wScale) {
+        if (ws == null || qs == null) {
+            return;
+        }
+
+        int size = qs.length;
+
+        for (int i = 0; i < size; i++) {
+            series.add(qs[i], wScale * (ws[i]+wTrans), false);
+        }
+    }
+
+
 
     /**
      * Add points to series (q to 1st dim, w to 2nd dim).

http://dive4elements.wald.intevation.org