[Schmitzm-commits] r738 - in trunk/src/schmitzm/jfree/feature: . style

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Mar 2 20:07:05 CET 2010


Author: alfonx
Date: 2010-03-02 20:07:03 +0100 (Tue, 02 Mar 2010)
New Revision: 738

Added:
   trunk/src/schmitzm/jfree/feature/AggregationFunction.java
Modified:
   trunk/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java
   trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java
   trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
   trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
   trunk/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java
Log:
Added weighted aggregation to the BAR chart.. There are compile erros that show the stuff only martin can implement ;-)

Added: trunk/src/schmitzm/jfree/feature/AggregationFunction.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/AggregationFunction.java	2010-03-02 16:53:13 UTC (rev 737)
+++ trunk/src/schmitzm/jfree/feature/AggregationFunction.java	2010-03-02 19:07:03 UTC (rev 738)
@@ -0,0 +1,162 @@
+package schmitzm.jfree.feature;
+
+import hep.aida.bin.StaticBin1D;
+
+import java.awt.Component;
+
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.ListCellRenderer;
+
+import schmitzm.jfree.JFreeChartUtil;
+import schmitzm.jfree.feature.style.FeatureChartStyle;
+import schmitzm.lang.ResourceProvider;
+
+/**
+ * Defines possible aggregation function to calculate on attribute categories.
+ * 
+ * @see FeatureChartStyle#setAttributeAggregation(int, AggregationFunction)
+ * @see FeatureChartStyle#getAttributeAggregation(int)
+ */
+public enum AggregationFunction {
+
+	/** Count of the attribute values. */
+	COUNT(false),
+	/** Sum of the attribute values. */
+	SUM(false),
+	// /** Sum of the absolute attribute values. */
+	// SUM_ABS,
+	/** Average of the attribute values. */
+	AVG(false),
+	/**
+	 * Weighted average of the attribute values. Needs an attribute for
+	 * weighting
+	 **/
+	AVG_WEIGHTED(true),
+	// /** Median of the attribute values. */
+	// MEDIAN,
+	/** Minimum attribute value. */
+	MIN(false),
+	/** Maximum attribute value. */
+	MAX(false),
+	/** Variance of the attribute values. */
+	VARIANCE(false),
+	/** Standard deviation of the attribute values. */
+	STND_DEV(false);
+
+	private final boolean weighted;
+
+	AggregationFunction(boolean weighted) {
+		this.weighted = weighted;
+	}
+
+	/**
+	 * Returns true, if this aggreation method is used a second attribute for
+	 * weighting
+	 **/
+	public boolean isWeighted() {
+		return weighted;
+	}
+
+	/**
+	 * Prefix for the title (.TITLE) and description (.DESC) key in the resource
+	 * bundle.
+	 * 
+	 * @see #getTitle()
+	 * @see #getDescription()
+	 */
+	public final String RESOURCE_PREFIX = getClass().getSimpleName() + "."
+			+ toString();
+
+	/**
+	 * Returns the result of the function from a statistic.
+	 * 
+	 * @param statistics
+	 *            Statistic to take the result from.
+	 */
+	public Double getResult(StaticBin1D statistics) {
+		switch (this) {
+		case AVG:
+		case AVG_WEIGHTED:
+			return statistics.mean();
+		case MAX:
+			return statistics.max();
+		case MIN:
+			return statistics.min();
+			// case SUM_ABS: // SK: Man müsste beim
+			// "packen der daten in die Statistik" schon abs() auf die werte
+			// anwenden und dann diese zeile einkommentieren
+		case SUM:
+			return statistics.sum();
+		case COUNT:
+			return ((Integer) statistics.size()).doubleValue();
+		case STND_DEV:
+			return statistics.standardDeviation();
+		case VARIANCE:
+			return Math.pow(statistics.standardDeviation(), 2);
+			// case MEDIAN:
+			// case SUM_ABS:
+		}
+		throw new UnsupportedOperationException(
+				"Aggregation function not yet supported: " + this);
+	}
+
+	/**
+	 * Returns a description of this kind of chart. Can be used for tool-tips.
+	 * May return <code>null</code> if no localized String found.
+	 */
+	public String getDescription() {
+		final String resource = JFreeChartUtil.R(RESOURCE_PREFIX + ".Desc");
+		if (resource == null
+				|| resource.equals(ResourceProvider.MISSING_RESOURCE_STRING))
+			return null;
+		return resource;
+	}
+
+	/**
+	 * Returns a localized title of this kind of chart. If no localized string
+	 * found, return the Enum.toString()
+	 */
+	public String getTitle() {
+		final String resource = JFreeChartUtil.R(RESOURCE_PREFIX + ".Title");
+		if (resource == null
+				|| resource.equals(ResourceProvider.MISSING_RESOURCE_STRING))
+			return toString();
+		return resource;
+	}
+
+	/**
+	 * A static {@link DefaultListCellRenderer} that will render instances of
+	 * {@link AggregationFunction} with the title and description field as a
+	 * tooltip.
+	 */
+	static ListCellRenderer listCellRenderer = new DefaultListCellRenderer() {
+
+		@Override
+		public Component getListCellRendererComponent(JList list, Object value,
+				int index, boolean isSelected, boolean cellHasFocus) {
+
+			Component proto = super.getListCellRendererComponent(list, value,
+					index, isSelected, cellHasFocus);
+
+			if (proto instanceof JLabel && value instanceof AggregationFunction) {
+				((JLabel) proto).setText(((AggregationFunction) value)
+						.getTitle());
+				((JLabel) proto).setToolTipText(((AggregationFunction) value)
+						.getDescription());
+			}
+
+			return proto;
+		}
+	};
+
+	/**
+	 * Returns a {@link ListCellRenderer} that will render elemnts of type
+	 * {@link AggregationFunction} with their title and description as tooltip
+	 **/
+	public static ListCellRenderer getListCellRenderer() {
+		return listCellRenderer;
+	}
+
+}


