[Schmitzm-commits] r843 - in trunk: src/schmitzm/jfree src/schmitzm/jfree/chart/style src_junit/schmitzm/jfree/feature/style
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon May 17 19:14:43 CEST 2010
Author: mojays
Date: 2010-05-17 19:14:42 +0200 (Mon, 17 May 2010)
New Revision: 843
Modified:
trunk/src/schmitzm/jfree/JFreeChartUtil.java
trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
Log:
BugFix: avoid endless loop in ChartRendererStyle.applyToRenderer(.)
Modified: trunk/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-05-12 18:48:15 UTC (rev 842)
+++ trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-05-17 17:14:42 UTC (rev 843)
@@ -447,6 +447,25 @@
}
/**
+ * Returns the series count from a dataset.
+ * For {@link PieDataset} this method always returns 1 because pies
+ * have only one series!
+ * @param dataset a dataset
+ * @return 0 if there is no series
+ */
+ public static int getSeriesCountFromDataset(Dataset dataset) {
+ if ( dataset instanceof CategoryDataset )
+ return ((CategoryDataset)dataset).getRowCount();
+ if ( dataset instanceof XYDataset )
+ return ((XYDataset)dataset).getSeriesCount();
+ if ( dataset instanceof PieDataset )
+ return 1;
+
+ LOGGER.warn("Could not determine series count for dataset: "+LangUtil.getSimpleClassName(dataset));
+ return 0;
+ }
+
+ /**
* Returns the series key for a series in a dataset.
* For {@link PieDataset} this method always returns an empty string (unless
* an invalid series < 0 is given), because pies have only one series!
Modified: trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java 2010-05-12 18:48:15 UTC (rev 842)
+++ trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java 2010-05-17 17:14:42 UTC (rev 843)
@@ -617,66 +617,68 @@
// LOGGER.warn("Renderer contains not series "+series+". Legend visibility can not be applied.");
// }
- // Apply series properties
- for (int i=0; ; i++)
- try {
- // Default: i-th series style for the i-th series
- int series = i;
- // If series key is set, determine the series index in the
- // dataset
- String seriesKey = getSeriesKey(i);
- if ( seriesKey != null ) {
- Dataset dataset = JFreeChartUtil.getDatasetFrom(renderer);
- int idx = JFreeChartUtil.getSeriesIndexFromDataset(dataset, seriesKey);
- if ( idx >= 0 )
- series = idx;
- }
-
- // Apply item label visibility
- if ( isSeriesItemLabelsVisible(series) != null )
- renderer.setSeriesItemLabelsVisible(series, isSeriesItemLabelsVisible(series), false);
- else if ( isDefaultItemLabelsVisible() != null )
- renderer.setSeriesItemLabelsVisible(series, isDefaultItemLabelsVisible(), false);
-
- // Apply shape visibility
- if ( isSeriesShapesVisible(series) != null || isDefaultShapesVisible() != null ) {
- Shape shape = null;
- if ( isSeriesShapesVisible(series) != null )
- shape = isSeriesShapesVisible(series) ? AbstractRenderer.DEFAULT_SHAPE : null;
- else
- shape = isDefaultShapesVisible() ? AbstractRenderer.DEFAULT_SHAPE : null;
- renderer.setSeriesShape(series, shape, false);
-// LOGGER.debug("Setting shape = "+shape +" for series "+series);
- }
- // Apply rendering color
- if ( getSeriesPaint(series) != null )
- renderer.setSeriesPaint(series, getSeriesPaint(series), false);
- else if ( getDefaultPaint() != null )
- renderer.setSeriesPaint(series, getDefaultPaint(), false);
-
- // Apply rendering stroke (line width)
- if ( getSeriesLineWidth(series) != null || getDefaultLineWidth() != null ) {
- Stroke stroke = null;
- if ( getSeriesLineWidth(series) != null )
- stroke = new BasicStroke( getSeriesLineWidth(series) );
- else
- stroke = new BasicStroke( getDefaultLineWidth() );
- renderer.setSeriesStroke(series, stroke, false);
+ // First apply general default properties to all series of
+ // the dataset
+ // NOTE: simply set the base-properties does not work (only the first
+ // series is applied by the base-properties! why?)
+ Dataset dataset = JFreeChartUtil.getDatasetFrom(renderer);
+ int seriesCount = JFreeChartUtil.getSeriesCountFromDataset(dataset);
+ for (int series=0; series<seriesCount; series++) {
+ if ( isDefaultItemLabelsVisible() != null )
+ renderer.setSeriesItemLabelsVisible(series, isDefaultItemLabelsVisible(), false);
+ if ( isDefaultShapesVisible() != null ) {
+ Shape shape = isDefaultShapesVisible() ? AbstractRenderer.DEFAULT_SHAPE : null;
+ renderer.setSeriesShape(series, shape, false);
+ }
+ if ( getDefaultPaint() != null )
+ renderer.setSeriesPaint(series, getDefaultPaint(), false);
+ if ( getDefaultLineWidth() != null ) {
+ Stroke stroke = new BasicStroke( getDefaultLineWidth() );
+ renderer.setSeriesStroke(series, stroke, false);
+ }
+ if ( isDefaultLegendVisible() != null )
+ renderer.setSeriesVisibleInLegend(series, isDefaultLegendVisible(), false);
+ }
+
+ // Apply explicit series properties
+ seriesCount = getSeriesCount();
+ for (int i=0; i<seriesCount; i++) {
+ // Default: i-th series style for the i-th series
+ int series = i;
+ // If series key is set, determine the series index in the
+ // dataset
+ String seriesKey = getSeriesKey(i);
+ if ( seriesKey != null ) {
+ int idx = JFreeChartUtil.getSeriesIndexFromDataset(dataset, seriesKey);
+ if ( idx >= 0 )
+ series = idx;
+ else {
+ LOGGER.warn("Series does not exist in renderer: "+seriesKey+" ("+series+")");
+ continue;
}
-
- // Apply legend visibility
- if ( isSeriesLegendVisible(series) != null )
- renderer.setSeriesVisibleInLegend(series, isSeriesLegendVisible(series), false);
- else if ( isDefaultLegendVisible() != null )
- renderer.setSeriesVisibleInLegend(series, isDefaultLegendVisible(), false);
+ }
- } catch (Exception err) {
-// LOGGER.warn("Renderer contains not series "+series+". Rendering properties for this series will be ignored.");
- // AbstractRenderer contains no method to determine the series
- // count, so we loop until an Exception occurs
- break;
+ // Apply item label visibility
+ if ( isSeriesItemLabelsVisible(series) != null )
+ renderer.setSeriesItemLabelsVisible(series, isSeriesItemLabelsVisible(series), false);
+ // Apply shape visibility
+ if ( isSeriesShapesVisible(series) != null ) {
+ Shape shape = isSeriesShapesVisible(series) ? AbstractRenderer.DEFAULT_SHAPE : null;
+ renderer.setSeriesShape(series, shape, false);
}
+ // Apply rendering color
+ if ( getSeriesPaint(series) != null )
+ renderer.setSeriesPaint(series, getSeriesPaint(series), false);
+ // Apply rendering stroke (line width)
+ if ( getSeriesLineWidth(series) != null ) {
+ Stroke stroke = new BasicStroke( getSeriesLineWidth(series) );
+ renderer.setSeriesStroke(series, stroke, false);
+ }
+ // Apply legend visibility
+ if ( isSeriesLegendVisible(series) != null )
+ renderer.setSeriesVisibleInLegend(series, isSeriesLegendVisible(series), false);
+ }
// Other properties must be applied according to the specific renderer type
Modified: trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-05-12 18:48:15 UTC (rev 842)
+++ trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-05-17 17:14:42 UTC (rev 843)
@@ -213,9 +213,11 @@
ChartRendererStyle chartRendererStyle = new ChartRendererStyle();
- chartRendererStyle.setSeriesLegendLabel(0, new ChartLabelStyle(
- "test 1. label"));
+// chartRendererStyle.setSeriesLegendLabel(0, new ChartLabelStyle(
+// "test 1. label"));
+ chartRendererStyle.setDefaultPaint(Color.blue);
+
chartRendererStyle.setSeriesPaint(0, Color.green);
chartRendererStyle.setSeriesPaint(1, Color.red);
chartRendererStyle.setSeriesPaint(2, Color.GRAY);
More information about the Schmitzm-commits
mailing list