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: * Outlier.java 29: * ------------ 30: * (C) Copyright 2003-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 (DG); 40: * ------------- JFREECHART 1.0.x --------------------------------------------- 41: * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG); 42: * 43: */ 44: 45: package org.jfree.chart.renderer; 46: 47: import java.awt.geom.Point2D; 48: 49: /** 50: * Represents one outlier in the box and whisker plot. 51: * <P> 52: * All the coordinates in this class are in Java2D space. 53: */ 54: public class Outlier implements Comparable { 55: 56: /** 57: * The xy coordinates of the bounding box containing the outlier ellipse. 58: */ 59: private Point2D point; 60: 61: /** The radius of the ellipse */ 62: private double radius; 63: 64: /** 65: * Constructs an outlier item consisting of a point and the radius of the 66: * outlier ellipse 67: * 68: * @param xCoord the x coordinate of the point. 69: * @param yCoord the y coordinate of the point. 70: * @param radius the radius of the ellipse. 71: */ 72: public Outlier(double xCoord, double yCoord, double radius) { 73: this.point = new Point2D.Double(xCoord - radius, yCoord - radius); 74: this.radius = radius; 75: } 76: 77: /** 78: * Returns the xy coordinates of the bounding box containing the outlier 79: * ellipse. 80: * 81: * @return The location of the outlier ellipse. 82: */ 83: public Point2D getPoint() { 84: return this.point; 85: } 86: 87: /** 88: * Sets the xy coordinates of the bounding box containing the outlier 89: * ellipse. 90: * 91: * @param point the location. 92: */ 93: public void setPoint(Point2D point) { 94: this.point = point; 95: } 96: 97: /** 98: * Returns the x coordinate of the bounding box containing the outlier 99: * ellipse. 100: * 101: * @return The x coordinate. 102: */ 103: public double getX() { 104: return getPoint().getX(); 105: } 106: 107: /** 108: * Returns the y coordinate of the bounding box containing the outlier 109: * ellipse. 110: * 111: * @return The y coordinate. 112: */ 113: public double getY() { 114: return getPoint().getY(); 115: } 116: 117: /** 118: * Returns the radius of the outlier ellipse. 119: * 120: * @return The radius. 121: */ 122: public double getRadius() { 123: return this.radius; 124: } 125: 126: /** 127: * Sets the radius of the outlier ellipse. 128: * 129: * @param radius the new radius. 130: */ 131: public void setRadius(double radius) { 132: this.radius = radius; 133: } 134: 135: /** 136: * Compares this object with the specified object for order, based on 137: * the outlier's point. 138: * 139: * @param o the Object to be compared. 140: * @return A negative integer, zero, or a positive integer as this object 141: * is less than, equal to, or greater than the specified object. 142: * 143: */ 144: public int compareTo(Object o) { 145: Outlier outlier = (Outlier) o; 146: Point2D p1 = getPoint(); 147: Point2D p2 = outlier.getPoint(); 148: if (p1.equals(p2)) { 149: return 0; 150: } 151: else if ((p1.getX() < p2.getX()) || (p1.getY() < p2.getY())) { 152: return -1; 153: } 154: else { 155: return 1; 156: } 157: } 158: 159: /** 160: * Returns a true if outlier is overlapped and false if it is not. 161: * Overlapping is determined by the respective bounding boxes plus 162: * a small margin. 163: * 164: * @param other the other outlier. 165: * 166: * @return A <code>boolean</code> indicating whether or not an overlap has 167: * occurred. 168: */ 169: public boolean overlaps(Outlier other) { 170: return ((other.getX() >= getX() - (this.radius * 1.1)) 171: && (other.getX() <= getX() + (this.radius * 1.1)) 172: && (other.getY() >= getY() - (this.radius * 1.1)) 173: && (other.getY() <= getY() + (this.radius * 1.1))); 174: } 175: 176: /** 177: * Returns a textual representation of the outlier. 178: * 179: * @return A <code>String</code> representing the outlier. 180: */ 181: public String toString() { 182: return "{" + getX() + "," + getY() + "}"; 183: } 184: 185: }