[Schmitzm-commits] r842 - in trunk: doc src/schmitzm/jfree src/schmitzm/jfree/chart/style
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed May 12 20:48:18 CEST 2010
Author: mojays
Date: 2010-05-12 20:48:15 +0200 (Wed, 12 May 2010)
New Revision: 842
Modified:
trunk/doc/Chart style XML structure.pdf
trunk/src/schmitzm/jfree/JFreeChartUtil.java
trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
Log:
- Chart style XML definition updated
- line width parameterizable for series in ChartRendererStyle
- series key definition in ChartRendererStyle
- global defaults for series properties in ChartRendererStyle
- some more nice utility methods in JFreeChartUtil
Modified: trunk/doc/Chart style XML structure.pdf
===================================================================
(Binary files differ)
Modified: trunk/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-05-11 16:42:25 UTC (rev 841)
+++ trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-05-12 18:48:15 UTC (rev 842)
@@ -48,10 +48,12 @@
import org.jfree.chart.labels.XYSeriesLabelGenerator;
import org.jfree.chart.labels.XYToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
+import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.AbstractRenderer;
+import org.jfree.chart.renderer.category.AbstractCategoryItemRenderer;
import org.jfree.chart.renderer.category.AreaRenderer;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
@@ -59,6 +61,7 @@
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.renderer.category.StackedAreaRenderer;
import org.jfree.chart.renderer.category.StackedBarRenderer;
+import org.jfree.chart.renderer.xy.AbstractXYItemRenderer;
import org.jfree.chart.renderer.xy.StackedXYAreaRenderer2;
import org.jfree.chart.renderer.xy.StackedXYBarRenderer;
import org.jfree.chart.renderer.xy.XYAreaRenderer;
@@ -72,10 +75,12 @@
import org.jfree.chart.urls.StandardXYURLGenerator;
import org.jfree.chart.urls.XYURLGenerator;
import org.jfree.data.Range;
+import org.jfree.data.category.CategoryDataset;
import org.jfree.data.function.Function2D;
import org.jfree.data.function.LineFunction2D;
import org.jfree.data.general.Dataset;
import org.jfree.data.general.DatasetUtilities;
+import org.jfree.data.general.PieDataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeriesCollection;
@@ -370,7 +375,101 @@
+ type);
}
- /**
+ /**
+ * Returns the plot from a renderer.
+ * @param renderer a renderer
+ */
+ public static Plot getPlotFromRenderer(AbstractRenderer renderer) {
+ if ( renderer instanceof AbstractCategoryItemRenderer )
+ return ((AbstractCategoryItemRenderer)renderer).getPlot();
+ if ( renderer instanceof AbstractXYItemRenderer )
+ return ((AbstractXYItemRenderer)renderer).getPlot();
+ LOGGER.warn("Could not determine plot for renderer: "+LangUtil.getSimpleClassName(renderer));
+ return null;
+ }
+
+
+ /**
+ * Returns the dataset from a plot.
+ * @param plot a plot
+ */
+ public static Dataset getDatasetFromPlot(Plot plot) {
+ if ( plot instanceof XYPlot )
+ return ((XYPlot)plot).getDataset();
+ if ( plot instanceof CategoryPlot )
+ return ((CategoryPlot)plot).getDataset();
+ if ( plot instanceof PiePlot )
+ return ((PiePlot)plot).getDataset();
+ LOGGER.warn("Could not determine dataset for plot: "+LangUtil.getSimpleClassName(plot));
+ return null;
+ }
+
+ /**
+ * Returns the dataset from a renderer or plot.
+ * @param renderer a renderer (also
+ */
+ public static Dataset getDatasetFrom(Object object) {
+ Dataset dataset = null;
+ if ( object instanceof AbstractRenderer )
+ object = getPlotFromRenderer((AbstractRenderer)object);
+ if ( object instanceof Plot )
+ dataset = getDatasetFromPlot((Plot)object);
+ return dataset;
+ }
+
+ /**
+ * Returns the series index for a series key in a dataset.
+ * For {@link PieDataset} this method always returns 0 (unless
+ * series key is {@code null}), because pies have only one
+ * series!
+ * @param dataset a dataset
+ * @param seriesKey a series key
+ * @return -1 if there is no series with the key
+ */
+ public static int getSeriesIndexFromDataset(Dataset dataset, Comparable seriesKey) {
+ if ( dataset instanceof CategoryDataset )
+ return ((CategoryDataset)dataset).getRowIndex(seriesKey);
+ if ( dataset instanceof XYDataset ) {
+ XYDataset xyDataset = (XYDataset)dataset;
+ for (int i=0; i<xyDataset.getSeriesCount(); i++)
+ if ( seriesKey.equals( xyDataset.getSeriesKey(i) ) )
+ return i;
+ // no series available for key
+ return -1;
+ }
+ if ( dataset instanceof PieDataset )
+ // PieDataset has only one series, so return this
+ // series for every key
+ return seriesKey != null ? 0 : -1;
+
+ LOGGER.warn("Could not determine series index for dataset: "+LangUtil.getSimpleClassName(dataset));
+ return -1;
+ }
+
+ /**
+ * 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!
+ * @param dataset a dataset
+ * @param series a series key
+ * @return {@code null} if there is no series for the index
+ */
+ public static Comparable getSeriesKeyFromDataset(Dataset dataset, int series) {
+ try {
+ if ( dataset instanceof CategoryDataset )
+ return ((CategoryDataset)dataset).getRowKey(series);
+ if ( dataset instanceof XYDataset )
+ return ((XYDataset)dataset).getSeriesKey(series);
+ if ( dataset instanceof PieDataset )
+ return series >= 0 ? "" : null;
+ } catch (IndexOutOfBoundsException err) {
+ return null;
+ }
+ LOGGER.warn("Could not determine series key for dataset: "+LangUtil.getSimpleClassName(dataset));
+ return null;
+ }
+
+ /**
* Returns the renderer for the {@code i}-th dataset of a plot.
*
* @param plot
Modified: trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java 2010-05-11 16:42:25 UTC (rev 841)
+++ trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java 2010-05-12 18:48:15 UTC (rev 842)
@@ -29,8 +29,10 @@
******************************************************************************/
package schmitzm.jfree.chart.style;
+import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Shape;
+import java.awt.Stroke;
import java.util.HashMap;
import java.util.Map;
@@ -44,6 +46,7 @@
import org.jfree.chart.renderer.xy.AbstractXYItemRenderer;
import org.jfree.chart.renderer.xy.XYBarRenderer;
import org.jfree.data.category.CategoryDataset;
+import org.jfree.data.general.Dataset;
import org.jfree.data.xy.XYDataset;
import schmitzm.jfree.JFreeChartUtil;
@@ -55,8 +58,11 @@
* properties are available:
* <ul>
* <li>color of series graphs</li>
+ * <li>line width of series graphs</li>
* <li>visibility of series item labels</li>
* <li>visibility of series shapes</li>
+ * <li>the legend labels of the series</li>
+ * <li>visibility of legend label</li>
* <li>percentage margin between bars (only applicable for {@link XYBarRenderer})</li>
* </ul>
@@ -72,10 +78,37 @@
/** Standard label generator used for Category-Charts. */
protected CategorySeriesLabelGenerator LABELGEN_CAT = new StandardCategorySeriesLabelGenerator();
+ /** Holds whether the item labels are visible (for all series this property
+ * is not set explicitly). */
+ protected Boolean defaultItemLabelsVisible = null;
+ /** Holds the color a series is painted with (for all series this property
+ * is not set explicitly). */
+ protected Color defaultPaint = null;
+ /** Holds the line width a series graph is painted with (for all series this property
+ * is not set explicitly). */
+ protected Integer defaultWidth = null;
+ /** Holds whether the shape of a series is visible (for all series this property
+ * is not set explicitly). */
+ protected Boolean defaultShapesVisible = null;
+ /** Holds whether the series is visible in the legend (for all series this property
+ * is not set explicitly). */
+ protected Boolean defaultLegendVisible = null;
+ /** Holds the label shown in the legend for the series (for all series this property
+ * is not set explicitly). */
+ protected ChartLabelStyle defaultLegendLabel = null;
+ /** Holds the tooltip shown in the legend for the series (for all series this property
+ * is not set explicitly). */
+ protected ChartLabelStyle defaultLegendTooltip = null;
+
+ /** Holds the ID of the series (series key of the dataset) the series style definition has
+ * to be used for.*/
+ protected Map<Integer, String> seriesKey = new HashMap<Integer, String>();
/** Holds whether the item labels are visible for a series. */
protected Map<Integer, Boolean> seriesItemLabelsVisible = new HashMap<Integer, Boolean>();
/** Holds the color a series is painted with. */
protected Map<Integer, Color> seriesPaint = new HashMap<Integer, Color>();
+ /** Holds the line width a series graph is painted with. */
+ protected Map<Integer, Integer> seriesWidth = new HashMap<Integer, Integer>();
/** Holds whether the shape of a series is visible. */
protected Map<Integer, Boolean> seriesShapesVisible = new HashMap<Integer, Boolean>();
/** Holds whether the series is visible in the legend. */
@@ -124,15 +157,32 @@
return copy();
dest.setMargin( getMargin() );
+ dest.setDefaultItemLabelsVisible(isDefaultItemLabelsVisible() );
+ dest.setDefaultPaint(getDefaultPaint() );
+ dest.setDefaultLineWidth(getDefaultLineWidth() );
+ dest.setDefaultShapesVisible(isDefaultShapesVisible() );
+ dest.setDefaultLegendVisible(isDefaultLegendVisible() );
+ if ( getDefaultLegendLabel() != null )
+ dest.setDefaultLegendLabel(getDefaultLegendLabel().copy() );
+ if ( getDefaultLegendTooltip() != null )
+ dest.setDefaultLegendTooltip(getDefaultLegendTooltip().copy() );
- dest.seriesItemLabelsVisible.clear();
- for ( int series : seriesItemLabelsVisible.keySet() )
- dest.setSeriesItemLabelsVisible( series, isSeriesItemLabelsVisible(series) );
-
+ dest.seriesKey.clear();
+ for ( int series : seriesKey.keySet() )
+ dest.setSeriesKey( series, getSeriesKey(series) );
+
dest.seriesPaint.clear();
for ( int series : seriesPaint.keySet() )
dest.setSeriesPaint( series, getSeriesPaint(series) );
+ dest.seriesWidth.clear();
+ for ( int series : seriesWidth.keySet() )
+ dest.setSeriesLineWidth( series, getSeriesLineWidth(series) );
+
+ dest.seriesItemLabelsVisible.clear();
+ for ( int series : seriesItemLabelsVisible.keySet() )
+ dest.setSeriesItemLabelsVisible( series, isSeriesItemLabelsVisible(series) );
+
dest.seriesShapesVisible.clear();
for ( int series : seriesShapesVisible.keySet() )
dest.setSeriesShapesVisible( series, isSeriesShapesVisible(series) );
@@ -178,6 +228,29 @@
}
/**
+ * Returns the series key (of the dataset), which identifies the series
+ * for which the i-th series style is used for.
+ * If not set the i-th series style is used for the i-th series.
+ * @param i series index
+ * @return {@code null} if no specific color is set for the series
+ */
+ public String getSeriesKey(int i) {
+ return seriesKey.get(i);
+ }
+
+ /**
+ * Sets the series key (of the dataset), which identifies the series
+ * for which the i-th series style is used for.
+ * If not set the i-th series style is used for the i-th series.
+ * @param i series index
+ * @param key the series key in the dataset
+ */
+ public void setSeriesKey(int i, String key) {
+ seriesKey.put(i,key);
+ updateSeriesCount();
+ }
+
+ /**
* Returns the color, a series is painted with.
* @param series series index
* @return {@code null} if no specific color is set for the series
@@ -198,6 +271,26 @@
}
/**
+ * Returns the line width, a series is painted with.
+ * @param series series index
+ * @return {@code null} if no specific width is set for the series
+ */
+ public Integer getSeriesLineWidth(int series) {
+ return seriesWidth.get(series);
+ }
+
+ /**
+ * Sets the line width, a series is painted with.
+ * @param series series index
+ * @param width line width for the series (can be {@code null} to reset
+ * to a non-specific color)
+ */
+ public void setSeriesLineWidth(int series, Integer width) {
+ seriesWidth.put(series,width);
+ updateSeriesCount();
+ }
+
+ /**
* Returns whether the item labels of a series are visible.
* @param series series index
* @return {@code null} if property is not set for the series
@@ -298,6 +391,139 @@
}
/**
+ * Returns the color, a series is painted with for these
+ * series this property is not set explicitly.
+ * @return {@code null} if no specific color is set for the series
+ */
+ public Color getDefaultPaint() {
+ return defaultPaint;
+ }
+
+ /**
+ * Sets the color, a series is painted with for these
+ * series this property is not set explicitly.
+ * @param color color for the series (can be {@code null} to reset
+ * to a non-specific color)
+ */
+ public void setDefaultPaint(Color color) {
+ defaultPaint = color;
+ }
+
+ /**
+ * Returns the line width, a series is painted with for these
+ * series this property is not set explicitly.
+ * @return {@code null} if no specific width is set for the series
+ */
+ public Integer getDefaultLineWidth() {
+ return defaultWidth;
+ }
+
+ /**
+ * Sets the line width, a series is painted with for these
+ * series this property is not set explicitly.
+ * @param width line width for the series (can be {@code null} to reset
+ * to a non-specific color)
+ */
+ public void setDefaultLineWidth(Integer width) {
+ defaultWidth = width;
+ }
+
+ /**
+ * Returns whether the item labels of a series are visible for these
+ * series this property is not set explicitly.
+ * @return {@code null} if property is not set for the series
+ */
+ public Boolean isDefaultItemLabelsVisible() {
+ return defaultItemLabelsVisible;
+ }
+
+ /**
+ * Sets whether the item labels of a series are visible for these
+ * series this property is not set explicitly.
+ * @param visible indicates the visibility of the series (can be
+ * {@code null} to reset to a non-specific property)
+ */
+ public void setDefaultItemLabelsVisible(Boolean visible) {
+ defaultItemLabelsVisible = visible;
+ }
+
+ /**
+ * Returns whether the shapes of a series are visible for these
+ * series this property is not set explicitly.
+ * @return {@code null} if property is not set for the series
+ */
+ public Boolean isDefaultShapesVisible() {
+ return defaultShapesVisible;
+ }
+
+ /**
+ * Sets whether the shapes of a series are visible for these
+ * series this property is not set explicitly.
+ * @param visible indicates the visibility of the series (can be
+ * {@code null} to reset to a non-specific property)
+ */
+ public void setDefaultShapesVisible(Boolean visible) {
+ defaultShapesVisible = visible;
+ }
+
+ /**
+ * Returns whether the series is shown in the legend for these
+ * series this property is not set explicitly.
+ * @return {@code null} if property is not set for the series
+ */
+ public Boolean isDefaultLegendVisible() {
+ return defaultLegendVisible;
+ }
+
+ /**
+ * Sets whether the series is shown in the legend for these
+ * series this property is not set explicitly.
+ * @param visible indicates the visibility of the series legend item (can be
+ * {@code null} to reset to a non-specific property)
+ */
+ public void setDefaultLegendVisible(Boolean visible) {
+ defaultLegendVisible = visible;
+ }
+
+ /**
+ * Returns the style of the series label in the legend for these
+ * series this property is not set explicitly.
+ * @return {@code null} if property is not set for the series
+ */
+ public ChartLabelStyle getDefaultLegendLabel() {
+ return defaultLegendLabel;
+ }
+
+ /**
+ * Sets the style of the series label in the legend for these
+ * series this property is not set explicitly.
+ * @param labelStyle the style for the series label in the legend (can be
+ * {@code null} to reset to a non-specific property)
+ */
+ public void setDefaultLegendLabel(ChartLabelStyle labelStyle) {
+ defaultLegendLabel = labelStyle;
+ }
+
+ /**
+ * Returns the style of the series tooltip in the legend for these
+ * series this property is not set explicitly.
+ * @return {@code null} if property is not set for the series
+ */
+ public ChartLabelStyle getDefaultLegendTooltip() {
+ return defaultLegendTooltip;
+ }
+
+ /**
+ * Sets the style of the series tooltip in the legend for these
+ * series this property is not set explicitly.
+ * @param labelStyle the style for the series tooltip in the legend (can be
+ * {@code null} to reset to a non-specific property)
+ */
+ public void setDefaultLegendTooltip(ChartLabelStyle tooltipStyle) {
+ defaultLegendTooltip = tooltipStyle;
+ }
+
+ /**
* Returns a label generator based on the <b>legend label</b>
* definitions of this style.
*/
@@ -319,7 +545,9 @@
*/
private void updateSeriesCount() {
maxSeriesIdx = LangUtil.max(
+ seriesKey.keySet(),
seriesPaint.keySet(),
+ seriesWidth.keySet(),
seriesShapesVisible.keySet(),
seriesItemLabelsVisible.keySet(),
seriesLegendVisible.keySet(),
@@ -344,51 +572,113 @@
LOGGER.debug("No renderer to be customised.");
return;
}
+
+// // Apply item label visibility
+// for (int series : seriesItemLabelsVisible.keySet())
+// try {
+// if ( isSeriesItemLabelsVisible(series) != null )
+// renderer.setSeriesItemLabelsVisible(series, isSeriesItemLabelsVisible(series), false);
+// } catch (Exception err) {
+// LOGGER.warn("Renderer contains not series "+series+". Label visibility can not be applied.");
+// }
+//
+// // Apply shape visibility
+// for (int series : seriesShapesVisible.keySet())
+// try {
+// if ( isSeriesShapesVisible(series) != null ) {
+// final Shape shape = isSeriesShapesVisible(series) ?
+// AbstractRenderer.DEFAULT_SHAPE
+// : null;
+// renderer.setSeriesShape(series,
+// shape,
+// false);
+//// LOGGER.debug("Setting shape = "+shape +" for series "+series);
+// }
+//
+// } catch (Exception err) {
+// LOGGER.warn("Renderer contains not series "+series+". Shapes visibility can not be applied.");
+// }
+//
+// // Apply rendering color
+// for (int series : seriesPaint.keySet())
+// try {
+// if ( getSeriesPaint(series) != null )
+// renderer.setSeriesPaint(series, getSeriesPaint(series), false);
+// } catch (Exception err) {
+// LOGGER.warn("Renderer contains not series "+series+". Paint can not be applied.");
+// }
+//
+// // Apply legend visibility
+// for (int series : seriesLegendVisible.keySet())
+// try {
+// if ( isSeriesLegendVisible(series) != null )
+// renderer.setSeriesVisibleInLegend(series, isSeriesLegendVisible(series), false);
+// } catch (Exception err) {
+// LOGGER.warn("Renderer contains not series "+series+". Legend visibility can not be applied.");
+// }
- // Apply item label visibility
- for (int series : seriesItemLabelsVisible.keySet())
+ // 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);
- } catch (Exception err) {
- LOGGER.warn("Renderer contains not series "+series+". Label visibility can not be applied.");
- }
-
- // Apply shape visibility
- for (int series : seriesShapesVisible.keySet())
- try {
- if ( isSeriesShapesVisible(series) != null ) {
- final Shape shape = isSeriesShapesVisible(series) ?
- AbstractRenderer.DEFAULT_SHAPE
- : null;
- renderer.setSeriesShape(series,
- shape,
- false);
-// LOGGER.debug("Setting shape = "+shape +" for series "+series);
- }
-
- } catch (Exception err) {
- LOGGER.warn("Renderer contains not series "+series+". Shapes visibility can not be applied.");
- }
+ 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
- for (int series : seriesPaint.keySet())
- try {
+ // Apply rendering color
if ( getSeriesPaint(series) != null )
renderer.setSeriesPaint(series, getSeriesPaint(series), false);
- } catch (Exception err) {
- LOGGER.warn("Renderer contains not series "+series+". Paint can not be applied.");
- }
-
- // Apply legend visibility
- for (int series : seriesLegendVisible.keySet())
- try {
+ 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);
+ }
+
+ // 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+". Legend visibility can not be applied.");
+// 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;
}
+
// Other properties must be applied according to the specific renderer type
if (renderer instanceof XYBarRenderer)
applyToBarRenderer((XYBarRenderer)renderer);
@@ -527,10 +817,12 @@
*/
@Override
public String generateLabel(XYDataset dataset, int series) {
+ if ( getSeriesLegendLabel(series) != null )
+ return getSeriesLegendLabel(series).getLabel();
+ if ( getDefaultLegendLabel() != null )
+ return getDefaultLegendLabel().getLabel();
// if label is not defined, use the standard label generator
- if ( getSeriesLegendLabel(series) == null )
- return LABELGEN_XY.generateLabel(dataset, series);
- return getSeriesLegendLabel(series).getLabel();
+ return LABELGEN_XY.generateLabel(dataset, series);
}
/**
@@ -541,10 +833,12 @@
*/
@Override
public String generateLabel(CategoryDataset dataset, int series) {
+ if ( getSeriesLegendLabel(series) != null )
+ return getSeriesLegendLabel(series).getLabel();
+ if ( getDefaultLegendLabel() != null )
+ return getDefaultLegendLabel().getLabel();
// if label is not defined, use the standard label generator
- if ( getSeriesLegendLabel(series) == null )
- return LABELGEN_CAT.generateLabel(dataset, series);
- return getSeriesLegendLabel(series).getLabel();
+ return LABELGEN_CAT.generateLabel(dataset, series);
}
}
@@ -584,10 +878,12 @@
}
public String generateLabel(int series) {
+ if ( getSeriesLegendTooltip(series) != null )
+ return getSeriesLegendTooltip(series).getLabel();
+ if ( getDefaultLegendTooltip() != null )
+ return getDefaultLegendTooltip().getLabel();
// if label is not defined, generate no tooltip
- if ( getSeriesLegendTooltip(series) == null )
- return null;
- return getSeriesLegendTooltip(series).getLabel();
+ return null;
}
}
Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java 2010-05-11 16:42:25 UTC (rev 841)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java 2010-05-12 18:48:15 UTC (rev 842)
@@ -275,15 +275,62 @@
if ( margin != null )
style.setMargin( margin );
- // read series properties
+ //##### read default series properties ######
+ // series paint
+ Color defaultPaint = XMLUtil.getColorAttribute(element, "paint");
+ if ( defaultPaint != null )
+ style.setDefaultPaint(defaultPaint);
+
+ // series line width
+ Integer defaultLineWidth = XMLUtil.getIntegerAttribute(element, "lineWidth");
+ if ( defaultLineWidth != null )
+ style.setDefaultLineWidth(defaultLineWidth);
+
+ // item label visibility
+ Boolean defaultLabelsVisible = XMLUtil.getBooleanAttribute(element, "itemLabelsVisible");
+ if ( defaultLabelsVisible != null )
+ style.setDefaultItemLabelsVisible(defaultLabelsVisible);
+
+ // item shapes visibility
+ Boolean defaultShapesVisible = XMLUtil.getBooleanAttribute(element, "shapesVisible");
+ if ( defaultShapesVisible != null )
+ style.setDefaultShapesVisible(defaultShapesVisible);
+
+ // legend visibility
+ Boolean defaultLegendVisible = XMLUtil.getBooleanAttribute(element, "legendVisible");
+ if ( defaultLegendVisible != null )
+ style.setDefaultLegendVisible(defaultLegendVisible);
+
+ // legend label
+ String defaultLegendLabel = XMLUtil.getAttribute(element, "legendLabel");
+ if ( defaultLegendLabel != null )
+ style.setDefaultLegendLabel(new ChartLabelStyle(defaultLegendLabel));
+
+ // legend tooltip
+ String defaultLegendTooltip = XMLUtil.getAttribute(element, "legendTooltip");
+ if ( defaultLegendTooltip != null )
+ style.setDefaultLegendTooltip(new ChartLabelStyle(defaultLegendTooltip));
+
+
+ //##### read explicit series properties ######
List<Element> seriesElements = element.getChildren("series");
for (int i=0; i<seriesElements.size(); i++) {
Element seriesElement = seriesElements.get(i);
// series paint
+ String seriesKey = XMLUtil.getAttribute(seriesElement, "seriesKey");
+ if ( seriesKey != null )
+ style.setSeriesKey(i, seriesKey);
+
+ // series paint
Color seriesPaint = XMLUtil.getColorAttribute(seriesElement, "paint");
if ( seriesPaint != null )
style.setSeriesPaint(i, seriesPaint);
+ // series line width
+ Integer seriesLineWidth = XMLUtil.getIntegerAttribute(seriesElement, "lineWidth");
+ if ( seriesLineWidth != null )
+ style.setSeriesLineWidth(i, seriesLineWidth);
+
// item label visibility
Boolean labelsVisible = XMLUtil.getBooleanAttribute(seriesElement, "itemLabelsVisible");
if ( labelsVisible != null )
@@ -630,10 +677,23 @@
if ( rendererStyle != null ) {
// Margin attribute
XMLUtil.setNotNullAttribute(element, "margin", rendererStyle.getMargin());
+ // Attributes for default series properties
+ XMLUtil.setNotNullAttribute(element, "paint", rendererStyle.getDefaultPaint());
+ XMLUtil.setNotNullAttribute(element, "lineWidth", rendererStyle.getDefaultLineWidth());
+ XMLUtil.setNotNullAttribute(element, "itemLabelsVisible", rendererStyle.isDefaultItemLabelsVisible());
+ XMLUtil.setNotNullAttribute(element, "shapesVisible", rendererStyle.isDefaultShapesVisible());
+ XMLUtil.setNotNullAttribute(element, "legendVisible", rendererStyle.isDefaultLegendVisible());
+ if ( rendererStyle.getDefaultLegendLabel() != null )
+ XMLUtil.setNotNullAttribute(element, "legendLabel", rendererStyle.getDefaultLegendLabel().getLabelTranslation());
+ if ( rendererStyle.getDefaultLegendTooltip() != null )
+ XMLUtil.setNotNullAttribute(element, "legendTooltip", rendererStyle.getDefaultLegendTooltip().getLabelTranslation());
+
// Create <series> child for all series
for ( int i=0; i<rendererStyle.getSeriesCount(); i++) {
Element seriesElem = addChildToElement(rendererElem, "series");
+ XMLUtil.setNotNullAttribute(seriesElem, "seriesKey", rendererStyle.getSeriesKey(i));
XMLUtil.setNotNullAttribute(seriesElem, "paint", rendererStyle.getSeriesPaint(i));
+ XMLUtil.setNotNullAttribute(seriesElem, "lineWidth", rendererStyle.getSeriesLineWidth(i));
XMLUtil.setNotNullAttribute(seriesElem, "itemLabelsVisible", rendererStyle.isSeriesItemLabelsVisible(i));
XMLUtil.setNotNullAttribute(seriesElem, "shapesVisible", rendererStyle.isSeriesShapesVisible(i));
XMLUtil.setNotNullAttribute(seriesElem, "legendVisible", rendererStyle.isSeriesLegendVisible(i));
More information about the Schmitzm-commits
mailing list