From: <mu...@us...> - 2008-10-08 14:31:13
|
Revision: 1662 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1662&view=rev Author: mungady Date: 2008-10-08 14:30:59 +0000 (Wed, 08 Oct 2008) Log Message: ----------- 2008-10-08 David Gilbert <dav...@ob...> Incorporating patch 2131001: * source/org/jfree/data/general/DatasetUtilities.java (iterateDomainBounds(XYDataset, boolean)): Ignore Double.NaN values, (iterateRangeBounds(CategoryDataset, boolean)): Likewise, (findStackedRangeBounds(CategoryDataset, KeyToGroupMap)): Cleanup, (findMinimumStackedRangeValue(CategoryDataset)): Likewise, (findMaximumStackedRangeValue(CategoryDataset)): Likewise, (findCumulativeRangeBounds(CategoryDataset)): Likewise. 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 Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2008-10-08 14:13:23 UTC (rev 1661) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2008-10-08 14:30:59 UTC (rev 1662) @@ -1,5 +1,16 @@ 2008-10-08 David Gilbert <dav...@ob...> + Incorporating patch 2131001: + * source/org/jfree/data/general/DatasetUtilities.java + (iterateDomainBounds(XYDataset, boolean)): Ignore Double.NaN values, + (iterateRangeBounds(CategoryDataset, boolean)): Likewise, + (findStackedRangeBounds(CategoryDataset, KeyToGroupMap)): Cleanup, + (findMinimumStackedRangeValue(CategoryDataset)): Likewise, + (findMaximumStackedRangeValue(CategoryDataset)): Likewise, + (findCumulativeRangeBounds(CategoryDataset)): Likewise. + +2008-10-08 David Gilbert <dav...@ob...> + * source/org/jfree/chart/labels/IntervalCategoryToolTipGenerator.java (equals): New method override, * source/org/jfree/chart/renderer/category/IntervalBarRenderer.java 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 2008-10-08 14:13:23 UTC (rev 1661) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/general/DatasetUtilities.java 2008-10-08 14:30:59 UTC (rev 1662) @@ -35,6 +35,7 @@ * Richard Atkinson; * Andreas Schroeder; * Rafal Skalny (patch 1925366); + * Jerome David (patch 2131001); * * Changes (from 18-Sep-2001) * -------------------------- @@ -108,6 +109,8 @@ * 28-Mar-2008 : Applied a variation of patch 1925366 (from Rafal Skalny) for * slightly more efficient iterateRangeBounds() methods (DG); * 08-Apr-2008 : Fixed typo in iterateRangeBounds() (DG); + * 08-Oct-2008 : Applied patch 2131001 by Jerome David, with some modifications + * and additions and some new unit tests (DG); * */ @@ -687,8 +690,12 @@ for (int item = 0; item < itemCount; item++) { lvalue = intervalXYData.getStartXValue(series, item); uvalue = intervalXYData.getEndXValue(series, item); - minimum = Math.min(minimum, lvalue); - maximum = Math.max(maximum, uvalue); + if (!Double.isNaN(lvalue)) { + minimum = Math.min(minimum, lvalue); + } + if (!Double.isNaN(uvalue)) { + maximum = Math.max(maximum, uvalue); + } } } } @@ -698,8 +705,10 @@ for (int item = 0; item < itemCount; item++) { lvalue = dataset.getXValue(series, item); uvalue = lvalue; - minimum = Math.min(minimum, lvalue); - maximum = Math.max(maximum, uvalue); + if (!Double.isNaN(lvalue)) { + minimum = Math.min(minimum, lvalue); + maximum = Math.max(maximum, uvalue); + } } } } @@ -845,10 +854,10 @@ for (int column = 0; column < columnCount; column++) { lvalue = icd.getStartValue(row, column); uvalue = icd.getEndValue(row, column); - if (lvalue != null) { + if (lvalue != null && !Double.isNaN(lvalue.doubleValue())) { minimum = Math.min(minimum, lvalue.doubleValue()); } - if (uvalue != null) { + if (uvalue != null && !Double.isNaN(uvalue.doubleValue())) { maximum = Math.max(maximum, uvalue.doubleValue()); } } @@ -861,8 +870,10 @@ Number value = dataset.getValue(row, column); if (value != null) { double v = value.doubleValue(); - minimum = Math.min(minimum, v); - maximum = Math.max(maximum, v); + if (!Double.isNaN(v)) { + minimum = Math.min(minimum, v); + maximum = Math.max(maximum, v); + } } } } @@ -1395,129 +1406,136 @@ */ public static Range findStackedRangeBounds(CategoryDataset dataset, KeyToGroupMap map) { - + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } + boolean hasValidData = false; Range result = null; - if (dataset != null) { - // create an array holding the group indices... - int[] groupIndex = new int[dataset.getRowCount()]; - for (int i = 0; i < dataset.getRowCount(); i++) { - groupIndex[i] = map.getGroupIndex( - map.getGroup(dataset.getRowKey(i)) - ); - } + // create an array holding the group indices for each series... + int[] groupIndex = new int[dataset.getRowCount()]; + for (int i = 0; i < dataset.getRowCount(); i++) { + groupIndex[i] = map.getGroupIndex(map.getGroup( + dataset.getRowKey(i))); + } - // minimum and maximum for each group... - int groupCount = map.getGroupCount(); - double[] minimum = new double[groupCount]; - double[] maximum = new double[groupCount]; + // minimum and maximum for each group... + int groupCount = map.getGroupCount(); + double[] minimum = new double[groupCount]; + double[] maximum = new double[groupCount]; - int categoryCount = dataset.getColumnCount(); - for (int item = 0; item < categoryCount; item++) { - double[] positive = new double[groupCount]; - double[] negative = new double[groupCount]; - int seriesCount = dataset.getRowCount(); - for (int series = 0; series < seriesCount; series++) { - Number number = dataset.getValue(series, item); - if (number != null) { - double value = number.doubleValue(); - if (value > 0.0) { - positive[groupIndex[series]] + int categoryCount = dataset.getColumnCount(); + for (int item = 0; item < categoryCount; item++) { + double[] positive = new double[groupCount]; + double[] negative = new double[groupCount]; + int seriesCount = dataset.getRowCount(); + for (int series = 0; series < seriesCount; series++) { + Number number = dataset.getValue(series, item); + if (number != null) { + hasValidData = true; + double value = number.doubleValue(); + if (value > 0.0) { + positive[groupIndex[series]] = positive[groupIndex[series]] + value; - } - if (value < 0.0) { - negative[groupIndex[series]] + } + if (value < 0.0) { + negative[groupIndex[series]] = negative[groupIndex[series]] + value; - // '+', remember value is negative - } + // '+', remember value is negative } } - for (int g = 0; g < groupCount; g++) { - minimum[g] = Math.min(minimum[g], negative[g]); - maximum[g] = Math.max(maximum[g], positive[g]); - } } + for (int g = 0; g < groupCount; g++) { + minimum[g] = Math.min(minimum[g], negative[g]); + maximum[g] = Math.max(maximum[g], positive[g]); + } + } + if (hasValidData) { for (int j = 0; j < groupCount; j++) { - result = Range.combine( - result, new Range(minimum[j], maximum[j]) - ); + result = Range.combine(result, new Range(minimum[j], + maximum[j])); } } return result; - } /** * Returns the minimum value in the dataset range, assuming that values in * each category are "stacked". * - * @param dataset the dataset. + * @param dataset the dataset (<code>null</code> not permitted). * * @return The minimum value. + * + * @see #findMaximumStackedRangeValue(CategoryDataset) */ public static Number findMinimumStackedRangeValue(CategoryDataset dataset) { - + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } Number result = null; - if (dataset != null) { - double minimum = 0.0; - int categoryCount = dataset.getRowCount(); - for (int item = 0; item < categoryCount; item++) { - double total = 0.0; - - int seriesCount = dataset.getColumnCount(); - for (int series = 0; series < seriesCount; series++) { - Number number = dataset.getValue(series, item); - if (number != null) { - double value = number.doubleValue(); - if (value < 0.0) { - total = total + value; - // '+', remember value is negative - } + boolean hasValidData = false; + double minimum = 0.0; + int categoryCount = dataset.getColumnCount(); + for (int item = 0; item < categoryCount; item++) { + double total = 0.0; + int seriesCount = dataset.getRowCount(); + for (int series = 0; series < seriesCount; series++) { + Number number = dataset.getValue(series, item); + if (number != null) { + hasValidData = true; + double value = number.doubleValue(); + if (value < 0.0) { + total = total + value; + // '+', remember value is negative } } - minimum = Math.min(minimum, total); - } + minimum = Math.min(minimum, total); + } + if (hasValidData) { result = new Double(minimum); } return result; - } /** * Returns the maximum value in the dataset range, assuming that values in * each category are "stacked". * - * @param dataset the dataset (<code>null</code> permitted). + * @param dataset the dataset (<code>null</code> not permitted). * * @return The maximum value (possibly <code>null</code>). + * + * @see #findMinimumStackedRangeValue(CategoryDataset) */ public static Number findMaximumStackedRangeValue(CategoryDataset dataset) { - + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } Number result = null; - - if (dataset != null) { - double maximum = 0.0; - int categoryCount = dataset.getColumnCount(); - for (int item = 0; item < categoryCount; item++) { - double total = 0.0; - int seriesCount = dataset.getRowCount(); - for (int series = 0; series < seriesCount; series++) { - Number number = dataset.getValue(series, item); - if (number != null) { - double value = number.doubleValue(); - if (value > 0.0) { - total = total + value; - } + boolean hasValidData = false; + double maximum = 0.0; + int categoryCount = dataset.getColumnCount(); + for (int item = 0; item < categoryCount; item++) { + double total = 0.0; + int seriesCount = dataset.getRowCount(); + for (int series = 0; series < seriesCount; series++) { + Number number = dataset.getValue(series, item); + if (number != null) { + hasValidData = true; + double value = number.doubleValue(); + if (value > 0.0) { + total = total + value; } } - maximum = Math.max(maximum, total); } + maximum = Math.max(maximum, total); + } + if (hasValidData) { result = new Double(maximum); } - return result; - } /** @@ -1612,11 +1630,9 @@ * @see #findRangeBounds(CategoryDataset) */ public static Range findCumulativeRangeBounds(CategoryDataset dataset) { - if (dataset == null) { throw new IllegalArgumentException("Null 'dataset' argument."); } - boolean allItemsNull = true; // we'll set this to false if there is at // least one non-null data item... double minimum = 0.0; @@ -1629,9 +1645,11 @@ if (n != null) { allItemsNull = false; double value = n.doubleValue(); - runningTotal = runningTotal + value; - minimum = Math.min(minimum, runningTotal); - maximum = Math.max(maximum, runningTotal); + if (!Double.isNaN(value)) { + runningTotal = runningTotal + value; + minimum = Math.min(minimum, runningTotal); + maximum = Math.max(maximum, runningTotal); + } } } } @@ -1641,7 +1659,6 @@ else { return null; } - } } 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 2008-10-08 14:13:23 UTC (rev 1661) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/general/junit/DatasetUtilitiesTests.java 2008-10-08 14:30:59 UTC (rev 1662) @@ -41,6 +41,8 @@ * 03-Feb-2005 : Added testFindStackedRangeBounds2() method (DG); * 26-Sep-2007 : Added testIsEmptyOrNullXYDataset() method (DG); * 28-Mar-2008 : Added and renamed various tests (DG); + * 08-Oct-2008 : New tests to support patch 2131001 and related + * changes (DG); * */ @@ -60,7 +62,9 @@ import org.jfree.data.general.DatasetUtilities; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; +import org.jfree.data.xy.DefaultIntervalXYDataset; import org.jfree.data.xy.DefaultTableXYDataset; +import org.jfree.data.xy.DefaultXYDataset; import org.jfree.data.xy.IntervalXYDataset; import org.jfree.data.xy.TableXYDataset; import org.jfree.data.xy.XYDataset; @@ -128,6 +132,69 @@ } /** + * This test checks that the standard method has 'includeInterval' + * defaulting to true. + */ + public void testFindDomainBounds2() { + DefaultIntervalXYDataset dataset = new DefaultIntervalXYDataset(); + double[] x1 = new double[] {1.0, 2.0, 3.0}; + double[] x1Start = new double[] {0.9, 1.9, 2.9}; + double[] x1End = new double[] {1.1, 2.1, 3.1}; + double[] y1 = new double[] {4.0, 5.0, 6.0}; + double[] y1Start = new double[] {1.09, 2.09, 3.09}; + double[] y1End = new double[] {1.11, 2.11, 3.11}; + double[][] data1 = new double[][] {x1, x1Start, x1End, y1, y1Start, + y1End}; + dataset.addSeries("S1", data1); + Range r = DatasetUtilities.findDomainBounds(dataset); + assertEquals(0.9, r.getLowerBound(), EPSILON); + assertEquals(3.1, r.getUpperBound(), EPSILON); + } + + /** + * This test checks that when the 'includeInterval' flag is false, the + * bounds come from the regular x-values. + */ + public void testFindDomainBounds3() { + DefaultIntervalXYDataset dataset = new DefaultIntervalXYDataset(); + double[] x1 = new double[] {1.0, 2.0, 3.0}; + double[] x1Start = new double[] {0.9, 1.9, 2.9}; + double[] x1End = new double[] {1.1, 2.1, 3.1}; + double[] y1 = new double[] {4.0, 5.0, 6.0}; + double[] y1Start = new double[] {1.09, 2.09, 3.09}; + double[] y1End = new double[] {1.11, 2.11, 3.11}; + double[][] data1 = new double[][] {x1, x1Start, x1End, y1, y1Start, + y1End}; + dataset.addSeries("S1", data1); + Range r = DatasetUtilities.findDomainBounds(dataset, false); + assertEquals(1.0, r.getLowerBound(), EPSILON); + assertEquals(3.0, r.getUpperBound(), EPSILON); + } + + /** + * This test checks that NaN values are ignored. + */ + public void testFindDomainBounds_NaN() { + DefaultIntervalXYDataset dataset = new DefaultIntervalXYDataset(); + double[] x1 = new double[] {1.0, 2.0, Double.NaN}; + double[] x1Start = new double[] {0.9, 1.9, Double.NaN}; + double[] x1End = new double[] {1.1, 2.1, Double.NaN}; + double[] y1 = new double[] {4.0, 5.0, 6.0}; + double[] y1Start = new double[] {1.09, 2.09, 3.09}; + double[] y1End = new double[] {1.11, 2.11, 3.11}; + double[][] data1 = new double[][] {x1, x1Start, x1End, y1, y1Start, + y1End}; + dataset.addSeries("S1", data1); + Range r = DatasetUtilities.findDomainBounds(dataset); + assertEquals(0.9, r.getLowerBound(), EPSILON); + assertEquals(2.1, r.getUpperBound(), EPSILON); + + r = DatasetUtilities.findDomainBounds(dataset, false); + assertEquals(1.0, r.getLowerBound(), EPSILON); + assertEquals(2.0, r.getUpperBound(), EPSILON); + } + + /** * Some tests for the iterateDomainBounds() method. */ public void testIterateDomainBounds() { @@ -138,9 +205,44 @@ } /** - * Some tests for the findRangeExtent() method. + * Check that NaN values in the dataset are ignored. */ - public void testFindRangeBounds1() { + public void testIterateDomainBounds_NaN() { + DefaultXYDataset dataset = new DefaultXYDataset(); + double[] x = new double[] {1.0, 2.0, Double.NaN, 3.0}; + double[] y = new double[] {9.0, 8.0, 7.0, 6.0}; + dataset.addSeries("S1", new double[][] {x, y}); + Range r = DatasetUtilities.iterateDomainBounds(dataset); + assertEquals(1.0, r.getLowerBound(), EPSILON); + assertEquals(3.0, r.getUpperBound(), EPSILON); + } + + /** + * Check that NaN values in the IntervalXYDataset are ignored. + */ + public void testIterateDomainBounds_NaN2() { + DefaultIntervalXYDataset dataset = new DefaultIntervalXYDataset(); + double[] x1 = new double[] {Double.NaN, 2.0, 3.0}; + double[] x1Start = new double[] {0.9, Double.NaN, 2.9}; + double[] x1End = new double[] {1.1, Double.NaN, 3.1}; + double[] y1 = new double[] {4.0, 5.0, 6.0}; + double[] y1Start = new double[] {1.09, 2.09, 3.09}; + double[] y1End = new double[] {1.11, 2.11, 3.11}; + double[][] data1 = new double[][] {x1, x1Start, x1End, y1, y1Start, + y1End}; + dataset.addSeries("S1", data1); + Range r = DatasetUtilities.iterateDomainBounds(dataset, false); + assertEquals(2.0, r.getLowerBound(), EPSILON); + assertEquals(3.0, r.getUpperBound(), EPSILON); + r = DatasetUtilities.iterateDomainBounds(dataset, true); + assertEquals(0.9, r.getLowerBound(), EPSILON); + assertEquals(3.1, r.getUpperBound(), EPSILON); + } + + /** + * Some tests for the findRangeBounds() for a CategoryDataset method. + */ + public void testFindRangeBounds_CategoryDataset() { CategoryDataset dataset = createCategoryDataset1(); Range r = DatasetUtilities.findRangeBounds(dataset); assertEquals(1.0, r.getLowerBound(), EPSILON); @@ -148,9 +250,9 @@ } /** - * Some tests for the findRangeBounds() method. + * Some tests for the findRangeBounds() method on an XYDataset. */ - public void testFindRangeBounds2() { + public void testFindRangeBounds() { XYDataset dataset = createXYDataset1(); Range r = DatasetUtilities.findRangeBounds(dataset); assertEquals(100.0, r.getLowerBound(), EPSILON); @@ -161,7 +263,7 @@ * A test for the findRangeBounds(XYDataset) method using * an IntervalXYDataset. */ - public void testFindRangeBounds3() { + public void testFindRangeBounds2() { YIntervalSeriesCollection dataset = new YIntervalSeriesCollection(); Range r = DatasetUtilities.findRangeBounds(dataset); assertNull(r); @@ -176,6 +278,10 @@ assertEquals(1.5, r.getLowerBound(), EPSILON); assertEquals(2.5, r.getUpperBound(), EPSILON); + r = DatasetUtilities.findRangeBounds(dataset, false); + assertEquals(2.0, r.getLowerBound(), EPSILON); + assertEquals(2.0, r.getUpperBound(), EPSILON); + // another item s1.add(2.0, 2.0, 1.4, 2.1); r = DatasetUtilities.findRangeBounds(dataset); @@ -199,7 +305,6 @@ r = DatasetUtilities.findRangeBounds(dataset, false); assertEquals(2.0, r.getLowerBound(), EPSILON); assertEquals(2.0, r.getUpperBound(), EPSILON); - } /** @@ -233,11 +338,11 @@ assertEquals(1.23, r.getLowerBound(), EPSILON); assertEquals(1.23, r.getUpperBound(), EPSILON); - // a Double.NaN messes things up + // a Double.NaN should be ignored dataset.addValue(Double.NaN, "R2", "C1"); r = DatasetUtilities.iterateRangeBounds(dataset, false); - assertTrue(Double.isNaN(r.getLowerBound())); - assertTrue(Double.isNaN(r.getUpperBound())); + assertEquals(1.23, r.getLowerBound(), EPSILON); + assertEquals(1.23, r.getUpperBound(), EPSILON); } /** @@ -268,7 +373,6 @@ r = DatasetUtilities.iterateRangeBounds(d, true); assertEquals(1.0, r.getLowerBound(), EPSILON); assertEquals(16.0, r.getUpperBound(), EPSILON); - } /** @@ -480,11 +584,25 @@ dataset.addValue(3.51, "Product 1", "Distribution"); dataset.addValue(32.64, "Product 1", "Total Expense"); Range range = DatasetUtilities.findCumulativeRangeBounds(dataset); - assertEquals(0.0, range.getLowerBound(), 0.00000001); - assertEquals(65.28, range.getUpperBound(), 0.00000001); + assertEquals(0.0, range.getLowerBound(), EPSILON); + assertEquals(65.28, range.getUpperBound(), EPSILON); } /** + * Check that the findCumulativeRangeBounds() method ignores Double.NaN + * values. + */ + public void testCumulativeRange_NaN() { + DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + dataset.addValue(10.0, "Series 1", "Start"); + dataset.addValue(15.0, "Series 1", "Delta 1"); + dataset.addValue(Double.NaN, "Series 1", "Delta 2"); + Range range = DatasetUtilities.findCumulativeRangeBounds(dataset); + assertEquals(0.0, range.getLowerBound(), EPSILON); + assertEquals(25.0, range.getUpperBound(), EPSILON); + } + + /** * Test the creation of a dataset from an array. */ public void testCreateCategoryDataset1() { @@ -550,7 +668,7 @@ /** * Some checks for the findStackedRangeBounds() method. */ - public void testFindStackedRangeBoundsForCategoryDataset1() { + public void testFindStackedRangeBounds_CategoryDataset1() { CategoryDataset d1 = createCategoryDataset1(); Range r = DatasetUtilities.findStackedRangeBounds(d1); assertEquals(0.0, r.getLowerBound(), EPSILON); @@ -565,13 +683,68 @@ /** * Some checks for the findStackedRangeBounds() method. */ - public void testFindStackedRangeBoundsForCategoryDataset2() { - CategoryDataset d1 = new DefaultCategoryDataset(); - Range r = DatasetUtilities.findStackedRangeBounds(d1); + public void testFindStackedRangeBounds_CategoryDataset2() { + DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + Range r = DatasetUtilities.findStackedRangeBounds(dataset); assertTrue(r == null); + + dataset.addValue(5.0, "R1", "C1"); + r = DatasetUtilities.findStackedRangeBounds(dataset, 3.0); + assertEquals(3.0, r.getLowerBound(), EPSILON); + assertEquals(8.0, r.getUpperBound(), EPSILON); + + dataset.addValue(-1.0, "R2", "C1"); + r = DatasetUtilities.findStackedRangeBounds(dataset, 3.0); + assertEquals(2.0, r.getLowerBound(), EPSILON); + assertEquals(8.0, r.getUpperBound(), EPSILON); + + dataset.addValue(null, "R3", "C1"); + r = DatasetUtilities.findStackedRangeBounds(dataset, 3.0); + assertEquals(2.0, r.getLowerBound(), EPSILON); + assertEquals(8.0, r.getUpperBound(), EPSILON); + + dataset.addValue(Double.NaN, "R4", "C1"); + r = DatasetUtilities.findStackedRangeBounds(dataset, 3.0); + assertEquals(2.0, r.getLowerBound(), EPSILON); + assertEquals(8.0, r.getUpperBound(), EPSILON); } /** + * Some checks for the findStackedRangeBounds(CategoryDataset, + * KeyToGroupMap) method. + */ + public void testFindStackedRangeBounds_CategoryDataset3() { + DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + KeyToGroupMap map = new KeyToGroupMap("Group A"); + Range r = DatasetUtilities.findStackedRangeBounds(dataset, map); + assertTrue(r == null); + + dataset.addValue(1.0, "R1", "C1"); + dataset.addValue(2.0, "R2", "C1"); + dataset.addValue(3.0, "R3", "C1"); + dataset.addValue(4.0, "R4", "C1"); + + map.mapKeyToGroup("R1", "Group A"); + map.mapKeyToGroup("R2", "Group A"); + map.mapKeyToGroup("R3", "Group B"); + map.mapKeyToGroup("R4", "Group B"); + + r = DatasetUtilities.findStackedRangeBounds(dataset, map); + assertEquals(0.0, r.getLowerBound(), EPSILON); + assertEquals(7.0, r.getUpperBound(), EPSILON); + + dataset.addValue(null, "R5", "C1"); + r = DatasetUtilities.findStackedRangeBounds(dataset, map); + assertEquals(0.0, r.getLowerBound(), EPSILON); + assertEquals(7.0, r.getUpperBound(), EPSILON); + + dataset.addValue(Double.NaN, "R6", "C1"); + r = DatasetUtilities.findStackedRangeBounds(dataset, map); + assertEquals(0.0, r.getLowerBound(), EPSILON); + assertEquals(7.0, r.getUpperBound(), EPSILON); + } + + /** * Some checks for the findStackedRangeBounds() method. */ public void testFindStackedRangeBoundsForTableXYDataset1() { @@ -671,6 +844,88 @@ } /** + * A simple check for the findMinimumStackedRangeValue() method. + */ + public void testFindMinimumStackedRangeValue() { + DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + + // an empty dataset should return a null max + Number min = DatasetUtilities.findMinimumStackedRangeValue(dataset); + assertNull(min); + + dataset.addValue(1.0, "R1", "C1"); + min = DatasetUtilities.findMinimumStackedRangeValue(dataset); + assertEquals(0.0, min.doubleValue(), EPSILON); + + dataset.addValue(2.0, "R2", "C1"); + min = DatasetUtilities.findMinimumStackedRangeValue(dataset); + assertEquals(0.0, min.doubleValue(), EPSILON); + + dataset.addValue(-3.0, "R3", "C1"); + min = DatasetUtilities.findMinimumStackedRangeValue(dataset); + assertEquals(-3.0, min.doubleValue(), EPSILON); + + dataset.addValue(Double.NaN, "R4", "C1"); + min = DatasetUtilities.findMinimumStackedRangeValue(dataset); + assertEquals(-3.0, min.doubleValue(), EPSILON); + } + + /** + * A simple check for the findMaximumStackedRangeValue() method. + */ + public void testFindMinimumStackedRangeValue2() { + DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + dataset.addValue(-1.0, "R1", "C1"); + Number min = DatasetUtilities.findMinimumStackedRangeValue(dataset); + assertEquals(-1.0, min.doubleValue(), EPSILON); + + dataset.addValue(-2.0, "R2", "C1"); + min = DatasetUtilities.findMinimumStackedRangeValue(dataset); + assertEquals(-3.0, min.doubleValue(), EPSILON); + } + + /** + * A simple check for the findMaximumStackedRangeValue() method. + */ + public void testFindMaximumStackedRangeValue() { + DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + + // an empty dataset should return a null max + Number max = DatasetUtilities.findMaximumStackedRangeValue(dataset); + assertNull(max); + + dataset.addValue(1.0, "R1", "C1"); + max = DatasetUtilities.findMaximumStackedRangeValue(dataset); + assertEquals(1.0, max.doubleValue(), EPSILON); + + dataset.addValue(2.0, "R2", "C1"); + max = DatasetUtilities.findMaximumStackedRangeValue(dataset); + assertEquals(3.0, max.doubleValue(), EPSILON); + + dataset.addValue(-3.0, "R3", "C1"); + max = DatasetUtilities.findMaximumStackedRangeValue(dataset); + assertEquals(3.0, max.doubleValue(), EPSILON); + + dataset.addValue(Double.NaN, "R4", "C1"); + max = DatasetUtilities.findMaximumStackedRangeValue(dataset); + assertEquals(3.0, max.doubleValue(), EPSILON); + } + + /** + * A simple check for the findMaximumStackedRangeValue() method. + */ + public void testFindMaximumStackedRangeValue2() { + DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + dataset.addValue(-1.0, "R1", "C1"); + Number max = DatasetUtilities.findMaximumStackedRangeValue(dataset); + assertEquals(0.0, max.doubleValue(), EPSILON); + + dataset.addValue(-2.0, "R2", "C1"); + max = DatasetUtilities.findMaximumStackedRangeValue(dataset); + assertEquals(0.0, max.doubleValue(), EPSILON); + } + + /** * Creates a dataset for testing. * * @return A dataset. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |