Mercurial > dive4elements > river
changeset 2108:b5cc53a84b66
StableXYDifferenceRenderer: Added code to calculate the area of the generated polygons.
flys-artifacts/trunk@3667 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 12 Jan 2012 16:49:00 +0000 |
parents | 51b9899f819d |
children | 60e3bf470c5b |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java |
diffstat | 2 files changed, 68 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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 <sascha.teichmann@intevation.de> + + * 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 <sascha.teichmann@intevation.de> * 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) {