List of usage examples for org.jfree.data KeyToGroupMap getGroupIndex
public int getGroupIndex(Comparable group)
From source file:org.jfree.data.KeyToGroupMapTest.java
/** * Tests the getGroupIndex() method.// www . ja v a 2 s.co m */ @Test public void testGetGroupIndex() { KeyToGroupMap m1 = new KeyToGroupMap("Default Group"); // the default group is always at index 0 assertEquals(0, m1.getGroupIndex("Default Group")); // a non-existent group should return -1 assertEquals(-1, m1.getGroupIndex("G3")); // indices are assigned in the order that groups are originally mapped m1.mapKeyToGroup("K3", "G3"); m1.mapKeyToGroup("K1", "G1"); m1.mapKeyToGroup("K2", "G2"); assertEquals(1, m1.getGroupIndex("G3")); assertEquals(2, m1.getGroupIndex("G1")); assertEquals(3, m1.getGroupIndex("G2")); }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset./* w w w.java 2 s.c o m*/ * @param map a structure that maps series to groups. * * @return The value range ({@code null} if the dataset contains no * values). */ public static Range findStackedRangeBounds(CategoryDataset dataset, KeyToGroupMap map) { Args.nullNotPermitted(dataset, "dataset"); boolean hasValidData = false; Range result = null; // 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]; 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]] = negative[groupIndex[series]] + value; // '+', 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]); } } if (hasValidData) { for (int j = 0; j < groupCount; j++) { result = Range.combine(result, new Range(minimum[j], maximum[j])); } } return result; }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset.//from ww w.j a v a2 s. co m * @param map a structure that maps series to groups. * * @return The value range (<code>null</code> if the dataset contains no * values). */ public static Range findStackedRangeBounds(CategoryDataset dataset, KeyToGroupMap map) { ParamChecks.nullNotPermitted(dataset, "dataset"); boolean hasValidData = false; Range result = null; // 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]; 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]] = negative[groupIndex[series]] + value; // '+', 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]); } } if (hasValidData) { for (int j = 0; j < groupCount; j++) { result = Range.combine(result, new Range(minimum[j], maximum[j])); } } return result; }