# HG changeset patch # User Sascha L. Teichmann # Date 1326386940 0 # Node ID b5cc53a84b662191d488f38f0ddcbe49fe1fecf1 # Parent 51b9899f819d251816313f8999c820e77b96aa4b StableXYDifferenceRenderer: Added code to calculate the area of the generated polygons. flys-artifacts/trunk@3667 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 51b9899f819d -r b5cc53a84b66 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Jan 12 16:01:01 2012 +0000 +++ b/flys-artifacts/ChangeLog Thu Jan 12 16:49:00 2012 +0000 @@ -1,3 +1,9 @@ +2011-01-12 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java: + Added code to calculate the area of the generated polygons. + TODO: Render the generated area sum to the plot. + 2011-01-12 Sascha L. Teichmann * src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java: diff -r 51b9899f819d -r b5cc53a84b66 flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java --- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java Thu Jan 12 16:01:01 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java Thu Jan 12 16:49:00 2012 +0000 @@ -137,6 +137,12 @@ private static Logger log = Logger.getLogger(StableXYDifferenceRenderer.class); + public static final int CALCULATE_NO_AREA = 0; + public static final int CALCULATE_POSITIVE_AREA = 1; + public static final int CALCULATE_NEGATIVE_AREA = 2; + public static final int CALCULATE_ALL_AREA = + CALCULATE_POSITIVE_AREA | CALCULATE_NEGATIVE_AREA; + /** For serialization. */ private static final long serialVersionUID = -8447915602375584857L; @@ -163,7 +169,11 @@ protected boolean drawOriginalSeries; - //private XYDatasetToZeroMapper mapper; + protected int areaCalculationMode; + + protected double positiveArea; + protected double negativeArea; + /** * This flag controls whether or not the x-coordinates (in Java2D space) @@ -183,6 +193,11 @@ this(Color.green, Color.red, false /*, null */); } + public StableXYDifferenceRenderer(Paint positivePaint, Paint negativePaint, + boolean shapes) { + this(positivePaint, negativePaint, shapes, CALCULATE_NO_AREA); + } + /** * Creates a new renderer. * @@ -193,7 +208,7 @@ * @param shapes draw shapes? */ public StableXYDifferenceRenderer(Paint positivePaint, Paint negativePaint, - boolean shapes) { + boolean shapes, int areaCalculationMode) { if (positivePaint == null) { throw new IllegalArgumentException( "Null 'positivePaint' argument."); @@ -211,8 +226,22 @@ this.outlineStroke = new BasicStroke(1); this.outlinePaint = Color.black; this.drawOriginalSeries = false; + this.areaCalculationMode = areaCalculationMode; } + public int getAreaCalculationMode() { + return areaCalculationMode; + } + + public void setAreaCalculationMode(int areaCalculationMode) { + this.areaCalculationMode = areaCalculationMode; + } + + + + public double getCalculatedArea() { + return positiveArea + negativeArea; + } /** * Sets color that is used if drawOutline is true. @@ -1405,6 +1434,23 @@ || (l_subtrahendLast < l_minuendFirst)); } + public static double calculateArea(Object [] xValues, Object [] yValues) { + double area = 0d; + + for (int i = 0, N = xValues.length; i < N; ++i) { + int j = (i + 1) % N; + double xi = ((Double)xValues[i]).doubleValue(); + double yi = ((Double)yValues[i]).doubleValue(); + double xj = ((Double)xValues[j]).doubleValue(); + double yj = ((Double)yValues[j]).doubleValue(); + + area += xi*yj; + area -= xj*yi; + } + + return 0.5d*area; + } + /** * Draws the visual representation of a polygon * @@ -1437,6 +1483,20 @@ Object[] l_xValues = x_xValues.toArray(); Object[] l_yValues = x_yValues.toArray(); + int acm = areaCalculationMode; + + if (acm != CALCULATE_NO_AREA) { + if ((x_positive && ((acm|CALCULATE_POSITIVE_AREA) + == CALCULATE_POSITIVE_AREA)) + || (!x_positive && ((acm|CALCULATE_NEGATIVE_AREA) + == CALCULATE_NEGATIVE_AREA)) + ) { + double area = calculateArea(l_xValues, l_yValues); + if (x_positive) positiveArea += area; + else negativeArea += area; + } + } + GeneralPath l_path = new GeneralPath(); if (PlotOrientation.VERTICAL == l_orientation) {