From: <mu...@us...> - 2007-09-26 10:16:51
|
Revision: 180 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=180&view=rev Author: mungady Date: 2007-09-26 03:16:48 -0700 (Wed, 26 Sep 2007) Log Message: ----------- 2007-09-26 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/XYPlot.java (getQuadrantPaint): Improve exception text, (setQuadrantPaint): Likewise, (getDomainAxisForDataset): Likewise, (getRangeAxisForDataset): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/XYPlot.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 09:48:12 UTC (rev 179) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 10:16:48 UTC (rev 180) @@ -1,5 +1,13 @@ 2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/XYPlot.java + (getQuadrantPaint): Improve exception text, + (setQuadrantPaint): Likewise, + (getDomainAxisForDataset): Likewise, + (getRangeAxisForDataset): Likewise. + +2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/Marker.java (readObject): Initialise listener list, * tests/org/jfree/chart/plot/junit/ValueMarkerTests.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/XYPlot.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/XYPlot.java 2007-09-26 09:48:12 UTC (rev 179) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/XYPlot.java 2007-09-26 10:16:48 UTC (rev 180) @@ -188,6 +188,7 @@ * 07-Jun-2007 : Modified drawBackground() to pass orientation to * fillBackground() for handling GradientPaint (DG); * 24-Sep-2007 : Added new zoom methods (DG); + * 26-Sep-2007 : Include index value in IllegalArgumentExceptions (DG); * */ @@ -2019,8 +2020,8 @@ */ public Paint getQuadrantPaint(int index) { if (index < 0 || index > 3) { - throw new IllegalArgumentException( - "The index should be in the range 0 to 3."); + throw new IllegalArgumentException("The index value (" + index + + ") should be in the range 0 to 3."); } return this.quadrantPaint[index]; } @@ -2036,8 +2037,8 @@ */ public void setQuadrantPaint(int index, Paint paint) { if (index < 0 || index > 3) { - throw new IllegalArgumentException( - "The index should be in the range 0 to 3."); + throw new IllegalArgumentException("The index value (" + index + + ") should be in the range 0 to 3."); } this.quadrantPaint[index] = paint; notifyListeners(new PlotChangeEvent(this)); @@ -3145,7 +3146,8 @@ public ValueAxis getDomainAxisForDataset(int index) { if (index < 0 || index >= getDatasetCount()) { - throw new IllegalArgumentException("Index 'index' out of bounds."); + throw new IllegalArgumentException("Index " + index + + " out of bounds."); } ValueAxis valueAxis = null; @@ -3171,7 +3173,8 @@ public ValueAxis getRangeAxisForDataset(int index) { if (index < 0 || index >= getDatasetCount()) { - throw new IllegalArgumentException("Index 'index' out of bounds."); + throw new IllegalArgumentException("Index " + index + + " out of bounds."); } ValueAxis valueAxis = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-26 11:01:38
|
Revision: 182 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=182&view=rev Author: mungady Date: 2007-09-26 04:01:36 -0700 (Wed, 26 Sep 2007) Log Message: ----------- 2007-09-26 David Gilbert <dav...@ob...> * source/org/jfree/data/general/Series.java (getItemCount): New abstract method, (isEmpty): New method. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/general/Series.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 10:46:58 UTC (rev 181) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 11:01:36 UTC (rev 182) @@ -1,5 +1,11 @@ 2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/data/general/Series.java + (getItemCount): New abstract method, + (isEmpty): New method. + +2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/XYPlot.java (getQuadrantPaint): Improve exception text, (setQuadrantPaint): Likewise, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/general/Series.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/general/Series.java 2007-09-26 10:46:58 UTC (rev 181) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/general/Series.java 2007-09-26 11:01:36 UTC (rev 182) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ----------- * Series.java * ----------- - * (C) Copyright 2001-2006, by Object Refinery Limited. + * (C) Copyright 2001-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -48,8 +48,9 @@ * 15-Oct-2003 : Added a flag to control whether or not change events are sent * to registered listeners (DG); * 19-May-2005 : Made abstract (DG); - * ------------- JFREECHART 1.0.0 --------------------------------------------- + * ------------- JFREECHART 1.0.x --------------------------------------------- * 04-May-2006 : Updated API docs (DG); + * 26-Sep-2007 : Added isEmpty() and getItemCount() methods (DG); * */ @@ -201,6 +202,25 @@ } /** + * Returns <code>true</code> if the series contains no data items, and + * <code>false</code> otherwise. + * + * @return A boolean. + * + * @since 1.0.7 + */ + public boolean isEmpty() { + return (getItemCount() == 0); + } + + /** + * Returns the number of data items in the series. + * + * @return The number of data items in the series. + */ + public abstract int getItemCount(); + + /** * Returns a clone of the series. * <P> * Notes: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-26 12:40:15
|
Revision: 184 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=184&view=rev Author: mungady Date: 2007-09-26 05:40:12 -0700 (Wed, 26 Sep 2007) Log Message: ----------- 2007-09-26 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/PlotUtilities.java: New class, * source/org/jfree/data/general/DatasetUtilities.java (isEmptyOrNull(XYDataset)): Return early if not empty, * tests/org/jfree/data/general/junit/DatasetUtilitiesTests.java (testIsEmptyOrNullXYDataset): New test method. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/general/DatasetUtilities.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/general/junit/DatasetUtilitiesTests.java Added Paths: ----------- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PlotUtilities.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 11:03:59 UTC (rev 183) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 12:40:12 UTC (rev 184) @@ -1,5 +1,13 @@ 2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/PlotUtilities.java: New class, + * source/org/jfree/data/general/DatasetUtilities.java + (isEmptyOrNull(XYDataset)): Return early if not empty, + * tests/org/jfree/data/general/junit/DatasetUtilitiesTests.java + (testIsEmptyOrNullXYDataset): New test method. + +2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/data/general/Series.java (getItemCount): New abstract method, (isEmpty): New method. Added: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PlotUtilities.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PlotUtilities.java (rev 0) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PlotUtilities.java 2007-09-26 12:40:12 UTC (rev 184) @@ -0,0 +1,76 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, 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.] + * + * ------------------ + * PlotUtilities.java + * ------------------ + * (C) Copyright 2007, by Sergei Ivanov and Contributors. + * + * Original Author: Sergei Ivanov; + * Contributor(s): David Gilbert (for Object Refinery Limited); + * + * $Id: ChartUtilities.java,v 1.4.2.4 2007/03/19 14:07:53 mungady Exp $ + * + * Changes + * ------- + * 26-Sep-2007 : Version 1, contributed by Sergei Ivanov (see patch + * 1772932) (DG); + * + */ + +package org.jfree.chart.plot; + +import org.jfree.data.general.DatasetUtilities; +import org.jfree.data.xy.XYDataset; + +/** + * Some utility methods related to the plot classes. + */ +public class PlotUtilities { + + /** + * Returns <code>true</code> if all the datasets belonging to the specified + * plot are empty or <code>null</code>, and <code>false</code> otherwise. + * + * @param plot the plot (<code>null</code> permitted). + * + * @return A boolean. + * + * @since 1.0.7 + */ + public static boolean isEmptyOrNull(XYPlot plot) { + if (plot != null) { + for (int i = 0, n = plot.getDatasetCount(); i < n; i++) { + final XYDataset dataset = plot.getDataset(i); + if (!DatasetUtilities.isEmptyOrNull(dataset)) { + return false; + } + } + } + return true; + } + +} Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/general/DatasetUtilities.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/general/DatasetUtilities.java 2007-09-26 11:03:59 UTC (rev 183) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/general/DatasetUtilities.java 2007-09-26 12:40:12 UTC (rev 184) @@ -592,20 +592,14 @@ * @return A boolean. */ public static boolean isEmptyOrNull(XYDataset dataset) { - - boolean result = true; - if (dataset != null) { for (int s = 0; s < dataset.getSeriesCount(); s++) { if (dataset.getItemCount(s) > 0) { - result = false; - continue; + return false; } } } - - return result; - + return true; } /** Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/general/junit/DatasetUtilitiesTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/general/junit/DatasetUtilitiesTests.java 2007-09-26 11:03:59 UTC (rev 183) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/general/junit/DatasetUtilitiesTests.java 2007-09-26 12:40:12 UTC (rev 184) @@ -41,7 +41,8 @@ * 04-Oct-2004 : Eliminated NumberUtils usage (DG); * 07-Jan-2005 : Updated for method name changes (DG); * 03-Feb-2005 : Added testFindStackedRangeBounds2() method (DG); - * + * 26-Sep-2007 : Added testIsEmptyOrNullXYDataset() method (DG); + * */ package org.jfree.data.general.junit; @@ -50,7 +51,6 @@ import junit.framework.TestCase; import junit.framework.TestSuite; -import org.jfree.data.DomainOrder; import org.jfree.data.KeyToGroupMap; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; @@ -59,7 +59,6 @@ import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; import org.jfree.data.xy.DefaultTableXYDataset; -import org.jfree.data.xy.DefaultXYDataset; import org.jfree.data.xy.TableXYDataset; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; @@ -409,6 +408,23 @@ } /** + * Some checks for the isEmptyOrNull(XYDataset) method. + */ + public void testIsEmptyOrNullXYDataset() { + XYSeriesCollection dataset = null; + assertTrue(DatasetUtilities.isEmptyOrNull(dataset)); + dataset = new XYSeriesCollection(); + assertTrue(DatasetUtilities.isEmptyOrNull(dataset)); + XYSeries s1 = new XYSeries("S1"); + dataset.addSeries(s1); + assertTrue(DatasetUtilities.isEmptyOrNull(dataset)); + s1.add(1.0, 2.0); + assertFalse(DatasetUtilities.isEmptyOrNull(dataset)); + s1.clear(); + assertTrue(DatasetUtilities.isEmptyOrNull(dataset)); + } + + /** * Some checks for the limitPieDataset() methods. */ public void testLimitPieDataset() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-26 13:30:01
|
Revision: 187 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=187&view=rev Author: mungady Date: 2007-09-26 06:29:57 -0700 (Wed, 26 Sep 2007) Log Message: ----------- 2007-09-26 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/xy/XYBarRenderer.java (drawItem): Apply margin in a way that works for inverted axes. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYBarRenderer.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 13:28:36 UTC (rev 186) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 13:29:57 UTC (rev 187) @@ -1,5 +1,10 @@ 2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/xy/XYBarRenderer.java + (drawItem): Apply margin in a way that works for inverted axes. + +2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/PlotUtilities.java: New class, * source/org/jfree/data/general/DatasetUtilities.java (isEmptyOrNull(XYDataset)): Return early if not empty, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYBarRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYBarRenderer.java 2007-09-26 13:28:36 UTC (rev 186) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYBarRenderer.java 2007-09-26 13:29:57 UTC (rev 187) @@ -33,6 +33,7 @@ * Contributor(s): Richard Atkinson; * Christian W. Zuckschwerdt; * Bill Kelemen; + * Marc van Glabbeek (bug 1775452); * * $Id: XYBarRenderer.java,v 1.14.2.17 2007/06/15 12:43:24 mungady Exp $ * @@ -86,6 +87,8 @@ * 17-May-2007 : Set datasetIndex and seriesIndex in getLegendItem() (DG); * 18-May-2007 : Set dataset and seriesKey for LegendItem (DG); * 15-Jun-2007 : Changed default for drawBarOutline to false (DG); + * 26-Sep-2007 : Fixed bug 1775452, problem with bar margins for inverted + * axes, thanks to Marc van Glabbeek (DG); * */ @@ -627,11 +630,12 @@ double translatedWidth = Math.max(1, Math.abs(translatedEndX - translatedStartX)); - + + double left = Math.min(translatedStartX, translatedEndX); if (getMargin() > 0.0) { double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; - translatedStartX = translatedStartX + cut / 2; + left = left + cut / 2; } Rectangle2D bar = null; @@ -641,18 +645,14 @@ bottom = Math.max(bottom, dataArea.getMinX()); top = Math.min(top, dataArea.getMaxX()); bar = new Rectangle2D.Double( - bottom, - Math.min(translatedStartX, translatedEndX), - top - bottom, translatedWidth); + bottom, left, top - bottom, translatedWidth); } else if (orientation == PlotOrientation.VERTICAL) { // clip top and bottom bounds to data area bottom = Math.max(bottom, dataArea.getMinY()); top = Math.min(top, dataArea.getMaxY()); - bar = new Rectangle2D.Double( - Math.min(translatedStartX, translatedEndX), - bottom, - translatedWidth, top - bottom); + bar = new Rectangle2D.Double(left, bottom, translatedWidth, + top - bottom); } Paint itemPaint = getItemPaint(series, item); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-26 13:55:16
|
Revision: 189 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=189&view=rev Author: mungady Date: 2007-09-26 06:55:12 -0700 (Wed, 26 Sep 2007) Log Message: ----------- 2007-09-26 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/GrayPaintScale.java (getPaint): Use constrained value to calculate gray scale value, * tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java (testConstructor): New test method, (testGetPaint): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/GrayPaintScale.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 13:34:39 UTC (rev 188) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 13:55:12 UTC (rev 189) @@ -1,5 +1,13 @@ 2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/GrayPaintScale.java + (getPaint): Use constrained value to calculate gray scale value, + * tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java + (testConstructor): New test method, + (testGetPaint): Likewise. + +2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/xy/XYBarRenderer.java (drawItem): Apply margin in a way that works for inverted axes. Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/GrayPaintScale.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/GrayPaintScale.java 2007-09-26 13:34:39 UTC (rev 188) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/GrayPaintScale.java 2007-09-26 13:55:12 UTC (rev 189) @@ -38,6 +38,7 @@ * ------- * 05-Jul-2006 : Version 1 (DG); * 31-Jan-2007 : Renamed min and max to lowerBound and upperBound (DG); + * 26-Sep-2007 : Fixed bug 1767315, problem in getPaint() method (DG); * */ @@ -75,6 +76,9 @@ * * @param lowerBound the lower bound. * @param upperBound the upper bound. + * + * @throws IllegalArgumentException if <code>lowerBound</code> is not + * less than <code>upperBound</code>. */ public GrayPaintScale(double lowerBound, double upperBound) { if (lowerBound >= upperBound) { @@ -89,6 +93,8 @@ * Returns the lower bound. * * @return The lower bound. + * + * @see #getUpperBound() */ public double getLowerBound() { return this.lowerBound; @@ -98,6 +104,8 @@ * Returns the upper bound. * * @return The upper bound. + * + * @see #getLowerBound() */ public double getUpperBound() { return this.upperBound; @@ -106,14 +114,15 @@ /** * Returns a paint for the specified value. * - * @param value the value. + * @param value the value (must be within the range specified by the + * lower and upper bounds for the scale). * * @return A paint for the specified value. */ public Paint getPaint(double value) { double v = Math.max(value, this.lowerBound); v = Math.min(v, this.upperBound); - int g = (int) ((value - this.lowerBound) / (this.upperBound + int g = (int) ((v - this.lowerBound) / (this.upperBound - this.lowerBound) * 255.0); return new Color(g, g, g); } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java 2007-09-26 13:34:39 UTC (rev 188) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java 2007-09-26 13:55:12 UTC (rev 189) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------ * GrayPaintScaleTests.java * ------------------------ - * (C) Copyright 2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2006, 2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -37,11 +37,13 @@ * Changes * ------- * 05-Jul-2006 : Version 1 (DG); + * 26-Sep-2007 : Added testConstructor() and testGetPaint() (DG); * */ package org.jfree.chart.renderer.junit; +import java.awt.Color; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInput; @@ -49,13 +51,13 @@ import java.io.ObjectOutput; import java.io.ObjectOutputStream; -import org.jfree.chart.renderer.GrayPaintScale; - import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; +import org.jfree.chart.renderer.GrayPaintScale; + /** * Tests for the {@link GrayPaintScale} class. */ @@ -79,7 +81,36 @@ super(name); } + private static final double EPSILON = 0.000000001; + + /** + * Simple check for the default constructor. + */ + public void testConstructor() { + GrayPaintScale gps = new GrayPaintScale(); + assertEquals(0.0, gps.getLowerBound(), EPSILON); + assertEquals(1.0, gps.getUpperBound(), EPSILON); + } + /** + * Some checks for the getPaint() method. + */ + public void testGetPaint() { + GrayPaintScale gps = new GrayPaintScale(); + Color c = (Color) gps.getPaint(0.0); + assertTrue(c.equals(Color.black)); + c = (Color) gps.getPaint(1.0); + assertTrue(c.equals(Color.white)); + + // check lookup values that are outside the bounds - see bug report + // 1767315 + c = (Color) gps.getPaint(-0.5); + assertTrue(c.equals(Color.black)); + c = (Color) gps.getPaint(1.5); + assertTrue(c.equals(Color.white)); + } + + /** * A test for the equals() method. */ public void testEquals() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-26 16:45:30
|
Revision: 193 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=193&view=rev Author: mungady Date: 2007-09-26 09:04:29 -0700 (Wed, 26 Sep 2007) Log Message: ----------- 2007-09-26 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java (drawItem): Simplified entity generation code. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog 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 2007-09-26 15:50:15 UTC (rev 192) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 16:04:29 UTC (rev 193) @@ -1,5 +1,10 @@ 2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java + (drawItem): Simplified entity generation code. + +2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/GrayPaintScale.java (getPaint): Use constrained value to calculate gray scale value, * tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java 2007-09-26 15:50:15 UTC (rev 192) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java 2007-09-26 16:04:29 UTC (rev 193) @@ -39,7 +39,7 @@ * 01-Feb-2005 : Version 1, contributed by Mofeed Shahin (DG); * 16-Jun-2005 : Added errorIndicatorPaint to be consistent with * StatisticalBarRenderer (DG); - * ------------- JFREECHART 1.0.0 --------------------------------------------- + * ------------- JFREECHART 1.0.x --------------------------------------------- * 11-Apr-2006 : Fixed bug 1468794, error bars drawn incorrectly when rendering * plots with horizontal orientation (DG); * 25-Sep-2006 : Fixed bug 1562759, constructor ignoring arguments (DG); @@ -64,10 +64,8 @@ import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.entity.CategoryItemEntity; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.event.RendererChangeEvent; -import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.CategoryDataset; @@ -116,6 +114,8 @@ * * @return The paint used for the error indicators (possibly * <code>null</code>). + * + * @see #setErrorIndicatorPaint(Paint) */ public Paint getErrorIndicatorPaint() { return this.errorIndicatorPaint; @@ -123,9 +123,12 @@ /** * Sets the paint used for the error indicators (if <code>null</code>, - * the item outline paint is used instead) + * the item outline paint is used instead) and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> permitted). + * + * @see #getErrorIndicatorPaint() */ public void setErrorIndicatorPaint(Paint paint) { this.errorIndicatorPaint = paint; @@ -315,28 +318,10 @@ } } - // collect entity and tool tip information... - if (state.getInfo() != null) { - EntityCollection entities = state.getEntityCollection(); - if (entities != null && shape != null) { - String tip = null; - CategoryToolTipGenerator tipster = getToolTipGenerator(row, - column); - if (tipster != null) { - tip = tipster.generateToolTip(dataset, row, column); - } - String url = null; - if (getItemURLGenerator(row, column) != null) { - url = getItemURLGenerator(row, column).generateURL( - dataset, row, column); - } - CategoryItemEntity entity = new CategoryItemEntity(shape, tip, - url, dataset, dataset.getRowKey(row), - dataset.getColumnKey(column)); - entities.add(entity); - - } - + // add an item entity, if this information is being collected + EntityCollection entities = state.getEntityCollection(); + if (entities != null && shape != null) { + addItemEntity(entities, dataset, row, column, shape); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-27 10:06:15
|
Revision: 194 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=194&view=rev Author: mungady Date: 2007-09-27 03:06:13 -0700 (Thu, 27 Sep 2007) Log Message: ----------- 2007-09-27 David Gilbert <dav...@ob...> * source/org/jfree/chart/axis/CategoryAxis.java (getCategorySeriesMiddle): New method, * source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java (useSeriesOffset): New field, (itemMargin): Likewise, (LineAndShapeRenderer(boolean, boolean)): Initialise new fields, (getUseSeriesOffset): New method, (setUseSeriesOffset): Likewise, (getItemMargin): Likewise, (setItemMargin): Likewise, (drawItem): Apply new offset option to x-coordinates, (equals): Check new fields, * tests/org/jfree/chart/renderer/category/junit/LineAndShapeRendererTests.java (testEquals): Updated for new fields. 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/LineAndShapeRenderer.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 16:04:29 UTC (rev 193) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-27 10:06:13 UTC (rev 194) @@ -1,3 +1,20 @@ +2007-09-27 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/axis/CategoryAxis.java + (getCategorySeriesMiddle): New method, + * source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java + (useSeriesOffset): New field, + (itemMargin): Likewise, + (LineAndShapeRenderer(boolean, boolean)): Initialise new fields, + (getUseSeriesOffset): New method, + (setUseSeriesOffset): Likewise, + (getItemMargin): Likewise, + (setItemMargin): Likewise, + (drawItem): Apply new offset option to x-coordinates, + (equals): Check new fields, + * tests/org/jfree/chart/renderer/category/junit/LineAndShapeRendererTests.java + (testEquals): Updated for new fields. + 2007-09-26 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java 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 2007-09-26 16:04:29 UTC (rev 193) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/CategoryAxis.java 2007-09-27 10:06:13 UTC (rev 194) @@ -83,6 +83,7 @@ * 30-Oct-2006 : Updated refreshTicks() method to account for possibility of * multiple domain axes (DG); * 07-Mar-2007 : Fixed bug in axis label positioning (DG); + * 27-Sep-2007 : Added getCategorySeriesMiddle() method (DG); * */ @@ -110,6 +111,7 @@ import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotRenderingInfo; +import org.jfree.data.category.CategoryDataset; import org.jfree.io.SerialUtilities; import org.jfree.text.G2TextMeasurer; import org.jfree.text.TextBlock; @@ -645,6 +647,43 @@ + calculateCategorySize(categoryCount, area, edge); } + + /** + * Returns the middle coordinate (in Java2D space) for a series within a + * category. + * + * @param category the category (<code>null</code> not permitted). + * @param seriesKey the series key (<code>null</code> not permitted). + * @param dataset the dataset (<code>null</code> not permitted). + * @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.7 + */ + public double getCategorySeriesMiddle(Comparable category, + Comparable seriesKey, CategoryDataset dataset, double itemMargin, + Rectangle2D area, RectangleEdge edge) { + + int categoryIndex = dataset.getColumnIndex(category); + int categoryCount = dataset.getColumnCount(); + int seriesIndex = dataset.getRowIndex(seriesKey); + int seriesCount = dataset.getRowCount(); + 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 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 2007-09-26 16:04:29 UTC (rev 193) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java 2007-09-27 10:06:13 UTC (rev 194) @@ -86,6 +86,7 @@ * 17-May-2007 : Set datasetIndex and seriesIndex in getLegendItem() (DG); * 18-May-2007 : Set dataset and seriesKey for LegendItem (DG); * 24-Sep-2007 : Deprecated redundant fields/methods (DG); + * 27-Sep-2007 : Added option to offset series x-position within category (DG); * */ @@ -189,8 +190,24 @@ * 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. + * + * @since 1.0.7 + */ + private boolean useSeriesOffset; /** + * The item margin used for series offsetting - this allows the positioning + * to match the bar positions of the {@link BarRenderer} class. + * + * @since 1.0.7 + */ + private double itemMargin; + + /** * Creates a renderer with both lines and shapes visible by default. */ public LineAndShapeRenderer() { @@ -217,6 +234,8 @@ this.useFillPaint = false; this.drawOutlines = true; this.useOutlinePaint = false; + this.useSeriesOffset = false; // preserves old behaviour + this.itemMargin = 0.0; } // LINES VISIBLE @@ -722,6 +741,73 @@ } /** + * 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) + * + * @since 1.0.7 + */ + 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() + * + * @since 1.0.7 + */ + public void setUseSeriesOffset(boolean offset) { + this.useSeriesOffset = offset; + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * 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() + * + * @since 1.0.7 + */ + 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() + * + * @since 1.0.7 + */ + public void setItemMargin(double margin) { + if (margin < 0.0 || margin >= 1.0) { + throw new IllegalArgumentException("Requires 0.0 <= margin < 1.0."); + } + this.itemMargin = margin; + notifyListeners(new RendererChangeEvent(this)); + } + + /** * Returns a legend item for a series. * * @param datasetIndex the dataset index (zero-based). @@ -824,8 +910,16 @@ PlotOrientation orientation = plot.getOrientation(); // current data point... - double x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), - dataArea, plot.getDomainAxisEdge()); + 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()); + } double value = v.doubleValue(); double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); @@ -836,9 +930,19 @@ if (previousValue != null) { // previous data point... double previous = previousValue.doubleValue(); - double x0 = domainAxis.getCategoryMiddle(column - 1, - getColumnCount(), dataArea, - plot.getDomainAxisEdge()); + double x0; + if (this.useSeriesOffset) { + x0 = domainAxis.getCategorySeriesMiddle( + dataset.getColumnKey(column - 1), + dataset.getRowKey(row), dataset, + this.itemMargin, dataArea, + plot.getDomainAxisEdge()); + } + else { + x0 = domainAxis.getCategoryMiddle(column - 1, + getColumnCount(), dataArea, + plot.getDomainAxisEdge()); + } double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge()); @@ -958,6 +1062,12 @@ 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); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-27 11:07:38
|
Revision: 198 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=198&view=rev Author: mungady Date: 2007-09-27 04:07:36 -0700 (Thu, 27 Sep 2007) Log Message: ----------- 2007-09-27 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java (drawItem): Apply new offset option to x-coordinates. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog 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 2007-09-27 10:19:47 UTC (rev 197) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-27 11:07:36 UTC (rev 198) @@ -1,5 +1,10 @@ 2007-09-27 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java + (drawItem): Apply new offset option to x-coordinates. + +2007-09-27 David Gilbert <dav...@ob...> + * source/org/jfree/chart/axis/CategoryAxis.java (getCategorySeriesMiddle): New method, * source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java 2007-09-27 10:19:47 UTC (rev 197) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java 2007-09-27 11:07:36 UTC (rev 198) @@ -47,6 +47,8 @@ * visible (DG); * 14-Jun-2007 : If the dataset is not a StatisticalCategoryDataset, revert * to the drawing behaviour of LineAndShapeRenderer (DG); + * 27-Sep-2007 : Added offset option to match new option in + * LineAndShapeRenderer (DG); * */ @@ -188,8 +190,16 @@ PlotOrientation orientation = plot.getOrientation(); // current data point... - double x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), - dataArea, plot.getDomainAxisEdge()); + double x1; + if (getUseSeriesOffset()) { + x1 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey( + column), dataset.getRowKey(row), dataset, getItemMargin(), + dataArea, plot.getDomainAxisEdge()); + } + else { + x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), + dataArea, plot.getDomainAxisEdge()); + } double y1 = rangeAxis.valueToJava2D(meanValue.doubleValue(), dataArea, plot.getRangeAxisEdge()); @@ -227,9 +237,19 @@ // previous data point... double previous = previousValue.doubleValue(); - double x0 = domainAxis.getCategoryMiddle(column - 1, - getColumnCount(), dataArea, - plot.getDomainAxisEdge()); + double x0; + if (getUseSeriesOffset()) { + x0 = domainAxis.getCategorySeriesMiddle( + dataset.getColumnKey(column - 1), + dataset.getRowKey(row), dataset, + getItemMargin(), dataArea, + plot.getDomainAxisEdge()); + } + else { + x0 = domainAxis.getCategoryMiddle(column - 1, + getColumnCount(), dataArea, + plot.getDomainAxisEdge()); + } double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge()); @@ -248,12 +268,6 @@ } RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); - RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); - double rectX = domainAxis.getCategoryStart(column, getColumnCount(), - dataArea, xAxisLocation); - - rectX = rectX + row * state.getBarWidth(); - g2.setPaint(getItemPaint(row, column)); //standard deviation lines This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-28 09:14:17
|
Revision: 200 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=200&view=rev Author: mungady Date: 2007-09-28 02:14:08 -0700 (Fri, 28 Sep 2007) Log Message: ----------- 2007-09-28 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java (setGroupStroke): Check for null argument, add event notification, (equals): New method override, * tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java (testEquals): Extended to cover additional fields. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-27 11:14:52 UTC (rev 199) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-28 09:14:08 UTC (rev 200) @@ -1,3 +1,11 @@ +2007-09-28 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java + (setGroupStroke): Check for null argument, add event notification, + (equals): New method override, + * tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java + (testEquals): Extended to cover additional fields. + 2007-09-27 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java 2007-09-27 11:14:52 UTC (rev 199) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java 2007-09-28 09:14:08 UTC (rev 200) @@ -55,6 +55,7 @@ * ------------- JFREECHART 1.0.x --------------------------------------------- * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 09-Mar-2007 : Fixed problem with horizontal rendering (DG); + * 28-Sep-2007 : Added equals() method override (DG); * */ @@ -89,6 +90,7 @@ import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.CategoryDataset; import org.jfree.io.SerialUtilities; +import org.jfree.util.PaintUtilities; /** * Renderer for drawing min max plot. This renderer draws all the series under @@ -215,12 +217,17 @@ /** * Sets the stroke of the line between the minimum value and the maximum - * value. + * value and sends a {@link RendererChangeEvent} to all registered + * listeners. * - * @param groupStroke The new stroke + * @param stroke the new stroke (<code>null</code> not permitted). */ - public void setGroupStroke(Stroke groupStroke) { - this.groupStroke = groupStroke; + public void setGroupStroke(Stroke stroke) { + if (stroke == null) { + throw new IllegalArgumentException("Null 'stroke' argument."); + } + this.groupStroke = stroke; + notifyListeners(new RendererChangeEvent(this)); } /** @@ -426,6 +433,36 @@ } } } + + /** + * Tests this instance for equality with an arbitrary object. The icon fields + * are NOT included in the test, so this implementation is a little weak. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + * + * @since 1.0.7 + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof MinMaxCategoryRenderer)) { + return false; + } + MinMaxCategoryRenderer that = (MinMaxCategoryRenderer) obj; + if (this.plotLines != that.plotLines) { + return false; + } + if (!PaintUtilities.equal(this.groupPaint, that.groupPaint)) { + return false; + } + if (!this.groupStroke.equals(that.groupStroke)) { + return false; + } + return super.equals(obj); + } /** * Returns an icon. @@ -469,7 +506,7 @@ } /** - * Returns an icon. + * Returns an icon from a shape. * * @param shape the shape. * @param fill the fill flag. @@ -478,7 +515,7 @@ * @return The icon. */ private Icon getIcon(Shape shape, final boolean fill, - final boolean outline) { + final boolean outline) { final int width = shape.getBounds().width; final int height = shape.getBounds().height; final GeneralPath path = new GeneralPath(shape); Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java 2007-09-27 11:14:52 UTC (rev 199) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java 2007-09-28 09:14:08 UTC (rev 200) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------------------------- * MinMaxCategoryRendererTests.java * -------------------------------- - * (C) Copyright 2003-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -37,11 +37,15 @@ * Changes * ------- * 22-Oct-2003 : Version 1 (DG); + * 28-Sep-2007 : Added testEquals() method (DG); * */ package org.jfree.chart.renderer.category.junit; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInput; @@ -90,6 +94,23 @@ MinMaxCategoryRenderer r1 = new MinMaxCategoryRenderer(); MinMaxCategoryRenderer r2 = new MinMaxCategoryRenderer(); assertEquals(r1, r2); + + r1.setDrawLines(true); + assertFalse(r1.equals(r2)); + r2.setDrawLines(true); + assertTrue(r1.equals(r2)); + + r1.setGroupPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, + Color.yellow)); + assertFalse(r1.equals(r2)); + r2.setGroupPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, + Color.yellow)); + assertTrue(r1.equals(r2)); + + r1.setGroupStroke(new BasicStroke(1.2f)); + assertFalse(r1.equals(r2)); + r2.setGroupStroke(new BasicStroke(1.2f)); + assertTrue(r1.equals(r2)); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-28 09:46:17
|
Revision: 201 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=201&view=rev Author: mungady Date: 2007-09-28 02:46:11 -0700 (Fri, 28 Sep 2007) Log Message: ----------- 2007-09-28 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java (drawItem): Simplified entity generation code. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-28 09:14:08 UTC (rev 200) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-28 09:46:11 UTC (rev 201) @@ -1,6 +1,11 @@ 2007-09-28 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java + (drawItem): Simplified entity generation code. + +2007-09-28 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java (setGroupStroke): Check for null argument, add event notification, (equals): New method override, * tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java 2007-09-28 09:14:08 UTC (rev 200) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java 2007-09-28 09:46:11 UTC (rev 201) @@ -82,10 +82,8 @@ import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.entity.CategoryItemEntity; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.event.RendererChangeEvent; -import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.CategoryDataset; @@ -415,21 +413,10 @@ } } - // collect entity and tool tip information... - if (state.getInfo() != null) { - EntityCollection entities = state.getEntityCollection(); - if (entities != null && shape != null) { - String tip = null; - CategoryToolTipGenerator tipster = getToolTipGenerator(row, - column); - if (tipster != null) { - tip = tipster.generateToolTip(dataset, row, column); - } - CategoryItemEntity entity = new CategoryItemEntity( - shape, tip, null, dataset, dataset.getRowKey(row), - dataset.getColumnKey(column)); - entities.add(entity); - } + // add an item entity, if this information is being collected + EntityCollection entities = state.getEntityCollection(); + if (entities != null && shape != null) { + addItemEntity(entities, dataset, row, column, shape); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-28 14:24:34
|
Revision: 207 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=207&view=rev Author: mungady Date: 2007-09-28 07:24:28 -0700 (Fri, 28 Sep 2007) Log Message: ----------- 2007-09-28 David Gilbert <dav...@ob...> * source/org/jfree/data/KeyedObjects.java (equals): Cleaned up, * source/org/jfree/data/KeyedObjects2D.java (equals): Likewise, (clone): Clone data storage, * source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java (clone): New method override, * source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java (clone): Likewise, * tests/org/jfree/data/junit/KeyedObjects2DTests.java (testEquals): New test, (testCloning): Check independence, * tests/org/jfree/data/junit/KeyedObjectsTests.java (testCloning2): New test, * tests/org/jfree/data/junit/KeyedObjectTests.java (testCloning2): New test, * tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java (testCloning): Check independence, * tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java (testCloning): Check independence. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects.java branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjectTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjects2DTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjectsTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-28 12:49:27 UTC (rev 206) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-28 14:24:28 UTC (rev 207) @@ -1,5 +1,28 @@ 2007-09-28 David Gilbert <dav...@ob...> + * source/org/jfree/data/KeyedObjects.java + (equals): Cleaned up, + * source/org/jfree/data/KeyedObjects2D.java + (equals): Likewise, + (clone): Clone data storage, + * source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java + (clone): New method override, + * source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java + (clone): Likewise, + * tests/org/jfree/data/junit/KeyedObjects2DTests.java + (testEquals): New test, + (testCloning): Check independence, + * tests/org/jfree/data/junit/KeyedObjectsTests.java + (testCloning2): New test, + * tests/org/jfree/data/junit/KeyedObjectTests.java + (testCloning2): New test, + * tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java + (testCloning): Check independence, + * tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java + (testCloning): Check independence. + +2007-09-28 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java (drawItem): Simplified entity generation code. Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects.java 2007-09-28 12:49:27 UTC (rev 206) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects.java 2007-09-28 14:24:28 UTC (rev 207) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,18 +27,17 @@ * ----------------- * KeyedObjects.java * ----------------- - * (C) Copyright 2003-2005, by Object Refinery Limited. + * (C) Copyright 2003-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: KeyedObjects.java,v 1.5.2.1 2005/10/25 21:29:13 mungady Exp $ - * * Changes: * -------- * 31-Oct-2002 : Version 1 (DG); * 11-Jan-2005 : Minor tidy up (DG); - * + * 28-Sep-2007 : Clean up equals() method (DG); + * */ package org.jfree.data; @@ -52,7 +51,7 @@ /** * A collection of (key, object) pairs. */ -public class KeyedObjects implements Cloneable, PublicCloneable, Serializable { +public class KeyedObjects implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 1321582394193530984L; @@ -95,13 +94,13 @@ } /** - * Returns a key. + * Returns the key at the specified position in the list. * * @param index the item index (zero-based). * - * @return The row key. + * @return The row key (or <code>null</code>). * - * @throws IndexOutOfBoundsException if <code>index</code> is out of bounds. + * @see #getIndex(Comparable) */ public Comparable getKey(int index) { Comparable result = null; @@ -120,6 +119,8 @@ * @param key the key. * * @return The index, or <code>-1</code> if the key is unrecognised. + * + * @see #getKey(int) */ public int getIndex(Comparable key) { int result = -1; @@ -136,7 +137,7 @@ } /** - * Returns the keys. + * Returns a list containing all the keys in the list. * * @return The keys (never <code>null</code>). */ @@ -157,6 +158,8 @@ * @param key the key. * * @return The object (possibly <code>null</code>). + * + * @see #addObject(Comparable, Object) */ public Object getObject(Comparable key) { return getObject(getIndex(key)); @@ -168,6 +171,8 @@ * * @param key the key. * @param object the object. + * + * @see #getObject(Comparable) */ public void addObject(Comparable key, Object object) { setObject(key, object); @@ -180,6 +185,8 @@ * * @param key the key. * @param object the object. + * + * @see #getObject(Comparable) */ public void setObject(Comparable key, Object object) { int keyIndex = getIndex(key); @@ -212,7 +219,9 @@ } /** - * Returns a clone of this object. + * Returns a clone of this object. Keys in the list should be immutable + * and are not cloned. Objects in the list are cloned only if they + * implement {@link PublicCloneable}. * * @return A clone. * @@ -230,39 +239,34 @@ } /** - * Tests if this object is equal to another. + * Tests this object for equality with an arbitrary object. * - * @param o the other object. + * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ - public boolean equals(Object o) { + public boolean equals(Object obj) { - if (o == null) { - return false; - } - if (o == this) { + if (obj == this) { return true; } - - if (!(o instanceof KeyedObjects)) { + if (!(obj instanceof KeyedObjects)) { return false; } - - KeyedObjects kos = (KeyedObjects) o; + KeyedObjects that = (KeyedObjects) obj; int count = getItemCount(); - if (count != kos.getItemCount()) { + if (count != that.getItemCount()) { return false; } for (int i = 0; i < count; i++) { Comparable k1 = getKey(i); - Comparable k2 = kos.getKey(i); + Comparable k2 = that.getKey(i); if (!k1.equals(k2)) { return false; } Object o1 = getObject(i); - Object o2 = kos.getObject(i); + Object o2 = that.getObject(i); if (o1 == null) { if (o2 != null) { return false; Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java 2007-09-28 12:49:27 UTC (rev 206) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java 2007-09-28 14:24:28 UTC (rev 207) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,13 +27,11 @@ * ------------------ * KeyedObject2D.java * ------------------ - * (C) Copyright 2003-2005, by Object Refinery Limited. + * (C) Copyright 2003-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: KeyedObjects2D.java,v 1.6.2.1 2005/10/25 21:29:13 mungady Exp $ - * * Changes * ------- * 05-Feb-2003 : Version 1 (DG); @@ -81,6 +79,8 @@ * Returns the row count. * * @return The row count. + * + * @see #getColumnCount() */ public int getRowCount() { return this.rowKeys.size(); @@ -90,6 +90,8 @@ * Returns the column count. * * @return The column count. + * + * @see #getRowCount() */ public int getColumnCount() { return this.columnKeys.size(); @@ -123,6 +125,8 @@ * @param row the row index (zero based). * * @return The row index. + * + * @see #getRowIndex(Comparable) */ public Comparable getRowKey(int row) { return (Comparable) this.rowKeys.get(row); @@ -134,6 +138,8 @@ * @param key the key. * * @return The row index. + * + * @see #getRowKey(int) */ public int getRowIndex(Comparable key) { return this.rowKeys.indexOf(key); @@ -143,6 +149,8 @@ * Returns the row keys. * * @return The row keys (never <code>null</code>). + * + * @see #getRowKeys() */ public List getRowKeys() { return Collections.unmodifiableList(this.rowKeys); @@ -154,6 +162,8 @@ * @param column the column. * * @return The key. + * + * @see #getColumnIndex(Comparable) */ public Comparable getColumnKey(int column) { return (Comparable) this.columnKeys.get(column); @@ -165,6 +175,8 @@ * @param key the key. * * @return The column index. + * + * @see #getColumnKey(int) */ public int getColumnIndex(Comparable key) { return this.columnKeys.indexOf(key); @@ -174,6 +186,8 @@ * Returns the column keys. * * @return The column keys (never <code>null</code>). + * + * @see #getRowKeys() */ public List getColumnKeys() { return Collections.unmodifiableList(this.columnKeys); @@ -304,40 +318,32 @@ * @return A boolean. */ public boolean equals(Object obj) { - - if (obj == null) { - return false; - } - if (obj == this) { return true; } - if (!(obj instanceof KeyedObjects2D)) { return false; } - KeyedObjects2D ko2D = (KeyedObjects2D) obj; - if (!getRowKeys().equals(ko2D.getRowKeys())) { + KeyedObjects2D that = (KeyedObjects2D) obj; + if (!getRowKeys().equals(that.getRowKeys())) { return false; } - if (!getColumnKeys().equals(ko2D.getColumnKeys())) { + if (!getColumnKeys().equals(that.getColumnKeys())) { return false; } int rowCount = getRowCount(); - if (rowCount != ko2D.getRowCount()) { + if (rowCount != that.getRowCount()) { return false; } - int colCount = getColumnCount(); - if (colCount != ko2D.getColumnCount()) { + if (colCount != that.getColumnCount()) { return false; } - for (int r = 0; r < rowCount; r++) { for (int c = 0; c < colCount; c++) { Object v1 = getObject(r, c); - Object v2 = ko2D.getObject(r, c); + Object v2 = that.getObject(r, c); if (v1 == null) { if (v2 != null) { return false; @@ -375,7 +381,16 @@ * exception, but subclasses (if any) might. */ public Object clone() throws CloneNotSupportedException { - return super.clone(); + KeyedObjects2D clone = (KeyedObjects2D) super.clone(); + clone.columnKeys = new java.util.ArrayList(this.columnKeys); + clone.rowKeys = new java.util.ArrayList(this.rowKeys); + clone.rows = new java.util.ArrayList(this.rows.size()); + Iterator iterator = this.rows.iterator(); + while (iterator.hasNext()) { + KeyedObjects row = (KeyedObjects) iterator.next(); + clone.rows.add(row.clone()); + } + return clone; } } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java 2007-09-28 12:49:27 UTC (rev 206) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java 2007-09-28 14:24:28 UTC (rev 207) @@ -33,8 +33,6 @@ * Science); * Contributor(s): David Gilbert (for Object Refinery Limited); * - * $Id: DefaultBoxAndWhiskerCategoryDataset.java,v 1.9.2.5 2007/06/13 15:26:00 mungady Exp $ - * * Changes * ------- * 05-Aug-2003 : Version 1, contributed by David Browning (DG); @@ -49,6 +47,7 @@ * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG); * 17-Apr-2007 : Fixed bug 1701822 (DG); * 13-Jun-2007 : Fixed error in previous patch (DG); + * 28-Sep-2007 : Fixed cloning bug (DG); * */ @@ -61,13 +60,14 @@ import org.jfree.data.RangeInfo; import org.jfree.data.general.AbstractDataset; import org.jfree.util.ObjectUtilities; +import org.jfree.util.PublicCloneable; /** * A convenience class that provides a default implementation of the * {@link BoxAndWhiskerCategoryDataset} interface. */ public class DefaultBoxAndWhiskerCategoryDataset extends AbstractDataset - implements BoxAndWhiskerCategoryDataset, RangeInfo { + implements BoxAndWhiskerCategoryDataset, RangeInfo, PublicCloneable { /** Storage for the data. */ protected KeyedObjects2D data; @@ -653,5 +653,19 @@ } return false; } + + /** + * Returns a clone of this dataset. + * + * @return A clone. + * + * @throws CloneNotSupportedException if cloning is not possible. + */ + public Object clone() throws CloneNotSupportedException { + DefaultBoxAndWhiskerCategoryDataset clone + = (DefaultBoxAndWhiskerCategoryDataset) super.clone(); + clone.data = (KeyedObjects2D) this.data.clone(); + return clone; + } } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java 2007-09-28 12:49:27 UTC (rev 206) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java 2007-09-28 14:24:28 UTC (rev 207) @@ -32,8 +32,6 @@ * Original Author: Pascal Collet; * Contributor(s): David Gilbert (for Object Refinery Limited); * - * $Id: DefaultStatisticalCategoryDataset.java,v 1.8.2.4 2007/02/02 15:50:24 mungady Exp $ - * * Changes * ------- * 21-Aug-2002 : Version 1, contributed by Pascal Collet (DG); @@ -50,6 +48,7 @@ * ------------- JFREECHART 1.0.x --------------------------------------------- * 08-Aug-2006 : Reworked implementation of RangeInfo methods (DG); * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG); + * 28-Sep-2007 : Fixed cloning bug (DG); * */ @@ -61,13 +60,14 @@ import org.jfree.data.Range; import org.jfree.data.RangeInfo; import org.jfree.data.general.AbstractDataset; +import org.jfree.util.PublicCloneable; /** * A convenience class that provides a default implementation of the * {@link StatisticalCategoryDataset} interface. */ public class DefaultStatisticalCategoryDataset extends AbstractDataset - implements StatisticalCategoryDataset, RangeInfo { + implements StatisticalCategoryDataset, RangeInfo, PublicCloneable { /** Storage for the data. */ private KeyedObjects2D data; @@ -410,4 +410,18 @@ } return true; } + + /** + * Returns a clone of this dataset. + * + * @return A clone of this dataset. + * + * @throws CloneNotSupportedException if cloning cannot be completed. + */ + public Object clone() throws CloneNotSupportedException { + DefaultStatisticalCategoryDataset clone + = (DefaultStatisticalCategoryDataset) super.clone(); + clone.data = (KeyedObjects2D) this.data.clone(); + return clone; + } } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjectTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjectTests.java 2007-09-28 12:49:27 UTC (rev 206) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjectTests.java 2007-09-28 14:24:28 UTC (rev 207) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,16 +27,15 @@ * --------------------- * KeyedObjectTests.java * --------------------- - * (C) Copyright 2004, 2005, by Object Refinery Limited. + * (C) Copyright 2004-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: KeyedObjectTests.java,v 1.1.2.1 2006/10/03 15:41:42 mungady Exp $ - * * Changes * ------- * 27-Jan-2004 : Version 1 (DG); + * 28-Sep-2007 : Added testCloning2() (DG); * */ @@ -48,12 +47,14 @@ import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; +import java.util.ArrayList; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.jfree.data.KeyedObject; +import org.jfree.data.general.DefaultPieDataset; /** * Tests for the {@link KeyedObject} class. @@ -108,12 +109,51 @@ ko2 = (KeyedObject) ko1.clone(); } catch (CloneNotSupportedException e) { - System.err.println("Failed to clone."); + e.printStackTrace(); } assertTrue(ko1 != ko2); assertTrue(ko1.getClass() == ko2.getClass()); assertTrue(ko1.equals(ko2)); } + + /** + * Confirm special features of cloning. + */ + public void testCloning2() { + // case 1 - object is mutable but not PublicCloneable + Object obj1 = new ArrayList(); + KeyedObject ko1 = new KeyedObject("Test", obj1); + KeyedObject ko2 = null; + try { + ko2 = (KeyedObject) ko1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(ko1 != ko2); + assertTrue(ko1.getClass() == ko2.getClass()); + assertTrue(ko1.equals(ko2)); + + // the clone contains a reference to the original object + assertTrue(ko2.getObject() == obj1); + + // CASE 2 - object is mutable AND PublicCloneable + obj1 = new DefaultPieDataset(); + ko1 = new KeyedObject("Test", obj1); + ko2 = null; + try { + ko2 = (KeyedObject) ko1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(ko1 != ko2); + assertTrue(ko1.getClass() == ko2.getClass()); + assertTrue(ko1.equals(ko2)); + + // the clone contains a reference to a CLONE of the original object + assertTrue(ko2.getObject() != obj1); + } /** * Serialize an instance, restore it, and check for equality. @@ -136,7 +176,7 @@ in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertEquals(ko1, ko2); Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjects2DTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjects2DTests.java 2007-09-28 12:49:27 UTC (rev 206) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjects2DTests.java 2007-09-28 14:24:28 UTC (rev 207) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,16 +27,15 @@ * ------------------------ * KeyedObjects2DTests.java * ------------------------ - * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2004-2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: KeyedObjects2DTests.java,v 1.1.2.1 2006/10/03 15:41:43 mungady Exp $ - * * Changes * ------- * 01-Mar-2004 : Version 1 (DG); + * 28-Sep-2007 : Added testEquals() and enhanced testClone() (DG); * */ @@ -77,6 +76,21 @@ public KeyedObjects2DTests(String name) { super(name); } + + /** + * Some checks for the equals() method. + */ + public void testEquals() { + KeyedObjects2D k1 = new KeyedObjects2D(); + KeyedObjects2D k2 = new KeyedObjects2D(); + assertTrue(k1.equals(k2)); + assertTrue(k2.equals(k1)); + + k1.addObject(new Integer(99), "R1", "C1"); + assertFalse(k1.equals(k2)); + k2.addObject(new Integer(99), "R1", "C1"); + assertTrue(k1.equals(k2)); + } /** * Confirm that cloning works. @@ -91,11 +105,15 @@ o2 = (KeyedObjects2D) o1.clone(); } catch (CloneNotSupportedException e) { - System.err.println("Failed to clone."); + e.printStackTrace(); } assertTrue(o1 != o2); assertTrue(o1.getClass() == o2.getClass()); assertTrue(o1.equals(o2)); + + // check independence + o1.addObject("XX", "R1", "C1"); + assertFalse(o1.equals(o2)); } /** @@ -118,13 +136,12 @@ out.close(); ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + new ByteArrayInputStream(buffer.toByteArray())); ko2D2 = (KeyedObjects2D) in.readObject(); in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertEquals(ko2D1, ko2D2); Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjectsTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjectsTests.java 2007-09-28 12:49:27 UTC (rev 206) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjectsTests.java 2007-09-28 14:24:28 UTC (rev 207) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,16 +27,15 @@ * ---------------------- * KeyedObjectsTests.java * ---------------------- - * (C) Copyright 2004, 2005, by Object Refinery Limited. + * (C) Copyright 2004-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: KeyedObjectsTests.java,v 1.1.2.1 2006/10/03 15:41:42 mungady Exp $ - * * Changes * ------- * 27-Jan-2004 : Version 1 (DG); + * 28-Sep-2007 : Added testCloning2() (DG); * */ @@ -48,12 +47,14 @@ import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; +import java.util.ArrayList; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.jfree.data.KeyedObjects; +import org.jfree.data.general.DefaultPieDataset; /** * Tests for the {@link KeyedObjects} class. @@ -106,6 +107,47 @@ } /** + * Confirm special features of cloning. + */ + public void testCloning2() { + // case 1 - object is mutable but not PublicCloneable + Object obj1 = new ArrayList(); + KeyedObjects ko1 = new KeyedObjects(); + ko1.addObject("K1", obj1); + KeyedObjects ko2 = null; + try { + ko2 = (KeyedObjects) ko1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(ko1 != ko2); + assertTrue(ko1.getClass() == ko2.getClass()); + assertTrue(ko1.equals(ko2)); + + // the clone contains a reference to the original object + assertTrue(ko2.getObject("K1") == obj1); + + // CASE 2 - object is mutable AND PublicCloneable + obj1 = new DefaultPieDataset(); + ko1 = new KeyedObjects(); + ko1.addObject("K1", obj1); + ko2 = null; + try { + ko2 = (KeyedObjects) ko1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(ko1 != ko2); + assertTrue(ko1.getClass() == ko2.getClass()); + assertTrue(ko1.equals(ko2)); + + // the clone contains a reference to a CLONE of the original object + assertTrue(ko2.getObject("K1") != obj1); + } + + /** * Check that inserting and retrieving values works as expected. */ public void testInsertAndRetrieve() { @@ -156,13 +198,12 @@ out.close(); ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + new ByteArrayInputStream(buffer.toByteArray())); ko2 = (KeyedObjects) in.readObject(); in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertEquals(ko1, ko2); Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java 2007-09-28 12:49:27 UTC (rev 206) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java 2007-09-28 14:24:28 UTC (rev 207) @@ -32,13 +32,12 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DefaultBoxAndWhiskerCategoryDatasetTests.java,v 1.1.2.2 2007/04/17 13:22:56 mungady Exp $ - * * Changes * ------- * 01-Mar-2004 : Version 1 (DG); * 17-Apr-2007 : Added a test for bug 1701822 (DG); - * + * 28-Sep-2007 : Enhanced testClone() (DG); + * */ package org.jfree.data.statistics.junit; @@ -152,6 +151,13 @@ assertTrue(d1 != d2); assertTrue(d1.getClass() == d2.getClass()); assertTrue(d1.equals(d2)); + + // test independence + d1.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), + new Double(3.0), new Double(4.0), new Double(5.0), + new Double(6.0), new Double(7.0), new Double(8.0), + new ArrayList()), "ROW2", "COLUMN1"); + assertFalse(d1.equals(d2)); } /** Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java 2007-09-28 12:49:27 UTC (rev 206) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java 2007-09-28 14:24:28 UTC (rev 207) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,17 +27,16 @@ * ------------------------------------------- * DefaultStatisticalCategoryDatasetTests.java * ------------------------------------------- - * (C) Copyright 2005, 2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2005-2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DefaultStatisticalCategoryDatasetTests.java,v 1.1.2.1 2006/10/03 15:41:42 mungady Exp $ - * * Changes * ------- * 05-Feb-2005 : Version 1 (DG); * 03-Aug-2006 : Added testGetRangeBounds() method (DG); + * 28-Sep-2007 : Enhanced testCloning() method (DG); * */ @@ -85,7 +84,7 @@ */ public void testGetRangeBounds() { DefaultStatisticalCategoryDataset d - = new DefaultStatisticalCategoryDataset(); + = new DefaultStatisticalCategoryDataset(); // an empty dataset should return null for bounds assertNull(d.getRangeBounds(true)); @@ -125,9 +124,9 @@ */ public void testEquals() { DefaultStatisticalCategoryDataset d1 - = new DefaultStatisticalCategoryDataset(); + = new DefaultStatisticalCategoryDataset(); DefaultStatisticalCategoryDataset d2 - = new DefaultStatisticalCategoryDataset(); + = new DefaultStatisticalCategoryDataset(); assertTrue(d1.equals(d2)); assertTrue(d2.equals(d1)); @@ -138,7 +137,7 @@ */ public void testCloning() { DefaultStatisticalCategoryDataset d1 - = new DefaultStatisticalCategoryDataset(); + = new DefaultStatisticalCategoryDataset(); d1.add(1.1, 2.2, "R1", "C1"); d1.add(3.3, 4.4, "R1", "C2"); d1.add(null, new Double(5.5), "R1", "C3"); @@ -153,6 +152,10 @@ assertTrue(d1 != d2); assertTrue(d1.getClass() == d2.getClass()); assertTrue(d1.equals(d2)); + + // check independence + d1.add(1.1, 2.2, "R3", "C1"); + assertFalse(d1.equals(d2)); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-02 09:52:36
|
Revision: 216 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=216&view=rev Author: mungady Date: 2007-10-02 02:52:32 -0700 (Tue, 02 Oct 2007) Log Message: ----------- 2007-10-02 David Gilbert <dav...@ob...> * source/org/jfree/data/statistics/BoxAndWhiskerItem.java (BoxAndWhiskerItem(double, double, double, double, double, double, double, double, List)): New constructor, * source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java (minimumRangeValue): Changed from Number to double, (minimumRangeValueRow): New field, (minimumRangeValueColumn): Likewise, (maximumRangeValue): Changed from Number to double, (maximumRangeValueRow): New field, (maximumRangeValueColumn): Likewise, (DefaultBoxAndWhiskerCategoryDataset): Updated for changed field types, (add): Fix updating of cached range values, (getRangeLowerBound): Update for changed field type, (getRangeUpperBound): Likewise, * tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDataset.java (testAdd): New test method, (testAddUpdatesCachedRange): Likewise, (testConstructor): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/BoxAndWhiskerItem.java branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-28 16:10:43 UTC (rev 215) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-02 09:52:32 UTC (rev 216) @@ -1,3 +1,24 @@ +2007-10-02 David Gilbert <dav...@ob...> + + * source/org/jfree/data/statistics/BoxAndWhiskerItem.java + (BoxAndWhiskerItem(double, double, double, double, double, double, + double, double, List)): New constructor, + * source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java + (minimumRangeValue): Changed from Number to double, + (minimumRangeValueRow): New field, + (minimumRangeValueColumn): Likewise, + (maximumRangeValue): Changed from Number to double, + (maximumRangeValueRow): New field, + (maximumRangeValueColumn): Likewise, + (DefaultBoxAndWhiskerCategoryDataset): Updated for changed field types, + (add): Fix updating of cached range values, + (getRangeLowerBound): Update for changed field type, + (getRangeUpperBound): Likewise, + * tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDataset.java + (testAdd): New test method, + (testAddUpdatesCachedRange): Likewise, + (testConstructor): Likewise. + 2007-09-28 David Gilbert <dav...@ob...> * source/org/jfree/data/KeyedObjects.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/BoxAndWhiskerItem.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/BoxAndWhiskerItem.java 2007-09-28 16:10:43 UTC (rev 215) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/BoxAndWhiskerItem.java 2007-10-02 09:52:32 UTC (rev 216) @@ -32,14 +32,13 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: BoxAndWhiskerItem.java,v 1.5.2.4 2007/01/17 15:35:00 mungady Exp $ - * * Changes * ------- * 27-Aug-2003 : Version 1 (DG); * 01-Mar-2004 : Added equals() method and implemented Serializable (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 15-Nov-2006 : Added toString() method override (DG); + * 02-Oct-2007 : Added new constructor (for convenience) (DG); * */ @@ -125,6 +124,33 @@ } /** + * Creates a new box-and-whisker item. + * + * @param mean the mean. + * @param median the median + * @param q1 the first quartile. + * @param q3 the third quartile. + * @param minRegularValue the minimum regular value. + * @param maxRegularValue the maximum regular value. + * @param minOutlier the minimum outlier value. + * @param maxOutlier the maximum outlier value. + * @param outliers a list of the outliers. + * + * @since 1.0.7 + */ + public BoxAndWhiskerItem(double mean, double median, double q1, double q3, + double minRegularValue, double maxRegularValue, double minOutlier, + double maxOutlier, List outliers) { + + // pass values to other constructor + this(new Double(mean), new Double(median), new Double(q1), + new Double(q3), new Double(minRegularValue), + new Double(maxRegularValue), new Double(minOutlier), + new Double(maxOutlier), outliers); + + } + + /** * Returns the mean. * * @return The mean (possibly <code>null</code>). Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java 2007-09-28 16:10:43 UTC (rev 215) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java 2007-10-02 09:52:32 UTC (rev 216) @@ -48,6 +48,7 @@ * 17-Apr-2007 : Fixed bug 1701822 (DG); * 13-Jun-2007 : Fixed error in previous patch (DG); * 28-Sep-2007 : Fixed cloning bug (DG); + * 02-Oct-2007 : Fixed bug in updating cached bounds (DG); * */ @@ -73,11 +74,27 @@ protected KeyedObjects2D data; /** The minimum range value. */ - private Number minimumRangeValue; + private double minimumRangeValue; + + /** The row index for the cell that the minimum range value comes from. */ + private int minimumRangeValueRow; + + /** + * The column index for the cell that the minimum range value comes from. + */ + private int minimumRangeValueColumn; /** The maximum range value. */ - private Number maximumRangeValue; + private double maximumRangeValue; + /** The row index for the cell that the maximum range value comes from. */ + private int maximumRangeValueRow; + + /** + * The column index for the cell that the maximum range value comes from. + */ + private int maximumRangeValueColumn; + /** The range of values. */ private Range rangeBounds; @@ -86,8 +103,12 @@ */ public DefaultBoxAndWhiskerCategoryDataset() { this.data = new KeyedObjects2D(); - this.minimumRangeValue = null; - this.maximumRangeValue = null; + this.minimumRangeValue = Double.NaN; + this.minimumRangeValueRow = -1; + this.minimumRangeValueColumn = -1; + this.maximumRangeValue = Double.NaN; + this.maximumRangeValueRow = -1; + this.maximumRangeValueColumn = -1; this.rangeBounds = new Range(0.0, 0.0); } @@ -119,6 +140,20 @@ Comparable columnKey) { this.data.addObject(item, rowKey, columnKey); + + // update cached min and max values + int r = this.data.getRowIndex(rowKey); + int c = this.data.getColumnIndex(columnKey); + if (this.maximumRangeValueRow == r + && this.maximumRangeValueColumn == c) { + this.maximumRangeValue = Double.NaN; + } + if (this.minimumRangeValueRow == r + && this.minimumRangeValueColumn == c) { + this.minimumRangeValue = Double.NaN; + } + + double minval = Double.NaN; if (item.getMinOutlier() != null) { minval = item.getMinOutlier().doubleValue(); @@ -128,22 +163,30 @@ maxval = item.getMaxOutlier().doubleValue(); } - if (this.maximumRangeValue == null) { - this.maximumRangeValue = new Double(maxval); + if (Double.isNaN(this.maximumRangeValue)) { + this.maximumRangeValue = maxval; + this.maximumRangeValueRow = r; + this.maximumRangeValueColumn = c; } - else if (maxval > this.maximumRangeValue.doubleValue()) { - this.maximumRangeValue = new Double(maxval); + else if (maxval > this.maximumRangeValue) { + this.maximumRangeValue = maxval; + this.maximumRangeValueRow = r; + this.maximumRangeValueColumn = c; } - if (this.minimumRangeValue == null) { - this.minimumRangeValue = new Double(minval); + if (Double.isNaN(this.minimumRangeValue)) { + this.minimumRangeValue = minval; + this.minimumRangeValueRow = r; + this.minimumRangeValueColumn = c; } - else if (minval < this.minimumRangeValue.doubleValue()) { - this.minimumRangeValue = new Double(minval); + else if (minval < this.minimumRangeValue) { + this.minimumRangeValue = minval; + this.minimumRangeValueRow = r; + this.minimumRangeValueColumn = c; } - this.rangeBounds = new Range(this.minimumRangeValue.doubleValue(), - this.maximumRangeValue.doubleValue()); + this.rangeBounds = new Range(this.minimumRangeValue, + this.maximumRangeValue); fireDatasetChanged(); @@ -168,6 +211,9 @@ * @param column the column index. * * @return The value. + * + * @see #getMedianValue(int, int) + * @see #getValue(Comparable, Comparable) */ public Number getValue(int row, int column) { return getMedianValue(row, column); @@ -180,6 +226,9 @@ * @param columnKey the columnKey. * * @return The value. + * + * @see #getMedianValue(Comparable, Comparable) + * @see #getValue(int, int) */ public Number getValue(Comparable rowKey, Comparable columnKey) { return getMedianValue(rowKey, columnKey); @@ -420,11 +469,7 @@ * @return The minimum value. */ public double getRangeLowerBound(boolean includeInterval) { - double result = Double.NaN; - if (this.minimumRangeValue != null) { - result = this.minimumRangeValue.doubleValue(); - } - return result; + return this.minimumRangeValue; } /** @@ -436,11 +481,7 @@ * @return The maximum value. */ public double getRangeUpperBound(boolean includeInterval) { - double result = Double.NaN; - if (this.maximumRangeValue != null) { - result = this.maximumRangeValue.doubleValue(); - } - return result; + return this.maximumRangeValue; } /** Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java 2007-09-28 16:10:43 UTC (rev 215) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java 2007-10-02 09:52:32 UTC (rev 216) @@ -37,6 +37,7 @@ * 01-Mar-2004 : Version 1 (DG); * 17-Apr-2007 : Added a test for bug 1701822 (DG); * 28-Sep-2007 : Enhanced testClone() (DG); + * 02-Oct-2007 : Added new tests (DG); * */ @@ -54,6 +55,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; +import org.jfree.data.Range; import org.jfree.data.statistics.BoxAndWhiskerItem; import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset; @@ -181,4 +183,84 @@ } } + + private static final double EPSILON = 0.0000000001; + + /** + * Some checks for the add() method. + */ + public void testAdd() { + DefaultBoxAndWhiskerCategoryDataset dataset + = new DefaultBoxAndWhiskerCategoryDataset(); + BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0, new ArrayList()); + dataset.add(item1, "R1", "C1"); + + assertEquals(2.0, dataset.getValue("R1", "C1").doubleValue(), EPSILON); + assertEquals(1.0, dataset.getMeanValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(2.0, dataset.getMedianValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(3.0, dataset.getQ1Value("R1", "C1").doubleValue(), + EPSILON); + assertEquals(4.0, dataset.getQ3Value("R1", "C1").doubleValue(), + EPSILON); + assertEquals(5.0, dataset.getMinRegularValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(6.0, dataset.getMaxRegularValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(7.0, dataset.getMinOutlier("R1", "C1").doubleValue(), + EPSILON); + assertEquals(8.0, dataset.getMaxOutlier("R1", "C1").doubleValue(), + EPSILON); + assertEquals(new Range(7.0, 8.0), dataset.getRangeBounds(false)); + } + + /** + * Some checks for the add() method. + */ + public void testAddUpdatesCachedRange() { + DefaultBoxAndWhiskerCategoryDataset dataset + = new DefaultBoxAndWhiskerCategoryDataset(); + BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0, new ArrayList()); + dataset.add(item1, "R1", "C1"); + + // now overwrite this item with another + BoxAndWhiskerItem item2 = new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, + 5.5, 6.5, 7.5, 8.5, new ArrayList()); + dataset.add(item2, "R1", "C1"); + + assertEquals(2.5, dataset.getValue("R1", "C1").doubleValue(), EPSILON); + assertEquals(1.5, dataset.getMeanValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(2.5, dataset.getMedianValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(3.5, dataset.getQ1Value("R1", "C1").doubleValue(), + EPSILON); + assertEquals(4.5, dataset.getQ3Value("R1", "C1").doubleValue(), + EPSILON); + assertEquals(5.5, dataset.getMinRegularValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(6.5, dataset.getMaxRegularValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(7.5, dataset.getMinOutlier("R1", "C1").doubleValue(), + EPSILON); + assertEquals(8.5, dataset.getMaxOutlier("R1", "C1").doubleValue(), + EPSILON); + assertEquals(new Range(7.5, 8.5), dataset.getRangeBounds(false)); + } + + /** + * Some basic checks for the constructor. + */ + public void testConstructor() { + DefaultBoxAndWhiskerCategoryDataset dataset + = new DefaultBoxAndWhiskerCategoryDataset(); + assertEquals(0, dataset.getColumnCount()); + assertEquals(0, dataset.getRowCount()); + assertTrue(Double.isNaN(dataset.getRangeLowerBound(false))); + assertTrue(Double.isNaN(dataset.getRangeUpperBound(false))); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-02 13:44:47
|
Revision: 218 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=218&view=rev Author: mungady Date: 2007-10-02 06:44:44 -0700 (Tue, 02 Oct 2007) Log Message: ----------- 2007-10-02 David Gilbert <dav...@ob...> * source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java (minimumRangeValueRow): New field, (minimumRangeValueColumn): Likewise, (minimumRangeValueIncStdDevRow): Likewise, (minimumRangeValueIncStdDevColumn): Likewise, (maximumRangeValueRow): Likewise, (maximumRangeValueColumn): Likewise, (maximumRangeValueIncStdDevRow): Likewise, (maximumRangeValueIncStdDevColumn): Likewise, (DefaultStatisticalCategoryDataset()): Initialise new fields, (add(Number, Number, Comparable, Comparable)): Fixed calculation of bounds, (updateBounds): New method, (getRangeLowerBound): Observe includeInterval flag, (getRangeUpperBound): Likewise, * source/org/jfree/data/statistics/MeanAndStandardDeviation.java (getMeanValue): New method, (getStandardDeviationValue): Likewise, (toString): Likewise, * tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java (testGetRangeBounds): Fixed broken test, (EPSILON): New field, (testAdd): New test method, (testGetRangeLowerBound): Likewise, (testGetRangeUpperBound): Likewise, (testGetRangeBounds2): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/MeanAndStandardDeviation.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-02 10:02:52 UTC (rev 217) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-02 13:44:44 UTC (rev 218) @@ -1,5 +1,33 @@ 2007-10-02 David Gilbert <dav...@ob...> + * source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java + (minimumRangeValueRow): New field, + (minimumRangeValueColumn): Likewise, + (minimumRangeValueIncStdDevRow): Likewise, + (minimumRangeValueIncStdDevColumn): Likewise, + (maximumRangeValueRow): Likewise, + (maximumRangeValueColumn): Likewise, + (maximumRangeValueIncStdDevRow): Likewise, + (maximumRangeValueIncStdDevColumn): Likewise, + (DefaultStatisticalCategoryDataset()): Initialise new fields, + (add(Number, Number, Comparable, Comparable)): Fixed calculation of bounds, + (updateBounds): New method, + (getRangeLowerBound): Observe includeInterval flag, + (getRangeUpperBound): Likewise, + * source/org/jfree/data/statistics/MeanAndStandardDeviation.java + (getMeanValue): New method, + (getStandardDeviationValue): Likewise, + (toString): Likewise, + * tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java + (testGetRangeBounds): Fixed broken test, + (EPSILON): New field, + (testAdd): New test method, + (testGetRangeLowerBound): Likewise, + (testGetRangeUpperBound): Likewise, + (testGetRangeBounds2): Likewise. + +2007-10-02 David Gilbert <dav...@ob...> + * source/org/jfree/data/statistics/BoxAndWhiskerItem.java (BoxAndWhiskerItem(double, double, double, double, double, double, double, double, List)): New constructor, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java 2007-10-02 10:02:52 UTC (rev 217) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java 2007-10-02 13:44:44 UTC (rev 218) @@ -49,6 +49,7 @@ * 08-Aug-2006 : Reworked implementation of RangeInfo methods (DG); * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG); * 28-Sep-2007 : Fixed cloning bug (DG); + * 02-Oct-2007 : Fixed bug updating cached range values (DG); * */ @@ -67,7 +68,7 @@ * {@link StatisticalCategoryDataset} interface. */ public class DefaultStatisticalCategoryDataset extends AbstractDataset - implements StatisticalCategoryDataset, RangeInfo, PublicCloneable { + implements StatisticalCategoryDataset, RangeInfo, PublicCloneable { /** Storage for the data. */ private KeyedObjects2D data; @@ -75,24 +76,68 @@ /** The minimum range value. */ private double minimumRangeValue; + /** The row index for the minimum range value. */ + private int minimumRangeValueRow; + + /** The column index for the minimum range value. */ + private int minimumRangeValueColumn; + /** The minimum range value including the standard deviation. */ private double minimumRangeValueIncStdDev; + /** + * The row index for the minimum range value (including the standard + * deviation). + */ + private int minimumRangeValueIncStdDevRow; + + /** + * The column index for the minimum range value (including the standard + * deviation). + */ + private int minimumRangeValueIncStdDevColumn; + /** The maximum range value. */ private double maximumRangeValue; + + /** The row index for the maximum range value. */ + private int maximumRangeValueRow; + + /** The column index for the maximum range value. */ + private int maximumRangeValueColumn; /** The maximum range value including the standard deviation. */ private double maximumRangeValueIncStdDev; + /** + * The row index for the maximum range value (including the standard + * deviation). + */ + private int maximumRangeValueIncStdDevRow; + + /** + * The column index for the maximum range value (including the standard + * deviation). + */ + private int maximumRangeValueIncStdDevColumn; + /** * Creates a new dataset. */ public DefaultStatisticalCategoryDataset() { this.data = new KeyedObjects2D(); this.minimumRangeValue = Double.NaN; + this.minimumRangeValueRow = -1; + this.minimumRangeValueColumn = -1; this.maximumRangeValue = Double.NaN; + this.maximumRangeValueRow = -1; + this.maximumRangeValueColumn = -1; this.minimumRangeValueIncStdDev = Double.NaN; + this.minimumRangeValueIncStdDevRow = -1; + this.minimumRangeValueIncStdDevColumn = -1; this.maximumRangeValueIncStdDev = Double.NaN; + this.maximumRangeValueIncStdDevRow = -1; + this.maximumRangeValueIncStdDevColumn = -1; } /** @@ -101,12 +146,12 @@ * @param row the row index (zero-based). * @param column the column index (zero-based). * - * @return The mean value. + * @return The mean value (possibly <code>null</code>). */ public Number getMeanValue(int row, int column) { Number result = null; - MeanAndStandardDeviation masd - = (MeanAndStandardDeviation) this.data.getObject(row, column); + MeanAndStandardDeviation masd = (MeanAndStandardDeviation) + this.data.getObject(row, column); if (masd != null) { result = masd.getMean(); } @@ -120,7 +165,7 @@ * @param row the row index. * @param column the column index. * - * @return The value. + * @return The value (possibly <code>null</code>). */ public Number getValue(int row, int column) { return getMeanValue(row, column); @@ -133,7 +178,7 @@ * @param rowKey the row key. * @param columnKey the columnKey. * - * @return The value. + * @return The value (possibly <code>null</code>). */ public Number getValue(Comparable rowKey, Comparable columnKey) { return getMeanValue(rowKey, columnKey); @@ -145,12 +190,12 @@ * @param rowKey the row key. * @param columnKey the columnKey. * - * @return The mean value. + * @return The mean value (possibly <code>null</code>). */ public Number getMeanValue(Comparable rowKey, Comparable columnKey) { Number result = null; - MeanAndStandardDeviation masd - = (MeanAndStandardDeviation) this.data.getObject(rowKey, columnKey); + MeanAndStandardDeviation masd = (MeanAndStandardDeviation) + this.data.getObject(rowKey, columnKey); if (masd != null) { result = masd.getMean(); } @@ -163,12 +208,12 @@ * @param row the row index (zero-based). * @param column the column index (zero-based). * - * @return The standard deviation. + * @return The standard deviation (possibly <code>null</code>). */ public Number getStdDevValue(int row, int column) { Number result = null; - MeanAndStandardDeviation masd - = (MeanAndStandardDeviation) this.data.getObject(row, column); + MeanAndStandardDeviation masd = (MeanAndStandardDeviation) + this.data.getObject(row, column); if (masd != null) { result = masd.getStandardDeviation(); } @@ -181,12 +226,12 @@ * @param rowKey the row key. * @param columnKey the columnKey. * - * @return The standard deviation. + * @return The standard deviation (possibly <code>null</code>). */ public Number getStdDevValue(Comparable rowKey, Comparable columnKey) { Number result = null; - MeanAndStandardDeviation masd - = (MeanAndStandardDeviation) this.data.getObject(rowKey, columnKey); + MeanAndStandardDeviation masd = (MeanAndStandardDeviation) + this.data.getObject(rowKey, columnKey); if (masd != null) { result = masd.getStandardDeviation(); } @@ -299,8 +344,9 @@ MeanAndStandardDeviation item = new MeanAndStandardDeviation( mean, standardDeviation); this.data.addObject(item, rowKey, columnKey); - double m = 0.0; - double sd = 0.0; + + double m = Double.NaN; + double sd = Double.NaN; if (mean != null) { m = mean.doubleValue(); } @@ -308,61 +354,188 @@ sd = standardDeviation.doubleValue(); } - if (!Double.isNaN(m)) { - if (Double.isNaN(this.maximumRangeValue) - || m > this.maximumRangeValue) { - this.maximumRangeValue = m; + // update cached range values + int r = this.data.getColumnIndex(columnKey); + int c = this.data.getRowIndex(rowKey); + if ((r == this.maximumRangeValueRow && c + == this.maximumRangeValueColumn) || (r + == this.maximumRangeValueIncStdDevRow && c + == this.maximumRangeValueIncStdDevColumn) || (r + == this.minimumRangeValueRow && c + == this.minimumRangeValueColumn) || (r + == this.minimumRangeValueIncStdDevRow && c + == this.minimumRangeValueIncStdDevColumn)) { + + // iterate over all data items and update mins and maxes + updateBounds(); + } + else { + if (!Double.isNaN(m)) { + if (Double.isNaN(this.maximumRangeValue) + || m > this.maximumRangeValue) { + this.maximumRangeValue = m; + this.maximumRangeValueRow = r; + this.maximumRangeValueColumn = c; + } } - } - if (!Double.isNaN(m + sd)) { - if (Double.isNaN(this.maximumRangeValueIncStdDev) - || (m + sd) > this.maximumRangeValueIncStdDev) { - this.maximumRangeValueIncStdDev = m + sd; + if (!Double.isNaN(m + sd)) { + if (Double.isNaN(this.maximumRangeValueIncStdDev) + || (m + sd) > this.maximumRangeValueIncStdDev) { + this.maximumRangeValueIncStdDev = m + sd; + this.maximumRangeValueIncStdDevRow = r; + this.maximumRangeValueIncStdDevColumn = c; + } } - } - if (!Double.isNaN(m)) { - if (Double.isNaN(this.minimumRangeValue) - || m < this.minimumRangeValue) { - this.minimumRangeValue = m; + if (!Double.isNaN(m)) { + if (Double.isNaN(this.minimumRangeValue) + || m < this.minimumRangeValue) { + this.minimumRangeValue = m; + this.minimumRangeValueRow = r; + this.minimumRangeValueColumn = c; + } } - } - if (!Double.isNaN(m - sd)) { - if (Double.isNaN(this.minimumRangeValueIncStdDev) - || (m - sd) < this.minimumRangeValueIncStdDev) { - this.minimumRangeValueIncStdDev = m - sd; + if (!Double.isNaN(m - sd)) { + if (Double.isNaN(this.minimumRangeValueIncStdDev) + || (m - sd) < this.minimumRangeValueIncStdDev) { + this.minimumRangeValueIncStdDev = m - sd; + this.minimumRangeValueIncStdDevRow = r; + this.minimumRangeValueIncStdDevColumn = c; + } } } - fireDatasetChanged(); } /** + * Iterate over all the data items and update the cached bound values. + */ + private void updateBounds() { + this.maximumRangeValue = Double.NaN; + this.maximumRangeValueRow = -1; + this.maximumRangeValueColumn = -1; + this.minimumRangeValue = Double.NaN; + this.minimumRangeValueRow = -1; + this.minimumRangeValueColumn = -1; + this.maximumRangeValueIncStdDev = Double.NaN; + this.maximumRangeValueIncStdDevRow = -1; + this.maximumRangeValueIncStdDevColumn = -1; + this.minimumRangeValueIncStdDev = Double.NaN; + this.minimumRangeValueIncStdDevRow = -1; + this.minimumRangeValueIncStdDevColumn = -1; + + int rowCount = this.data.getRowCount(); + int columnCount = this.data.getColumnCount(); + for (int r = 0; r < rowCount; r++) { + for (int c = 0; c < columnCount; c++) { + double m = Double.NaN; + double sd = Double.NaN; + MeanAndStandardDeviation masd = (MeanAndStandardDeviation) + this.data.getObject(r, c); + if (masd == null) { + continue; + } + m = masd.getMeanValue(); + sd = masd.getStandardDeviationValue(); + + if (!Double.isNaN(m)) { + + // update the max value + if (Double.isNaN(this.maximumRangeValue)) { + this.maximumRangeValue = m; + this.maximumRangeValueRow = r; + this.maximumRangeValueColumn = c; + } + else { + if (m > this.maximumRangeValue) { + this.maximumRangeValue = m; + this.maximumRangeValueRow = r; + this.maximumRangeValueColumn = c; + } + } + + // update the min value + if (Double.isNaN(this.minimumRangeValue)) { + this.minimumRangeValue = m; + this.minimumRangeValueRow = r; + this.minimumRangeValueColumn = c; + } + else { + if (m < this.minimumRangeValue) { + this.minimumRangeValue = m; + this.minimumRangeValueRow = r; + this.minimumRangeValueColumn = c; + } + } + + if (!Double.isNaN(sd)) { + // update the max value + if (Double.isNaN(this.maximumRangeValueIncStdDev)) { + this.maximumRangeValueIncStdDev = m + sd; + this.maximumRangeValueIncStdDevRow = r; + this.maximumRangeValueIncStdDevColumn = c; + } + else { + if (m + sd > this.maximumRangeValueIncStdDev) { + this.maximumRangeValueIncStdDev = m + sd; + this.maximumRangeValueIncStdDevRow = r; + this.maximumRangeValueIncStdDevColumn = c; + } + } + + // update the min value + if (Double.isNaN(this.minimumRangeValueIncStdDev)) { + this.minimumRangeValueIncStdDev = m - sd; + this.minimumRangeValueIncStdDevRow = r; + this.minimumRangeValueIncStdDevColumn = c; + } + else { + if (m - sd < this.minimumRangeValueIncStdDev) { + this.minimumRangeValueIncStdDev = m - sd; + this.minimumRangeValueIncStdDevRow = r; + this.minimumRangeValueIncStdDevColumn = c; + } + } + } + } + } + } + } + + /** * Returns the minimum y-value in the dataset. * * @param includeInterval a flag that determines whether or not the - * y-interval is taken into account (ignored for - * this dataset). + * y-interval is taken into account. * * @return The minimum value. */ public double getRangeLowerBound(boolean includeInterval) { - return this.minimumRangeValue; + if (includeInterval) { + return this.minimumRangeValueIncStdDev; + } + else { + return this.minimumRangeValue; + } } /** * Returns the maximum y-value in the dataset. * * @param includeInterval a flag that determines whether or not the - * y-interval is taken into account (ignored for - * this dataset). + * y-interval is taken into account. * * @return The maximum value. */ public double getRangeUpperBound(boolean includeInterval) { - return this.maximumRangeValue; + if (includeInterval) { + return this.maximumRangeValueIncStdDev; + } + else { + return this.maximumRangeValue; + } } /** @@ -404,7 +577,7 @@ return false; } DefaultStatisticalCategoryDataset that - = (DefaultStatisticalCategoryDataset) obj; + = (DefaultStatisticalCategoryDataset) obj; if (!this.data.equals(that.data)) { return false; } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/MeanAndStandardDeviation.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/MeanAndStandardDeviation.java 2007-10-02 10:02:52 UTC (rev 217) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/MeanAndStandardDeviation.java 2007-10-02 13:44:44 UTC (rev 218) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,17 +27,17 @@ * ----------------------------- * MeanAndStandardDeviation.java * ----------------------------- - * (C) Copyright 2003-2005, by Object Refinery Limited. + * (C) Copyright 2003-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: MeanAndStandardDeviation.java,v 1.3.2.1 2005/10/25 21:34:46 mungady Exp $ - * * Changes: * -------- * 05-Feb-2002 : Version 1 (DG); * 05-Feb-2005 : Added equals() method and implemented Serializable (DG); + * 02-Oct-2007 : Added getMeanValue() and getStandardDeviationValue() methods + * for convenience, and toString() method for debugging (DG); * */ @@ -93,6 +93,24 @@ public Number getMean() { return this.mean; } + + /** + * Returns the mean as a double primitive. If the underlying mean is + * <code>null</code>, this method will return <code>Double.NaN</code>. + * + * @return The mean. + * + * @see #getMean() + * + * @since 1.0.7 + */ + public double getMeanValue() { + double result = Double.NaN; + if (this.mean != null) { + result = this.mean.doubleValue(); + } + return result; + } /** * Returns the standard deviation. @@ -104,6 +122,23 @@ } /** + * Returns the standard deviation as a double primitive. If the underlying + * standard deviation is <code>null</code>, this method will return + * <code>Double.NaN</code>. + * + * @return The standard deviation. + * + * @since 1.0.7 + */ + public double getStandardDeviationValue() { + double result = Double.NaN; + if (this.standardDeviation != null) { + result = this.standardDeviation.doubleValue(); + } + return result; + } + + /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). @@ -128,4 +163,16 @@ } return true; } -} + + /** + * Returns a string representing this instance. + * + * @return A string. + * + * @since 1.0.7 + */ + public String toString() { + return "[" + this.mean + ", " + this.standardDeviation + "]"; + } + +} \ No newline at end of file Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java 2007-10-02 10:02:52 UTC (rev 217) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java 2007-10-02 13:44:44 UTC (rev 218) @@ -37,6 +37,7 @@ * 05-Feb-2005 : Version 1 (DG); * 03-Aug-2006 : Added testGetRangeBounds() method (DG); * 28-Sep-2007 : Enhanced testCloning() method (DG); + * 02-Oct-2007 : Added new bounds tests (DG); * */ @@ -113,10 +114,10 @@ // try a Double.POSITIVE_INFINITY d.add(Double.POSITIVE_INFINITY, 0.0, "R1", "C3"); - assertEquals(new Range(Double.NEGATIVE_INFINITY, - Double.POSITIVE_INFINITY), d.getRangeBounds(false)); - assertEquals(new Range(Double.NEGATIVE_INFINITY, - Double.POSITIVE_INFINITY), d.getRangeBounds(true)); + assertEquals(new Range(0.5, Double.POSITIVE_INFINITY), + d.getRangeBounds(false)); + assertEquals(new Range(-1.5, Double.POSITIVE_INFINITY), + d.getRangeBounds(true)); } /** @@ -211,4 +212,59 @@ assertEquals(d1, d2); } + private static final double EPSILON = 0.0000000001; + + /** + * Some checks for the add() method. + */ + public void testAdd() { + DefaultStatisticalCategoryDataset d1 + = new DefaultStatisticalCategoryDataset(); + d1.add(1.0, 2.0, "R1", "C1"); + assertEquals(1.0, d1.getValue("R1", "C1").doubleValue(), EPSILON); + assertEquals(2.0, d1.getStdDevValue("R1", "C1").doubleValue(), EPSILON); + + // overwrite the value + d1.add(10.0, 20.0, "R1", "C1"); + assertEquals(10.0, d1.getValue("R1", "C1").doubleValue(), EPSILON); + assertEquals(20.0, d1.getStdDevValue("R1", "C1").doubleValue(), EPSILON); + } + + /** + * Some checks for the getRangeLowerBound() method. + */ + public void testGetRangeLowerBound() { + DefaultStatisticalCategoryDataset d1 + = new DefaultStatisticalCategoryDataset(); + d1.add(1.0, 2.0, "R1", "C1"); + assertEquals(1.0, d1.getRangeLowerBound(false), EPSILON); + assertEquals(-1.0, d1.getRangeLowerBound(true), EPSILON); + } + + /** + * Some checks for the getRangeUpperBound() method. + */ + public void testGetRangeUpperBound() { + DefaultStatisticalCategoryDataset d1 + = new DefaultStatisticalCategoryDataset(); + d1.add(1.0, 2.0, "R1", "C1"); + assertEquals(1.0, d1.getRangeUpperBound(false), EPSILON); + assertEquals(3.0, d1.getRangeUpperBound(true), EPSILON); + } + + /** + * Some checks for the getRangeBounds() method. + */ + public void testGetRangeBounds2() { + DefaultStatisticalCategoryDataset d1 + = new DefaultStatisticalCategoryDataset(); + d1.add(1.0, 2.0, "R1", "C1"); + assertEquals(new Range(1.0, 1.0), d1.getRangeBounds(false)); + assertEquals(new Range(-1.0, 3.0), d1.getRangeBounds(true)); + + d1.add(10.0, 20.0, "R1", "C1"); + assertEquals(new Range(10.0, 10.0), d1.getRangeBounds(false)); + assertEquals(new Range(-10.0, 30.0), d1.getRangeBounds(true)); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-03 09:27:34
|
Revision: 224 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=224&view=rev Author: mungady Date: 2007-10-03 02:13:34 -0700 (Wed, 03 Oct 2007) Log Message: ----------- 2007-10-03 David Gilbert <dav...@ob...> * source/org/jfree/data/DefaultKeyedValues.java (removeValue(Comparable)): Throw UnknownKeyException for unrecognised key, * source/org/jfree/data/KeyedObjects.java (getObject(int)): Allow IndexOutOfBoundsException to be thrown, (getKey(int)): Likewise, (getIndex): Check for null argument, (getObject): Throw UnknownKeyException for unrecognised key, (insertValue): New method, (removeValue): Throw UnknownKeyException for unrecognised key, (clear): New method, (hashCode): Likewise, * source/org/jfree/data/KeyedObjects2D.java (getObject): Check for missing key in underlying data structure, * tests/org/jfree/data/junit/DefaultKeyedValuesTests.java (testRemoveValue): Updated checks for consistency with KeyedObjects, * tests/org/jfree/data/junit/KeyedObjectsTests.java (testInsertAndRetrieve): Updated checks, (testGetObject): New test method, (testGetKey): Likewise, (testGetIndex): Likewise, (testSetObject): Likewise, (testRemoveValue): Likewise, (testRemoveValueInt): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/DefaultKeyedValues.java branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects.java branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/DefaultKeyedValuesTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjectsTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-02 14:32:27 UTC (rev 223) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-03 09:13:34 UTC (rev 224) @@ -1,3 +1,29 @@ +2007-10-03 David Gilbert <dav...@ob...> + + * source/org/jfree/data/DefaultKeyedValues.java + (removeValue(Comparable)): Throw UnknownKeyException for unrecognised key, + * source/org/jfree/data/KeyedObjects.java + (getObject(int)): Allow IndexOutOfBoundsException to be thrown, + (getKey(int)): Likewise, + (getIndex): Check for null argument, + (getObject): Throw UnknownKeyException for unrecognised key, + (insertValue): New method, + (removeValue): Throw UnknownKeyException for unrecognised key, + (clear): New method, + (hashCode): Likewise, + * source/org/jfree/data/KeyedObjects2D.java + (getObject): Check for missing key in underlying data structure, + * tests/org/jfree/data/junit/DefaultKeyedValuesTests.java + (testRemoveValue): Updated checks for consistency with KeyedObjects, + * tests/org/jfree/data/junit/KeyedObjectsTests.java + (testInsertAndRetrieve): Updated checks, + (testGetObject): New test method, + (testGetKey): Likewise, + (testGetIndex): Likewise, + (testSetObject): Likewise, + (testRemoveValue): Likewise, + (testRemoveValueInt): Likewise. + 2007-10-02 David Gilbert <dav...@ob...> * source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/DefaultKeyedValues.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/DefaultKeyedValues.java 2007-10-02 14:32:27 UTC (rev 223) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/DefaultKeyedValues.java 2007-10-03 09:13:34 UTC (rev 224) @@ -51,6 +51,7 @@ * 31-Jul-2006 : Added a clear() method (DG); * 01-Aug-2006 : Added argument check to getIndex() method (DG); * 30-Apr-2007 : Added insertValue() methods (DG); + * 03-Oct-2007 : Make removeValue() throw UnknownKeyException (DG); * */ @@ -101,7 +102,7 @@ * * @param item the item of interest (zero-based index). * - * @return The value. + * @return The value (possibly <code>null</code>). * * @throws IndexOutOfBoundsException if <code>item</code> is out of bounds. */ @@ -280,7 +281,7 @@ if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } - int pos = this.getIndex(key); + int pos = getIndex(key); if (pos >= 0) { this.data.remove(pos); } @@ -314,12 +315,15 @@ * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. + * @throws UnknownKeyException if <code>key</code> is not recognised. */ public void removeValue(Comparable key) { int index = getIndex(key); - if (index >= 0) { - removeValue(index); + if (index < 0) { + throw new UnknownKeyException("The key (" + key + + ") is not recognised."); } + removeValue(index); } /** Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects.java 2007-10-02 14:32:27 UTC (rev 223) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects.java 2007-10-03 09:13:34 UTC (rev 224) @@ -37,6 +37,7 @@ * 31-Oct-2002 : Version 1 (DG); * 11-Jan-2005 : Minor tidy up (DG); * 28-Sep-2007 : Clean up equals() method (DG); + * 03-Oct-2007 : Make method behaviour consistent with DefaultKeyedValues (DG); * */ @@ -76,19 +77,19 @@ } /** - * Returns an object. + * Returns an object from the list. * * @param item the item index (zero-based). * - * @return The object (<code>null</code> if the index is out of range). + * @return The object (possibly <code>null</code>). + * + * @throws IndexOutOfBoundsException if <code>item</code> is out of bounds. */ public Object getObject(int item) { Object result = null; - if (item >= 0 && item < this.data.size()) { - KeyedObject kobj = (KeyedObject) this.data.get(item); - if (kobj != null) { - result = kobj.getObject(); - } + KeyedObject kobj = (KeyedObject) this.data.get(item); + if (kobj != null) { + result = kobj.getObject(); } return result; } @@ -98,42 +99,44 @@ * * @param index the item index (zero-based). * - * @return The row key (or <code>null</code>). + * @return The row key. + * + * @throws IndexOutOfBoundsException if <code>item</code> is out of bounds. * * @see #getIndex(Comparable) */ public Comparable getKey(int index) { Comparable result = null; - if (index >= 0 && index < this.data.size()) { - KeyedObject item = (KeyedObject) this.data.get(index); - if (item != null) { - result = item.getKey(); - } + KeyedObject item = (KeyedObject) this.data.get(index); + if (item != null) { + result = item.getKey(); } return result; } /** - * Returns the index for a given key. + * Returns the index for a given key, or <code>-1</code>. * - * @param key the key. + * @param key the key (<code>null</code> not permitted). * * @return The index, or <code>-1</code> if the key is unrecognised. * * @see #getKey(int) */ public int getIndex(Comparable key) { - int result = -1; + if (key == null) { + throw new IllegalArgumentException("Null 'key' argument."); + } int i = 0; Iterator iterator = this.data.iterator(); while (iterator.hasNext()) { KeyedObject ko = (KeyedObject) iterator.next(); if (ko.getKey().equals(key)) { - result = i; + return i; } i++; } - return result; + return -1; } /** @@ -162,7 +165,12 @@ * @see #addObject(Comparable, Object) */ public Object getObject(Comparable key) { - return getObject(getIndex(key)); + int index = getIndex(key); + if (index < 0) { + throw new UnknownKeyException("The key (" + key + + ") is not recognised."); + } + return getObject(index); } /** @@ -183,7 +191,7 @@ * This is the same as the {@link #addObject(Comparable, Object)} * method. * - * @param key the key. + * @param key the key (<code>null</code> not permitted). * @param object the object. * * @see #getObject(Comparable) @@ -201,9 +209,43 @@ } /** + * Inserts a new value at the specified position in the dataset or, if + * there is an existing item with the specified key, updates the value + * for that item and moves it to the specified position. + * + * @param position the position (in the range <code>0</code> to + * <code>getItemCount()</code>). + * @param key the key (<code>null</code> not permitted). + * @param value the value (<code>null</code> permitted). + * + * @since 1.0.7 + */ + public void insertValue(int position, Comparable key, Object value) { + if (position < 0 || position > this.data.size()) { + throw new IllegalArgumentException("'position' out of bounds."); + } + if (key == null) { + throw new IllegalArgumentException("Null 'key' argument."); + } + int pos = getIndex(key); + if (pos >= 0) { + this.data.remove(pos); + } + KeyedObject item = new KeyedObject(key, value); + if (position <= this.data.size()) { + this.data.add(position, item); + } + else { + this.data.add(item); + } + } + + /** * Removes a value from the collection. * * @param index the index of the item to remove. + * + * @see #removeValue(Comparable) */ public void removeValue(int index) { this.data.remove(index); @@ -212,13 +254,32 @@ /** * Removes a value from the collection. * - * @param key the key of the item to remove. + * @param key the key (<code>null</code> not permitted). + * + * @see #removeValue(int) + * + * @throws UnknownKeyException if the key is not recognised. */ public void removeValue(Comparable key) { - removeValue(getIndex(key)); + // defer argument checking + int index = getIndex(key); + if (index < 0) { + throw new UnknownKeyException("The key (" + key.toString() + + ") is not recognised."); + } + removeValue(index); } /** + * Clears all values from the collection. + * + * @since 1.0.7 + */ + public void clear() { + this.data.clear(); + } + + /** * Returns a clone of this object. Keys in the list should be immutable * and are not cloned. Objects in the list are cloned only if they * implement {@link PublicCloneable}. @@ -282,4 +343,13 @@ } + /** + * Returns a hash code. + * + * @return A hash code. + */ + public int hashCode() { + return (this.data != null ? this.data.hashCode() : 0); + } + } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java 2007-10-02 14:32:27 UTC (rev 223) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java 2007-10-03 09:13:34 UTC (rev 224) @@ -37,6 +37,8 @@ * 05-Feb-2003 : Version 1 (DG); * 01-Mar-2004 : Added equals() and clone() methods and implemented * Serializable (DG); + * 03-Oct-2007 : Updated getObject() to handle modified behaviour in + * KeyedObjects class (DG); * */ @@ -106,17 +108,18 @@ * @return The object. */ public Object getObject(int row, int column) { - Object result = null; KeyedObjects rowData = (KeyedObjects) this.rows.get(row); if (rowData != null) { Comparable columnKey = (Comparable) this.columnKeys.get(column); if (columnKey != null) { - result = rowData.getObject(columnKey); + int index = rowData.getIndex(columnKey); + if (index >= 0) { + result = rowData.getObject(columnKey); + } } } return result; - } /** Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/DefaultKeyedValuesTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/DefaultKeyedValuesTests.java 2007-10-02 14:32:27 UTC (rev 223) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/DefaultKeyedValuesTests.java 2007-10-03 09:13:34 UTC (rev 224) @@ -32,8 +32,6 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DefaultKeyedValuesTests.java,v 1.1.2.2 2007/04/30 15:28:04 mungady Exp $ - * * Changes * ------- * 05-Mar-2003 : Version 1 (DG); @@ -41,6 +39,7 @@ * 31-Jul-2006 : Added test for new clear() method (DG); * 01-Aug-2006 : Extended testGetIndex() method (DG); * 30-Apr-2007 : Added some new tests (DG); + * 03-Oct-2007 : Updated testRemoveValue() (DG); * */ @@ -350,12 +349,12 @@ data.removeValue("B"); assertEquals(-1, data.getIndex("B")); - boolean pass = true; + boolean pass = false; try { data.removeValue("XXX"); } - catch (Exception e) { - pass = false; + catch (UnknownKeyException e) { + pass = true; } assertTrue(pass); } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjectsTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjectsTests.java 2007-10-02 14:32:27 UTC (rev 223) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjectsTests.java 2007-10-03 09:13:34 UTC (rev 224) @@ -36,6 +36,7 @@ * ------- * 27-Jan-2004 : Version 1 (DG); * 28-Sep-2007 : Added testCloning2() (DG); + * 03-Oct-2007 : New tests (DG); * */ @@ -54,6 +55,7 @@ import junit.framework.TestSuite; import org.jfree.data.KeyedObjects; +import org.jfree.data.UnknownKeyException; import org.jfree.data.general.DefaultPieDataset; /** @@ -169,8 +171,16 @@ assertEquals(data.getObject("B"), new Double(2.0)); assertEquals(data.getObject("C"), new Double(3.0)); assertEquals(data.getObject("D"), null); - assertEquals(data.getObject("Not a key"), null); - + + boolean pass = false; + try { + data.getObject("Not a key"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + // check retrieve value by index assertEquals(data.getObject(0), new Double(1.0)); assertEquals(data.getObject(1), new Double(2.0)); @@ -208,5 +218,199 @@ assertEquals(ko1, ko2); } + + /** + * Simple checks for the getObject(int) method. + */ + public void testGetObject() { + // retrieve an item + KeyedObjects ko1 = new KeyedObjects(); + ko1.addObject("Key 1", "Object 1"); + ko1.addObject("Key 2", null); + ko1.addObject("Key 3", "Object 2"); + assertEquals("Object 1", ko1.getObject(0)); + assertNull(ko1.getObject(1)); + assertEquals("Object 2", ko1.getObject(2)); + + // request with a negative index + boolean pass = false; + try { + ko1.getObject(-1); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + + // request width index == itemCount + pass = false; + try { + ko1.getObject(3); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Simple checks for the getKey(int) method. + */ + public void testGetKey() { + // retrieve an item + KeyedObjects ko1 = new KeyedObjects(); + ko1.addObject("Key 1", "Object 1"); + ko1.addObject("Key 2", null); + ko1.addObject("Key 3", "Object 2"); + assertEquals("Key 1", ko1.getKey(0)); + assertEquals("Key 2", ko1.getKey(1)); + assertEquals("Key 3", ko1.getKey(2)); + + // request with a negative index + boolean pass = false; + try { + ko1.getKey(-1); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + + // request width index == itemCount + pass = false; + try { + ko1.getKey(3); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Simple checks for the getIndex(Comparable) method. + */ + public void testGetIndex() { + KeyedObjects ko1 = new KeyedObjects(); + ko1.addObject("Key 1", "Object 1"); + ko1.addObject("Key 2", null); + ko1.addObject("Key 3", "Object 2"); + assertEquals(0, ko1.getIndex("Key 1")); + assertEquals(1, ko1.getIndex("Key 2")); + assertEquals(2, ko1.getIndex("Key 3")); + + // check null argument + boolean pass = false; + try { + ko1.getIndex(null); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the setObject(Comparable, Object) method. + */ + public void testSetObject() { + KeyedObjects ko1 = new KeyedObjects(); + ko1.setObject("Key 1", "Object 1"); + ko1.setObject("Key 2", null); + ko1.setObject("Key 3", "Object 2"); + + assertEquals("Object 1", ko1.getObject("Key 1")); + assertEquals(null, ko1.getObject("Key 2")); + assertEquals("Object 2", ko1.getObject("Key 3")); + + // replace an existing value + ko1.setObject("Key 2", "AAA"); + ko1.setObject("Key 3", "BBB"); + assertEquals("AAA", ko1.getObject("Key 2")); + assertEquals("BBB", ko1.getObject("Key 3")); + + // try a null key - should throw an exception + boolean pass = false; + try { + ko1.setObject(null, "XX"); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the removeValue() methods. + */ + public void testRemoveValue() { + KeyedObjects ko1 = new KeyedObjects(); + ko1.setObject("Key 1", "Object 1"); + ko1.setObject("Key 2", null); + ko1.setObject("Key 3", "Object 2"); + + ko1.removeValue(1); + assertEquals(2, ko1.getItemCount()); + assertEquals(1, ko1.getIndex("Key 3")); + + ko1.removeValue("Key 1"); + assertEquals(1, ko1.getItemCount()); + assertEquals(0, ko1.getIndex("Key 3")); + + // try unknown key + boolean pass = false; + try { + ko1.removeValue("UNKNOWN"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + + // try null argument + pass = false; + try { + ko1.removeValue(null); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the removeValue(int) method. + */ + public void testRemoveValueInt() { + KeyedObjects ko1 = new KeyedObjects(); + ko1.setObject("Key 1", "Object 1"); + ko1.setObject("Key 2", null); + ko1.setObject("Key 3", "Object 2"); + + ko1.removeValue(1); + assertEquals(2, ko1.getItemCount()); + assertEquals(1, ko1.getIndex("Key 3")); + + + // try negative key index + boolean pass = false; + try { + ko1.removeValue(-1); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + + // try key index == itemCount + pass = false; + try { + ko1.removeValue(2); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-03 10:51:11
|
Revision: 226 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=226&view=rev Author: mungady Date: 2007-10-03 03:51:09 -0700 (Wed, 03 Oct 2007) Log Message: ----------- 2007-10-03 David Gilbert <dav...@ob...> * source/org/jfree/data/KeyedObjects2D.java (getObject(Comparable, Comparable)): Check arguments for null or unrecognised keys, (setObject(Object, Comparable, Comparable): Check for null arguments, (removeObject): Check if row or column needs removing, (removeRow(Comparable)): Check for unrecognised key, (removeColumn(Comparable)): Likewise, * tests/org/jfree/data/junit/KeyedObjects2DTests.java (testGetValueByIndex): New test method, (testGetValueByKey): Likewise, (testSetObject): Likewise, (testRemoveRowByIndex): Likewise, (testRemoveColumnByIndex): Likewise, (testRemoveRowByKey): Likewise, (testRemoveColumnByKey): Likewise, (testRemoveValue): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjects2DTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-03 09:24:09 UTC (rev 225) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-03 10:51:09 UTC (rev 226) @@ -1,5 +1,24 @@ 2007-10-03 David Gilbert <dav...@ob...> + * source/org/jfree/data/KeyedObjects2D.java + (getObject(Comparable, Comparable)): Check arguments for null or + unrecognised keys, + (setObject(Object, Comparable, Comparable): Check for null arguments, + (removeObject): Check if row or column needs removing, + (removeRow(Comparable)): Check for unrecognised key, + (removeColumn(Comparable)): Likewise, + * tests/org/jfree/data/junit/KeyedObjects2DTests.java + (testGetValueByIndex): New test method, + (testGetValueByKey): Likewise, + (testSetObject): Likewise, + (testRemoveRowByIndex): Likewise, + (testRemoveColumnByIndex): Likewise, + (testRemoveRowByKey): Likewise, + (testRemoveColumnByKey): Likewise, + (testRemoveValue): Likewise. + +2007-10-03 David Gilbert <dav...@ob...> + * source/org/jfree/data/DefaultKeyedValues.java (removeValue(Comparable)): Throw UnknownKeyException for unrecognised key, * source/org/jfree/data/KeyedObjects.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java 2007-10-03 09:24:09 UTC (rev 225) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java 2007-10-03 10:51:09 UTC (rev 226) @@ -102,10 +102,12 @@ /** * Returns the object for a given row and column. * - * @param row the row index. - * @param column the column index. + * @param row the row index (in the range 0 to getRowCount() - 1). + * @param column the column index (in the range 0 to getColumnCount() - 1). * - * @return The object. + * @return The object (possibly <code>null</code>). + * + * @see #getObject(Comparable, Comparable) */ public Object getObject(int row, int column) { Object result = null; @@ -199,33 +201,52 @@ /** * Returns the object for the given row and column keys. * - * @param rowKey the row key. - * @param columnKey the column key. + * @param rowKey the row key (<code>null</code> not permitted). + * @param columnKey the column key (<code>null</code> not permitted). * - * @return The object. + * @return The object (possibly <code>null</code>). + * + * @throws IllegalArgumentException if <code>rowKey<code> or + * <code>columnKey</code> is <code>null</code>. + * @throws UnknownKeyException if <code>rowKey</code> or + * <code>columnKey</code> is not recognised. */ public Object getObject(Comparable rowKey, Comparable columnKey) { - - Object result = null; + if (rowKey == null) { + throw new IllegalArgumentException("Null 'rowKey' argument."); + } + if (columnKey == null) { + throw new IllegalArgumentException("Null 'columnKey' argument."); + } int row = this.rowKeys.indexOf(rowKey); - if (row >= 0) { - KeyedObjects rowData = (KeyedObjects) this.rows.get(row); - result = rowData.getObject(columnKey); + if (row < 0) { + throw new UnknownKeyException("Row key (" + rowKey + + ") not recognised."); } - return result; - + int column = this.columnKeys.indexOf(columnKey); + if (column < 0) { + throw new UnknownKeyException("Column key (" + columnKey + + ") not recognised."); + } + KeyedObjects rowData = (KeyedObjects) this.rows.get(row); + int index = rowData.getIndex(columnKey); + if (index >= 0) { + return rowData.getObject(index); + } + else { + return null; + } } /** * Adds an object to the table. Performs the same function as setObject(). * * @param object the object. - * @param rowKey the row key. - * @param columnKey the column key. + * @param rowKey the row key (<code>null</code> not permitted). + * @param columnKey the column key (<code>null</code> not permitted). */ - public void addObject(Object object, - Comparable rowKey, - Comparable columnKey) { + public void addObject(Object object, Comparable rowKey, + Comparable columnKey) { setObject(object, rowKey, columnKey); } @@ -233,13 +254,18 @@ * Adds or updates an object. * * @param object the object. - * @param rowKey the row key. - * @param columnKey the column key. + * @param rowKey the row key (<code>null</code> not permitted). + * @param columnKey the column key (<code>null</code> not permitted). */ - public void setObject(Object object, - Comparable rowKey, - Comparable columnKey) { + public void setObject(Object object, Comparable rowKey, + Comparable columnKey) { + if (rowKey == null) { + throw new IllegalArgumentException("Null 'rowKey' argument."); + } + if (columnKey == null) { + throw new IllegalArgumentException("Null 'columnKey' argument."); + } KeyedObjects row; int rowIndex = this.rowKeys.indexOf(rowKey); if (rowIndex >= 0) { @@ -259,21 +285,68 @@ } /** - * Removes an object. + * Removes an object from the table by setting it to <code>null</code>. If + * all the objects in the specified row and/or column are now + * <code>null</code>, the row and/or column is removed from the table. * - * @param rowKey the row key. - * @param columnKey the column key. + * @param rowKey the row key (<code>null</code> not permitted). + * @param columnKey the column key (<code>null</code> not permitted). + * + * @see #addObject(Object, Comparable, Comparable) */ public void removeObject(Comparable rowKey, Comparable columnKey) { setObject(null, rowKey, columnKey); - // actually, a null value is different to a value that doesn't exist - // at all, need to fix this code. + + // 1. check whether the row is now empty. + boolean allNull = true; + int rowIndex = getRowIndex(rowKey); + KeyedObjects row = (KeyedObjects) this.rows.get(rowIndex); + + for (int item = 0, itemCount = row.getItemCount(); item < itemCount; + item++) { + if (row.getObject(item) != null) { + allNull = false; + break; + } + } + + if (allNull) { + this.rowKeys.remove(rowIndex); + this.rows.remove(rowIndex); + } + + // 2. check whether the column is now empty. + allNull = true; + + for (int item = 0, itemCount = this.rows.size(); item < itemCount; + item++) { + row = (KeyedObjects) this.rows.get(item); + int columnIndex = row.getIndex(columnKey); + if (columnIndex >= 0 && row.getObject(columnIndex) != null) { + allNull = false; + break; + } + } + + if (allNull) { + for (int item = 0, itemCount = this.rows.size(); item < itemCount; + item++) { + row = (KeyedObjects) this.rows.get(item); + int columnIndex = row.getIndex(columnKey); + if (columnIndex >= 0) { + row.removeValue(columnIndex); + } + } + this.columnKeys.remove(columnKey); + } } /** - * Removes a row. + * Removes an entire row from the table. * * @param rowIndex the row index. + * + * @see #removeColumn(int) */ public void removeRow(int rowIndex) { this.rowKeys.remove(rowIndex); @@ -281,18 +354,29 @@ } /** - * Removes a row. + * Removes an entire row from the table. * - * @param rowKey the row key. + * @param rowKey the row key (<code>null</code> not permitted). + * + * @throws UnknownKeyException if <code>rowKey</code> is not recognised. + * + * @see #removeColumn(Comparable) */ public void removeRow(Comparable rowKey) { - removeRow(getRowIndex(rowKey)); + int index = getRowIndex(rowKey); + if (index < 0) { + throw new UnknownKeyException("Row key (" + rowKey + + ") not recognised."); + } + removeRow(index); } /** - * Removes a column. + * Removes an entire column from the table. * * @param columnIndex the column index. + * + * @see #removeRow(int) */ public void removeColumn(int columnIndex) { Comparable columnKey = getColumnKey(columnIndex); @@ -300,15 +384,27 @@ } /** - * Removes a column. + * Removes an entire column from the table. * - * @param columnKey the column key. + * @param columnKey the column key (<code>null</code> not permitted). + * + * @throws UnknownKeyException if <code>rowKey</code> is not recognised. + * + * @see #removeRow(Comparable) */ public void removeColumn(Comparable columnKey) { + int index = getColumnIndex(columnKey); + if (index < 0) { + throw new UnknownKeyException("Column key (" + columnKey + + ") not recognised."); + } Iterator iterator = this.rows.iterator(); while (iterator.hasNext()) { KeyedObjects rowData = (KeyedObjects) iterator.next(); - rowData.removeValue(columnKey); + int i = rowData.getIndex(columnKey); + if (i >= 0) { + rowData.removeValue(i); + } } this.columnKeys.remove(columnKey); } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjects2DTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjects2DTests.java 2007-10-03 09:24:09 UTC (rev 225) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/junit/KeyedObjects2DTests.java 2007-10-03 10:51:09 UTC (rev 226) @@ -36,6 +36,7 @@ * ------- * 01-Mar-2004 : Version 1 (DG); * 28-Sep-2007 : Added testEquals() and enhanced testClone() (DG); + * 03-Oct-2007 : Added new tests (DG); * */ @@ -53,6 +54,7 @@ import junit.framework.TestSuite; import org.jfree.data.KeyedObjects2D; +import org.jfree.data.UnknownKeyException; /** * Tests for the {@link KeyedObjects2D} class. @@ -146,5 +148,282 @@ assertEquals(ko2D1, ko2D2); } + + /** + * Some checks for the getValue(int, int) method. + */ + public void testGetValueByIndex() { + KeyedObjects2D data = new KeyedObjects2D(); + data.addObject("Obj1", "R1", "C1"); + data.addObject("Obj2", "R2", "C2"); + assertEquals("Obj1", data.getObject(0, 0)); + assertEquals("Obj2", data.getObject(1, 1)); + assertNull(data.getObject(0, 1)); + assertNull(data.getObject(1, 0)); + + // check invalid indices + boolean pass = false; + try { + data.getObject(-1, 0); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + + pass = false; + try { + data.getObject(0, -1); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + pass = false; + try { + data.getObject(2, 0); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + + pass = false; + try { + data.getObject(0, 2); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the getValue(Comparable, Comparable) method. + */ + public void testGetValueByKey() { + KeyedObjects2D data = new KeyedObjects2D(); + data.addObject("Obj1", "R1", "C1"); + data.addObject("Obj2", "R2", "C2"); + assertEquals("Obj1", data.getObject("R1", "C1")); + assertEquals("Obj2", data.getObject("R2", "C2")); + assertNull(data.getObject("R1", "C2")); + assertNull(data.getObject("R2", "C1")); + + // check invalid indices + boolean pass = false; + try { + data.getObject("XX", "C1"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + + pass = false; + try { + data.getObject("R1", "XX"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + + pass = false; + try { + data.getObject("XX", "C1"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + + pass = false; + try { + data.getObject("R1", "XX"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the setObject(Object, Comparable, Comparable) method. + */ + public void testSetObject() { + KeyedObjects2D data = new KeyedObjects2D(); + data.setObject("Obj1", "R1", "C1"); + data.setObject("Obj2", "R2", "C2"); + assertEquals("Obj1", data.getObject("R1", "C1")); + assertEquals("Obj2", data.getObject("R2", "C2")); + assertNull(data.getObject("R1", "C2")); + assertNull(data.getObject("R2", "C1")); + + // confirm overwriting an existing value + data.setObject("ABC", "R2", "C2"); + assertEquals("ABC", data.getObject("R2", "C2")); + + // try null keys + boolean pass = false; + try { + data.setObject("X", null, "C1"); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + + pass = false; + try { + data.setObject("X", "R1", null); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the removeRow(int) method. + */ + public void testRemoveRowByIndex() { + KeyedObjects2D data = new KeyedObjects2D(); + data.setObject("Obj1", "R1", "C1"); + data.setObject("Obj2", "R2", "C2"); + data.removeRow(0); + assertEquals(1, data.getRowCount()); + assertEquals("Obj2", data.getObject(0, 1)); + + // try negative row index + boolean pass = false; + try { + data.removeRow(-1); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + + // try row index too high + pass = false; + try { + data.removeRow(data.getRowCount()); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the removeColumn(int) method. + */ + public void testRemoveColumnByIndex() { + KeyedObjects2D data = new KeyedObjects2D(); + data.setObject("Obj1", "R1", "C1"); + data.setObject("Obj2", "R2", "C2"); + data.removeColumn(0); + assertEquals(1, data.getColumnCount()); + assertEquals("Obj2", data.getObject(1, 0)); + + // try negative column index + boolean pass = false; + try { + data.removeColumn(-1); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + + // try column index too high + pass = false; + try { + data.removeColumn(data.getColumnCount()); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the removeRow(Comparable) method. + */ + public void testRemoveRowByKey() { + KeyedObjects2D data = new KeyedObjects2D(); + data.setObject("Obj1", "R1", "C1"); + data.setObject("Obj2", "R2", "C2"); + data.removeRow("R2"); + assertEquals(1, data.getRowCount()); + assertEquals("Obj1", data.getObject(0, 0)); + + // try unknown row key + boolean pass = false; + try { + data.removeRow("XXX"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + + // try null row key + pass = false; + try { + data.removeRow(null); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the removeColumn(Comparable) method. + */ + public void testRemoveColumnByKey() { + KeyedObjects2D data = new KeyedObjects2D(); + data.setObject("Obj1", "R1", "C1"); + data.setObject("Obj2", "R2", "C2"); + data.removeColumn("C2"); + assertEquals(1, data.getColumnCount()); + assertEquals("Obj1", data.getObject(0, 0)); + + // try unknown column key + boolean pass = false; + try { + data.removeColumn("XXX"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + + // try null column key + pass = false; + try { + data.removeColumn(null); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * A simple check for the removeValue() method. + */ + public void testRemoveValue() { + KeyedObjects2D data = new KeyedObjects2D(); + data.setObject("Obj1", "R1", "C1"); + data.setObject("Obj2", "R2", "C2"); + data.removeObject("R2", "C2"); + assertEquals(1, data.getRowCount()); + assertEquals(1, data.getColumnCount()); + assertEquals("Obj1", data.getObject(0, 0)); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-03 13:14:20
|
Revision: 230 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=230&view=rev Author: mungady Date: 2007-10-03 06:14:17 -0700 (Wed, 03 Oct 2007) Log Message: ----------- 2007-10-03 David Gilbert <dav...@ob...> * source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java (add(BoxAndWhiskerItem, Comparable, Comparable)): Update cached bounds by iteration if necessary, (updateBounds): New private method, * tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java (testGetRangeBounds): New test method. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-03 13:04:39 UTC (rev 229) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-03 13:14:17 UTC (rev 230) @@ -1,5 +1,14 @@ 2007-10-03 David Gilbert <dav...@ob...> + * source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java + (add(BoxAndWhiskerItem, Comparable, Comparable)): Update cached bounds by + iteration if necessary, + (updateBounds): New private method, + * tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java + (testGetRangeBounds): New test method. + +2007-10-03 David Gilbert <dav...@ob...> + * source/org/jfree/data/KeyedObjects2D.java (getObject(Comparable, Comparable)): Check arguments for null or unrecognised keys, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java 2007-10-03 13:04:39 UTC (rev 229) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java 2007-10-03 13:14:17 UTC (rev 230) @@ -49,6 +49,7 @@ * 13-Jun-2007 : Fixed error in previous patch (DG); * 28-Sep-2007 : Fixed cloning bug (DG); * 02-Oct-2007 : Fixed bug in updating cached bounds (DG); + * 03-Oct-2007 : Fixed another bug in updating cached bounds (DG); * */ @@ -118,12 +119,14 @@ * * @param list a collection of values from which the various medians will * be calculated. - * @param rowKey the row key. - * @param columnKey the column key. + * @param rowKey the row key (<code>null</code> not permitted). + * @param columnKey the column key (<code>null</code> not permitted). + * + * @see #add(BoxAndWhiskerItem, Comparable, Comparable) */ public void add(List list, Comparable rowKey, Comparable columnKey) { - BoxAndWhiskerItem item - = BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(list); + BoxAndWhiskerItem item = BoxAndWhiskerCalculator + .calculateBoxAndWhiskerStatistics(list); add(item, rowKey, columnKey); } @@ -132,62 +135,60 @@ * table. The various median values are calculated. * * @param item a box and whisker item (<code>null</code> not permitted). - * @param rowKey the row key. - * @param columnKey the column key. + * @param rowKey the row key (<code>null</code> not permitted). + * @param columnKey the column key (<code>null</code> not permitted). + * + * @see #add(List, Comparable, Comparable) */ - public void add(BoxAndWhiskerItem item, - Comparable rowKey, - Comparable columnKey) { + public void add(BoxAndWhiskerItem item, Comparable rowKey, + Comparable columnKey) { this.data.addObject(item, rowKey, columnKey); // update cached min and max values int r = this.data.getRowIndex(rowKey); int c = this.data.getColumnIndex(columnKey); - if (this.maximumRangeValueRow == r - && this.maximumRangeValueColumn == c) { - this.maximumRangeValue = Double.NaN; + if ((this.maximumRangeValueRow == r && this.maximumRangeValueColumn + == c) || (this.minimumRangeValueRow == r + && this.minimumRangeValueColumn == c)) { + updateBounds(); } - if (this.minimumRangeValueRow == r - && this.minimumRangeValueColumn == c) { - this.minimumRangeValue = Double.NaN; - } + else { + double minval = Double.NaN; + if (item.getMinOutlier() != null) { + minval = item.getMinOutlier().doubleValue(); + } + double maxval = Double.NaN; + if (item.getMaxOutlier() != null) { + maxval = item.getMaxOutlier().doubleValue(); + } - double minval = Double.NaN; - if (item.getMinOutlier() != null) { - minval = item.getMinOutlier().doubleValue(); - } - double maxval = Double.NaN; - if (item.getMaxOutlier() != null) { - maxval = item.getMaxOutlier().doubleValue(); - } + if (Double.isNaN(this.maximumRangeValue)) { + this.maximumRangeValue = maxval; + this.maximumRangeValueRow = r; + this.maximumRangeValueColumn = c; + } + else if (maxval > this.maximumRangeValue) { + this.maximumRangeValue = maxval; + this.maximumRangeValueRow = r; + this.maximumRangeValueColumn = c; + } - if (Double.isNaN(this.maximumRangeValue)) { - this.maximumRangeValue = maxval; - this.maximumRangeValueRow = r; - this.maximumRangeValueColumn = c; + if (Double.isNaN(this.minimumRangeValue)) { + this.minimumRangeValue = minval; + this.minimumRangeValueRow = r; + this.minimumRangeValueColumn = c; + } + else if (minval < this.minimumRangeValue) { + this.minimumRangeValue = minval; + this.minimumRangeValueRow = r; + this.minimumRangeValueColumn = c; + } } - else if (maxval > this.maximumRangeValue) { - this.maximumRangeValue = maxval; - this.maximumRangeValueRow = r; - this.maximumRangeValueColumn = c; - } - if (Double.isNaN(this.minimumRangeValue)) { - this.minimumRangeValue = minval; - this.minimumRangeValueRow = r; - this.minimumRangeValueColumn = c; - } - else if (minval < this.minimumRangeValue) { - this.minimumRangeValue = minval; - this.minimumRangeValueRow = r; - this.minimumRangeValueColumn = c; - } - this.rangeBounds = new Range(this.minimumRangeValue, this.maximumRangeValue); - fireDatasetChanged(); } @@ -241,6 +242,8 @@ * @param column the column index (zero-based). * * @return The mean value. + * + * @see #getItem(int, int) */ public Number getMeanValue(int row, int column) { @@ -261,6 +264,8 @@ * @param columnKey the column key. * * @return The mean value. + * + * @see #getItem(int, int) */ public Number getMeanValue(Comparable rowKey, Comparable columnKey) { Number result = null; @@ -279,6 +284,8 @@ * @param column the column index (zero-based). * * @return The median value. + * + * @see #getItem(int, int) */ public Number getMedianValue(int row, int column) { Number result = null; @@ -297,6 +304,8 @@ * @param columnKey the columnKey. * * @return The median value. + * + * @see #getItem(int, int) */ public Number getMedianValue(Comparable rowKey, Comparable columnKey) { Number result = null; @@ -315,6 +324,8 @@ * @param column the column index (zero-based). * * @return The first quartile value. + * + * @see #getItem(int, int) */ public Number getQ1Value(int row, int column) { Number result = null; @@ -333,6 +344,8 @@ * @param columnKey the column key. * * @return The first quartile value. + * + * @see #getItem(int, int) */ public Number getQ1Value(Comparable rowKey, Comparable columnKey) { Number result = null; @@ -351,6 +364,8 @@ * @param column the column index (zero-based). * * @return The third quartile value. + * + * @see #getItem(int, int) */ public Number getQ3Value(int row, int column) { Number result = null; @@ -369,6 +384,8 @@ * @param columnKey the column key. * * @return The third quartile value. + * + * @see #getItem(int, int) */ public Number getQ3Value(Comparable rowKey, Comparable columnKey) { Number result = null; @@ -386,6 +403,8 @@ * @param key the column key. * * @return The column index. + * + * @see #getColumnKey(int) */ public int getColumnIndex(Comparable key) { return this.data.getColumnIndex(key); @@ -397,6 +416,8 @@ * @param column the column index (zero-based). * * @return The column key. + * + * @see #getColumnIndex(Comparable) */ public Comparable getColumnKey(int column) { return this.data.getColumnKey(column); @@ -406,6 +427,8 @@ * Returns the column keys. * * @return The keys. + * + * @see #getRowKeys() */ public List getColumnKeys() { return this.data.getColumnKeys(); @@ -417,6 +440,8 @@ * @param key the row key. * * @return The row index. + * + * @see #getRowKey(int) */ public int getRowIndex(Comparable key) { return this.data.getRowIndex(key); @@ -428,6 +453,8 @@ * @param row the row index (zero-based). * * @return The row key. + * + * @see #getRowIndex(Comparable) */ public Comparable getRowKey(int row) { return this.data.getRowKey(row); @@ -437,6 +464,8 @@ * Returns the row keys. * * @return The keys. + * + * @see #getColumnKeys() */ public List getRowKeys() { return this.data.getRowKeys(); @@ -446,6 +475,8 @@ * Returns the number of rows in the table. * * @return The row count. + * + * @see #getColumnCount() */ public int getRowCount() { return this.data.getRowCount(); @@ -455,6 +486,8 @@ * Returns the number of columns in the table. * * @return The column count. + * + * @see #getRowCount() */ public int getColumnCount() { return this.data.getColumnCount(); @@ -467,6 +500,8 @@ * y-interval is taken into account. * * @return The minimum value. + * + * @see #getRangeUpperBound(boolean) */ public double getRangeLowerBound(boolean includeInterval) { return this.minimumRangeValue; @@ -479,6 +514,8 @@ * y-interval is taken into account. * * @return The maximum value. + * + * @see #getRangeLowerBound(boolean) */ public double getRangeUpperBound(boolean includeInterval) { return this.maximumRangeValue; @@ -503,6 +540,8 @@ * @param column the column index (zero-based). * * @return The minimum regular value. + * + * @see #getItem(int, int) */ public Number getMinRegularValue(int row, int column) { Number result = null; @@ -521,6 +560,8 @@ * @param columnKey the column key. * * @return The minimum regular value. + * + * @see #getItem(int, int) */ public Number getMinRegularValue(Comparable rowKey, Comparable columnKey) { Number result = null; @@ -539,6 +580,8 @@ * @param column the column index (zero-based). * * @return The maximum regular value. + * + * @see #getItem(int, int) */ public Number getMaxRegularValue(int row, int column) { Number result = null; @@ -557,6 +600,8 @@ * @param columnKey the column key. * * @return The maximum regular value. + * + * @see #getItem(int, int) */ public Number getMaxRegularValue(Comparable rowKey, Comparable columnKey) { Number result = null; @@ -575,6 +620,8 @@ * @param column the column index (zero-based). * * @return The minimum outlier. + * + * @see #getItem(int, int) */ public Number getMinOutlier(int row, int column) { Number result = null; @@ -593,6 +640,8 @@ * @param columnKey the column key. * * @return The minimum outlier. + * + * @see #getItem(int, int) */ public Number getMinOutlier(Comparable rowKey, Comparable columnKey) { Number result = null; @@ -611,6 +660,8 @@ * @param column the column index (zero-based). * * @return The maximum outlier. + * + * @see #getItem(int, int) */ public Number getMaxOutlier(int row, int column) { Number result = null; @@ -629,6 +680,8 @@ * @param columnKey the column key. * * @return The maximum outlier. + * + * @see #getItem(int, int) */ public Number getMaxOutlier(Comparable rowKey, Comparable columnKey) { Number result = null; @@ -647,6 +700,8 @@ * @param column the column index (zero-based). * * @return A list of outlier values. + * + * @see #getItem(int, int) */ public List getOutliers(int row, int column) { List result = null; @@ -665,6 +720,8 @@ * @param columnKey the column key. * * @return A list of outlier values. + * + * @see #getItem(int, int) */ public List getOutliers(Comparable rowKey, Comparable columnKey) { List result = null; @@ -677,6 +734,52 @@ } /** + * Resets the cached bounds, by iterating over the entire dataset to find + * the current bounds. + */ + private void updateBounds() { + this.minimumRangeValue = Double.NaN; + this.minimumRangeValueRow = -1; + this.minimumRangeValueColumn = -1; + this.maximumRangeValue = Double.NaN; + this.maximumRangeValueRow = -1; + this.maximumRangeValueColumn = -1; + int rowCount = getRowCount(); + int columnCount = getColumnCount(); + for (int r = 0; r < rowCount; r++) { + for (int c = 0; c < columnCount; c++) { + BoxAndWhiskerItem item = getItem(r, c); + if (item != null) { + Number min = item.getMinOutlier(); + if (min != null) { + double minv = min.doubleValue(); + if (!Double.isNaN(minv)) { + if (minv < this.minimumRangeValue || Double.isNaN( + this.minimumRangeValue)) { + this.minimumRangeValue = minv; + this.minimumRangeValueRow = r; + this.minimumRangeValueColumn = c; + } + } + } + Number max = item.getMaxOutlier(); + if (max != null) { + double maxv = max.doubleValue(); + if (!Double.isNaN(maxv)) { + if (maxv > this.maximumRangeValue || Double.isNaN( + this.maximumRangeValue)) { + this.maximumRangeValue = maxv; + this.maximumRangeValueRow = r; + this.maximumRangeValueColumn = c; + } + } + } + } + } + } + } + + /** * Tests this dataset for equality with an arbitrary object. * * @param obj the object to test against (<code>null</code> permitted). Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java 2007-10-03 13:04:39 UTC (rev 229) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java 2007-10-03 13:14:17 UTC (rev 230) @@ -38,6 +38,7 @@ * 17-Apr-2007 : Added a test for bug 1701822 (DG); * 28-Sep-2007 : Enhanced testClone() (DG); * 02-Oct-2007 : Added new tests (DG); + * 03-Oct-2007 : Added getTestRangeBounds() (DG); * */ @@ -262,5 +263,34 @@ assertTrue(Double.isNaN(dataset.getRangeLowerBound(false))); assertTrue(Double.isNaN(dataset.getRangeUpperBound(false))); } + + /** + * Some checks for the getRangeBounds() method. + */ + public void testGetRangeBounds() { + DefaultBoxAndWhiskerCategoryDataset d1 + = new DefaultBoxAndWhiskerCategoryDataset(); + d1.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, + new ArrayList()), "R1", "C1"); + assertEquals(new Range(7.0, 8.0), d1.getRangeBounds(false)); + assertEquals(new Range(7.0, 8.0), d1.getRangeBounds(true)); + + d1.add(new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, + new ArrayList()), "R1", "C1"); + assertEquals(new Range(7.5, 8.5), d1.getRangeBounds(false)); + assertEquals(new Range(7.5, 8.5), d1.getRangeBounds(true)); + + d1.add(new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, + new ArrayList()), "R2", "C1"); + assertEquals(new Range(7.5, 9.5), d1.getRangeBounds(false)); + assertEquals(new Range(7.5, 9.5), d1.getRangeBounds(true)); + + // this replaces the entry with the current minimum value, but the new + // minimum value is now in a different item + d1.add(new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 8.6, 9.6, + new ArrayList()), "R1", "C1"); + assertEquals(new Range(8.5, 9.6), d1.getRangeBounds(false)); + assertEquals(new Range(8.5, 9.6), d1.getRangeBounds(true)); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-03 14:43:49
|
Revision: 235 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=235&view=rev Author: mungady Date: 2007-10-03 07:43:41 -0700 (Wed, 03 Oct 2007) Log Message: ----------- 2007-10-03 David Gilbert <dav...@ob...> * source/org/jfree/data/KeyedObjects2D.java (getRowIndex): Check for null argument, (getColumnIndex): Likewise, (removeObject): Check for unknown keys, (clear): New method, * source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java (rangeBounds): Removed, (DefaultBoxAndWhiskerCategoryDataset()): Updated for removed field, (add(BoxAndWhiskerItem, Comparable, Comparable)): Likewise, (remove(Comparable, Comparable)): New method, (removeRow(int)): Likewise, (removeRow(Comparable)): Likewise, (removeColumn(int)): Likewise, (removeColumn(Comparable)): Likewise, (clear): Likewise, (getRangeBounds): Return new instance every time, * source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java (remove(Comparable, Comparable)): New method, (removeRow(int)): Likewise, (removeRow(Comparable)): Likewise, (removeColumn(int)): Likewise, (removeColumn(Comparable)): Likewise, (clear): Likewise, (getRangeBounds): Return new instance every time, * tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java (testRemove): New method, * tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java (testRemove): New method. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-03 14:14:27 UTC (rev 234) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-03 14:43:41 UTC (rev 235) @@ -1,6 +1,37 @@ 2007-10-03 David Gilbert <dav...@ob...> + * source/org/jfree/data/KeyedObjects2D.java + (getRowIndex): Check for null argument, + (getColumnIndex): Likewise, + (removeObject): Check for unknown keys, + (clear): New method, * source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java + (rangeBounds): Removed, + (DefaultBoxAndWhiskerCategoryDataset()): Updated for removed field, + (add(BoxAndWhiskerItem, Comparable, Comparable)): Likewise, + (remove(Comparable, Comparable)): New method, + (removeRow(int)): Likewise, + (removeRow(Comparable)): Likewise, + (removeColumn(int)): Likewise, + (removeColumn(Comparable)): Likewise, + (clear): Likewise, + (getRangeBounds): Return new instance every time, + * source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java + (remove(Comparable, Comparable)): New method, + (removeRow(int)): Likewise, + (removeRow(Comparable)): Likewise, + (removeColumn(int)): Likewise, + (removeColumn(Comparable)): Likewise, + (clear): Likewise, + (getRangeBounds): Return new instance every time, + * tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java + (testRemove): New method, + * tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java + (testRemove): New method. + +2007-10-03 David Gilbert <dav...@ob...> + + * source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java (add(BoxAndWhiskerItem, Comparable, Comparable)): Update cached bounds by iteration if necessary, (updateBounds): New private method, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java 2007-10-03 14:14:27 UTC (rev 234) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/KeyedObjects2D.java 2007-10-03 14:43:41 UTC (rev 235) @@ -38,7 +38,7 @@ * 01-Mar-2004 : Added equals() and clone() methods and implemented * Serializable (DG); * 03-Oct-2007 : Updated getObject() to handle modified behaviour in - * KeyedObjects class (DG); + * KeyedObjects class, added clear() method (DG); * */ @@ -49,7 +49,6 @@ import java.util.Iterator; import java.util.List; - /** * A data structure that stores zero, one or many objects, where each object is * associated with two keys (a 'row' key and a 'column' key). @@ -138,15 +137,19 @@ } /** - * Returns the row index for a given key. + * Returns the row index for a given key, or <code>-1</code> if the key + * is not recognised. * - * @param key the key. + * @param key the key (<code>null</code> not permitted). * * @return The row index. * * @see #getRowKey(int) */ public int getRowIndex(Comparable key) { + if (key == null) { + throw new IllegalArgumentException("Null 'key' argument."); + } return this.rowKeys.indexOf(key); } @@ -175,15 +178,19 @@ } /** - * Returns the column index for a given key. + * Returns the column index for a given key, or <code>-1</code> if the key + * is not recognised. * - * @param key the key. + * @param key the key (<code>null</code> not permitted). * * @return The column index. * * @see #getColumnKey(int) */ public int getColumnIndex(Comparable key) { + if (key == null) { + throw new IllegalArgumentException("Null 'key' argument."); + } return this.columnKeys.indexOf(key); } @@ -295,11 +302,20 @@ * @see #addObject(Object, Comparable, Comparable) */ public void removeObject(Comparable rowKey, Comparable columnKey) { + int rowIndex = getRowIndex(rowKey); + if (rowIndex < 0) { + throw new UnknownKeyException("Row key (" + rowKey + + ") not recognised."); + } + int columnIndex = getColumnIndex(columnKey); + if (columnIndex < 0) { + throw new UnknownKeyException("Column key (" + columnKey + + ") not recognised."); + } setObject(null, rowKey, columnKey); // 1. check whether the row is now empty. boolean allNull = true; - int rowIndex = getRowIndex(rowKey); KeyedObjects row = (KeyedObjects) this.rows.get(rowIndex); for (int item = 0, itemCount = row.getItemCount(); item < itemCount; @@ -321,8 +337,8 @@ for (int item = 0, itemCount = this.rows.size(); item < itemCount; item++) { row = (KeyedObjects) this.rows.get(item); - int columnIndex = row.getIndex(columnKey); - if (columnIndex >= 0 && row.getObject(columnIndex) != null) { + int colIndex = row.getIndex(columnKey); + if (colIndex >= 0 && row.getObject(colIndex) != null) { allNull = false; break; } @@ -332,9 +348,9 @@ for (int item = 0, itemCount = this.rows.size(); item < itemCount; item++) { row = (KeyedObjects) this.rows.get(item); - int columnIndex = row.getIndex(columnKey); - if (columnIndex >= 0) { - row.removeValue(columnIndex); + int colIndex = row.getIndex(columnKey); + if (colIndex >= 0) { + row.removeValue(colIndex); } } this.columnKeys.remove(columnKey); @@ -410,6 +426,17 @@ } /** + * Clears all the data and associated keys. + * + * @since 1.0.7 + */ + public void clear() { + this.rowKeys.clear(); + this.columnKeys.clear(); + this.rows.clear(); + } + + /** * Tests this object for equality with an arbitrary object. * * @param obj the object to test (<code>null</code> permitted). Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java 2007-10-03 14:14:27 UTC (rev 234) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java 2007-10-03 14:43:41 UTC (rev 235) @@ -49,7 +49,8 @@ * 13-Jun-2007 : Fixed error in previous patch (DG); * 28-Sep-2007 : Fixed cloning bug (DG); * 02-Oct-2007 : Fixed bug in updating cached bounds (DG); - * 03-Oct-2007 : Fixed another bug in updating cached bounds (DG); + * 03-Oct-2007 : Fixed another bug in updating cached bounds, added removal + * methods (DG); * */ @@ -61,6 +62,7 @@ import org.jfree.data.Range; import org.jfree.data.RangeInfo; import org.jfree.data.general.AbstractDataset; +import org.jfree.data.general.DatasetChangeEvent; import org.jfree.util.ObjectUtilities; import org.jfree.util.PublicCloneable; @@ -96,9 +98,6 @@ */ private int maximumRangeValueColumn; - /** The range of values. */ - private Range rangeBounds; - /** * Creates a new dataset. */ @@ -110,7 +109,6 @@ this.maximumRangeValue = Double.NaN; this.maximumRangeValueRow = -1; this.maximumRangeValueColumn = -1; - this.rangeBounds = new Range(0.0, 0.0); } /** @@ -187,13 +185,115 @@ } } - this.rangeBounds = new Range(this.minimumRangeValue, - this.maximumRangeValue); fireDatasetChanged(); } + + /** + * Removes an item from the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @param rowKey the row key (<code>null</code> not permitted). + * @param columnKey the column key (<code>null</code> not permitted). + * + * @see #add(BoxAndWhiskerItem, Comparable, Comparable) + * + * @since 1.0.7 + */ + public void remove(Comparable rowKey, Comparable columnKey) { + // defer null argument checks + int r = getRowIndex(rowKey); + int c = getColumnIndex(columnKey); + this.data.removeObject(rowKey, columnKey); + + // if this cell held a maximum and/or minimum value, we'll need to + // update the cached bounds... + if ((this.maximumRangeValueRow == r && this.maximumRangeValueColumn + == c) || (this.minimumRangeValueRow == r + && this.minimumRangeValueColumn == c)) { + updateBounds(); + } + + fireDatasetChanged(); + } /** + * Removes a row from the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @param rowIndex the row index. + * + * @see #removeColumn(int) + * + * @since 1.0.7 + */ + public void removeRow(int rowIndex) { + this.data.removeRow(rowIndex); + updateBounds(); + fireDatasetChanged(); + } + + /** + * Removes a row from the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @param rowKey the row key. + * + * @see #removeColumn(Comparable) + * + * @since 1.0.7 + */ + public void removeRow(Comparable rowKey) { + this.data.removeRow(rowKey); + updateBounds(); + fireDatasetChanged(); + } + + /** + * Removes a column from the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @param columnIndex the column index. + * + * @see #removeRow(int) + * + * @since 1.0.7 + */ + public void removeColumn(int columnIndex) { + this.data.removeColumn(columnIndex); + updateBounds(); + fireDatasetChanged(); + } + + /** + * Removes a column from the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @param columnKey the column key. + * + * @see #removeRow(Comparable) + * + * @since 1.0.7 + */ + public void removeColumn(Comparable columnKey) { + this.data.removeColumn(columnKey); + updateBounds(); + fireDatasetChanged(); + } + + /** + * Clears all data from the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @since 1.0.7 + */ + public void clear() { + this.data.clear(); + updateBounds(); + fireDatasetChanged(); + } + + /** * Return an item from within the dataset. * * @param row the row index. @@ -400,7 +500,7 @@ /** * Returns the column index for a given key. * - * @param key the column key. + * @param key the column key (<code>null</code> not permitted). * * @return The column index. * @@ -437,13 +537,14 @@ /** * Returns the row index for a given key. * - * @param key the row key. + * @param key the row key (<code>null</code> not permitted). * * @return The row index. * * @see #getRowKey(int) */ public int getRowIndex(Comparable key) { + // defer null argument check return this.data.getRowIndex(key); } @@ -530,7 +631,7 @@ * @return The range. */ public Range getRangeBounds(boolean includeInterval) { - return this.rangeBounds; + return new Range(this.minimumRangeValue, this.maximumRangeValue); } /** Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java 2007-10-03 14:14:27 UTC (rev 234) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java 2007-10-03 14:43:41 UTC (rev 235) @@ -61,6 +61,7 @@ import org.jfree.data.Range; import org.jfree.data.RangeInfo; import org.jfree.data.general.AbstractDataset; +import org.jfree.data.general.DatasetChangeEvent; import org.jfree.util.PublicCloneable; /** @@ -241,11 +242,12 @@ /** * Returns the column index for a given key. * - * @param key the column key. + * @param key the column key (<code>null</code> not permitted). * * @return The column index. */ public int getColumnIndex(Comparable key) { + // defer null argument check return this.data.getColumnIndex(key); } @@ -272,11 +274,12 @@ /** * Returns the row index for a given key. * - * @param key the row key. + * @param key the row key (<code>null</code> not permitted). * * @return The row index. */ public int getRowIndex(Comparable key) { + // defer null argument check return this.data.getRowIndex(key); } @@ -408,8 +411,120 @@ } fireDatasetChanged(); } + + /** + * Removes an item from the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @param rowKey the row key (<code>null</code> not permitted). + * @param columnKey the column key (<code>null</code> not permitted). + * + * @see #add(double, double, Comparable, Comparable) + * + * @since 1.0.7 + */ + public void remove(Comparable rowKey, Comparable columnKey) { + // defer null argument checks + int r = getRowIndex(rowKey); + int c = getColumnIndex(columnKey); + this.data.removeObject(rowKey, columnKey); + + // if this cell held a maximum and/or minimum value, we'll need to + // update the cached bounds... + if ((r == this.maximumRangeValueRow && c + == this.maximumRangeValueColumn) || (r + == this.maximumRangeValueIncStdDevRow && c + == this.maximumRangeValueIncStdDevColumn) || (r + == this.minimumRangeValueRow && c + == this.minimumRangeValueColumn) || (r + == this.minimumRangeValueIncStdDevRow && c + == this.minimumRangeValueIncStdDevColumn)) { + + // iterate over all data items and update mins and maxes + updateBounds(); + } + + fireDatasetChanged(); + } + /** + * Removes a row from the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @param rowIndex the row index. + * + * @see #removeColumn(int) + * + * @since 1.0.7 + */ + public void removeRow(int rowIndex) { + this.data.removeRow(rowIndex); + updateBounds(); + fireDatasetChanged(); + } + + /** + * Removes a row from the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @param rowKey the row key. + * + * @see #removeColumn(Comparable) + * + * @since 1.0.7 + */ + public void removeRow(Comparable rowKey) { + this.data.removeRow(rowKey); + updateBounds(); + fireDatasetChanged(); + } + + /** + * Removes a column from the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @param columnIndex the column index. + * + * @see #removeRow(int) + * + * @since 1.0.7 + */ + public void removeColumn(int columnIndex) { + this.data.removeColumn(columnIndex); + updateBounds(); + fireDatasetChanged(); + } + + /** + * Removes a column from the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @param columnKey the column key. + * + * @see #removeRow(Comparable) + * + * @since 1.0.7 + */ + public void removeColumn(Comparable columnKey) { + this.data.removeColumn(columnKey); + updateBounds(); + fireDatasetChanged(); + } + + /** + * Clears all data from the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @since 1.0.7 + */ + public void clear() { + this.data.clear(); + updateBounds(); + fireDatasetChanged(); + } + + /** * Iterate over all the data items and update the cached bound values. */ private void updateBounds() { Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java 2007-10-03 14:14:27 UTC (rev 234) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java 2007-10-03 14:43:41 UTC (rev 235) @@ -38,7 +38,7 @@ * 17-Apr-2007 : Added a test for bug 1701822 (DG); * 28-Sep-2007 : Enhanced testClone() (DG); * 02-Oct-2007 : Added new tests (DG); - * 03-Oct-2007 : Added getTestRangeBounds() (DG); + * 03-Oct-2007 : Added getTestRangeBounds() and testRemove() (DG); * */ @@ -57,6 +57,7 @@ import junit.framework.TestSuite; import org.jfree.data.Range; +import org.jfree.data.UnknownKeyException; import org.jfree.data.statistics.BoxAndWhiskerItem; import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset; @@ -292,5 +293,35 @@ assertEquals(new Range(8.5, 9.6), d1.getRangeBounds(false)); assertEquals(new Range(8.5, 9.6), d1.getRangeBounds(true)); } + + /** + * Some checks for the remove method. + */ + public void testRemove() { + DefaultBoxAndWhiskerCategoryDataset data + = new DefaultBoxAndWhiskerCategoryDataset(); + + boolean pass = false; + try { + data.remove("R1", "R2"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + data.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, + new ArrayList()), "R1", "C1"); + assertEquals(new Range(7.0, 8.0), data.getRangeBounds(false)); + assertEquals(new Range(7.0, 8.0), data.getRangeBounds(true)); + + data.add(new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, + new ArrayList()), "R2", "C1"); + assertEquals(new Range(7.0, 9.5), data.getRangeBounds(false)); + assertEquals(new Range(7.0, 9.5), data.getRangeBounds(true)); + + data.remove("R1", "C1"); + assertEquals(new Range(8.5, 9.5), data.getRangeBounds(false)); + assertEquals(new Range(8.5, 9.5), data.getRangeBounds(true)); + } } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java 2007-10-03 14:14:27 UTC (rev 234) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java 2007-10-03 14:43:41 UTC (rev 235) @@ -38,6 +38,7 @@ * 03-Aug-2006 : Added testGetRangeBounds() method (DG); * 28-Sep-2007 : Enhanced testCloning() method (DG); * 02-Oct-2007 : Added new bounds tests (DG); + * 03-Oct-2007 : Added testRemove() method (DG); * */ @@ -55,6 +56,7 @@ import junit.framework.TestSuite; import org.jfree.data.Range; +import org.jfree.data.UnknownKeyException; import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; /** @@ -266,5 +268,40 @@ assertEquals(new Range(10.0, 10.0), d1.getRangeBounds(false)); assertEquals(new Range(-10.0, 30.0), d1.getRangeBounds(true)); } + + /** + * Some checks for the remove method. + */ + public void testRemove() { + DefaultStatisticalCategoryDataset data + = new DefaultStatisticalCategoryDataset(); + + boolean pass = false; + try { + data.remove("R1", "R2"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + data.add(1.0, 0.5, "R1", "C1"); + assertEquals(new Range(1.0, 1.0), data.getRangeBounds(false)); + assertEquals(new Range(0.5, 1.5), data.getRangeBounds(true)); + + data.add(1.4, 0.2, "R2", "C1"); + + assertEquals(1.0, data.getRangeLowerBound(false), EPSILON); + assertEquals(1.4, data.getRangeUpperBound(false), EPSILON); + assertEquals(0.5, data.getRangeLowerBound(true), EPSILON); + assertEquals(1.6, data.getRangeUpperBound(true), EPSILON); + + data.remove("R1", "C1"); + assertEquals(1.4, data.getRangeLowerBound(false), EPSILON); + assertEquals(1.4, data.getRangeUpperBound(false), EPSILON); + assertEquals(1.2, data.getRangeLowerBound(true), EPSILON); + assertEquals(1.6, data.getRangeUpperBound(true), EPSILON); + } + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-05 14:18:06
|
Revision: 274 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=274&view=rev Author: mungady Date: 2007-10-05 07:18:04 -0700 (Fri, 05 Oct 2007) Log Message: ----------- 2007-10-05 David Gilbert <dav...@ob...> Based on patch 1805262 by Alex Moots: * source/org/jfree/chart/plot/PiePlot3D.java (darkerSides): New field, (getDarkerSides): New method, (setDarkerSides): Likewise, (drawSide): Make side colour darker if necessary, (equals): Updated for new field, * tests/org/jfree/chart/plot/junit/PiePlot3DTests.java (testEquals): Updated for new field. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PiePlot3D.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/PiePlot3DTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-05 13:43:34 UTC (rev 273) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-05 14:18:04 UTC (rev 274) @@ -1,3 +1,15 @@ +2007-10-05 David Gilbert <dav...@ob...> + + Based on patch 1805262 by Alex Moots: + * source/org/jfree/chart/plot/PiePlot3D.java + (darkerSides): New field, + (getDarkerSides): New method, + (setDarkerSides): Likewise, + (drawSide): Make side colour darker if necessary, + (equals): Updated for new field, + * tests/org/jfree/chart/plot/junit/PiePlot3DTests.java + (testEquals): Updated for new field. + 2007-10-03 David Gilbert <dav...@ob...> * source/org/jfree/data/KeyedObjects2D.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PiePlot3D.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PiePlot3D.java 2007-10-05 13:43:34 UTC (rev 273) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PiePlot3D.java 2007-10-05 14:18:04 UTC (rev 274) @@ -72,6 +72,8 @@ * 27-Sep-2006 : Updated draw() method for new lookup methods (DG); * 22-Mar-2007 : Added equals() override (DG); * 18-Jun-2007 : Added handling for simple label option (DG); + * 04-Oct-2007 : Added option to darken sides of plot - thanks to Alex Moots + * (see patch 1805262) (DG); * */ @@ -120,6 +122,15 @@ /** The factor of the depth of the pie from the plot height */ private double depthFactor = 0.2; + /** + * A flag that controls whether or not the sides of the pie chart + * are rendered using a darker colour. + * + * @since 1.0.7. + */ + private boolean darkerSides = false; // default preserves previous + // behaviour + /** * Creates a new instance with no dataset. */ @@ -163,6 +174,38 @@ } /** + * Returns a flag that controls whether or not the sides of the pie chart + * are rendered using a darker colour. This is only applied if the + * section colour is an instance of {@link java.awt.Color}. + * + * @return A boolean. + * + * @see #setDarkerSides(boolean) + * + * @since 1.0.7 + */ + public boolean getDarkerSides() { + return this.darkerSides; + } + + /** + * Sets a flag that controls whether or not the sides of the pie chart + * are rendered using a darker colour, and sends a {@link PlotChangeEvent} + * to all registered listeners. This is only applied if the + * section colour is an instance of {@link java.awt.Color}. + * + * @param darker true to darken the sides, false to use the default behaviour. + * + * @see #getDarkerSides() + * + * @since 1.0.7. + */ + public void setDarkerSides(boolean darker) { + this.darkerSides = darker; + notifyListeners(new PlotChangeEvent(this)); + } + + /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). This method is called by the * {@link org.jfree.chart.JFreeChart} class, you don't normally need @@ -541,6 +584,14 @@ boolean drawFront, boolean drawBack) { + if (getDarkerSides()) { + if (paint instanceof Color) { + Color c = (Color) paint; + c = c.darker(); + paint = c; + } + } + double start = arc.getAngleStart(); double extent = arc.getAngleExtent(); double end = start + extent; @@ -937,6 +988,9 @@ if (this.depthFactor != that.depthFactor) { return false; } + if (this.darkerSides != that.darkerSides) { + return false; + } return super.equals(obj); } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/PiePlot3DTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/PiePlot3DTests.java 2007-10-05 13:43:34 UTC (rev 273) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/PiePlot3DTests.java 2007-10-05 14:18:04 UTC (rev 274) @@ -36,6 +36,7 @@ * ------- * 18-Mar-2003 : Version 1 (DG); * 22-Mar-2007 : Added testEquals() (DG); + * 05-Oct-2007 : Modified testEquals() for new field (DG); * */ @@ -90,6 +91,11 @@ assertFalse(p1.equals(p2)); p2.setDepthFactor(1.23); assertTrue(p1.equals(p2)); + + p1.setDarkerSides(true); + assertFalse(p1.equals(p2)); + p2.setDarkerSides(true); + assertTrue(p1.equals(p2)); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-08 09:06:17
|
Revision: 280 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=280&view=rev Author: mungady Date: 2007-10-08 02:06:16 -0700 (Mon, 08 Oct 2007) Log Message: ----------- 2007-10-08 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/xy/CandlestickRenderer.java (volumePaint): New field, (CandlestickRenderer(double, boolean, XYToolTipGenerator)): Initialise new field, (getVolumePaint): New method, (setVolumePaint): Likewise, (drawItem): Use new paint attribute, (equals): Add check for new field, (writeObject): Handle serialization for new field, (readObject): Likewise, * tests/org/jfree/chart/renderer/xy/junit/CandlestickRendererTests.java (EPSILON): New field, (testConstructor): New method, (testEquals): Added check for new field. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/CandlestickRenderer.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/CandlestickRendererTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-05 16:11:14 UTC (rev 279) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-08 09:06:16 UTC (rev 280) @@ -1,3 +1,20 @@ +2007-10-08 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/renderer/xy/CandlestickRenderer.java + (volumePaint): New field, + (CandlestickRenderer(double, boolean, XYToolTipGenerator)): Initialise new + field, + (getVolumePaint): New method, + (setVolumePaint): Likewise, + (drawItem): Use new paint attribute, + (equals): Add check for new field, + (writeObject): Handle serialization for new field, + (readObject): Likewise, + * tests/org/jfree/chart/renderer/xy/junit/CandlestickRendererTests.java + (EPSILON): New field, + (testConstructor): New method, + (testEquals): Added check for new field. + 2007-10-05 David Gilbert <dav...@ob...> Based on patch 1805262 by Alex Moots: Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/CandlestickRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/CandlestickRenderer.java 2007-10-05 16:11:14 UTC (rev 279) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/CandlestickRenderer.java 2007-10-08 09:06:16 UTC (rev 280) @@ -77,6 +77,7 @@ * other data values (DG); * 17-Aug-2006 : Corrections to the equals() method (DG); * 05-Mar-2007 : Added flag to allow optional use of outline paint (DG); + * 08-Oct-2007 : Added new volumePaint field (DG); * */ @@ -176,6 +177,14 @@ /** A flag controlling whether or not volume bars are drawn on the chart. */ private boolean drawVolume; + /** + * The paint used to fill the volume bars (if they are visible). Once + * initialised, this field should never be set to <code>null</code>. + * + * @since 1.0.7 + */ + private transient Paint volumePaint; + /** Temporary storage for the maximum volume. */ private transient double maxVolume; @@ -225,6 +234,7 @@ setBaseToolTipGenerator(toolTipGenerator); this.candleWidth = candleWidth; this.drawVolume = drawVolume; + this.volumePaint = Color.gray; this.upPaint = Color.green; this.downPaint = Color.red; this.useOutlinePaint = false; // false preserves the old behaviour @@ -473,6 +483,39 @@ notifyListeners(new RendererChangeEvent(this)); } } + + /** + * Returns the paint that is used to fill the volume bars if they are + * visible. + * + * @return The paint (never <code>null</code>). + * + * @see #setVolumePaint(Paint) + * + * @since 1.0.7 + */ + public Paint getVolumePaint() { + return this.volumePaint; + } + + /** + * Sets the paint used to fill the volume bars, and sends a + * {@link RendererChangeEvent} to all registered listeners. + * + * @param paint the paint (<code>null</code> not permitted). + * + * @see #getVolumePaint() + * @see #getDrawVolume() + * + * @since 1.0.7 + */ + public void setVolumePaint(Paint paint) { + if (paint == null) { + throw new IllegalArgumentException("Null 'paint' argument."); + } + this.volumePaint = paint; + notifyListeners(new RendererChangeEvent(this)); + } /** * Returns the flag that controls whether or not the renderer's outline @@ -711,7 +754,7 @@ double zzVolume = volumeHeight * (max - min); - g2.setPaint(Color.gray); + g2.setPaint(getVolumePaint()); Composite originalComposite = g2.getComposite(); g2.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f) @@ -858,6 +901,9 @@ if (this.useOutlinePaint != that.useOutlinePaint) { return false; } + if (!PaintUtilities.equal(this.volumePaint, that.volumePaint)) { + return false; + } return super.equals(obj); } @@ -883,6 +929,7 @@ stream.defaultWriteObject(); SerialUtilities.writePaint(this.upPaint, stream); SerialUtilities.writePaint(this.downPaint, stream); + SerialUtilities.writePaint(this.volumePaint, stream); } /** @@ -898,6 +945,7 @@ stream.defaultReadObject(); this.upPaint = SerialUtilities.readPaint(stream); this.downPaint = SerialUtilities.readPaint(stream); + this.volumePaint = SerialUtilities.readPaint(stream); } // --- DEPRECATED CODE ---------------------------------------------------- Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/CandlestickRendererTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/CandlestickRendererTests.java 2007-10-05 16:11:14 UTC (rev 279) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/CandlestickRendererTests.java 2007-10-08 09:06:16 UTC (rev 280) @@ -39,6 +39,7 @@ * 17-Aug-2006 : Strengthened testEquals() and added testFindRangeBounds() * method (DG); * 05-Mar-2007 : Added new field to testEquals() (DG); + * 08-Oct-2007 : Added tests for new volumePaint field (DG); * */ @@ -87,7 +88,24 @@ super(name); } + private static final double EPSILON = 0.0000000001; + /** + * Some checks for the constructor. + */ + public void testConstructor() { + CandlestickRenderer r1 = new CandlestickRenderer(); + + // check defaults + assertEquals(Color.green, r1.getUpPaint()); + assertEquals(Color.red, r1.getDownPaint()); + assertFalse(r1.getUseOutlinePaint()); + assertTrue(r1.getDrawVolume()); + assertEquals(Color.gray, r1.getVolumePaint()); + assertEquals(-1.0, r1.getCandleWidth(), EPSILON); + } + + /** * Check that the equals() method distinguishes all fields. */ public void testEquals() { @@ -151,6 +169,11 @@ assertFalse(r1.equals(r2)); r2.setUseOutlinePaint(true); assertTrue(r1.equals(r2)); + + r1.setVolumePaint(Color.blue); + assertFalse(r1.equals(r2)); + r2.setVolumePaint(Color.blue); + assertTrue(r1.equals(r2)); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-08 09:29:59
|
Revision: 282 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=282&view=rev Author: mungady Date: 2007-10-08 02:29:58 -0700 (Mon, 08 Oct 2007) Log Message: ----------- 2007-10-08 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/ValueMarker.java (ValueMarker(double, Paint, Stroke, Paint, Stroke, float)): Fixed call to super, * tests/org/jfree/chart/plot/junit/ValueMarkerTests.java (test1808376): New test method. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ValueMarker.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/ValueMarkerTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-08 09:16:30 UTC (rev 281) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-08 09:29:58 UTC (rev 282) @@ -1,3 +1,11 @@ +2007-10-08 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/plot/ValueMarker.java + (ValueMarker(double, Paint, Stroke, Paint, Stroke, float)): Fixed call + to super, + * tests/org/jfree/chart/plot/junit/ValueMarkerTests.java + (test1808376): New test method. + 2007-10-08 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/xy/CandlestickRenderer.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ValueMarker.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ValueMarker.java 2007-10-08 09:16:30 UTC (rev 281) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ValueMarker.java 2007-10-08 09:29:58 UTC (rev 282) @@ -38,6 +38,8 @@ * 16-Feb-2005 : Added new constructor (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Sep-2006 : Added setValue() method (DG); + * 08-Oct-2007 : Fixed bug 1808376, constructor calling super with incorrect + * values (DG); * */ @@ -86,11 +88,11 @@ * @param stroke the stroke (<code>null</code> not permitted). * @param outlinePaint the outline paint (<code>null</code> permitted). * @param outlineStroke the outline stroke (<code>null</code> permitted). - * @param alpha the alpha transparency. + * @param alpha the alpha transparency (in the range 0.0f to 1.0f). */ public ValueMarker(double value, Paint paint, Stroke stroke, Paint outlinePaint, Stroke outlineStroke, float alpha) { - super(paint, stroke, paint, stroke, alpha); + super(paint, stroke, outlinePaint, outlineStroke, alpha); this.value = value; } @@ -98,6 +100,8 @@ * Returns the value. * * @return The value. + * + * @see #setValue(double) */ public double getValue() { return this.value; @@ -109,6 +113,8 @@ * * @param value the value. * + * @see #getValue() + * * @since 1.0.3 */ public void setValue(double value) { Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/ValueMarkerTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/ValueMarkerTests.java 2007-10-08 09:16:30 UTC (rev 281) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/ValueMarkerTests.java 2007-10-08 09:29:58 UTC (rev 282) @@ -39,6 +39,7 @@ * 01-Jun-2005 : Strengthened equals() test (DG); * 05-Sep-2006 : Added checks for MarkerChangeEvent generation (DG); * 26-Sep-2007 : Added test1802195() method (DG); + * 08-Oct-2007 : Added test1808376() method (DG); * */ @@ -48,6 +49,7 @@ import java.awt.Color; import java.awt.Font; import java.awt.GradientPaint; +import java.awt.Stroke; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInput; @@ -280,4 +282,20 @@ } + /** + * A test for bug report 1808376. + */ + public void test1808376() { + Stroke stroke = new BasicStroke(1.0f); + Stroke outlineStroke = new BasicStroke(2.0f); + ValueMarker m = new ValueMarker(1.0, Color.red, stroke, Color.blue, + outlineStroke, 0.5f); + assertEquals(1.0, m.getValue(), EPSILON); + assertEquals(Color.red, m.getPaint()); + assertEquals(stroke, m.getStroke()); + assertEquals(Color.blue, m.getOutlinePaint()); + assertEquals(outlineStroke, m.getOutlineStroke()); + assertEquals(0.5f, m.getAlpha(), EPSILON); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-08 13:33:41
|
Revision: 289 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=289&view=rev Author: mungady Date: 2007-10-08 06:33:40 -0700 (Mon, 08 Oct 2007) Log Message: ----------- 2007-10-08 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/MultiShapeRenderer.java: New file, * source/org/jfree/data/statistics/DefaultMultiValueCategoryDataset.java: Likewise, * source/org/jfree/data/statistics/MultiValueCategoryDataset.java: Likewise, * tests/org/jfree/chart/renderer/category/junit/MultiShapeRendererTests.java: Likewise, * tests/org/jfree/chart/renderer/category/junit/RendererCategoryPackageTests.java (suite): Added MultiShapeRendererTests, * tests/org/jfree/data/statistics/junit/DataStatisticsPackageTests.java (suite): Added DefaultMultiValueCategoryDatasetTests, * tests/org/jfree/data/statistics/junit/DefaultMultiValueCategoryDatasetTests.java: New file. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog Added Paths: ----------- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MultiShapeRenderer.java branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultMultiValueCategoryDataset.java branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/MultiValueCategoryDataset.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MultiShapeRendererTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultMultiValueCategoryDatasetTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-08 11:18:10 UTC (rev 288) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-08 13:33:40 UTC (rev 289) @@ -1,3 +1,20 @@ +2007-10-08 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/renderer/category/MultiShapeRenderer.java: + New file, + * source/org/jfree/data/statistics/DefaultMultiValueCategoryDataset.java: + Likewise, + * source/org/jfree/data/statistics/MultiValueCategoryDataset.java: + Likewise, + * tests/org/jfree/chart/renderer/category/junit/MultiShapeRendererTests.java: + Likewise, + * tests/org/jfree/chart/renderer/category/junit/RendererCategoryPackageTests.java + (suite): Added MultiShapeRendererTests, + * tests/org/jfree/data/statistics/junit/DataStatisticsPackageTests.java + (suite): Added DefaultMultiValueCategoryDatasetTests, + * tests/org/jfree/data/statistics/junit/DefaultMultiValueCategoryDatasetTests.java: + New file. + 2007-10-08 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/ValueMarker.java Added: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MultiShapeRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MultiShapeRenderer.java (rev 0) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MultiShapeRenderer.java 2007-10-08 13:33:40 UTC (rev 289) @@ -0,0 +1,553 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, 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.] + * + * ----------------------- + * MultiShapeRenderer.java + * ----------------------- + * (C) Copyright 2007, 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); + * + */ + +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. + * + * @since 1.0.7 + */ +public class MultiShapeRenderer 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 MultiShapeRenderer() { + 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; + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * 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; + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * 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; + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * 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. + * + * @param use the flag. + * + * @see #getUseOutlinePaint() + */ + public void setUseOutlinePaint(boolean use) { + this.useOutlinePaint = use; + notifyListeners(new RendererChangeEvent(this)); + } + + // 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. + * + * @param series the series index (zero-based). + * @param filled the flag. + */ + public void setSeriesShapesFilled(int series, Boolean filled) { + this.seriesShapesFilled.setBoolean(series, filled); + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * Sets the 'shapes filled' flag for a series. + * + * @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)); + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * Returns the base 'shape filled' attribute. + * + * @return The base flag. + */ + public boolean getBaseShapesFilled() { + return this.baseShapesFilled; + } + + /** + * Sets the base 'shapes filled' flag. + * + * @param flag the flag. + */ + public void setBaseShapesFilled(boolean flag) { + this.baseShapesFilled = flag; + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * 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; + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * 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 = lookupSeriesShape(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.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 MultiShapeRenderer)) { + return false; + } + MultiShapeRenderer that = (MultiShapeRenderer) 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 { + MultiShapeRenderer clone = (MultiShapeRenderer) 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(); + + } + +} Added: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultMultiValueCategoryDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultMultiValueCategoryDataset.java (rev 0) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultMultiValueCategoryDataset.java 2007-10-08 13:33:40 UTC (rev 289) @@ -0,0 +1,404 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, 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.] + * + * ------------------------------------- + * DefaultMultiValueCategoryDataset.java + * ------------------------------------- + * (C) Copyright 2007, by David Forslund and Contributors. + * + * Original Author: David Forslund; + * Contributor(s): David Gilbert (for Object Refinery Limited);; + * + * Changes + * ------- + * 08-Oct-2007 : Version 1, see patch 1780779 (DG); + * + */ + +package org.jfree.data.statistics; + + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.jfree.data.KeyedObjects2D; +import org.jfree.data.Range; +import org.jfree.data.RangeInfo; +import org.jfree.data.general.AbstractDataset; +import org.jfree.data.general.DatasetChangeEvent; +import org.jfree.util.PublicCloneable; + +/** + * A category dataset that defines multiple values for each item. + * + * @since 1.0.7 + */ +public class DefaultMultiValueCategoryDataset extends AbstractDataset + implements MultiValueCategoryDataset, RangeInfo, PublicCloneable { + + /** + * Storage for the data. + */ + protected KeyedObjects2D data; + + /** + * The minimum range value. + */ + private Number minimumRangeValue; + + /** + * The maximum range value. + */ + private Number maximumRangeValue; + + /** + * The range of values. + */ + private Range rangeBounds; + + /** + * Creates a new dataset. + */ + public DefaultMultiValueCategoryDataset() { + this.data = new KeyedObjects2D(); + this.minimumRangeValue = null; + this.maximumRangeValue = null; + this.rangeBounds = new Range(0.0, 0.0); + } + + /** + * Adds a list of values to the dataset (<code>null</code> and Double.NaN + * items are automatically removed) and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @param values a list of values (<code>null</code> not permitted). + * @param rowKey the row key (<code>null</code> not permitted). + * @param columnKey the column key (<code>null</code> not permitted). + */ + public void add(List values, Comparable rowKey, Comparable columnKey) { + + if (values == null) { + throw new IllegalArgumentException("Null 'values' argument."); + } + if (rowKey == null) { + throw new IllegalArgumentException("Null 'rowKey' argument."); + } + if (columnKey == null) { + throw new IllegalArgumentException("Null 'columnKey' argument."); + } + List vlist = new ArrayList(values.size()); + Iterator iterator = values.listIterator(); + while (iterator.hasNext()) { + Object obj = iterator.next(); + if (obj instanceof Number) { + Number n = (Number) obj; + double v = n.doubleValue(); + if (!Double.isNaN(v)) { + vlist.add(n); + } + } + } + Collections.sort(vlist); + this.data.addObject(vlist, rowKey, columnKey); + + if (vlist.size() > 0) { + double maxval = Double.NEGATIVE_INFINITY; + double minval = Double.POSITIVE_INFINITY; + for (int i = 0; i < vlist.size(); i++) { + Number n = (Number) vlist.get(i); + double v = n.doubleValue(); + minval = Math.min(minval, v); + maxval = Math.max(maxval, v); + } + + // update the cached range values... + if (this.maximumRangeValue == null) { + this.maximumRangeValue = new Double(maxval); + } + else if (maxval > this.maximumRangeValue.doubleValue()) { + this.maximumRangeValue = new Double(maxval); + } + + if (this.minimumRangeValue == null) { + this.minimumRangeValue = new Double(minval); + } + else if (minval < this.minimumRangeValue.doubleValue()) { + this.minimumRangeValue = new Double(minval); + } + this.rangeBounds = new Range(this.minimumRangeValue.doubleValue(), + this.maximumRangeValue.doubleValue()); + } + + fireDatasetChanged(); + } + + /** + * Returns a list (possibly empty) of the values for the specified item. + * The returned list should be unmodifiable. + * + * @param row the row index (zero-based). + * @param column the column index (zero-based). + * + * @return The list of values. + */ + public List getValues(int row, int column) { + List values = (List) this.data.getObject(row, column); + if (values != null) { + return Collections.unmodifiableList(values); + } + else { + return null; + } + } + + /** + * Returns a list (possibly empty) of the values for the specified item. + * The returned list should be unmodifiable. + * + * @param rowKey the row key (<code>null</code> not permitted). + * @param columnKey the column key (<code>null</code> not permitted). + * + * @return The list of values. + */ + public List getValues(Comparable rowKey, Comparable columnKey) { + return Collections.unmodifiableList((List) this.data.getObject(rowKey, + columnKey)); + } + + /** + * Returns the average value for the specified item. + * + * @param row the row key. + * @param column the column key. + * + * @return The average value. + */ + public Number getValue(Comparable row, Comparable column) { + List l = (List) this.data.getObject(row, column); + double average = 0.0d; + int count = 0; + if (l != null && l.size() > 0) { + for (int i = 0; i < l.size(); i++) { + Number n = (Number) l.get(i); + average += n.doubleValue(); + count += 1; + } + if (count > 0) { + average = average / count; + } + } + if (count == 0) { + return null; + } + return new Double(average); + } + + /** + * Returns the average value for the specified item. + * + * @param row the row index. + * @param column the column index. + * + * @return The average value. + */ + public Number getValue(int row, int column) { + List l = (List) this.data.getObject(row, column); + double average = 0.0d; + int count = 0; + if (l != null && l.size() > 0) { + for (int i = 0; i < l.size(); i++) { + Number n = (Number) l.get(i); + average += n.doubleValue(); + count += 1; + } + if (count > 0) { + average = average / count; + } + } + if (count == 0) { + return null; + } + return new Double(average); + } + + /** + * Returns the column index for a given key. + * + * @param key the column key. + * + * @return The column index. + */ + public int getColumnIndex(Comparable key) { + return this.data.getColumnIndex(key); + } + + /** + * Returns a column key. + * + * @param column the column index (zero-based). + * + * @return The column key. + */ + public Comparable getColumnKey(int column) { + return this.data.getColumnKey(column); + } + + /** + * Returns the column keys. + * + * @return The keys. + */ + public List getColumnKeys() { + return this.data.getColumnKeys(); + } + + /** + * Returns the row index for a given key. + * + * @param key the row key. + * + * @return The row index. + */ + public int getRowIndex(Comparable key) { + return this.data.getRowIndex(key); + } + + /** + * Returns a row key. + * + * @param row the row index (zero-based). + * + * @return The row key. + */ + public Comparable getRowKey(int row) { + return this.data.getRowKey(row); + } + + /** + * Returns the row keys. + * + * @return The keys. + */ + public List getRowKeys() { + return this.data.getRowKeys(); + } + + /** + * Returns the number of rows in the table. + * + * @return The row count. + */ + public int getRowCount() { + return this.data.getRowCount(); + } + + /** + * Returns the number of columns in the table. + * + * @return The column count. + */ + public int getColumnCount() { + return this.data.getColumnCount(); + } + + /** + * Returns the minimum y-value in the dataset. + * + * @param includeInterval a flag that determines whether or not the + * y-interval is taken into account. + * + * @return The minimum value. + */ + public double getRangeLowerBound(boolean includeInterval) { + double result = Double.NaN; + if (this.minimumRangeValue != null) { + result = this.minimumRangeValue.doubleValue(); + } + return result; + } + + /** + * Returns the maximum y-value in the dataset. + * + * @param includeInterval a flag that determines whether or not the + * y-interval is taken into account. + * + * @return The maximum value. + */ + public double getRangeUpperBound(boolean includeInterval) { + double result = Double.NaN; + if (this.maximumRangeValue != null) { + result = this.maximumRangeValue.doubleValue(); + } + return result; + } + + /** + * Returns the range of the values in this dataset's range. + * + * @param includeInterval a flag that determines whether or not the + * y-interval is taken into account. + * @return The range. + */ + public Range getRangeBounds(boolean includeInterval) { + return this.rangeBounds; + } + + /** + * Tests this dataset 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 DefaultMultiValueCategoryDataset)) { + return false; + } + DefaultMultiValueCategoryDataset that + = (DefaultMultiValueCategoryDataset) obj; + return this.data.equals(that.data); + } + + /** + * Returns a clone of this instance. + * + * @return A clone. + * + * @throws CloneNotSupportedException if the dataset cannot be cloned. + */ + public Object clone() throws CloneNotSupportedException { + DefaultMultiValueCategoryDataset clone + = (DefaultMultiValueCategoryDataset) super.clone(); + clone.data = (KeyedObjects2D) this.data.clone(); + return clone; + } +} Added: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/MultiValueCategoryDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/MultiValueCategoryDataset.java (rev 0) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/MultiValueCategoryDataset.java 2007-10-08 13:33:40 UTC (rev 289) @@ -0,0 +1,76 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, 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.] + * + * ------------------------------ + * MultiValueCategoryDataset.java + * ------------------------------ + * (C) Copyright 2007, by David Forslund and Contributors. + * + * Original Author: David Forslund; + * Contributor(s): David Gilbert (for Object Refinery Limited);; + * + * Changes + * ------- + * 08-Oct-2007 : Version 1, see patch 1780779 (DG); + * + */ + +package org.jfree.data.statistics; + +import org.jfree.data.category.CategoryDataset; + +import java.util.List; + +/** + * A category dataset that defines multiple values for each item. + * + * @since 1.0.7 + */ +public interface MultiValueCategoryDataset extends CategoryDataset { + + /** + * Returns a list (possibly empty) of the values for the specified item. + * The returned list should be unmodifiable. + * + * @param row the row index (zero-based). + * @param column the column index (zero-based). + * + * @return The list of values. + */ + public List getValues(int row, int column); + + /** + * Returns a list (possibly empty) of the values for the specified item. + * The returned list should be unmodifiable. + * + * @param rowKey the row key (<code>null</code> not permitted). + * @param columnKey the column key (<code>null</code> not permitted). + * + * @return The list of values. + */ + public List getValues(Comparable rowKey, Comparable columnKey); + +} \ No newline at end of file Added: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MultiShapeRendererTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MultiShapeRendererTests.java (rev 0) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MultiShapeRendererTests.java 2007-10-08 13:33:40 UTC (rev 289) @@ -0,0 +1,217 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, 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.] + * + * ---------------------------- + * MultiShapeRendererTests.java + * ---------------------------- + * (C) Copyright 2007, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 08-Oct-2007 : Version 1 (DG); + * + */ + +package org.jfree.chart.renderer.category.junit; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.chart.renderer.category.MultiShapeRenderer; + +/** + * Tests for the {@link MultiShapeRenderer} class. + */ +public class MultiShapeRendererTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(MultiShapeRendererTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public MultiShapeRendererTests(String name) { + super(name); + } + + /** + * Test that the equals() method distinguishes all fields. + */ + public void testEquals() { + + MultiShapeRenderer r1 = new MultiShapeRenderer(); + MultiShapeRenderer r2 = new MultiShapeRenderer(); + assertEquals(r1, r2); + + r1.setSeriesShapesFilled(1, true); + assertFalse(r1.equals(r2)); + r2.setSeriesShapesFilled(1, true); + assertTrue(r1.equals(r2)); + + r1.setBaseShapesFilled(false); + assertFalse(r1.equals(r2)); + r2.setBaseShapesFilled(false); + assertTrue(r1.equals(r2)); + + r1.setUseFillPaint(true); + assertFalse(r1.equals(r2)); + r2.setUseFillPaint(true); + assertTrue(r1.equals(r2)); + + r1.setDrawOutlines(true); + assertFalse(r1.equals(r2)); + r2.setDrawOutlines(true); + assertTrue(r1.equals(r2)); + + r1.setUseOutlinePaint(true); + assertFalse(r1.equals(r2)); + r2.setUseOutlinePaint(true); + assertTrue(r1.equals(r2)); + + r1.setUseSeriesOffset(false); + assertFalse(r1.equals(r2)); + r2.setUseSeriesOffset(false); + assertTrue(r1.equals(r2)); + + } + + /** + * Two objects that are equal are required to return the same hashCode. + */ + public void testHashcode() { + MultiShapeRenderer r1 = new MultiShapeRenderer(); + MultiShapeRenderer r2 = new MultiShapeRenderer(); + assertTrue(r1.equals(r2)); + int h1 = r1.hashCode(); + int h2 = r2.hashCode(); + assertEquals(h1, h2); + } + + /** + * Confirm that cloning works. + */ + public void testCloning() { + MultiShapeRenderer r1 = new MultiShapeRenderer(); + MultiShapeRenderer r2 = null; + try { + r2 = (MultiShapeRenderer) r1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(r1 != r2); + assertTrue(r1.getClass() == r2.getClass()); + assertTrue(r1.equals(r2)); + + assertTrue(checkIndependence(r1, r2)); + + } + + /** + * Checks that the two renderers are equal but independent of one another. + * + * @param r1 renderer 1. + * @param r2 renderer 2. + * + * @return A boolean. + */ + private boolean checkIndependence(MultiShapeRenderer r1, + MultiShapeRenderer r2) { + + // should be equal... + if (!r1.equals(r2)) { + return false; + } + + // and independent... + r1.setSeriesShapesFilled(1, true); + if (r1.equals(r2)) { + return false; + } + r2.setSeriesShapesFilled(1, true); + if (!r1.equals(r2)) { + return false; + } + + r1.setBaseShapesFilled(false); + r2.setBaseShapesFilled(true); + if (r1.equals(r2)) { + return false; + } + r2.setBaseShapesFilled(false); + if (!r1.equals(r2)) { + return false; + } + return true; + + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + + MultiShapeRenderer r1 = new MultiShapeRenderer(); + MultiShapeRenderer r2 = null; + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(r1); + out.close(); + + ObjectInput in = new ObjectInputStream( + new ByteArrayInputStream(buffer.toByteArray())); + r2 = (MultiShapeRenderer) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(r1, r2); + + } + +} Added: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultMultiValueCategoryDatasetTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultMultiValueCategoryDatasetTests.java (rev 0) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultMultiValueCategoryDatasetTests.java 2007-10-08 13:33:40 UTC (rev 289) @@ -0,0 +1,294 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, 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.] + * + * ------------------------------------------ + * DefaultMultiValueCategoryDatasetTests.java + * ------------------------------------------ + * (C) Copyright 2007, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 28-Sep-2007 : Version 1 (DG); + * + */ + +package org.jfree.data.statistics.junit; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.data.UnknownKeyException; +import org.jfree.data.statistics.DefaultMultiValueCategoryDataset; + +/** + * Tests for the {@link DefaultMultiValueCategoryDataset} class. + */ +public class DefaultMultiValueCategoryDatasetTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(DefaultMultiValueCategoryDatasetTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public DefaultMultiValueCategoryDatasetTests(String name) { + super(name); + } + + /** + * Some checks for the getValue() method. + */ + public void testGetValue() { + DefaultMultiValueCategoryDataset d + = new DefaultMultiValueCategoryDataset(); + List values = new ArrayList(); + values.add(new Integer(1)); + values.add(new Integer(2)); + d.add(values, "R1", "C1"); + assertEquals(new Double(1.5), d.getValue("R1", "C1")); + boolean pass = false; + try { + d.getValue("XX", "C1"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + + pass = false; + try { + d.getValue("R1", "XX"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * A simple check for the getValue(int, int) method. + */ + public void testGetValue2() { + DefaultMultiValueCategoryDataset d + = new DefaultMultiValueCategoryDataset(); + boolean pass = false; + try { + /* Number n =*/ d.getValue(0, 0); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some tests for the getRowCount() method. + */ + public void testGetRowCount() { + DefaultMultiValueCategoryDataset d + = new DefaultMultiValueCategoryDataset(); + assertTrue(d.getRowCount() == 0); + List values = new ArrayList(); + d.add(values, "R1", "C1"); + assertTrue(d.getRowCount() == 1); + + d.add(values, "R2", "C1"); + assertTrue(d.getRowCount() == 2); + + d.add(values, "R2", "C1"); + assertTrue(d.getRowCount() == 2); + } + + /** + * Some tests for the getColumnCount() method. + */ + public void testGetColumnCount() { + DefaultMultiValueCategoryDataset d + = new DefaultMultiValueCategoryDataset(); + assertTrue(d.getColumnCount() == 0); + + List values = new ArrayList(); + d.add(values, "R1", "C1"); + assertTrue(d.getColumnCount() == 1); + + d.add(values, "R1", "C2"); + assertTrue(d.getColumnCount() == 2); + + d.add(values, "R1", "C2"); + assertTrue(d.getColumnCount() == 2); + + } + + /** + * Confirm that the equals method can distinguish all the required fields. + */ + public void testEquals() { + DefaultMultiValueCategoryDataset d1 + = new DefaultMultiValueCategoryDataset(); + DefaultMultiValueCategoryDataset d2 + = new DefaultMultiValueCategoryDataset(); + assertTrue(d1.equals(d2)); + assertTrue(d2.equals(d1)); + + List values = new ArrayList(); + d1.add(values, "R1", "C1"); + assertFalse(d1.equals(d2)); + d2.add(values, "R1", "C1"); + assertTrue(d1.equals(d2)); + + values.add(new Integer(99)); + d1.add(values, "R1", "C1"); + assertFalse(d1.equals(d2)); + d2.add(values, "R1", "C1"); + assertTrue(d1.equals(d2)); + + values.add(new Integer(99)); + d1.add(values, "R1", "C2"); + assertFalse(d1.equals(d2)); + d2.add(values, "R1", "C2"); + assertTrue(d1.equals(d2)); + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + + DefaultMultiValueCategoryDataset d1 + = new DefaultMultiValueCategoryDataset(); + DefaultMultiValueCategoryDataset d2 + = new DefaultMultiValueCategoryDataset(); + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(d1); + out.close(); + + ObjectInput in = new ObjectInputStream( + new ByteArrayInputStream(buffer.toByteArray())); + d2 = (DefaultMultiValueCategoryDataset) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(d1, d2); + + } + + /** + * Some checks for the add() method. + */ + public void testAddValue() { + DefaultMultiValueCategoryDataset d1 + = new DefaultMultiValueCategoryDataset(); + + boolean pass = false; + try { + d1.add(null, "R1", "C1"); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + + List values = new ArrayList(); + d1.add(values, "R2", "C1"); + assertEquals(values, d1.getValues("R2", "C1")); + + pass = false; + try { + d1.add(values, null, "C2"); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Confirm that cloning works. + */ + public void testCloning() { + DefaultMultiValueCategoryDataset d1 + = new DefaultMultiValueCategoryDataset(); + DefaultMultiValueCategoryDataset d2 = null; + try { + d2 = (DefaultMultiValueCategoryDataset) d1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(d1 != d2); + assertTrue(d1.getClass() == d2.getClass()); + assertTrue(d1.equals(d2)); + + // try a dataset with some content... + List values = new ArrayList(); + values.add(new Integer(99)); + d1.add(values, "R1", "C1"); + try { + d2 = (DefaultMultiValueCategoryDataset) d1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(d1 != d2); + assertTrue(d1.getClass() == d2.getClass()); + assertTrue(d1.equals(d2)); + + // check that the clone doesn't share the same underlying arrays. + List values2 = new ArrayList(); + values2.add(new Integer(111)); + d1.add(values2, "R2", "C2"); + assertFalse(d1.equals(d2)); + d2.add(values2, "R2", "C2"); + assertTrue(d1.equals(d2)); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-08 15:18:46
|
Revision: 293 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=293&view=rev Author: mungady Date: 2007-10-08 08:18:43 -0700 (Mon, 08 Oct 2007) Log Message: ----------- 2007-10-08 David Gilbert <dav...@ob...> Based on Patch 1769088: * source/org/jfree/chart/plot/ThermometerPlot.java (BULB_RADIUS): Deprecated, (BULB_DIAMETER): Likewise, (COLUMN_RADIUS): Likewise, (COLUMN_DIAMETER): Likewise, (GAP_RADIUS): Likewise, (GAP_DIAMETER): Likewise, (bulbRadius): New field, (columnRadius): Likewise, (gapRadius): Likewise, (getBulbRadius): New method, (setBulbRadius): Likewise, (getBulbDiameter): Likewise, (getColumnRadius): Likewise, (setColumnRadius): Likewise, (getColumnDiameter): Likewise, (getGapRadius): Likewise, (setGapRadius): Likewise, (getGapDiameter): Likewise, (draw): Use attributes rather than constants, (equals): Updated for new fields, * tests/org/jfree/chart/plot/junit/ThermometerPlotTests.java (testEquals): Updated for new fields. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ThermometerPlot.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/ThermometerPlotTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-08 14:15:05 UTC (rev 292) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-08 15:18:43 UTC (rev 293) @@ -1,5 +1,32 @@ 2007-10-08 David Gilbert <dav...@ob...> + Based on Patch 1769088: + * source/org/jfree/chart/plot/ThermometerPlot.java + (BULB_RADIUS): Deprecated, + (BULB_DIAMETER): Likewise, + (COLUMN_RADIUS): Likewise, + (COLUMN_DIAMETER): Likewise, + (GAP_RADIUS): Likewise, + (GAP_DIAMETER): Likewise, + (bulbRadius): New field, + (columnRadius): Likewise, + (gapRadius): Likewise, + (getBulbRadius): New method, + (setBulbRadius): Likewise, + (getBulbDiameter): Likewise, + (getColumnRadius): Likewise, + (setColumnRadius): Likewise, + (getColumnDiameter): Likewise, + (getGapRadius): Likewise, + (setGapRadius): Likewise, + (getGapDiameter): Likewise, + (draw): Use attributes rather than constants, + (equals): Updated for new fields, + * tests/org/jfree/chart/plot/junit/ThermometerPlotTests.java + (testEquals): Updated for new fields. + +2007-10-08 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/category/MultiShapeRenderer.java: New file, * source/org/jfree/data/statistics/DefaultMultiValueCategoryDataset.java: Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ThermometerPlot.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ThermometerPlot.java 2007-10-08 14:15:05 UTC (rev 292) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ThermometerPlot.java 2007-10-08 15:18:43 UTC (rev 293) @@ -82,6 +82,8 @@ * getMinimum/MaximumVerticalDataValue(), and fixed serialization * bug (DG); * 24-Sep-2007 : Implemented new methods in Zoomable interface (DG); + * 08-Oct-2007 : Added attributes for thermometer dimensions - see patch 1769088 + * by Julien Henry (DG); * */ @@ -181,22 +183,46 @@ /** A constant for the 'critical' range. */ public static final int CRITICAL = 2; - /** The bulb radius. */ + /** + * The bulb radius. + * + * @deprecated As of 1.0.7, use {@link #getBulbRadius()}. + */ protected static final int BULB_RADIUS = 40; - /** The bulb diameter. */ + /** + * The bulb diameter. + * + * @deprecated As of 1.0.7, use {@link #getBulbDiameter()}. + */ protected static final int BULB_DIAMETER = BULB_RADIUS * 2; - /** The column radius. */ + /** + * The column radius. + * + * @deprecated As of 1.0.7, use {@link #getColumnRadius()}. + */ protected static final int COLUMN_RADIUS = 20; - /** The column diameter.*/ + /** + * The column diameter. + * + * @deprecated As of 1.0.7, use {@link #getColumnDiameter()}. + */ protected static final int COLUMN_DIAMETER = COLUMN_RADIUS * 2; - /** The gap radius. */ + /** + * The gap radius. + * + * @deprecated As of 1.0.7, use {@link #getGapRadius()}. + */ protected static final int GAP_RADIUS = 5; - /** The gap diameter. */ + /** + * The gap diameter. + * + * @deprecated As of 1.0.7, use {@link #getGapDiameter()}. + */ protected static final int GAP_DIAMETER = GAP_RADIUS * 2; /** The axis gap. */ @@ -224,6 +250,27 @@ /** The default upper bound. */ protected static final double DEFAULT_UPPER_BOUND = 100.0; + /** + * The default bulb radius. + * + * @since 1.0.7 + */ + protected static final int DEFAULT_BULB_RADIUS = 40; + + /** + * The default column radius. + * + * @since 1.0.7 + */ + protected static final int DEFAULT_COLUMN_RADIUS = 20; + + /** + * The default gap radius. + * + * @since 1.0.7 + */ + protected static final int DEFAULT_GAP_RADIUS = 5; + /** The dataset for the plot. */ private ValueDataset dataset; @@ -237,6 +284,27 @@ private double upperBound = DEFAULT_UPPER_BOUND; /** + * The value label position. + * + * @since 1.0.7 + */ + private int bulbRadius = DEFAULT_BULB_RADIUS; + + /** + * The column radius. + * + * @since 1.0.7 + */ + private int columnRadius = DEFAULT_COLUMN_RADIUS; + + /** + * The gap radius. + * + * @since 1.0.7 + */ + private int gapRadius = DEFAULT_GAP_RADIUS; + + /** * Blank space inside the plot area around the outside of the thermometer. */ private RectangleInsets padding; @@ -963,6 +1031,124 @@ } /** + * Returns the bulb radius, in Java2D units. + + * @return The bulb radius. + * + * @since 1.0.7 + */ + public int getBulbRadius() { + return this.bulbRadius; + } + + /** + * Sets the bulb radius (in Java2D units) and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param r the new radius (in Java2D units). + * + * @see #getBulbRadius() + * + * @since 1.0.7 + */ + public void setBulbRadius(int r) { + this.bulbRadius = r; + notifyListeners(new PlotChangeEvent(this)); + } + + /** + * Returns the bulb diameter, which is always twice the value returned + * by {@link #getBulbRadius()}. + * + * @return The bulb diameter. + * + * @since 1.0.7 + */ + public int getBulbDiameter() { + return getBulbRadius() * 2; + } + + /** + * Returns the column radius, in Java2D units. + * + * @return The column radius. + * + * @see #setColumnRadius(int) + * + * @since 1.0.7 + */ + public int getColumnRadius() { + return this.columnRadius; + } + + /** + * Sets the column radius (in Java2D units) and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param r the new radius. + * + * @see #getColumnRadius() + * + * @since 1.0.7 + */ + public void setColumnRadius(int r) { + this.columnRadius = r; + notifyListeners(new PlotChangeEvent(this)); + } + + /** + * Returns the column diameter, which is always twice the value returned + * by {@link #getColumnRadius()}. + * + * @return The column diameter. + * + * @since 1.0.7 + */ + public int getColumnDiameter() { + return getColumnRadius() * 2; + } + + /** + * Returns the gap radius in Java2D units. + * + * @return The gap radius. + * + * @see #setGapRadius(int) + * + * @since 1.0.7 + */ + public int getGapRadius() { + return this.gapRadius; + } + + /** + * Sets the gap radius (in Java2D units) and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param r the new radius. + * + * @see #getGapRadius() + * + * @since 1.0.7 + */ + public void setGapRadius(int r) { + this.gapRadius = r; + notifyListeners(new PlotChangeEvent(this)); + } + + /** + * Returns the gap diameter, which is always twice the value returned by + * {@link #getGapRadius()}. + * + * @return The gap diameter, in Java2D units. + * + * @since 1.0.7 + */ + public int getGapDiameter() { + return getGapRadius() * 2; + } + + /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * @@ -997,30 +1183,31 @@ this.padding.trim(interior); int midX = (int) (interior.getX() + (interior.getWidth() / 2)); int midY = (int) (interior.getY() + (interior.getHeight() / 2)); - int stemTop = (int) (interior.getMinY() + BULB_RADIUS); - int stemBottom = (int) (interior.getMaxY() - BULB_DIAMETER); - Rectangle2D dataArea = new Rectangle2D.Double(midX - COLUMN_RADIUS, - stemTop, COLUMN_RADIUS, stemBottom - stemTop); + int stemTop = (int) (interior.getMinY() + getBulbRadius()); + int stemBottom = (int) (interior.getMaxY() - getBulbDiameter()); + Rectangle2D dataArea = new Rectangle2D.Double(midX - getColumnRadius(), + stemTop, getColumnRadius(), stemBottom - stemTop); - outerBulb.setFrame(midX - BULB_RADIUS, stemBottom, BULB_DIAMETER, - BULB_DIAMETER); + outerBulb.setFrame(midX - getBulbRadius(), stemBottom, + getBulbDiameter(), getBulbDiameter()); - outerStem.setRoundRect(midX - COLUMN_RADIUS, interior.getMinY(), - COLUMN_DIAMETER, stemBottom + BULB_DIAMETER - stemTop, - COLUMN_DIAMETER, COLUMN_DIAMETER); + outerStem.setRoundRect(midX - getColumnRadius(), interior.getMinY(), + getColumnDiameter(), stemBottom + getBulbDiameter() - stemTop, + getColumnDiameter(), getColumnDiameter()); Area outerThermometer = new Area(outerBulb); Area tempArea = new Area(outerStem); outerThermometer.add(tempArea); - innerBulb.setFrame(midX - BULB_RADIUS + GAP_RADIUS, - stemBottom + GAP_RADIUS, BULB_DIAMETER - GAP_DIAMETER, - BULB_DIAMETER - GAP_DIAMETER); + innerBulb.setFrame(midX - getBulbRadius() + getGapRadius(), + stemBottom + getGapRadius(), getBulbDiameter() + - getGapDiameter(), getBulbDiameter() - getGapDiameter()); - innerStem.setRoundRect(midX - COLUMN_RADIUS + GAP_RADIUS, - interior.getMinY() + GAP_RADIUS, COLUMN_DIAMETER - GAP_DIAMETER, - stemBottom + BULB_DIAMETER - GAP_DIAMETER - stemTop, - COLUMN_DIAMETER - GAP_DIAMETER, COLUMN_DIAMETER - GAP_DIAMETER); + innerStem.setRoundRect(midX - getColumnRadius() + getGapRadius(), + interior.getMinY() + getGapRadius(), getColumnDiameter() + - getGapDiameter(), stemBottom + getBulbDiameter() + - getGapDiameter() - stemTop, getColumnDiameter() + - getGapDiameter(), getColumnDiameter() - getGapDiameter()); Area innerThermometer = new Area(innerBulb); tempArea = new Area(innerStem); @@ -1031,20 +1218,20 @@ double ds = this.rangeAxis.valueToJava2D(current, dataArea, RectangleEdge.LEFT); - int i = COLUMN_DIAMETER - GAP_DIAMETER; // already calculated - int j = COLUMN_RADIUS - GAP_RADIUS; // already calculated + int i = getColumnDiameter() - getGapDiameter(); // already calculated + int j = getColumnRadius() - getGapRadius(); // already calculated int l = (i / 2); int k = (int) Math.round(ds); - if (k < (GAP_RADIUS + interior.getMinY())) { - k = (int) (GAP_RADIUS + interior.getMinY()); - l = BULB_RADIUS; + if (k < (getGapRadius() + interior.getMinY())) { + k = (int) (getGapRadius() + interior.getMinY()); + l = getBulbRadius(); } Area mercury = new Area(innerBulb); - if (k < (stemBottom + BULB_RADIUS)) { + if (k < (stemBottom + getBulbRadius())) { mercuryStem.setRoundRect(midX - j, k, i, - (stemBottom + BULB_RADIUS) - k, l, l); + (stemBottom + getBulbRadius()) - k, l, l); tempArea = new Area(mercuryStem); mercury.add(tempArea); } @@ -1060,7 +1247,7 @@ // draw start of normal range double value = this.subrangeInfo[NORMAL][RANGE_LOW]; if (range.contains(value)) { - double x = midX + COLUMN_RADIUS + 2; + double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); @@ -1071,7 +1258,7 @@ // draw start of warning range value = this.subrangeInfo[WARNING][RANGE_LOW]; if (range.contains(value)) { - double x = midX + COLUMN_RADIUS + 2; + double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); @@ -1082,7 +1269,7 @@ // draw start of critical range value = this.subrangeInfo[CRITICAL][RANGE_LOW]; if (range.contains(value)) { - double x = midX + COLUMN_RADIUS + 2; + double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); @@ -1095,14 +1282,14 @@ if ((this.rangeAxis != null) && (this.axisLocation != NONE)) { int drawWidth = AXIS_GAP; if (this.showValueLines) { - drawWidth += COLUMN_DIAMETER; + drawWidth += getColumnDiameter(); } Rectangle2D drawArea; double cursor = 0; switch (this.axisLocation) { case RIGHT: - cursor = midX + COLUMN_RADIUS; + cursor = midX + getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, @@ -1112,7 +1299,7 @@ case LEFT: default: //cursor = midX - COLUMN_RADIUS - AXIS_GAP; - cursor = midX - COLUMN_RADIUS; + cursor = midX - getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, @@ -1129,19 +1316,19 @@ switch (this.valueLocation) { case RIGHT: g2.drawString(this.valueFormat.format(current), - midX + COLUMN_RADIUS + GAP_RADIUS, midY); + midX + getColumnRadius() + getGapRadius(), midY); break; case LEFT: String valueString = this.valueFormat.format(current); int stringWidth = metrics.stringWidth(valueString); - g2.drawString(valueString, midX - COLUMN_RADIUS - - GAP_RADIUS - stringWidth, midY); + g2.drawString(valueString, midX - getColumnRadius() + - getGapRadius() - stringWidth, midY); break; case BULB: temp = this.valueFormat.format(current); i = metrics.stringWidth(temp) / 2; g2.drawString(temp, midX - i, - stemBottom + BULB_RADIUS + GAP_RADIUS); + stemBottom + getBulbRadius() + getGapRadius()); break; default: } @@ -1153,7 +1340,7 @@ // draw units indicator metrics = g2.getFontMetrics(); - int tickX1 = midX - COLUMN_RADIUS - GAP_DIAMETER + int tickX1 = midX - getColumnRadius() - getGapDiameter() - metrics.stringWidth(UNITS[this.units]); if (tickX1 > area.getMinX()) { g2.drawString(UNITS[this.units], tickX1, @@ -1411,6 +1598,15 @@ if (this.useSubrangePaint != that.useSubrangePaint) { return false; } + if (this.bulbRadius != that.bulbRadius) { + return false; + } + if (this.columnRadius != that.columnRadius) { + return false; + } + if (this.gapRadius != that.gapRadius) { + return false; + } for (int i = 0; i < this.subrangePaint.length; i++) { if (!PaintUtilities.equal(this.subrangePaint[i], that.subrangePaint[i])) { Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/ThermometerPlotTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/ThermometerPlotTests.java 2007-10-08 14:15:05 UTC (rev 292) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/ThermometerPlotTests.java 2007-10-08 15:18:43 UTC (rev 293) @@ -37,6 +37,7 @@ * 26-Mar-2003 : Version 1 (DG); * 30-Apr-2007 : Added new serialization test (DG); * 03-May-2007 : Added cloning test (DG); + * 08-Oct-2007 : Updated testEquals() for new fields (DG); * */ @@ -178,6 +179,20 @@ 3.0f, 4.0f, Color.yellow)); assertTrue(p2.equals(p1)); + p1.setBulbRadius(9); + assertFalse(p1.equals(p2)); + p2.setBulbRadius(9); + assertTrue(p2.equals(p1)); + + p1.setColumnRadius(8); + assertFalse(p1.equals(p2)); + p2.setColumnRadius(8); + assertTrue(p2.equals(p1)); + + p1.setGapRadius(7); + assertFalse(p1.equals(p2)); + p2.setGapRadius(7); + assertTrue(p2.equals(p1)); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-11 14:09:37
|
Revision: 328 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=328&view=rev Author: mungady Date: 2007-10-11 07:09:35 -0700 (Thu, 11 Oct 2007) Log Message: ----------- 2007-10-11 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/ThermometerPlot.java (DEFAULT_GAP_RADIUS): Renamed DEFAULT_GAP, (gapRadius): Renamed gap, (getGapRadius): Renamed getGap(), (setGapRadius): Renamed setGap(), (getGapDiameter): Removed, (draw): Updated for method name changes, (equals): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ThermometerPlot.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-11 08:50:44 UTC (rev 327) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-11 14:09:35 UTC (rev 328) @@ -1,3 +1,14 @@ +2007-10-11 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/plot/ThermometerPlot.java + (DEFAULT_GAP_RADIUS): Renamed DEFAULT_GAP, + (gapRadius): Renamed gap, + (getGapRadius): Renamed getGap(), + (setGapRadius): Renamed setGap(), + (getGapDiameter): Removed, + (draw): Updated for method name changes, + (equals): Likewise. + 2007-10-08 David Gilbert <dav...@ob...> Based on Patch 1769088: Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ThermometerPlot.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ThermometerPlot.java 2007-10-11 08:50:44 UTC (rev 327) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ThermometerPlot.java 2007-10-11 14:09:35 UTC (rev 328) @@ -215,14 +215,14 @@ /** * The gap radius. * - * @deprecated As of 1.0.7, use {@link #getGapRadius()}. + * @deprecated As of 1.0.7, use {@link #getGap()}. */ protected static final int GAP_RADIUS = 5; /** * The gap diameter. * - * @deprecated As of 1.0.7, use {@link #getGapDiameter()}. + * @deprecated As of 1.0.7, use {@link #getGap()} times two. */ protected static final int GAP_DIAMETER = GAP_RADIUS * 2; @@ -266,11 +266,11 @@ protected static final int DEFAULT_COLUMN_RADIUS = 20; /** - * The default gap radius. + * The default gap between the outlines representing the thermometer. * * @since 1.0.7 */ - protected static final int DEFAULT_GAP_RADIUS = 5; + protected static final int DEFAULT_GAP = 5; /** The dataset for the plot. */ private ValueDataset dataset; @@ -299,11 +299,11 @@ private int columnRadius = DEFAULT_COLUMN_RADIUS; /** - * The gap radius. + * The gap between the two outlines the represent the thermometer. * * @since 1.0.7 */ - private int gapRadius = DEFAULT_GAP_RADIUS; + private int gap = DEFAULT_GAP; /** * Blank space inside the plot area around the outside of the thermometer. @@ -1110,46 +1110,36 @@ } /** - * Returns the gap radius in Java2D units. + * Returns the gap, in Java2D units, between the two outlines that + * represent the thermometer. * - * @return The gap radius. + * @return The gap. * - * @see #setGapRadius(int) + * @see #setGap(int) * * @since 1.0.7 */ - public int getGapRadius() { - return this.gapRadius; + public int getGap() { + return this.gap; } /** - * Sets the gap radius (in Java2D units) and sends a - * {@link PlotChangeEvent} to all registered listeners. + * Sets the gap (in Java2D units) between the two outlines that represent + * the thermometer, and sends a {@link PlotChangeEvent} to all registered + * listeners. * - * @param r the new radius. + * @param gap the new gap. * - * @see #getGapRadius() + * @see #getGap() * * @since 1.0.7 */ - public void setGapRadius(int r) { - this.gapRadius = r; + public void setGap(int gap) { + this.gap = gap; notifyListeners(new PlotChangeEvent(this)); } /** - * Returns the gap diameter, which is always twice the value returned by - * {@link #getGapRadius()}. - * - * @return The gap diameter, in Java2D units. - * - * @since 1.0.7 - */ - public int getGapDiameter() { - return getGapRadius() * 2; - } - - /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * @@ -1200,15 +1190,15 @@ Area tempArea = new Area(outerStem); outerThermometer.add(tempArea); - innerBulb.setFrame(midX - getBulbRadius() + getGapRadius(), - stemBottom + getGapRadius(), getBulbDiameter() - - getGapDiameter(), getBulbDiameter() - getGapDiameter()); + innerBulb.setFrame(midX - getBulbRadius() + getGap(), stemBottom + + getGap(), getBulbDiameter() - getGap() * 2, getBulbDiameter() + - getGap() * 2); - innerStem.setRoundRect(midX - getColumnRadius() + getGapRadius(), - interior.getMinY() + getGapRadius(), getColumnDiameter() - - getGapDiameter(), stemBottom + getBulbDiameter() - - getGapDiameter() - stemTop, getColumnDiameter() - - getGapDiameter(), getColumnDiameter() - getGapDiameter()); + innerStem.setRoundRect(midX - getColumnRadius() + getGap(), + interior.getMinY() + getGap(), getColumnDiameter() + - getGap() * 2, stemBottom + getBulbDiameter() - getGap() * 2 + - stemTop, getColumnDiameter() - getGap() * 2, + getColumnDiameter() - getGap() * 2); Area innerThermometer = new Area(innerBulb); tempArea = new Area(innerStem); @@ -1219,12 +1209,12 @@ double ds = this.rangeAxis.valueToJava2D(current, dataArea, RectangleEdge.LEFT); - int i = getColumnDiameter() - getGapDiameter(); // already calculated - int j = getColumnRadius() - getGapRadius(); // already calculated + int i = getColumnDiameter() - getGap() * 2; // already calculated + int j = getColumnRadius() - getGap(); // already calculated int l = (i / 2); int k = (int) Math.round(ds); - if (k < (getGapRadius() + interior.getMinY())) { - k = (int) (getGapRadius() + interior.getMinY()); + if (k < (getGap() + interior.getMinY())) { + k = (int) (getGap() + interior.getMinY()); l = getBulbRadius(); } @@ -1317,19 +1307,19 @@ switch (this.valueLocation) { case RIGHT: g2.drawString(this.valueFormat.format(current), - midX + getColumnRadius() + getGapRadius(), midY); + midX + getColumnRadius() + getGap(), midY); break; case LEFT: String valueString = this.valueFormat.format(current); int stringWidth = metrics.stringWidth(valueString); g2.drawString(valueString, midX - getColumnRadius() - - getGapRadius() - stringWidth, midY); + - getGap() - stringWidth, midY); break; case BULB: temp = this.valueFormat.format(current); i = metrics.stringWidth(temp) / 2; g2.drawString(temp, midX - i, - stemBottom + getBulbRadius() + getGapRadius()); + stemBottom + getBulbRadius() + getGap()); break; default: } @@ -1341,7 +1331,7 @@ // draw units indicator metrics = g2.getFontMetrics(); - int tickX1 = midX - getColumnRadius() - getGapDiameter() + int tickX1 = midX - getColumnRadius() - getGap() * 2 - metrics.stringWidth(UNITS[this.units]); if (tickX1 > area.getMinX()) { g2.drawString(UNITS[this.units], tickX1, @@ -1605,7 +1595,7 @@ if (this.columnRadius != that.columnRadius) { return false; } - if (this.gapRadius != that.gapRadius) { + if (this.gap != that.gap) { return false; } for (int i = 0; i < this.subrangePaint.length; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-11 14:42:01
|
Revision: 330 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=330&view=rev Author: mungady Date: 2007-10-11 07:41:52 -0700 (Thu, 11 Oct 2007) Log Message: ----------- 2007-10-11 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/MultiValueRenderer.java: Renamed ScatterRenderer.java; * tests/org/jfree/chart/renderer/category/junit/MultiValueRendererTests.java: Renamed ScatterRendererTests.java. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog Added Paths: ----------- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/ScatterRenderer.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/ScatterRendererTests.java Removed Paths: ------------- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MultiShapeRenderer.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MultiShapeRendererTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-11 14:31:36 UTC (rev 329) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-11 14:41:52 UTC (rev 330) @@ -1,5 +1,12 @@ 2007-10-11 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/category/MultiValueRenderer.java: + Renamed ScatterRenderer.java; + * tests/org/jfree/chart/renderer/category/junit/MultiValueRendererTests.java: + Renamed ScatterRendererTests.java. + +2007-10-11 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/ThermometerPlot.java (DEFAULT_GAP_RADIUS): Renamed DEFAULT_GAP, (gapRadius): Renamed gap, Deleted: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MultiShapeRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MultiShapeRenderer.java 2007-10-11 14:31:36 UTC (rev 329) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MultiShapeRenderer.java 2007-10-11 14:41:52 UTC (rev 330) @@ -1,553 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2007, 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.] - * - * ----------------------- - * MultiShapeRenderer.java - * ----------------------- - * (C) Copyright 2007, 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); - * - */ - -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. - * - * @since 1.0.7 - */ -public class MultiShapeRenderer 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 MultiShapeRenderer() { - 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; - notifyListeners(new RendererChangeEvent(this)); - } - - /** - * 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; - notifyListeners(new RendererChangeEvent(this)); - } - - /** - * 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; - notifyListeners(new RendererChangeEvent(this)); - } - - /** - * 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. - * - * @param use the flag. - * - * @see #getUseOutlinePaint() - */ - public void setUseOutlinePaint(boolean use) { - this.useOutlinePaint = use; - notifyListeners(new RendererChangeEvent(this)); - } - - // 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. - * - * @param series the series index (zero-based). - * @param filled the flag. - */ - public void setSeriesShapesFilled(int series, Boolean filled) { - this.seriesShapesFilled.setBoolean(series, filled); - notifyListeners(new RendererChangeEvent(this)); - } - - /** - * Sets the 'shapes filled' flag for a series. - * - * @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)); - notifyListeners(new RendererChangeEvent(this)); - } - - /** - * Returns the base 'shape filled' attribute. - * - * @return The base flag. - */ - public boolean getBaseShapesFilled() { - return this.baseShapesFilled; - } - - /** - * Sets the base 'shapes filled' flag. - * - * @param flag the flag. - */ - public void setBaseShapesFilled(boolean flag) { - this.baseShapesFilled = flag; - notifyListeners(new RendererChangeEvent(this)); - } - - /** - * 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; - notifyListeners(new RendererChangeEvent(this)); - } - - /** - * 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 = lookupSeriesShape(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.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 MultiShapeRenderer)) { - return false; - } - MultiShapeRenderer that = (MultiShapeRenderer) 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 { - MultiShapeRenderer clone = (MultiShapeRenderer) 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(); - - } - -} Copied: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/ScatterRenderer.java (from rev 291, branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/MultiShapeRenderer.java) =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/ScatterRenderer.java (rev 0) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/ScatterRenderer.java 2007-10-11 14:41:52 UTC (rev 330) @@ -0,0 +1,554 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, 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, 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); + * + */ + +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. + * + * @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; + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * 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; + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * 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; + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * 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. + * + * @param use the flag. + * + * @see #getUseOutlinePaint() + */ + public void setUseOutlinePaint(boolean use) { + this.useOutlinePaint = use; + notifyListeners(new RendererChangeEvent(this)); + } + + // 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. + * + * @param series the series index (zero-based). + * @param filled the flag. + */ + public void setSeriesShapesFilled(int series, Boolean filled) { + this.seriesShapesFilled.setBoolean(series, filled); + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * Sets the 'shapes filled' flag for a series. + * + * @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)); + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * Returns the base 'shape filled' attribute. + * + * @return The base flag. + */ + public boolean getBaseShapesFilled() { + return this.baseShapesFilled; + } + + /** + * Sets the base 'shapes filled' flag. + * + * @param flag the flag. + */ + public void setBaseShapesFilled(boolean flag) { + this.baseShapesFilled = flag; + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * 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; + notifyListeners(new RendererChangeEvent(this)); + } + + /** + * 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 = lookupSeriesShape(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.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(); + + } + +} Deleted: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MultiShapeRendererTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MultiShapeRendererTests.java 2007-10-11 14:31:36 UTC (rev 329) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MultiShapeRendererTests.java 2007-10-11 14:41:52 UTC (rev 330) @@ -1,217 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2007, 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.] - * - * ---------------------------- - * MultiShapeRendererTests.java - * ---------------------------- - * (C) Copyright 2007, by Object Refinery Limited and Contributors. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes - * ------- - * 08-Oct-2007 : Version 1 (DG); - * - */ - -package org.jfree.chart.renderer.category.junit; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInput; -import java.io.ObjectInputStream; -import java.io.ObjectOutput; -import java.io.ObjectOutputStream; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.jfree.chart.renderer.category.MultiShapeRenderer; - -/** - * Tests for the {@link MultiShapeRenderer} class. - */ -public class MultiShapeRendererTests extends TestCase { - - /** - * Returns the tests as a test suite. - * - * @return The test suite. - */ - public static Test suite() { - return new TestSuite(MultiShapeRendererTests.class); - } - - /** - * Constructs a new set of tests. - * - * @param name the name of the tests. - */ - public MultiShapeRendererTests(String name) { - super(name); - } - - /** - * Test that the equals() method distinguishes all fields. - */ - public void testEquals() { - - MultiShapeRenderer r1 = new MultiShapeRenderer(); - MultiShapeRenderer r2 = new MultiShapeRenderer(); - assertEquals(r1, r2); - - r1.setSeriesShapesFilled(1, true); - assertFalse(r1.equals(r2)); - r2.setSeriesShapesFilled(1, true); - assertTrue(r1.equals(r2)); - - r1.setBaseShapesFilled(false); - assertFalse(r1.equals(r2)); - r2.setBaseShapesFilled(false); - assertTrue(r1.equals(r2)); - - r1.setUseFillPaint(true); - assertFalse(r1.equals(r2)); - r2.setUseFillPaint(true); - assertTrue(r1.equals(r2)); - - r1.setDrawOutlines(true); - assertFalse(r1.equals(r2)); - r2.setDrawOutlines(true); - assertTrue(r1.equals(r2)); - - r1.setUseOutlinePaint(true); - assertFalse(r1.equals(r2)); - r2.setUseOutlinePaint(true); - assertTrue(r1.equals(r2)); - - r1.setUseSeriesOffset(false); - assertFalse(r1.equals(r2)); - r2.setUseSeriesOffset(false); - assertTrue(r1.equals(r2)); - - } - - /** - * Two objects that are equal are required to return the same hashCode. - */ - public void testHashcode() { - MultiShapeRenderer r1 = new MultiShapeRenderer(); - MultiShapeRenderer r2 = new MultiShapeRenderer(); - assertTrue(r1.equals(r2)); - int h1 = r1.hashCode(); - int h2 = r2.hashCode(); - assertEquals(h1, h2); - } - - /** - * Confirm that cloning works. - */ - public void testCloning() { - MultiShapeRenderer r1 = new MultiShapeRenderer(); - MultiShapeRenderer r2 = null; - try { - r2 = (MultiShapeRenderer) r1.clone(); - } - catch (CloneNotSupportedException e) { - e.printStackTrace(); - } - assertTrue(r1 != r2); - assertTrue(r1.getClass() == r2.getClass()); - assertTrue(r1.equals(r2)); - - assertTrue(checkIndependence(r1, r2)); - - } - - /** - * Checks that the two renderers are equal but independent of one another. - * - * @param r1 renderer 1. - * @param r2 renderer 2. - * - * @return A boolean. - */ - private boolean checkIndependence(MultiShapeRenderer r1, - MultiShapeRenderer r2) { - - // should be equal... - if (!r1.equals(r2)) { - return false; - } - - // and independent... - r1.setSeriesShapesFilled(1, true); - if (r1.equals(r2)) { - return false; - } - r2.setSeriesShapesFilled(1, true); - if (!r1.equals(r2)) { - return false; - } - - r1.setBaseShapesFilled(false); - r2.setBaseShapesFilled(true); - if (r1.equals(r2)) { - return false; - } - r2.setBaseShapesFilled(false); - if (!r1.equals(r2)) { - return false; - } - return true; - - } - - /** - * Serialize an instance, restore it, and check for equality. - */ - public void testSerialization() { - - MultiShapeRenderer r1 = new MultiShapeRenderer(); - MultiShapeRenderer r2 = null; - - try { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ObjectOutput out = new ObjectOutputStream(buffer); - out.writeObject(r1); - out.close(); - - ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray())); - r2 = (MultiShapeRenderer) in.readObject(); - in.close(); - } - catch (Exception e) { - e.printStackTrace(); - } - assertEquals(r1, r2); - - } - -} Copied: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/ScatterRendererTests.java (from rev 291, branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/MultiShapeRendererTests.java) =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/ScatterRendererTests.java (rev 0) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/ScatterRendererTests.java 2007-10-11 14:41:52 UTC (rev 330) @@ -0,0 +1,218 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, 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.] + * + * ------------------------- + * ScatterRendererTests.java + * ------------------------- + * (C) Copyright 2007, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 08-Oct-2007 : Version 1 (DG); + * 11-Oct-2007 : Renamed ScatterRenderer (DG); + * + */ + +package org.jfree.chart.renderer.category.junit; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.chart.renderer.category.ScatterRenderer; + +/** + * Tests for the {@link ScatterRenderer} class. + */ +public class ScatterRendererTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(ScatterRendererTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public ScatterRendererTests(String name) { + super(name); + } + + /** + * Test that the equals() method distinguishes all fields. + */ + public void testEquals() { + + ScatterRenderer r1 = new ScatterRenderer(); + ScatterRenderer r2 = new ScatterRenderer(); + assertEquals(r1, r2); + + r1.setSeriesShapesFilled(1, true); + assertFalse(r1.equals(r2)); + r2.setSeriesShapesFilled(1, true); + assertTrue(r1.equals(r2)); + + r1.setBaseShapesFilled(false); + assertFalse(r1.equals(r2)); + r2.setBaseShapesFilled(false); + assertTrue(r1.equals(r2)); + + r1.setUseFillPaint(true); + assertFalse(r1.equals(r2)); + r2.setUseFillPaint(true); + assertTrue(r1.equals(r2)); + + r1.setDrawOutlines(true); + assertFalse(r1.equals(r2)); + r2.setDrawOutlines(true); + assertTrue(r1.equals(r2)); + + r1.setUseOutlinePaint(true); + assertFalse(r1.equals(r2)); + r2.setUseOutlinePaint(true); + assertTrue(r1.equals(r2)); + + r1.setUseSeriesOffset(false); + assertFalse(r1.equals(r2)); + r2.setUseSeriesOffset(false); + assertTrue(r1.equals(r2)); + + } + + /** + * Two objects that are equal are required to return the same hashCode. + */ + public void testHashcode() { + ScatterRenderer r1 = new ScatterRenderer(); + ScatterRenderer r2 = new ScatterRenderer(); + assertTrue(r1.equals(r2)); + int h1 = r1.hashCode(); + int h2 = r2.hashCode(); + assertEquals(h1, h2); + } + + /** + * Confirm that cloning works. + */ + public void testCloning() { + ScatterRenderer r1 = new ScatterRenderer(); + ScatterRenderer r2 = null; + try { + r2 = (ScatterRenderer) r1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(r1 != r2); + assertTrue(r1.getClass() == r2.getClass()); + assertTrue(r1.equals(r2)); + + assertTrue(checkIndependence(r1, r2)); + + } + + /** + * Checks that the two renderers are equal but independent of one another. + * + * @param r1 renderer 1. + * @param r2 renderer 2. + * + * @return A boolean. + */ + private boolean checkIndependence(ScatterRenderer r1, + ScatterRenderer r2) { + + // should be equal... + if (!r1.equals(r2)) { + return false; + } + + // and independent... + r1.setSeriesShapesFilled(1, true); + if (r1.equals(r2)) { + return false; + } + r2.setSeriesShapesFilled(1, true); + if (!r1.equals(r2)) { + return false; + } + + r1.setBaseShapesFilled(false); + r2.setBaseShapesFilled(true); + if (r1.equals(r2)) { + return false; + } + r2.setBaseShapesFilled(false); + if (!r1.equals(r2)) { + return false; + } + return true; + + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + + ScatterRenderer r1 = new ScatterRenderer(); + ScatterRenderer r2 = null; + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(r1); + out.close(); + + ObjectInput in = new ObjectInputStream( + new ByteArrayInputStream(buffer.toByteArray())); + r2 = (ScatterRenderer) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(r1, r2); + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-16 08:29:35
|
Revision: 341 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=341&view=rev Author: mungady Date: 2007-10-16 01:29:31 -0700 (Tue, 16 Oct 2007) Log Message: ----------- 2007-10-16 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/BarRenderer3D.java (drawRangeMarker): Use adjusted data area; * source/org/jfree/chart/renderer/category/LineRenderer3D.java (drawRangeMarker): Use adjusted data area, and call super to hanle IntervalMarker (DG); Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/BarRenderer3D.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineRenderer3D.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-13 11:49:05 UTC (rev 340) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-10-16 08:29:31 UTC (rev 341) @@ -1,3 +1,11 @@ +2007-10-16 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/renderer/category/BarRenderer3D.java + (drawRangeMarker): Use adjusted data area; + * source/org/jfree/chart/renderer/category/LineRenderer3D.java + (drawRangeMarker): Use adjusted data area, and call super to hanle + IntervalMarker (DG); + 2007-10-11 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/MultiValueRenderer.java: Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/BarRenderer3D.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/BarRenderer3D.java 2007-10-13 11:49:05 UTC (rev 340) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/BarRenderer3D.java 2007-10-16 08:29:31 UTC (rev 341) @@ -90,6 +90,7 @@ * 07-Dec-2006 : Implemented equals() override (DG); * 17-Jan-2007 : Fixed bug in drawDomainGridline() method (DG); * 03-Apr-2007 : Fixed bugs in drawBackground() method (DG); + * 16-Oct-2007 : Fixed bug in range marker drawing (DG); * */ @@ -513,6 +514,10 @@ Marker marker, Rectangle2D dataArea) { + + Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), + dataArea.getY() + getYOffset(), dataArea.getWidth() + - getXOffset(), dataArea.getHeight() - getYOffset()); if (marker instanceof ValueMarker) { ValueMarker vm = (ValueMarker) marker; double value = vm.getValue(); @@ -521,10 +526,6 @@ return; } - Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), - dataArea.getY() + getYOffset(), dataArea.getWidth() - - getXOffset(), dataArea.getHeight() - getYOffset()); - GeneralPath path = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { @@ -574,7 +575,7 @@ } else { - super.drawRangeMarker(g2, plot, axis, marker, dataArea); + super.drawRangeMarker(g2, plot, axis, marker, adjusted); // TODO: draw the interval marker with a 3D effect } } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineRenderer3D.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineRenderer3D.java 2007-10-13 11:49:05 UTC (rev 340) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineRenderer3D.java 2007-10-16 08:29:31 UTC (rev 341) @@ -46,6 +46,7 @@ * 17-Jan-2007 : Fixed bug in drawDomainGridline() method and added * argument check to setWallPaint() (DG); * 03-Apr-2007 : Fixed bugs in drawBackground() method (DG); + * 16-Oct-2007 : Fixed bug in range marker drawing (DG); * */ @@ -435,6 +436,11 @@ Marker marker, Rectangle2D dataArea) { + Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), + dataArea.getY() + getYOffset(), + dataArea.getWidth() - getXOffset(), + dataArea.getHeight() - getYOffset()); + if (marker instanceof ValueMarker) { ValueMarker vm = (ValueMarker) marker; double value = vm.getValue(); @@ -443,11 +449,6 @@ return; } - Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), - dataArea.getY() + getYOffset(), - dataArea.getWidth() - getXOffset(), - dataArea.getHeight() - getYOffset()); - GeneralPath path = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { @@ -480,6 +481,10 @@ g2.setPaint(marker.getOutlinePaint()); g2.draw(path); } + else { + super.drawRangeMarker(g2, plot, axis, marker, adjusted); + // TODO: draw the interval marker with a 3D effect + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |