From: <mu...@us...> - 2009-01-14 14:59:15
|
Revision: 1786 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1786&view=rev Author: mungady Date: 2009-01-14 14:59:11 +0000 (Wed, 14 Jan 2009) Log Message: ----------- 2009-01-14 David Gilbert <dav...@ob...> Patch 2497611 by Peter Kolb: * source/org/jfree/chart/axis/CategoryAxis.java (getCategorySeriesMiddle): New method, * source/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.java (initialise): Record visible series indices, * source/org/jfree/chart/renderer/category/BarRenderer.java (calculateBarWidth): Look for visible series count in state, (calculateBarW0): Likewise, (drawItem): Use the visible row index, * source/org/jfree/chart/renderer/category/CategoryItemRendererState.java (visibleSeries): New field, (getVisibleSeriesIndex): New method, (getVisibleSeriesCount): Likewise, (setVisibleSeriesArray): Likewise, * source/org/jfree/chart/renderer/category/IntervalBarRenderer.java (drawInterval): Use the visible row index, * source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java (drawItem): Likewise, * source/org/jfree/chart/renderer/category/ScatterRenderer.java (drawItem): Likewise, * source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java (drawItem): Likewise, (drawHorizontalItem): Changed signature, (drawVerticalItem): Likewise, * source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java (drawItem): Use the visible row index. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/CategoryAxis.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/BarRenderer.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/CategoryItemRendererState.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/IntervalBarRenderer.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/ScatterRenderer.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2009-01-14 14:29:00 UTC (rev 1785) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2009-01-14 14:59:11 UTC (rev 1786) @@ -1,5 +1,34 @@ 2009-01-14 David Gilbert <dav...@ob...> + Patch 2497611 by Peter Kolb: + * source/org/jfree/chart/axis/CategoryAxis.java + (getCategorySeriesMiddle): New method, + * source/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.java + (initialise): Record visible series indices, + * source/org/jfree/chart/renderer/category/BarRenderer.java + (calculateBarWidth): Look for visible series count in state, + (calculateBarW0): Likewise, + (drawItem): Use the visible row index, + * source/org/jfree/chart/renderer/category/CategoryItemRendererState.java + (visibleSeries): New field, + (getVisibleSeriesIndex): New method, + (getVisibleSeriesCount): Likewise, + (setVisibleSeriesArray): Likewise, + * source/org/jfree/chart/renderer/category/IntervalBarRenderer.java + (drawInterval): Use the visible row index, + * source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java + (drawItem): Likewise, + * source/org/jfree/chart/renderer/category/ScatterRenderer.java + (drawItem): Likewise, + * source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java + (drawItem): Likewise, + (drawHorizontalItem): Changed signature, + (drawVerticalItem): Likewise, + * source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java + (drawItem): Use the visible row index. + +2009-01-14 David Gilbert <dav...@ob...> + * source/org/jfree/chart/axis/LogAxis.java (refreshTicksHorizontal): Read minorTickCount from the tick unit, (refreshTicksVertical): Likewise, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/CategoryAxis.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/CategoryAxis.java 2009-01-14 14:29:00 UTC (rev 1785) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/CategoryAxis.java 2009-01-14 14:59:11 UTC (rev 1786) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,10 +27,11 @@ * ----------------- * CategoryAxis.java * ----------------- - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert; * Contributor(s): Pady Srinivasan (patch 1217634); + * Peter Kolb (patch 2497611); * * Changes * ------- @@ -88,6 +89,8 @@ * calculateTextBlockWidth() (DG); * 26-Jun-2008 : Added new getCategoryMiddle() method (DG); * 27-Oct-2008 : Set font on Graphics2D when creating category labels (DG); + * 14-Jan-2009 : Added new variant of getCategorySeriesMiddle() to make it + * simpler for renderers with hidden series (PK); * */ @@ -721,6 +724,40 @@ } /** + * Returns the middle coordinate (in Java2D space) for a series within a + * category. + * + * @param categoryIndex the category index. + * @param categoryCount the category count. + * @param seriesIndex the series index. + * @param seriesCount the series count. + * @param itemMargin the item margin (0.0 <= itemMargin < 1.0); + * @param area the area (<code>null</code> not permitted). + * @param edge the edge (<code>null</code> not permitted). + * + * @return The coordinate in Java2D space. + * + * @since 1.0.13 + */ + public double getCategorySeriesMiddle(int categoryIndex, int categoryCount, + int seriesIndex, int seriesCount, double itemMargin, + Rectangle2D area, RectangleEdge edge) { + + double start = getCategoryStart(categoryIndex, categoryCount, area, + edge); + double end = getCategoryEnd(categoryIndex, categoryCount, area, edge); + double width = end - start; + if (seriesCount == 1) { + return start + width / 2.0; + } + else { + double gap = (width * itemMargin) / (seriesCount - 1); + double ww = (width * (1 - itemMargin)) / seriesCount; + return start + (seriesIndex * (ww + gap)) + ww / 2.0; + } + } + + /** * Calculates the size (width or height, depending on the location of the * axis) of a category. * Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.java 2009-01-14 14:29:00 UTC (rev 1785) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.java 2009-01-14 14:59:11 UTC (rev 1786) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,10 +27,11 @@ * --------------------------------- * AbstractCategoryItemRenderer.java * --------------------------------- - * (C) Copyright 2002-2008, by Object Refinery Limited. + * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Richard Atkinson; + * Peter Kolb (patch 2497611); * * Changes: * -------- @@ -96,6 +97,7 @@ * 17-Jun-2008 : Apply legend shape, font and paint attributes (DG); * 26-Jun-2008 : Added crosshair support (DG); * 25-Nov-2008 : Fixed bug in findRangeBounds() method (DG); + * 14-Jan-2009 : Update initialise() to store visible series indices (PK); * */ @@ -659,8 +661,20 @@ this.rowCount = 0; this.columnCount = 0; } - return createState(info); - + CategoryItemRendererState state = createState(info); + int[] visibleSeriesTemp = new int[this.rowCount]; + int visibleSeriesCount = 0; + for (int row = 0; row < this.rowCount; row++){ + if (isSeriesVisible(row)) { + visibleSeriesTemp[visibleSeriesCount] = row; + visibleSeriesCount++; + } + } + int[] visibleSeries = new int[visibleSeriesCount]; + System.arraycopy(visibleSeriesTemp, 0, visibleSeries, 0, + visibleSeriesCount); + state.setVisibleSeriesArray(visibleSeries); + return state; } /** Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/BarRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/BarRenderer.java 2009-01-14 14:29:00 UTC (rev 1785) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/BarRenderer.java 2009-01-14 14:59:11 UTC (rev 1786) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,10 +27,11 @@ * ---------------- * BarRenderer.java * ---------------- - * (C) Copyright 2002-2008, by Object Refinery Limited. + * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Christian W. Zuckschwerdt; + * Peter Kolb (patch 2497611); * * Changes * ------- @@ -86,6 +87,7 @@ * 24-Jun-2008 : Added barPainter mechanism (DG); * 26-Jun-2008 : Added crosshair support (DG); * 13-Aug-2008 : Added shadowPaint attribute (DG); + * 14-Jan-2009 : Added support for seriesVisible flags (PK); * */ @@ -748,7 +750,8 @@ CategoryDataset dataset = plot.getDataset(rendererIndex); if (dataset != null) { int columns = dataset.getColumnCount(); - int rows = dataset.getRowCount(); + int rows = state.getVisibleSeriesCount() >= 0 + ? state.getVisibleSeriesCount() : dataset.getRowCount(); double space = 0.0; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { @@ -810,7 +813,8 @@ } double barW0 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); - int seriesCount = getRowCount(); + int seriesCount = state.getVisibleSeriesCount() >= 0 + ? state.getVisibleSeriesCount() : getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = space * getItemMargin() @@ -959,6 +963,12 @@ int column, int pass) { + // nothing is drawn if the row index is not included in the list with + // the indices of the visible rows... + int visibleRow = state.getVisibleSeriesIndex(row); + if (visibleRow < 0) { + return; + } // nothing is drawn for null values... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { @@ -968,7 +978,7 @@ final double value = dataValue.doubleValue(); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, - state, row, column); + state, visibleRow, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/CategoryItemRendererState.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/CategoryItemRendererState.java 2009-01-14 14:29:00 UTC (rev 1785) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/CategoryItemRendererState.java 2009-01-14 14:59:11 UTC (rev 1786) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,10 +27,10 @@ * ------------------------------ * CategoryItemRendererState.java * ------------------------------ - * (C) Copyright 2003-2008, by Object Refinery Limited. + * (C) Copyright 2003-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; + * Contributor(s): Peter Kolb (patch 2497611); * * Changes (since 20-Oct-2003): * ---------------------------- @@ -38,6 +38,7 @@ * ------------- JFREECHART 1.0.x --------------------------------------------- * 01-Dec-2006 : Updated API docs (DG); * 26-Jun-2008 : Added CrosshairState (DG); + * 14-Jan-2009 : Added visibleSeries[] array (PK); * */ @@ -59,6 +60,9 @@ /** The series running total. */ private double seriesRunningTotal; + /** The array with the indices of the visible series.*/ + private int[] visibleSeries; + /** * State information for crosshairs in the plot (this is updated by the * renderer, but may be passed to several renderers in one chart). @@ -151,4 +155,56 @@ this.crosshairState = state; } + /** + * Returns the index of the row relative to the visible rows. If no + * visible rows have been specified, the original row index is returned. + * If the row index is not included in the array of visible rows, + * -1 is returned. + * + * @param rowIndex the row index. + * + * @return The new row index or -1. + * + * @since 1.0.13 + */ + public int getVisibleSeriesIndex(int rowIndex) { + if (this.visibleSeries == null) { + return rowIndex; + } + int index = -1; + for (int vRow = 0; vRow < this.visibleSeries.length ; vRow++){ + if (this.visibleSeries[vRow] == rowIndex) { + index = vRow; + break; + } + } + return index; + } + + /** + * Returns the number of visible series or -1 if no visible series have + * been specified. + * + * @return The number or -1. + * + * @since 1.0.13 + */ + public int getVisibleSeriesCount() { + if (this.visibleSeries == null) { + return -1; + } + return this.visibleSeries.length; + } + + /** + * Sets an array with the indices of the visible rows. + * + * @param visibleSeries the array (<code>null</code> permitted). + * + * @since 1.0.13 + */ + public void setVisibleSeriesArray(int[] visibleSeries) { + this.visibleSeries = visibleSeries; + } + } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/IntervalBarRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/IntervalBarRenderer.java 2009-01-14 14:29:00 UTC (rev 1785) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/IntervalBarRenderer.java 2009-01-14 14:59:11 UTC (rev 1786) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,11 +27,12 @@ * ------------------------ * IntervalBarRenderer.java * ------------------------ - * (C) Copyright 2002-2008, by Jeremy Bowman. + * (C) Copyright 2002-2009, by Jeremy Bowman. * * Original Author: Jeremy Bowman; * Contributor(s): David Gilbert (for Object Refinery Limited); * Christian W. Zuckschwerdt; + * Peter Kolb (patch 2497611); * * Changes * ------- @@ -57,6 +58,7 @@ * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 24-Jun-2008 : Added new barPainter mechanism (DG); * 07-Oct-2008 : Override equals() method to fix minor bug (DG); + * 14-Jan-2009 : Added support for seriesVisible flags (PK); * */ @@ -157,7 +159,13 @@ int row, int column) { - int seriesCount = getRowCount(); + int visibleRow = state.getVisibleSeriesIndex(row); + if (visibleRow < 0) { + return; + } + int seriesCount = state.getVisibleSeriesCount() >= 0 + ? state.getVisibleSeriesCount() : getRowCount(); + int categoryCount = getColumnCount(); PlotOrientation orientation = plot.getOrientation(); @@ -207,10 +215,10 @@ if (seriesCount > 1) { double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); - rectY = rectY + row * (state.getBarWidth() + seriesGap); + rectY = rectY + visibleRow * (state.getBarWidth() + seriesGap); } else { - rectY = rectY + row * state.getBarWidth(); + rectY = rectY + visibleRow * state.getBarWidth(); } rectX = java2dValue0; @@ -227,10 +235,10 @@ if (seriesCount > 1) { double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); - rectX = rectX + row * (state.getBarWidth() + seriesGap); + rectX = rectX + visibleRow * (state.getBarWidth() + seriesGap); } else { - rectX = rectX + row * state.getBarWidth(); + rectX = rectX + visibleRow * state.getBarWidth(); } rectY = java2dValue0; Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java 2009-01-14 14:29:00 UTC (rev 1785) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java 2009-01-14 14:59:11 UTC (rev 1786) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,13 +27,14 @@ * ------------------------- * LineAndShapeRenderer.java * ------------------------- - * (C) Copyright 2001-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2001-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Mark Watson (www.markwatson.com); * Jeremy Bowman; * Richard Atkinson; * Christian W. Zuckschwerdt; + * Peter Kolb (patch 2497611); * * Changes * ------- @@ -87,6 +88,7 @@ * 27-Sep-2007 : Added option to offset series x-position within category (DG); * 17-Jun-2008 : Apply legend shape, font and paint attributes (DG); * 26-Jun-2008 : Added crosshair support (DG); + * 14-Jan-2009 : Added support for seriesVisible flags (PK); * */ @@ -916,14 +918,20 @@ return; } + int visibleRow = state.getVisibleSeriesIndex(row); + if (visibleRow < 0) { + return; + } + int visibleRowCount = state.getVisibleSeriesCount(); + PlotOrientation orientation = plot.getOrientation(); // current data point... double x1; if (this.useSeriesOffset) { - x1 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey( - column), dataset.getRowKey(row), dataset, this.itemMargin, - dataArea, plot.getDomainAxisEdge()); + x1 = domainAxis.getCategorySeriesMiddle(column, + dataset.getColumnCount(), visibleRow, visibleRowCount, + this.itemMargin, dataArea, plot.getDomainAxisEdge()); } else { x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), @@ -942,8 +950,8 @@ double x0; if (this.useSeriesOffset) { x0 = domainAxis.getCategorySeriesMiddle( - dataset.getColumnKey(column - 1), - dataset.getRowKey(row), dataset, + column - 1, dataset.getColumnCount(), + visibleRow, visibleRowCount, this.itemMargin, dataArea, plot.getDomainAxisEdge()); } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/ScatterRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/ScatterRenderer.java 2009-01-14 14:29:00 UTC (rev 1785) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/ScatterRenderer.java 2009-01-14 14:59:11 UTC (rev 1786) @@ -1,569 +1,580 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. - * - * Project Info: http://www.jfree.org/jfreechart/index.html - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * -------------------- - * ScatterRenderer.java - * -------------------- - * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): David Forslund; - * - * Changes - * ------- - * 08-Oct-2007 : Version 1, based on patch 1780779 by David Forslund (DG); - * 11-Oct-2007 : Renamed ScatterRenderer (DG); - * 17-Jun-2008 : Apply legend shape, font and paint attributes (DG); - * - */ - -package org.jfree.chart.renderer.category; - -import java.awt.Graphics2D; -import java.awt.Paint; -import java.awt.Shape; -import java.awt.Stroke; -import java.awt.geom.Line2D; -import java.awt.geom.Rectangle2D; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.List; - -import org.jfree.chart.LegendItem; -import org.jfree.chart.axis.CategoryAxis; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.event.RendererChangeEvent; -import org.jfree.chart.plot.CategoryPlot; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.data.category.CategoryDataset; -import org.jfree.data.statistics.MultiValueCategoryDataset; -import org.jfree.util.BooleanList; -import org.jfree.util.BooleanUtilities; -import org.jfree.util.ObjectUtilities; -import org.jfree.util.PublicCloneable; -import org.jfree.util.ShapeUtilities; - -/** - * A renderer that handles the multiple values from a - * {@link MultiValueCategoryDataset} by plotting a shape for each value for - * each given item in the dataset. The example shown here is generated by - * the <code>ScatterRendererDemo1.java</code> program included in the - * JFreeChart Demo Collection: - * <br><br> - * <img src="../../../../../images/ScatterRendererSample.png" - * alt="ScatterRendererSample.png" /> - * - * @since 1.0.7 - */ -public class ScatterRenderer extends AbstractCategoryItemRenderer - implements Cloneable, PublicCloneable, Serializable { - - /** - * A table of flags that control (per series) whether or not shapes are - * filled. - */ - private BooleanList seriesShapesFilled; - - /** - * The default value returned by the getShapeFilled() method. - */ - private boolean baseShapesFilled; - - /** - * A flag that controls whether the fill paint is used for filling - * shapes. - */ - private boolean useFillPaint; - - /** - * A flag that controls whether outlines are drawn for shapes. - */ - private boolean drawOutlines; - - /** - * A flag that controls whether the outline paint is used for drawing shape - * outlines - if not, the regular series paint is used. - */ - private boolean useOutlinePaint; - - /** - * A flag that controls whether or not the x-position for each item is - * offset within the category according to the series. - */ - private boolean useSeriesOffset; - - /** - * The item margin used for series offsetting - this allows the positioning - * to match the bar positions of the {@link BarRenderer} class. - */ - private double itemMargin; - - /** - * Constructs a new renderer. - */ - public ScatterRenderer() { - this.seriesShapesFilled = new BooleanList(); - this.baseShapesFilled = true; - this.useFillPaint = false; - this.drawOutlines = false; - this.useOutlinePaint = false; - this.useSeriesOffset = true; - this.itemMargin = 0.20; - } - - /** - * Returns the flag that controls whether or not the x-position for each - * data item is offset within the category according to the series. - * - * @return A boolean. - * - * @see #setUseSeriesOffset(boolean) - */ - public boolean getUseSeriesOffset() { - return this.useSeriesOffset; - } - - /** - * Sets the flag that controls whether or not the x-position for each - * data item is offset within its category according to the series, and - * sends a {@link RendererChangeEvent} to all registered listeners. - * - * @param offset the offset. - * - * @see #getUseSeriesOffset() - */ - public void setUseSeriesOffset(boolean offset) { - this.useSeriesOffset = offset; - fireChangeEvent(); - } - - /** - * Returns the item margin, which is the gap between items within a - * category (expressed as a percentage of the overall category width). - * This can be used to match the offset alignment with the bars drawn by - * a {@link BarRenderer}). - * - * @return The item margin. - * - * @see #setItemMargin(double) - * @see #getUseSeriesOffset() - */ - public double getItemMargin() { - return this.itemMargin; - } - - /** - * Sets the item margin, which is the gap between items within a category - * (expressed as a percentage of the overall category width), and sends - * a {@link RendererChangeEvent} to all registered listeners. - * - * @param margin the margin (0.0 <= margin < 1.0). - * - * @see #getItemMargin() - * @see #getUseSeriesOffset() - */ - public void setItemMargin(double margin) { - if (margin < 0.0 || margin >= 1.0) { - throw new IllegalArgumentException("Requires 0.0 <= margin < 1.0."); - } - this.itemMargin = margin; - fireChangeEvent(); - } - - /** - * Returns <code>true</code> if outlines should be drawn for shapes, and - * <code>false</code> otherwise. - * - * @return A boolean. - * - * @see #setDrawOutlines(boolean) - */ - public boolean getDrawOutlines() { - return this.drawOutlines; - } - - /** - * Sets the flag that controls whether outlines are drawn for - * shapes, and sends a {@link RendererChangeEvent} to all registered - * listeners. - * <p/> - * In some cases, shapes look better if they do NOT have an outline, but - * this flag allows you to set your own preference. - * - * @param flag the flag. - * - * @see #getDrawOutlines() - */ - public void setDrawOutlines(boolean flag) { - this.drawOutlines = flag; - fireChangeEvent(); - } - - /** - * Returns the flag that controls whether the outline paint is used for - * shape outlines. If not, the regular series paint is used. - * - * @return A boolean. - * - * @see #setUseOutlinePaint(boolean) - */ - public boolean getUseOutlinePaint() { - return this.useOutlinePaint; - } - - /** - * Sets the flag that controls whether the outline paint is used for shape - * outlines, and sends a {@link RendererChangeEvent} to all registered - * listeners. - * - * @param use the flag. - * - * @see #getUseOutlinePaint() - */ - public void setUseOutlinePaint(boolean use) { - this.useOutlinePaint = use; - fireChangeEvent(); - } - - // SHAPES FILLED - - /** - * Returns the flag used to control whether or not the shape for an item - * is filled. The default implementation passes control to the - * <code>getSeriesShapesFilled</code> method. You can override this method - * if you require different behaviour. - * - * @param series the series index (zero-based). - * @param item the item index (zero-based). - * @return A boolean. - */ - public boolean getItemShapeFilled(int series, int item) { - return getSeriesShapesFilled(series); - } - - /** - * Returns the flag used to control whether or not the shapes for a series - * are filled. - * - * @param series the series index (zero-based). - * @return A boolean. - */ - public boolean getSeriesShapesFilled(int series) { - Boolean flag = this.seriesShapesFilled.getBoolean(series); - if (flag != null) { - return flag.booleanValue(); - } - else { - return this.baseShapesFilled; - } - - } - - /** - * Sets the 'shapes filled' flag for a series and sends a - * {@link RendererChangeEvent} to all registered listeners. - * - * @param series the series index (zero-based). - * @param filled the flag. - */ - public void setSeriesShapesFilled(int series, Boolean filled) { - this.seriesShapesFilled.setBoolean(series, filled); - fireChangeEvent(); - } - - /** - * Sets the 'shapes filled' flag for a series and sends a - * {@link RendererChangeEvent} to all registered listeners. - * - * @param series the series index (zero-based). - * @param filled the flag. - */ - public void setSeriesShapesFilled(int series, boolean filled) { - this.seriesShapesFilled.setBoolean(series, - BooleanUtilities.valueOf(filled)); - fireChangeEvent(); - } - - /** - * Returns the base 'shape filled' attribute. - * - * @return The base flag. - */ - public boolean getBaseShapesFilled() { - return this.baseShapesFilled; - } - - /** - * Sets the base 'shapes filled' flag and sends a - * {@link RendererChangeEvent} to all registered listeners. - * - * @param flag the flag. - */ - public void setBaseShapesFilled(boolean flag) { - this.baseShapesFilled = flag; - fireChangeEvent(); - } - - /** - * Returns <code>true</code> if the renderer should use the fill paint - * setting to fill shapes, and <code>false</code> if it should just - * use the regular paint. - * - * @return A boolean. - */ - public boolean getUseFillPaint() { - return this.useFillPaint; - } - - /** - * Sets the flag that controls whether the fill paint is used to fill - * shapes, and sends a {@link RendererChangeEvent} to all - * registered listeners. - * - * @param flag the flag. - */ - public void setUseFillPaint(boolean flag) { - this.useFillPaint = flag; - fireChangeEvent(); - } - - /** - * Draw a single data item. - * - * @param g2 the graphics device. - * @param state the renderer state. - * @param dataArea the area in which the data is drawn. - * @param plot the plot. - * @param domainAxis the domain axis. - * @param rangeAxis the range axis. - * @param dataset the dataset. - * @param row the row index (zero-based). - * @param column the column index (zero-based). - * @param pass the pass index. - */ - public void drawItem(Graphics2D g2, CategoryItemRendererState state, - Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, - ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, - int pass) { - - // do nothing if item is not visible - if (!getItemVisible(row, column)) { - return; - } - - PlotOrientation orientation = plot.getOrientation(); - - MultiValueCategoryDataset d = (MultiValueCategoryDataset) dataset; - List values = d.getValues(row, column); - if (values == null) { - return; - } - int valueCount = values.size(); - for (int i = 0; i < valueCount; i++) { - // current data point... - double x1; - if (this.useSeriesOffset) { - x1 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey( - column), dataset.getRowKey(row), dataset, - this.itemMargin, dataArea, plot.getDomainAxisEdge()); - } - else { - x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), - dataArea, plot.getDomainAxisEdge()); - } - Number n = (Number) values.get(i); - double value = n.doubleValue(); - double y1 = rangeAxis.valueToJava2D(value, dataArea, - plot.getRangeAxisEdge()); - - Shape shape = getItemShape(row, column); - if (orientation == PlotOrientation.HORIZONTAL) { - shape = ShapeUtilities.createTranslatedShape(shape, y1, x1); - } - else if (orientation == PlotOrientation.VERTICAL) { - shape = ShapeUtilities.createTranslatedShape(shape, x1, y1); - } - if (getItemShapeFilled(row, column)) { - if (this.useFillPaint) { - g2.setPaint(getItemFillPaint(row, column)); - } - else { - g2.setPaint(getItemPaint(row, column)); - } - g2.fill(shape); - } - if (this.drawOutlines) { - if (this.useOutlinePaint) { - g2.setPaint(getItemOutlinePaint(row, column)); - } - else { - g2.setPaint(getItemPaint(row, column)); - } - g2.setStroke(getItemOutlineStroke(row, column)); - g2.draw(shape); - } - } - - } - - /** - * Returns a legend item for a series. - * - * @param datasetIndex the dataset index (zero-based). - * @param series the series index (zero-based). - * - * @return The legend item. - */ - public LegendItem getLegendItem(int datasetIndex, int series) { - - CategoryPlot cp = getPlot(); - if (cp == null) { - return null; - } - - if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) { - CategoryDataset dataset = cp.getDataset(datasetIndex); - String label = getLegendItemLabelGenerator().generateLabel( - dataset, series); - String description = label; - String toolTipText = null; - if (getLegendItemToolTipGenerator() != null) { - toolTipText = getLegendItemToolTipGenerator().generateLabel( - dataset, series); - } - String urlText = null; - if (getLegendItemURLGenerator() != null) { - urlText = getLegendItemURLGenerator().generateLabel( - dataset, series); - } - Shape shape = lookupLegendShape(series); - Paint paint = lookupSeriesPaint(series); - Paint fillPaint = (this.useFillPaint - ? getItemFillPaint(series, 0) : paint); - boolean shapeOutlineVisible = this.drawOutlines; - Paint outlinePaint = (this.useOutlinePaint - ? getItemOutlinePaint(series, 0) : paint); - Stroke outlineStroke = lookupSeriesOutlineStroke(series); - LegendItem result = new LegendItem(label, description, toolTipText, - urlText, true, shape, getItemShapeFilled(series, 0), - fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, - false, new Line2D.Double(-7.0, 0.0, 7.0, 0.0), - getItemStroke(series, 0), getItemPaint(series, 0)); - result.setLabelFont(lookupLegendTextFont(series)); - Paint labelPaint = lookupLegendTextPaint(series); - if (labelPaint != null) { - result.setLabelPaint(labelPaint); - } - result.setDataset(dataset); - result.setDatasetIndex(datasetIndex); - result.setSeriesKey(dataset.getRowKey(series)); - result.setSeriesIndex(series); - return result; - } - return null; - - } - - /** - * Tests this renderer for equality with an arbitrary object. - * - * @param obj the object (<code>null</code> permitted). - * @return A boolean. - */ - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof ScatterRenderer)) { - return false; - } - ScatterRenderer that = (ScatterRenderer) obj; - if (!ObjectUtilities.equal(this.seriesShapesFilled, - that.seriesShapesFilled)) { - return false; - } - if (this.baseShapesFilled != that.baseShapesFilled) { - return false; - } - if (this.useFillPaint != that.useFillPaint) { - return false; - } - if (this.drawOutlines != that.drawOutlines) { - return false; - } - if (this.useOutlinePaint != that.useOutlinePaint) { - return false; - } - if (this.useSeriesOffset != that.useSeriesOffset) { - return false; - } - if (this.itemMargin != that.itemMargin) { - return false; - } - return super.equals(obj); - } - - /** - * Returns an independent copy of the renderer. - * - * @return A clone. - * - * @throws CloneNotSupportedException should not happen. - */ - public Object clone() throws CloneNotSupportedException { - ScatterRenderer clone = (ScatterRenderer) super.clone(); - clone.seriesShapesFilled - = (BooleanList) this.seriesShapesFilled.clone(); - return clone; - } - - /** - * Provides serialization support. - * - * @param stream the output stream. - * @throws java.io.IOException if there is an I/O error. - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - - } - - /** - * Provides serialization support. - * - * @param stream the input stream. - * @throws java.io.IOException if there is an I/O error. - * @throws ClassNotFoundException if there is a classpath problem. - */ - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - - } - -} +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. + * + * Project Info: http://www.jfree.org/jfreechart/index.html + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * -------------------- + * ScatterRenderer.java + * -------------------- + * (C) Copyright 2007-2009, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): David Forslund; + * Peter Kolb (patch 2497611); + * + * Changes + * ------- + * 08-Oct-2007 : Version 1, based on patch 1780779 by David Forslund (DG); + * 11-Oct-2007 : Renamed ScatterRenderer (DG); + * 17-Jun-2008 : Apply legend shape, font and paint attributes (DG); + * 14-Jan-2009 : Added support for seriesVisible flags (PK); + * + */ + +package org.jfree.chart.renderer.category; + +import java.awt.Graphics2D; +import java.awt.Paint; +import java.awt.Shape; +import java.awt.Stroke; +import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.List; + +import org.jfree.chart.LegendItem; +import org.jfree.chart.axis.CategoryAxis; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.event.RendererChangeEvent; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.data.category.CategoryDataset; +import org.jfree.data.statistics.MultiValueCategoryDataset; +import org.jfree.util.BooleanList; +import org.jfree.util.BooleanUtilities; +import org.jfree.util.ObjectUtilities; +import org.jfree.util.PublicCloneable; +import org.jfree.util.ShapeUtilities; + +/** + * A renderer that handles the multiple values from a + * {@link MultiValueCategoryDataset} by plotting a shape for each value for + * each given item in the dataset. The example shown here is generated by + * the <code>ScatterRendererDemo1.java</code> program included in the + * JFreeChart Demo Collection: + * <br><br> + * <img src="../../../../../images/ScatterRendererSample.png" + * alt="ScatterRendererSample.png" /> + * + * @since 1.0.7 + */ +public class ScatterRenderer extends AbstractCategoryItemRenderer + implements Cloneable, PublicCloneable, Serializable { + + /** + * A table of flags that control (per series) whether or not shapes are + * filled. + */ + private BooleanList seriesShapesFilled; + + /** + * The default value returned by the getShapeFilled() method. + */ + private boolean baseShapesFilled; + + /** + * A flag that controls whether the fill paint is used for filling + * shapes. + */ + private boolean useFillPaint; + + /** + * A flag that controls whether outlines are drawn for shapes. + */ + private boolean drawOutlines; + + /** + * A flag that controls whether the outline paint is used for drawing shape + * outlines - if not, the regular series paint is used. + */ + private boolean useOutlinePaint; + + /** + * A flag that controls whether or not the x-position for each item is + * offset within the category according to the series. + */ + private boolean useSeriesOffset; + + /** + * The item margin used for series offsetting - this allows the positioning + * to match the bar positions of the {@link BarRenderer} class. + */ + private double itemMargin; + + /** + * Constructs a new renderer. + */ + public ScatterRenderer() { + this.seriesShapesFilled = new BooleanList(); + this.baseShapesFilled = true; + this.useFillPaint = false; + this.drawOutlines = false; + this.useOutlinePaint = false; + this.useSeriesOffset = true; + this.itemMargin = 0.20; + } + + /** + * Returns the flag that controls whether or not the x-position for each + * data item is offset within the category according to the series. + * + * @return A boolean. + * + * @see #setUseSeriesOffset(boolean) + */ + public boolean getUseSeriesOffset() { + return this.useSeriesOffset; + } + + /** + * Sets the flag that controls whether or not the x-position for each + * data item is offset within its category according to the series, and + * sends a {@link RendererChangeEvent} to all registered listeners. + * + * @param offset the offset. + * + * @see #getUseSeriesOffset() + */ + public void setUseSeriesOffset(boolean offset) { + this.useSeriesOffset = offset; + fireChangeEvent(); + } + + /** + * Returns the item margin, which is the gap between items within a + * category (expressed as a percentage of the overall category width). + * This can be used to match the offset alignment with the bars drawn by + * a {@link BarRenderer}). + * + * @return The item margin. + * + * @see #setItemMargin(double) + * @see #getUseSeriesOffset() + */ + public double getItemMargin() { + return this.itemMargin; + } + + /** + * Sets the item margin, which is the gap between items within a category + * (expressed as a percentage of the overall category width), and sends + * a {@link RendererChangeEvent} to all registered listeners. + * + * @param margin the margin (0.0 <= margin < 1.0). + * + * @see #getItemMargin() + * @see #getUseSeriesOffset() + */ + public void setItemMargin(double margin) { + if (margin < 0.0 || margin >= 1.0) { + throw new IllegalArgumentException("Requires 0.0 <= margin < 1.0."); + } + this.itemMargin = margin; + fireChangeEvent(); + } + + /** + * Returns <code>true</code> if outlines should be drawn for shapes, and + * <code>false</code> otherwise. + * + * @return A boolean. + * + * @see #setDrawOutlines(boolean) + */ + public boolean getDrawOutlines() { + return this.drawOutlines; + } + + /** + * Sets the flag that controls whether outlines are drawn for + * shapes, and sends a {@link RendererChangeEvent} to all registered + * listeners. + * <p/> + * In some cases, shapes look better if they do NOT have an outline, but + * this flag allows you to set your own preference. + * + * @param flag the flag. + * + * @see #getDrawOutlines() + */ + public void setDrawOutlines(boolean flag) { + this.drawOutlines = flag; + fireChangeEvent(); + } + + /** + * Returns the flag that controls whether the outline paint is used for + * shape outlines. If not, the regular series paint is used. + * + * @return A boolean. + * + * @see #setUseOutlinePaint(boolean) + */ + public boolean getUseOutlinePaint() { + return this.useOutlinePaint; + } + + /** + * Sets the flag that controls whether the outline paint is used for shape + * outlines, and sends a {@link RendererChangeEvent} to all registered + * listeners. + * + * @param use the flag. + * + * @see #getUseOutlinePaint() + */ + public void setUseOutlinePaint(boolean use) { + this.useOutlinePaint = use; + fireChangeEvent(); + } + + // SHAPES FILLED + + /** + * Returns the flag used to control whether or not the shape for an item + * is filled. The default implementation passes control to the + * <code>getSeriesShapesFilled</code> method. You can override this method + * if you require different behaviour. + * + * @param series the series index (zero-based). + * @param item the item index (zero-based). + * @return A boolean. + */ + public boolean getItemShapeFilled(int series, int item) { + return getSeriesShapesFilled(series); + } + + /** + * Returns the flag used to control whether or not the shapes for a series + * are filled. + * + * @param series the series index (zero-based). + * @return A boolean. + */ + public boolean getSeriesShapesFilled(int series) { + Boolean flag = this.seriesShapesFilled.getBoolean(series); + if (flag != null) { + return flag.booleanValue(); + } + else { + return this.baseShapesFilled; + } + + } + + /** + * Sets the 'shapes filled' flag for a series and sends a + * {@link RendererChangeEvent} to all registered listeners. + * + * @param series the series index (zero-based). + * @param filled the flag. + */ + public void setSeriesShapesFilled(int series, Boolean filled) { + this.seriesShapesFilled.setBoolean(series, filled); + fireChangeEvent(); + } + + /** + * Sets the 'shapes filled' flag for a series and sends a + * {@link RendererChangeEvent} to all registered listeners. + * + * @param series the series index (zero-based). + * @param filled the flag. + */ + public void setSeriesShapesFilled(int series, boolean filled) { + this.seriesShapesFilled.setBoolean(series, + BooleanUtilities.valueOf(filled)); + fireChangeEvent(); + } + + /** + * Returns the base 'shape filled' attribute. + * + * @return The base flag. + */ + public boolean getBaseShapesFilled() { + return this.baseShapesFilled; + } + + /** + * Sets the base 'shapes filled' flag and sends a + * {@link RendererChangeEvent} to all registered listeners. + * + * @param flag the flag. + */ + public void setBaseShapesFilled(boolean flag) { + this.baseShapesFilled = flag; + fireChangeEvent(); + } + + /** + * Returns <code>true</code> if the renderer should use the fill paint + * setting to fill shapes, and <code>false</code> if it should just + * use the regular paint. + * + * @return A boolean. + */ + public boolean getUseFillPaint() { + return this.useFillPaint; + } + + /** + * Sets the flag that controls whether the fill paint is used to fill + * shapes, and sends a {@link RendererChangeEvent} to all + * registered listeners. + * + * @param flag the flag. + */ + public void setUseFillPaint(boolean flag) { + this.useFillPaint = flag; + fireChangeEvent(); + } + + /** + * Draw a single data item. + * + * @param g2 the graphics device. + * @param state the renderer state. + * @param dataArea the area in which the data is drawn. + * @param plot the plot. + * @param domainAxis the domain axis. + * @param rangeAxis the range axis. + * @param dataset the dataset. + * @param row the row index (zero-based). + * @param column the column index (zero-based). + * @param pass the pass index. + */ + public void drawItem(Graphics2D g2, CategoryItemRendererState state, + Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, + ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, + int pass) { + + // do nothing if item is not visible + if (!getItemVisible(row, column)) { + return; + } + int visibleRow = state.getVisibleSeriesIndex(row); + if (visibleRow < 0) { + return; + } + int visibleRowCount = state.getVisibleSeriesCount(); + + PlotOrientation orientation = plot.getOrientation(); + + MultiValueCategoryDataset d = (MultiValueCategoryDataset) dataset; + List values = d.getValues(row, column); + if (values == null) { + return; + } + int valueCount = values.size(); + for (int i = 0; i < valueCount; i++) { + // current data point... + double x1; + if (this.useSeriesOffset) { + /*x1 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey( + column), dataset.getRowKey(row), dataset, + this.itemMargin, dataArea, plot.getDomainAxisEdge());*/ + x1 = domainAxis.getCategorySeriesMiddle(column,dataset.getColumnCount(), + visibleRow, visibleRowCount, + this.itemMargin, dataArea, plot.getDomainAxisEdge()); + + } + else { + x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), + dataArea, plot.getDomainAxisEdge()); + } + Number n = (Number) values.get(i); + double value = n.doubleValue(); + double y1 = rangeAxis.valueToJava2D(value, dataArea, + plot.getRangeAxisEdge()); + + Shape shape = getItemShape(row, column); + if (orientation == PlotOrientation.HORIZONTAL) { + shape = ShapeUtilities.createTranslatedShape(shape, y1, x1); + } + else if (orientation == PlotOrientation.VERTICAL) { + shape = ShapeUtilities.createTranslatedShape(shape, x1, y1); + } + if (getItemShapeFilled(row, column)) { + if (this.useFillPaint) { + g2.setPaint(getItemFillPaint(row, column)); + } + else { + g2.setPaint(getItemPaint(row, column)); + } + g2.fill(shape); + } + if (this.drawOutlines) { + if (this.useOutlinePaint) { + g2.setPaint(getItemOutlinePaint(row, column)); + } + else { + g2.setPaint(getItemPaint(row, column)); + } + g2.setStroke(getItemOutlineStroke(row, column)); + g2.draw(shape); + } + } + + } + + /** + * Returns a legend item for a series. + * + * @param datasetIndex the dataset index (zero-based). + * @param series the series index (zero-based). + * + * @return The legend item. + */ + public LegendItem getLegendItem(int datasetIndex, int series) { + + CategoryPlot cp = getPlot(); + if (cp == null) { + return null; + } + + if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) { + CategoryDataset dataset = cp.getDataset(datasetIndex); + String label = getLegendItemLabelGenerator().generateLabel( + dataset, series); + String description = label; + String toolTipText = null; + if (getLegendItemToolTipGenerator() != null) { + toolTipText = getLegendItemToolTipGenerator().generateLabel( + dataset, series); + } + String urlText = null; + if (getLegendItemURLGenerator() != null) { + urlText = getLegendItemURLGenerator().generateLabel( + dataset, series); + } + Shape shape = lookupLegendShape(series); + Paint paint = lookupSeriesPaint(series); + Paint fillPaint = (this.useFillPaint + ? getItemFillPaint(series, 0) : paint); + boolean shapeOutlineVisible = this.drawOutlines; + Paint outlinePaint = (this.useOutlinePaint + ? getItemOutlinePaint(series, 0) : paint); + Stroke outlineStroke = lookupSeriesOutlineStroke(series); + LegendItem result = new LegendItem(label, description, toolTipText, + urlText, true, shape, getItemShapeFilled(series, 0), + fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, + false, new Line2D.Double(-7.0, 0.0, 7.0, 0.0), + getItemStroke(series, 0), getItemPaint(series, 0)); + result.setLabelFont(lookupLegendTextFont(series)); + Paint labelPaint = lookupLegendTextPaint(series); + if (labelPaint != null) { + result.setLabelPaint(labelPaint); + } + result.setDataset(dataset); + result.setDatasetIndex(datasetIndex); + result.setSeriesKey(dataset.getRowKey(series)); + result.setSeriesIndex(series); + return result; + } + return null; + + } + + /** + * Tests this renderer for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> permitted). + * @return A boolean. + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof ScatterRenderer)) { + return false; + } + ScatterRenderer that = (ScatterRenderer) obj; + if (!ObjectUtilities.equal(this.seriesShapesFilled, + that.seriesShapesFilled)) { + return false; + } + if (this.baseShapesFilled != that.baseShapesFilled) { + return false; + } + if (this.useFillPaint != that.useFillPaint)... [truncated message content] |