# HG changeset patch # User Felix Wolfsteller # Date 1372322496 -7200 # Node ID 126c76184c3e2a3188cb080f69bef5341b15b471 # Parent 2e850d56ae87011841e5cc1b9e875aa426e5c0fe StyledSeriesBuilder: More convenience methods to scale and translate values while adding. diff -r 2e850d56ae87 -r 126c76184c3e artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java --- 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).