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 under the terms
  10. * of the GNU Lesser General Public License as published by the Free Software Foundation;
  11. * either version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License along with this
  18. * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. *
  21. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  22. * in the United States and other countries.]
  23. *
  24. * ------------------
  25. * XYDotRenderer.java
  26. * ------------------
  27. * (C) Copyright 2002-2005, by Object Refinery Limited.
  28. *
  29. * Original Author: David Gilbert (for Object Refinery Limited);
  30. * Contributor(s): Christian W. Zuckschwerdt;
  31. ;
  32. *
  33. * $Id: XYDotRenderer.java,v 1.2 2005/01/19 12:41:39 mungady Exp $
  34. *
  35. * Changes (from 29-Oct-2002)
  36. * --------------------------
  37. * 29-Oct-2002 : Added standard header (DG);
  38. * 25-Mar-2003 : Implemented Serializable (DG);
  39. * 01-May-2003 : Modified drawItem(...) method signature (DG);
  40. * 30-Jul-2003 : Modified entity constructor (CZ);
  41. * 20-Aug-2003 : Implemented Cloneable and PublicCloneable (DG);
  42. * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
  43. * 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState (DG);
  44. * 19-Jan-2005 : Now uses only primitives from dataset (DG);
  45. *
  46. */
  47. package org.jfree.chart.renderer.xy;
  48. import java.awt.Graphics2D;
  49. import java.awt.geom.Rectangle2D;
  50. import java.io.Serializable;
  51. import org.jfree.chart.axis.ValueAxis;
  52. import org.jfree.chart.plot.CrosshairState;
  53. import org.jfree.chart.plot.PlotOrientation;
  54. import org.jfree.chart.plot.PlotRenderingInfo;
  55. import org.jfree.chart.plot.XYPlot;
  56. import org.jfree.data.xy.XYDataset;
  57. import org.jfree.ui.RectangleEdge;
  58. import org.jfree.util.PublicCloneable;
  59. /**
  60. * A renderer that draws a small dot at each data point for an {@link XYPlot}.
  61. *
  62. */
  63. public class XYDotRenderer extends AbstractXYItemRenderer
  64. implements XYItemRenderer,
  65. Cloneable,
  66. PublicCloneable,
  67. Serializable {
  68. /**
  69. * Constructs a new renderer.
  70. */
  71. public XYDotRenderer() {
  72. super();
  73. }
  74. /**
  75. * Draws the visual representation of a single data item.
  76. *
  77. * @param g2 the graphics device.
  78. * @param state the renderer state.
  79. * @param dataArea the area within which the data is being drawn.
  80. * @param info collects information about the drawing.
  81. * @param plot the plot (can be used to obtain standard color information etc).
  82. * @param domainAxis the domain (horizontal) axis.
  83. * @param rangeAxis the range (vertical) axis.
  84. * @param dataset the dataset.
  85. * @param series the series index (zero-based).
  86. * @param item the item index (zero-based).
  87. * @param crosshairState crosshair information for the plot (<code>null</code> permitted).
  88. * @param pass the pass index.
  89. */
  90. public void drawItem(Graphics2D g2,
  91. XYItemRendererState state,
  92. Rectangle2D dataArea,
  93. PlotRenderingInfo info,
  94. XYPlot plot,
  95. ValueAxis domainAxis,
  96. ValueAxis rangeAxis,
  97. XYDataset dataset,
  98. int series,
  99. int item,
  100. CrosshairState crosshairState,
  101. int pass) {
  102. // get the data point...
  103. double x = dataset.getXValue(series, item);
  104. double y = dataset.getYValue(series, item);
  105. if (!Double.isNaN(y)) {
  106. RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
  107. RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
  108. double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
  109. double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
  110. g2.setPaint(this.getItemPaint(series, item));
  111. PlotOrientation orientation = plot.getOrientation();
  112. if (orientation == PlotOrientation.HORIZONTAL) {
  113. g2.drawRect((int) transY, (int) transX, 1, 1);
  114. }
  115. else if (orientation == PlotOrientation.VERTICAL) {
  116. g2.drawRect((int) transX, (int) transY, 1, 1);
  117. }
  118. updateCrosshairValues(crosshairState, x, y, transX, transY, orientation);
  119. }
  120. }
  121. /**
  122. * Returns a clone of the renderer.
  123. *
  124. * @return A clone.
  125. *
  126. * @throws CloneNotSupportedException if the renderer cannot be cloned.
  127. */
  128. public Object clone() throws CloneNotSupportedException {
  129. return super.clone();
  130. }
  131. }