1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2005, 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 License
  20. * along with this library; if not, write to the Free Software Foundation,
  21. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  24. * in the United States and other countries.]
  25. *
  26. * ------------
  27. * Outlier.java
  28. * ------------
  29. * (C) Copyright 2003-2005, by David Browning and Contributors.
  30. *
  31. * Original Author: David Browning (for Australian Institute of Marine
  32. * Science);
  33. * Contributor(s): David Gilbert (for Object Refinery Limited);
  34. *
  35. * $Id: Outlier.java,v 1.2 2005/02/09 13:57:23 mungady Exp $
  36. *
  37. * Changes
  38. * -------
  39. * 05-Aug-2003 : Version 1, contributed by David Browning (DG);
  40. * 28-Aug-2003 : Minor tidy-up (DG);
  41. *
  42. */
  43. package org.jfree.chart.renderer;
  44. import java.awt.geom.Point2D;
  45. /**
  46. * Represents one outlier in the box and whisker plot.
  47. * <P>
  48. * All the coordinates in this class are in Java2D space.
  49. *
  50. * @author David Browning
  51. */
  52. public class Outlier implements Comparable {
  53. /**
  54. * The xy coordinates of the bounding box containing the outlier ellipse.
  55. */
  56. private Point2D point;
  57. /** The radius of the ellipse */
  58. private double radius;
  59. /**
  60. * Constructs an outlier item consisting of a point and the radius of the
  61. * outlier ellipse
  62. *
  63. * @param xCoord the x coordinate of the point.
  64. * @param yCoord the y coordinate of the point.
  65. * @param radius the radius of the ellipse.
  66. */
  67. public Outlier(double xCoord, double yCoord, double radius) {
  68. this.point = new Point2D.Double(xCoord - radius, yCoord - radius);
  69. this.radius = radius;
  70. }
  71. /**
  72. * Returns the xy coordinates of the bounding box containing the outlier
  73. * ellipse.
  74. *
  75. * @return The location of the outlier ellipse.
  76. */
  77. public Point2D getPoint() {
  78. return this.point;
  79. }
  80. /**
  81. * Sets the xy coordinates of the bounding box containing the outlier
  82. * ellipse.
  83. *
  84. * @param point the location.
  85. */
  86. public void setPoint(Point2D point) {
  87. this.point = point;
  88. }
  89. /**
  90. * Returns the x coordinate of the bounding box containing the outlier
  91. * ellipse.
  92. *
  93. * @return The x coordinate.
  94. */
  95. public double getX() {
  96. return getPoint().getX();
  97. }
  98. /**
  99. * Returns the y coordinate of the bounding box containing the outlier
  100. * ellipse.
  101. *
  102. * @return The y coordinate.
  103. */
  104. public double getY() {
  105. return getPoint().getY();
  106. }
  107. /**
  108. * Returns the radius of the outlier ellipse.
  109. *
  110. * @return The radius.
  111. */
  112. public double getRadius() {
  113. return this.radius;
  114. }
  115. /**
  116. * Sets the radius of the outlier ellipse.
  117. *
  118. * @param radius the new radius.
  119. */
  120. public void setRadius(double radius) {
  121. this.radius = radius;
  122. }
  123. /**
  124. * Compares this object with the specified object for order, based on
  125. * the outlier's point.
  126. *
  127. * @param o the Object to be compared.
  128. * @return a negative integer, zero, or a positive integer as this object
  129. * is less than, equal to, or greater than the specified object.
  130. *
  131. */
  132. public int compareTo(Object o) {
  133. Outlier outlier = (Outlier) o;
  134. Point2D p1 = getPoint();
  135. Point2D p2 = outlier.getPoint();
  136. if (p1.equals(p2)) {
  137. return 0;
  138. }
  139. else if ((p1.getX() < p2.getX()) || (p1.getY() < p2.getY())) {
  140. return -1;
  141. }
  142. else {
  143. return 1;
  144. }
  145. }
  146. /**
  147. * Returns a true if outlier is overlapped and false if it is not.
  148. * Overlapping is determined by the respective bounding boxes plus
  149. * a small margin.
  150. *
  151. * @param other the other outlier.
  152. *
  153. * @return A <code>boolean</code> indicating whether or not an overlap has
  154. * occurred.
  155. */
  156. public boolean overlaps(Outlier other) {
  157. return ((other.getX() >= this.getX() - (this.radius * 1.1))
  158. && (other.getX() <= this.getX() + (this.radius * 1.1))
  159. && (other.getY() >= this.getY() - (this.radius * 1.1))
  160. && (other.getY() <= this.getY() + (this.radius * 1.1)));
  161. }
  162. /**
  163. * Returns a textual representation of the outlier.
  164. *
  165. * @return A <code>String</code> representing the outlier.
  166. */
  167. public String toString() {
  168. return "{" + this.getX() + "," + this.getY() + "}";
  169. }
  170. }