Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jfreechart/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * ---------------- 28: * OutlierList.java 29: * ---------------- 30: * (C) Copyright 2003, 2004, 2007, by David Browning and Contributors. 31: * 32: * Original Author: David Browning (for Australian Institute of Marine 33: * Science); 34: * Contributor(s): David Gilbert (for Object Refinery Limited); 35: * 36: * Changes 37: * ------- 38: * 05-Aug-2003 : Version 1, contributed by David Browning (DG); 39: * 28-Aug-2003 : Minor tidy-up including Javadocs (DG); 40: * ------------- JFREECHART 1.0.x --------------------------------------------- 41: * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG); 42: * 43: */ 44: package org.jfree.chart.renderer; 45: 46: import java.awt.geom.Point2D; 47: import java.util.ArrayList; 48: import java.util.Iterator; 49: import java.util.List; 50: 51: /** 52: * A collection of outliers for a single entity in a box and whisker plot. 53: * 54: * Outliers are grouped in lists for each entity. Lists contain 55: * one or more outliers, determined by whether overlaps have 56: * occured. Overlapping outliers are grouped in the same list. 57: * 58: * Each list contains an averaged outlier, which is the same as a single 59: * outlier if there is only one outlier in the list, but the average of 60: * all the outliers in the list if there is more than one. 61: * 62: * NB This is simply my scheme for displaying outliers, and might not be 63: * acceptable by the wider community. 64: */ 65: public class OutlierList { 66: 67: /** Storage for the outliers. */ 68: private List outliers; 69: 70: /** The averaged outlier. */ 71: private Outlier averagedOutlier; 72: 73: /** 74: * A flag that indicates whether or not there are multiple outliers in the 75: * list. 76: */ 77: private boolean multiple = false; 78: 79: /** 80: * Creates a new list containing a single outlier. 81: * 82: * @param outlier the outlier. 83: */ 84: public OutlierList(Outlier outlier) { 85: this.outliers = new ArrayList(); 86: setAveragedOutlier(outlier); 87: } 88: 89: /** 90: * Adds an outlier to the list. 91: * 92: * @param outlier the outlier. 93: * 94: * @return A boolean. 95: */ 96: public boolean add(Outlier outlier) { 97: return this.outliers.add(outlier); 98: } 99: 100: /** 101: * Returns the number of outliers in the list. 102: * 103: * @return The item count. 104: */ 105: public int getItemCount() { 106: return this.outliers.size(); 107: } 108: 109: /** 110: * Returns the averaged outlier. 111: * 112: * @return The averaged outlier. 113: */ 114: public Outlier getAveragedOutlier() { 115: return this.averagedOutlier; 116: } 117: 118: /** 119: * Sets the averaged outlier. 120: * 121: * @param averagedOutlier the averaged outlier. 122: */ 123: public void setAveragedOutlier(Outlier averagedOutlier) { 124: this.averagedOutlier = averagedOutlier; 125: } 126: 127: /** 128: * Returns <code>true</code> if the list contains multiple outliers, and 129: * <code>false</code> otherwise. 130: * 131: * @return A boolean. 132: */ 133: public boolean isMultiple() { 134: return this.multiple; 135: } 136: 137: /** 138: * Sets the flag that indicates whether or not this list represents 139: * multiple outliers. 140: * 141: * @param multiple the flag. 142: */ 143: public void setMultiple(boolean multiple) { 144: this.multiple = multiple; 145: } 146: 147: /** 148: * Returns <code>true</code> if the outlier overlaps, and 149: * <code>false</code> otherwise. 150: * 151: * @param other the outlier. 152: * 153: * @return A boolean. 154: */ 155: public boolean isOverlapped(Outlier other) { 156: 157: if (other == null) { 158: return false; 159: } 160: 161: boolean result = other.overlaps(getAveragedOutlier()); 162: return result; 163: 164: } 165: 166: /** 167: * Updates the averaged outlier. 168: * 169: */ 170: public void updateAveragedOutlier() { 171: double totalXCoords = 0.0; 172: double totalYCoords = 0.0; 173: int size = getItemCount(); 174: for (Iterator iterator = this.outliers.iterator(); 175: iterator.hasNext();) { 176: Outlier o = (Outlier) iterator.next(); 177: totalXCoords += o.getX(); 178: totalYCoords += o.getY(); 179: } 180: getAveragedOutlier().getPoint().setLocation( 181: new Point2D.Double(totalXCoords / size, totalYCoords / size) 182: ); 183: } 184: 185: }