Property changes on: trunk/src/schmitzm/jfree/feature/AggregationFunction.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java	2010-03-02 16:53:13 UTC (rev 737)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java	2010-03-02 19:07:03 UTC (rev 738)
@@ -40,6 +40,7 @@
 import schmitzm.jfree.chart.style.BasicChartStyle;
 import schmitzm.jfree.chart.style.ChartStyle;
 import schmitzm.jfree.chart.style.ChartType;
+import schmitzm.jfree.feature.AggregationFunction;
 
 /**
  * This class extends the {@link BasicChartStyle} with the properties

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java	2010-03-02 16:53:13 UTC (rev 737)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java	2010-03-02 19:07:03 UTC (rev 738)
@@ -29,19 +29,11 @@
  ******************************************************************************/
 package schmitzm.jfree.feature.style;
 
-import hep.aida.bin.StaticBin1D;
-
-import java.awt.Component;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
-import javax.swing.DefaultListCellRenderer;
-import javax.swing.JLabel;
-import javax.swing.JList;
-import javax.swing.ListCellRenderer;
-
 import org.geotools.feature.FeatureCollection;
 import org.jfree.chart.JFreeChart;
 import org.jfree.data.category.CategoryDataset;
@@ -50,11 +42,10 @@
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 
-import schmitzm.jfree.JFreeChartUtil;
 import schmitzm.jfree.chart.style.AbstractChartStyle;
 import schmitzm.jfree.chart.style.ChartStyle;
+import schmitzm.jfree.feature.AggregationFunction;
 import schmitzm.lang.LangUtil;
