[Schmitzm-commits] r869 - in trunk/src/schmitzm/jfree: . feature/style
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri May 28 13:32:55 CEST 2010
Author: mojays
Date: 2010-05-28 13:32:53 +0200 (Fri, 28 May 2010)
New Revision: 869
Modified:
trunk/src/schmitzm/jfree/JFreeChartUtil.java
trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
Log:
Utility method to get a series from XYSeriesCollection (with automatic add).
Series grouping (according to series attribute) for XYDataset.
Modified: trunk/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-05-26 23:25:21 UTC (rev 868)
+++ trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-05-28 11:32:53 UTC (rev 869)
@@ -75,6 +75,7 @@
import org.jfree.chart.urls.StandardXYURLGenerator;
import org.jfree.chart.urls.XYURLGenerator;
import org.jfree.data.Range;
+import org.jfree.data.UnknownKeyException;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.function.Function2D;
import org.jfree.data.function.LineFunction2D;
@@ -82,6 +83,7 @@
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.general.PieDataset;
import org.jfree.data.xy.XYDataset;
+import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import schmitzm.jfree.chart.renderer.SelectionRenderer;
@@ -516,6 +518,24 @@
}
/**
+ * Returns a series from a dataset. If no series exists a new one is created.
+ * @param dataset the dataset
+ * @param seriesKey the key to return the series for
+ * @param autoSort indicates the "autosort" property for the series (if a new series is created)
+ * @param allowDupl indicates whether duplicate x values are allowed in the series (if a new series is created)
+ * @return never {@code null}
+ */
+ public static XYSeries getOrAddSeriesFromDataset(XYSeriesCollection dataset, Comparable seriesKey, boolean autoSort, boolean allowDupl) {
+ try {
+ return dataset.getSeries(seriesKey);
+ } catch (UnknownKeyException err) {
+ XYSeries xySeries = new XYSeries(seriesKey, autoSort, allowDupl); // IMPORTANT: Do not use autosort!!
+ dataset.addSeries( xySeries );
+ return xySeries;
+ }
+ }
+
+ /**
* Searchs the renderers of a plot for {@link SelectionRenderer} for a
* {@link Dataset}.
*
Modified: trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java 2010-05-26 23:25:21 UTC (rev 868)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java 2010-05-28 11:32:53 UTC (rev 869)
@@ -48,6 +48,7 @@
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
+import org.jfree.data.UnknownKeyException;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;
@@ -233,21 +234,26 @@
for (int i = 1; i < attrCount; i++)
statisticsForAggregation[i] = new HashMap<Comparable<?>, QuantileBin1D>();
- // Create a series for each range attribute (note: the 0
- // array element useless, but it is more comfortable to
- // use an array of the same size as "attributes"
- XYSeries[] xySeries = new XYSeries[attrCount];
- for (int i = 1; i < xySeries.length; i++)
- // IMPORTANT: Do not use autosort!!
- xySeries[i] = new XYSeries(chartStyle.getAttributeName(i), false, true);
-
+//MS-01.so
+//### Because of the potential grouping attribute, the series can
+//### not be prepared anymore
+// // Create a series for each range attribute (note: the 0
+// // array element useless, but it is more comfortable to
+// // use an array of the same size as "attributes"
+// XYSeries[] xySeries = new XYSeries[attrCount];
+// for (int i = 1; i < xySeries.length; i++)
+// // IMPORTANT: Do not use autosort!!
+// xySeries[i] = new XYSeries(chartStyle.getAttributeName(i), false, true);
+//MS-01.eo
// Create a new dataset and insert the series
XYSeriesCollection dataset = new XYSeriesCollection();
Feature2SeriesDatasetMapping mapping = new Feature2SeriesDatasetMapping(fc,
dataset);
dataset.setGroup(new FeatureDatasetMetaData(mapping));
- for (int i = 1; i < xySeries.length; i++)
- dataset.addSeries(xySeries[i]);
+//MS-01.so
+// for (int i = 1; i < xySeries.length; i++)
+// dataset.addSeries(xySeries[i]);
+//MS-01.eo
// If dataset should be sorted, the features must be sorted first
// according to the domain attribute. The "autoSort" functionality
@@ -285,6 +291,15 @@
if (xValue == null)
continue;
+ // If grouping series attribute is used, filter out
+ // its no data values
+ Object seriesID = null;
+ if ( chartStyle.getSeriesAttributeName() != null ) {
+ seriesID = determineSeriesAttributeValueFromFeature(f, chartStyle);
+ if ( seriesID == null )
+ continue;
+ }
+
// Normalization of the domain axis value (if they are not handled as
// categories)
if (chartStyle.isAttributeNormalized(ChartStyle.DOMAIN_AXIS))
@@ -303,13 +318,23 @@
if (yValue == null)
continue;
+
// Fill series, if no aggregation function is defined.
// Otherwise fill statistic (dataset is filled later!)
if (chartStyle.getAttributeAggregation(attrIdx) == null) {
// Fill series
- xySeries[attrIdx].add(xValue, yValue);
+//MS-01.sc
+// xySeries[attrIdx].add(xValue, yValue);
+ String yAttrName = chartStyle.getAttributeName(attrIdx);
+ // If grouping series attribute is used, add its value
+ // to the series ID
+ if ( seriesID != null )
+ yAttrName = yAttrName + "_" + seriesID.toString();
+
+ XYSeries xySeries = JFreeChartUtil.getOrAddSeriesFromDataset(dataset, yAttrName, false, true);
+ xySeries.add(xValue, yValue);
+//MS-01.ec
// Mapping between FID and data index in series
- String yAttrName = chartStyle.getAttributeName(attrIdx);
mapping.setMapping(f.getID(), yAttrName, datasetIdx++);
} else {
QuantileBin1D aggrStat = statisticsForAggregation[attrIdx].get(xValue);
@@ -348,7 +373,12 @@
yValue = normalize(yValue, yAttrName, statisticsForNormalization);
// Fill series
- xySeries[attrIdx].add(((Number) xValue), yValue);
+//MS-01.sc
+// xySeries[attrIdx].add(((Number) xValue), yValue);
+ XYSeries xySeries = JFreeChartUtil.getOrAddSeriesFromDataset(dataset, yAttrName, false, true);
+ xySeries.add((Number)xValue, yValue);
+//MS-01.ec
+
// TODO: Mapping setzen
// Problem: Pro dataset item kann nur EINE FeatureID gesetzt
// werden (Feature2DatasetMapping, Zeile 124)
@@ -359,7 +389,7 @@
}
return dataset;
}
-
+
/**
* Calculates the attribute sum for all weight-aggregated range attributes
* grouped by the domain attribute values.<br>
More information about the Schmitzm-commits
mailing list