-import schmitzm.lang.ResourceProvider;
 
 /**
  * This interface extends the chart style with several functionalities used to
@@ -66,154 +57,6 @@
 public interface FeatureChartStyle extends ChartStyle {
 
 	/**
-	 * Defines possible aggregation function to calculate on attribute
-	 * categories.
-	 * 
-	 * @see FeatureChartStyle#setAttributeAggregation(int, AggregationFunction)
-	 * @see FeatureChartStyle#getAttributeAggregation(int)
-	 */
-	public static enum AggregationFunction {
-		/** Count of the attribute values. */
-		COUNT(false),
-		/** Sum of the attribute values. */
-		SUM(false),
-		// /** Sum of the absolute attribute values. */
-		// SUM_ABS,
-		/** Average of the attribute values. */
-		AVG(false),
-		/** Weighted average of the attribute values. Need another attribute column selected **/
-		AVG_WEIGHTED(true),
-		// /** Median of the attribute values. */
-		// MEDIAN,
-		/** Minimum attribute value. */
-		MIN(false),
-		/** Maximum attribute value. */
-		MAX(false),
-		/** Variance of the attribute values. */
-		VARIANCE(false),
-		/** Standard deviation of the attribute values. */
-		STND_DEV(false);
-		
-		private final boolean weighted;
-
-		private AggregationFunction(boolean weighted) {
-			this.weighted = weighted;
-		}
-
-		/**
-		 * Prefix for the title (.TITLE) and description (.DESC) key in the
-		 * resource bundle.
-		 * 
-		 * @see #getTitle()
-		 * @see #getDescription()
-		 */
-		public final String RESOURCE_PREFIX = getClass().getSimpleName() + "."
-				+ toString();
-
-		/**
-		 * Returns the result of the function from a statistic.
-		 * 
-		 * @param statistics
-		 *            Statistic to take the result from.
-		 */
-		public Double getResult(StaticBin1D statistics) {
-			switch (this) {
-			case AVG:
-			case AVG_WEIGHTED:
-				return statistics.mean();
-			case MAX:
-				return statistics.max();
-			case MIN:
-				return statistics.min();
-				// case SUM_ABS: // SK: Man müsste beim
-				// "packen der daten in die Statistik" schon abs() auf die werte
-				// anwenden und dann diese zeile einkommentieren
-			case SUM:
-				return statistics.sum();
-			case COUNT:
-				return ((Integer) statistics.size()).doubleValue();
-			case STND_DEV:
-				return statistics.standardDeviation();
-			case VARIANCE:
-				return Math.pow(statistics.standardDeviation(), 2);
-				// case MEDIAN:
-				// case SUM_ABS:
-			}
-			throw new UnsupportedOperationException(
-					"Aggregation function not yet supported: " + this);
-		}
-
-		/**
-		 * Returns a description of this kind of chart. Can be used for
-		 * tool-tips. May return <code>null</code> if no localized String found.
-		 */
-		public String getDescription() {
-			final String resource = JFreeChartUtil.R(RESOURCE_PREFIX + ".Desc");
-			if (resource == null
-					|| resource
-							.equals(ResourceProvider.MISSING_RESOURCE_STRING))
-				return null;
-			return resource;
-		}
-
-		/**
-		 * Returns a localized title of this kind of chart. If no localized
-		 * string found, return the Enum.toString()
-		 */
-		public String getTitle() {
-			final String resource = JFreeChartUtil
-					.R(RESOURCE_PREFIX + ".Title");
-			if (resource == null
-					|| resource
-							.equals(ResourceProvider.MISSING_RESOURCE_STRING))
-				return toString();
-			return resource;
-		}
-
-		/**
-		 * A static {@link DefaultListCellRenderer} that will render instances
-		 * of {@link AggregationFunction} with the title and description field
-		 * as a tooltip.
-		 */
-		static ListCellRenderer listCellRenderer = new DefaultListCellRenderer() {
-
-			@Override
-			public Component getListCellRendererComponent(JList list,
-					Object value, int index, boolean isSelected,
-					boolean cellHasFocus) {
-
-				Component proto = super.getListCellRendererComponent(list,
-						value, index, isSelected, cellHasFocus);
-
-				if (proto instanceof JLabel
-						&& value instanceof AggregationFunction) {
-					((JLabel) proto).setText(((AggregationFunction) value)
-							.getTitle());
-					((JLabel) proto)
-							.setToolTipText(((AggregationFunction) value)
-									.getDescription());
-				}
-
-				return proto;
-			}
-		};
-
-		/**
-		 * Returns a {@link ListCellRenderer} that will render elemnts of type
-		 * {@link AggregationFunction} with their title and description as
-		 * tooltip
-		 **/
-		public static ListCellRenderer getListCellRenderer() {
-			return listCellRenderer;
-		}
-
-		/** Returns true, if this aggreation method is used a second attribute for weighting **/
-		public boolean isWeighted() {
-			return weighted;
-		}
-	}
-
-	/**
 	 * Returns the maximum number of feature attributes that can be specified by
 	 * this style.
 	 * 
@@ -575,7 +418,7 @@
 			// !! copy only this classes properties !!
 			// !! Reason: the dummy does not maintain the !!
 			// !! super class properties and we !!
-			// do not want to overwrite them !!
+			// !! do not want to overwrite them !!
 			if (dest instanceof FeatureChartStyle) {
 				FeatureChartStyle destFCS = (FeatureChartStyle) dest;
 				destFCS.setSortDomainAxis(isSortDomainAxis());
@@ -884,4 +727,42 @@
 		}
 	}
 
+	/**
+	 * TODO Martin! ;-) Wenn attIdx == 0 return. Sonst soll der Name eines
+	 * Attributs zurückgegeben werden oder null! Dieses Attributfeld wird nur
+	 * benutzt, wenn die aggregationsmethode für dieses attribut .isWeighted ==
+	 * true hat
+	 **/
+	public String getAttributeAggregationWeightAttributeName(int attrIdx);
+	
+	/**
+	 * TODO Martin! ;-) Wenn attIdx == 0 thorws exception. Sonst soll der Name eines
+	 * Attributs übergeben werden (oder vielleicht auch mal null)! Dieses Attributfeld wird nur
+	 * benutzt, wenn die aggregationsmethode für dieses attribut .isWeighted ==
+	 * true hat
+	 **/
+	public String setAttributeAggregationWeightAttributeName(int attrIdx, String weightAttribName);
+
+	/**
+	 * Checks whether the given value is one of the "No data" values for the
+	 * weight attribute.
+	 * 
+	 * @param idx
+	 *            attribute index the "No Data" value is checked for
+	 * @param value
+	 *            an attribute value
+	 */
+	public boolean isNoDataWeightValue(int idx, Object value);
+
+
+	/**
+	 * Sets the values, which are interpreted as "No Data" for the optional weight attribute of this attribute 
+	 * 
+	 * @param idx
+	 *            attribute index the "No Data" values are set for
+	 * @param noDataValues
+	 *            the "No Data" values
+	 */
+	public void setNoDataWeightValues(int idx, Set<Object> noDataValues);
+
 }

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java	2010-03-02 16:53:13 UTC (rev 737)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java	2010-03-02 19:07:03 UTC (rev 738)
@@ -38,6 +38,7 @@
 import schmitzm.jfree.chart.style.ChartStyle;
 import schmitzm.jfree.chart.style.ChartStyleXMLFactory;
 import schmitzm.jfree.chart.style.ChartType;
+import schmitzm.jfree.feature.AggregationFunction;
 import schmitzm.xml.XMLUtil;
 
 /**
@@ -97,7 +98,7 @@
       chartStyle.setAttributeNormalized(rangeAttrNo, XMLUtil.getBooleanAttribute(domainAttrElem, "normalize", false));
       String aggrFuncStr = XMLUtil.getAttribute(domainAttrElem, "function", (String)null);
       if ( aggrFuncStr != null )
-        chartStyle.setAttributeAggregation(rangeAttrNo, FeatureChartStyle.AggregationFunction.valueOf(aggrFuncStr) );
+        chartStyle.setAttributeAggregation(rangeAttrNo, AggregationFunction.valueOf(aggrFuncStr) );
     }
   }
 

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java	2010-03-02 16:53:13 UTC (rev 737)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java	2010-03-02 19:07:03 UTC (rev 738)
@@ -64,11 +64,11 @@
 import schmitzm.jfree.chart.selection.DatasetSelectionModelProvider;
 import schmitzm.jfree.chart.style.ChartStyle;
 import schmitzm.jfree.chart.style.ChartStyleXMLFactory;
+import schmitzm.jfree.feature.AggregationFunction;
 import schmitzm.jfree.feature.Feature2CategoryDatasetMapping;
 import schmitzm.jfree.feature.Feature2SeriesDatasetMapping;
 import schmitzm.jfree.feature.FeatureDatasetMetaData;
 import schmitzm.jfree.feature.FeatureDatasetSelectionModel;
-import schmitzm.jfree.feature.style.FeatureChartStyle.AggregationFunction;
 import skrueger.AttributeMetadata;
 import skrueger.geotools.AttributeMetadataMap;
 
@@ -306,14 +306,9 @@
 			for (int attrIdx = 1; attrIdx < attrCount; attrIdx++) {
 				String yAttrName = chartStyle.getAttributeName(attrIdx);
 				Number yValue = (Number) f.getAttribute(yAttrName);
-				AggregationFunction attributeAggregation = chartStyle
-						.getAttributeAggregation(attrIdx);
+				// AggregationFunction attributeAggregation = chartStyle
+				// .getAttributeAggregation(attrIdx);
 
-				long yWeightValue = 1;
-//				if (attributeAggregation != null && attributeAggregation.isWeighted())
-//					yWeightValue = ((Number) f.getAttribute("POP_CNTRY"))
-//							.longValue();
-
 				// Filter out NoDataValues
 				yValue = chartStyle.filterNoDataValue(attrIdx, yValue);
 				if (yValue == null)
@@ -326,51 +321,51 @@
 
 				// Fill series, if no aggregation function is defined.
 				// Otherwise fill statistic (dataset is filled later!)
-				if (attributeAggregation == null) {
-					// Fill series
-					xySeries[attrIdx].add(xValue, yValue);
-					// Mapping between FID and data index in series
-					mapping.setMapping(f.getID(), yAttrName, datasetIdx++);
-				} else {
-					// The values for this are aggregated
-					StaticBin1D aggrStat = statisticsForAggregation[attrIdx]
-							.get(xValue);
-					if (aggrStat == null) {
-						aggrStat = new DynamicBin1D();
-						statisticsForAggregation[attrIdx].put(xValue, aggrStat);
-					}
-
-					// The default weight is 1
-//					for (int i = 0; i < yWeightValue; i++)
-						aggrStat.add(yValue.doubleValue());
-
-					// TODO: Mapping vormerken (??)
-					// Problem: siehe unten
-				}
-			}
-		}
-
-		// Fill series for aggregated range attributes
-		for (int attrIdx = 1; attrIdx < attrCount; attrIdx++) {
-//			String yAttrName = chartStyle.getAttributeName(attrIdx);
-			FeatureChartStyle.AggregationFunction aggrFunc = chartStyle
-					.getAttributeAggregation(attrIdx);
-			if (aggrFunc == null)
-				continue;
-			for (Number xValue : statisticsForAggregation[attrIdx].keySet()) {
-				StaticBin1D aggrStat = statisticsForAggregation[attrIdx]
-						.get(xValue);
-				Number yValue = aggrFunc.getResult(aggrStat);
+				// if (attributeAggregation == null) {
 				// Fill series
 				xySeries[attrIdx].add(xValue, yValue);
-				// TODO: Mapping setzen
-				// Problem: Pro dataset item kann nur EINE FeatureID gesetzt
-				// werden (Feature2DatasetMapping, Zeile 124)
-				// // Mapping between FID and data index in series
-				// mapping.setMapping(f.getID() ??, yAttrName, datasetIdx++);
+				// Mapping between FID and data index in series
+				mapping.setMapping(f.getID(), yAttrName, datasetIdx++);
+				// } else {
+				// // The values for this are aggregated
+				// StaticBin1D aggrStat = statisticsForAggregation[attrIdx]
+				// .get(xValue);
+				// if (aggrStat == null) {
+				// aggrStat = new DynamicBin1D();
+				// statisticsForAggregation[attrIdx].put(xValue, aggrStat);
+				// }
+				//
+				// // The default weight is 1
+				// // for (int i = 0; i < yWeightValue; i++)
+				// aggrStat.add(yValue.doubleValue());
+				//
+				// // TODO: Mapping vormerken (??)
+				// // Problem: siehe unten
+				// }
 			}
 		}
 
+		// // Fill series for aggregated range attributes
+		// for (int attrIdx = 1; attrIdx < attrCount; attrIdx++) {
+		// // String yAttrName = chartStyle.getAttributeName(attrIdx);
+		// AggregationFunction aggrFunc = chartStyle
+		// .getAttributeAggregation(attrIdx);
+		// if (aggrFunc == null)
+		// continue;
+		// for (Number xValue : statisticsForAggregation[attrIdx].keySet()) {
+		// StaticBin1D aggrStat = statisticsForAggregation[attrIdx]
+		// .get(xValue);
+		// Number yValue = aggrFunc.getResult(aggrStat);
+		// // Fill series
+		// xySeries[attrIdx].add(xValue, yValue);
+		// // TODO: Mapping setzen
+		// // Problem: Pro dataset item kann nur EINE FeatureID gesetzt
+		// // werden (Feature2DatasetMapping, Zeile 124)
+		// // // Mapping between FID and data index in series
+		// // mapping.setMapping(f.getID() ??, yAttrName, datasetIdx++);
+		// }
+		// }
+
 		return dataset;
 	}
 
@@ -546,6 +541,71 @@
 		// createXYDataset(..))
 		Iterator<SimpleFeature> fi = null;
 		FeatureIterator<SimpleFeature> features = null;
+
+		// Für die Gewichtung muss zuerst Summe aller Gewichte ermittelt werden
+		Double[] sumWeights = new Double[attrCount];
+		for (int attrIdx = 1; attrIdx < attrCount; attrIdx++)
+			sumWeights[attrIdx - 1] = 0.;
+		long[] validFeaturesCount = new long[attrCount];
+		{
+			features = fc.features();
+			try {
+				while (features.hasNext()) {
+
+					SimpleFeature next = features.next();
+					// Determine the Y values and fill the dataset
+					for (int attrIdx = 1; attrIdx < attrCount; attrIdx++) {
+						AggregationFunction attributeAggregation = chartStyle
+								.getAttributeAggregation(attrIdx);
+
+						if (attributeAggregation == null)
+							continue;
+						if (!attributeAggregation.isWeighted())
+							continue;
+						if (chartStyle
+								.getAttributeAggregationWeightAttributeName(attrIdx) == null)
+							continue;
+
+						// Filter out NODATA values
+						// Weder der eigentliche attributwert, noch das WEIGHT
+						// attribut, noch das DOMAIN attribute dürfen hier
+						// NODATA sein
+
+						// NODATA Check yValue attribute
+						String yAttrName = chartStyle.getAttributeName(attrIdx);
+						Number yValue = (Number) next.getAttribute(yAttrName);
+						yValue = chartStyle.filterNoDataValue(attrIdx, yValue);
+						if (yValue == null)
+							continue;
+
+						// NODATA Check WEIGHT attribute
+						Number weight = (Number) next
+								.getAttribute(chartStyle
+										.getAttributeAggregationWeightAttributeName(attrIdx));
+						if (chartStyle.isNoDataWeightValue(attrIdx, weight))
+							continue;
+
+						// NODATA Check Domain attribute
+						Comparable<?> catValue = (Comparable<?>) next
+								.getAttribute(xAttrName);
+						catValue = chartStyle.filterNoDataValue(
+								ChartStyle.DOMAIN_AXIS, catValue);
+						if (catValue == null)
+							continue;
+
+						// So, alle drei werte sind nicht NODATA
+						sumWeights[attrIdx - 1] += weight.doubleValue();
+						validFeaturesCount[attrIdx - 1]++;
+					}
+				}
+			} finally {
+				if (features != null) {
+					// this is a hint
+					fc.close(features);
+				}
+			}
+		} // Die Summe aller gewichte ist ermittelt
+
 		if (chartStyle.isSortDomainAxis()) {
 			Vector<SimpleFeature> sortedFeatures = FeatureUtil.sortFeatures(fc,
 					xAttrName);
@@ -557,7 +617,6 @@
 		}
 
 		try {
-
 			// Iterate the FeatureCollection and fill the series
 			for (int fIdx = 0; fi.hasNext(); fIdx++) {
 				SimpleFeature f = fi.next();
@@ -574,16 +633,18 @@
 
 				// Determine the Y values and fill the dataset
 				for (int attrIdx = 1; attrIdx < attrCount; attrIdx++) {
-					AggregationFunction attributeAggregation = chartStyle.getAttributeAggregation(attrIdx);
-					
+					AggregationFunction attributeAggregation = chartStyle
+							.getAttributeAggregation(attrIdx);
+
 					String yAttrName = chartStyle.getAttributeName(attrIdx);
 					Number yValue = (Number) f.getAttribute(yAttrName);
 
-					// By default the wight is 1 => no weighting. If the aggregation uses weighting, read the weight attribnute
-					long yWeightValue = 1;
-//					if (attributeAggregation != null && attributeAggregation.isWeighted())
-//						yWeightValue = ((Number) f.getAttribute("POP_CNTRY"))
-//								.longValue();
+					// By default the wight is 1 => no weighting. If the
+					// aggregation uses weighting, read the weight attribnute
+					// if (attributeAggregation != null &&
+					// attributeAggregation.isWeighted())
+					// yWeightValue = ((Number) f.getAttribute(WEIGHTATTRIB))
+					// .longValue();
 
 					// Filter out NoDataValues
 					yValue = chartStyle.filterNoDataValue(attrIdx, yValue);
@@ -610,11 +671,29 @@
 							statisticsForAggregation[attrIdx].put(catValue,
 									aggrStat);
 						}
-						
-						// The default weight is 1
-//						for (int i = 0; i < yWeightValue; i++)
+
+						if (attributeAggregation.isWeighted()
+								&& chartStyle
+										.getAttributeAggregationWeightAttributeName(attrIdx) != null) {
+							Object weightObj = f
+									.getAttribute(chartStyle
+											.getAttributeAggregationWeightAttributeName(attrIdx));
+
+							if (!chartStyle.isNoDataWeightValue(attrIdx,
+									weightObj)) {
+								Number weight = (Number) weightObj;
+								aggrStat.add(yValue.doubleValue()
+										* weight.doubleValue()
+										/ sumWeights[attrIdx - 1]
+										* validFeaturesCount[attrIdx - 1]);
+							} else {
+								// NIchts added, denn das weight ist hier NODATA
+							}
+
+						} else {
 							aggrStat.add(yValue.doubleValue());
-						
+						}
+
 						// TODO: Mapping vormerken (??)
 						// Problem: siehe unten
 					}
@@ -625,7 +704,7 @@
 			// Fill series for aggregated range attributes
 			for (int attrIdx = 1; attrIdx < attrCount; attrIdx++) {
 				String yAttrName = chartStyle.getAttributeName(attrIdx);
-				FeatureChartStyle.AggregationFunction aggrFunc = chartStyle
+				AggregationFunction aggrFunc = chartStyle
 						.getAttributeAggregation(attrIdx);
 				if (aggrFunc == null)
 					continue;
@@ -675,6 +754,7 @@
 
 		for (int idx = 0; idx < featureChartStyle.getAttributeCount(); idx++) {
 
+			// Check the main attribute
 			String attributeName = featureChartStyle.getAttributeName(idx);
 
 			AttributeDescriptor foundDescr = schema
@@ -682,12 +762,35 @@
 			if (foundDescr == null) {
 				Name bestMatch = FeatureUtil.findBestMatchingAttribute(schema,
 						attributeName);
-				if (bestMatch == null)
+				if (bestMatch == null) {
 					willRemove.add(idx);
-				else
+					continue;
+				} else
 					featureChartStyle.setAttributeName(idx, bestMatch
 							.getLocalPart());
 			}
+
+			// Check the optional weight attribute value
+			if (idx > 0) {
+				String weightAtt = featureChartStyle
+						.getAttributeAggregationWeightAttributeName(idx);
+				if (weightAtt != null) {
+					AttributeDescriptor foundWeightDescr = schema
+							.getDescriptor(attributeName);
+					if (foundWeightDescr == null) {
+						Name bestMatch = FeatureUtil.findBestMatchingAttribute(
+								schema, weightAtt);
+						if (bestMatch == null) {
+							featureChartStyle
+									.setAttributeAggregationWeightAttributeName(
+											idx, null);
+						} else
+							featureChartStyle
+									.setAttributeAggregationWeightAttributeName(
+											idx, bestMatch.getLocalPart());
+					}
+				}
+			}
 		}
 
 		// Remove the ones that were not findable in the schema
@@ -702,7 +805,7 @@
 
 	/**
 	 * Passes the NODATA Values stored in the {@link AttributeMetadataMap} to
-	 * the attributes of the {@link ChartStyle}.
+	 * the attributes (and optional weighting attributes) of the {@link ChartStyle}.
 	 */
 	public static void passNoDataValues(
 			AttributeMetadataMap attributeMetaDataMap,
@@ -719,7 +822,18 @@
 				featureChartStyle.setNoDataValues(idx, attributeMetadata
 						.getNodataValues());
 			}
+
+			// Set NODATA-Values for the weight attributes
+			String weightAtt = featureChartStyle
+					.getAttributeAggregationWeightAttributeName(idx);
+			if (weightAtt != null) {
+				AttributeMetadata weightAttributeMetadata = attributeMetaDataMap
+						.get(attributeName);
+				if (weightAttributeMetadata != null) {
+					featureChartStyle.setNoDataWeightValues(idx,
+							weightAttributeMetadata.getNodataValues());
+				}
+			}
 		}
-
 	}
 }

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java	2010-03-02 16:53:13 UTC (rev 737)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java	2010-03-02 19:07:03 UTC (rev 738)
@@ -41,7 +41,7 @@
 
 import schmitzm.jfree.chart.style.ChartStyle;
 import schmitzm.jfree.chart.style.ScatterChartStyle;
-import schmitzm.jfree.feature.style.FeatureChartStyle.AggregationFunction;
+import schmitzm.jfree.feature.AggregationFunction;
 
 /**
  * This class extends the {@link ScatterChartStyle} with the properties



More information about the Schmitzm-commits mailing list