Class CrosshairState

java.lang.Object
org.jfree.chart.plot.CrosshairState
Direct Known Subclasses:
CategoryCrosshairState, XYCrosshairState

public class CrosshairState extends Object
Maintains state information about crosshairs on a plot between successive calls to the renderer's draw method. This class is used internally by JFreeChart - it is not intended for external use.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Point2D
    The anchor point in Java2D space - if null, don't update crosshair.
    private double
    The x-value (in data space) for the anchor point.
    private double
    The y-value (in data space) for the anchor point.
    private boolean
    A flag that controls whether the distance is calculated in data space or Java2D space.
    private double
    The x-value for the current crosshair point.
    private double
    The y-value for the current crosshair point.
    private int
    The dataset index that the crosshair point relates to (this determines the axes that the crosshairs will be plotted against).
    private double
    The smallest distance (so far) between the anchor point and a data point.
    private int
    The index of the domain axis that the crosshair x-value is measured against.
    private int
    The index of the range axis that the crosshair y-value is measured against.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new CrosshairState instance that calculates distance in Java2D space.
    CrosshairState(boolean calculateDistanceInDataSpace)
    Creates a new CrosshairState instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the anchor point.
    double
    Returns the x-coordinate (in data space) for the anchor point.
    double
    Returns the y-coordinate (in data space) for the anchor point.
    double
    Returns the distance between the anchor point and the current crosshair point.
    double
    Get the x-value for the crosshair point.
    double
    Get the y-value for the crosshair point.
    int
    Returns the dataset index that the crosshair values relate to.
    int
    Deprecated.
    As of version 1.0.11, the domain axis should be determined using the dataset index.
    int
    Deprecated.
    As of version 1.0.11, the domain axis should be determined using the dataset index.
    void
    Sets the anchor point.
    void
    setAnchorX(double x)
    Sets the x-coordinate (in data space) for the anchor point.
    void
    setAnchorY(double y)
    Sets the y-coordinate (in data space) for the anchor point.
    void
    setCrosshairDistance(double distance)
    Sets the distance between the anchor point and the current crosshair point.
    void
    setCrosshairX(double x)
    Sets the x coordinate for the crosshair.
    void
    setCrosshairY(double y)
    Sets the y coordinate for the crosshair.
    void
    setDatasetIndex(int index)
    Sets the dataset index that the current crosshair values relate to.
    void
    updateCrosshairPoint(double x, double y, double transX, double transY, PlotOrientation orientation)
    void
    updateCrosshairPoint(double x, double y, int domainAxisIndex, int rangeAxisIndex, double transX, double transY, PlotOrientation orientation)
    Evaluates a data point and if it is the closest to the anchor point it becomes the new crosshair point.
    void
    updateCrosshairX(double candidateX)
    void
    updateCrosshairX(double candidateX, int domainAxisIndex)
    Evaluates an x-value and if it is the closest to the anchor x-value it becomes the new crosshair value.
    void
    updateCrosshairY(double candidateY)
    void
    updateCrosshairY(double candidateY, int rangeAxisIndex)
    Evaluates a y-value and if it is the closest to the anchor y-value it becomes the new crosshair value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • calculateDistanceInDataSpace

      private boolean calculateDistanceInDataSpace
      A flag that controls whether the distance is calculated in data space or Java2D space.
    • anchorX

      private double anchorX
      The x-value (in data space) for the anchor point.
    • anchorY

      private double anchorY
      The y-value (in data space) for the anchor point.
    • anchor

      private Point2D anchor
      The anchor point in Java2D space - if null, don't update crosshair.
    • crosshairX

      private double crosshairX
      The x-value for the current crosshair point.
    • crosshairY

      private double crosshairY
      The y-value for the current crosshair point.
    • datasetIndex

      private int datasetIndex
      The dataset index that the crosshair point relates to (this determines the axes that the crosshairs will be plotted against).
      Since:
      1.0.11
    • domainAxisIndex

      private int domainAxisIndex
      The index of the domain axis that the crosshair x-value is measured against.
      Since:
      1.0.4
    • rangeAxisIndex

      private int rangeAxisIndex
      The index of the range axis that the crosshair y-value is measured against.
      Since:
      1.0.4
    • distance

      private double distance
      The smallest distance (so far) between the anchor point and a data point.
  • Constructor Details

    • CrosshairState

      public CrosshairState()
      Creates a new CrosshairState instance that calculates distance in Java2D space.
    • CrosshairState

      public CrosshairState(boolean calculateDistanceInDataSpace)
      Creates a new CrosshairState instance.
      Parameters:
      calculateDistanceInDataSpace - a flag that controls whether the distance is calculated in data space or Java2D space.
  • Method Details

    • getCrosshairDistance

      public double getCrosshairDistance()
      Returns the distance between the anchor point and the current crosshair point.
      Returns:
      The distance.
      Since:
      1.0.3
      See Also:
    • setCrosshairDistance

      public void setCrosshairDistance(double distance)
      Sets the distance between the anchor point and the current crosshair point. As each data point is processed, its distance to the anchor point is compared with this value and, if it is closer, the data point becomes the new crosshair point.
      Parameters:
      distance - the distance.
      See Also:
    • updateCrosshairPoint

      public void updateCrosshairPoint(double x, double y, double transX, double transY, PlotOrientation orientation)
      Evaluates a data point and if it is the closest to the anchor point it becomes the new crosshair point.

      To understand this method, you need to know the context in which it will be called. An instance of this class is passed to an XYItemRenderer as each data point is plotted. As the point is plotted, it is passed to this method to see if it should be the new crosshair point.

      Parameters:
      x - x coordinate (measured against the domain axis).
      y - y coordinate (measured against the range axis).
      transX - x translated into Java2D space.
      transY - y translated into Java2D space.
      orientation - the plot orientation.
    • updateCrosshairPoint

      public void updateCrosshairPoint(double x, double y, int domainAxisIndex, int rangeAxisIndex, double transX, double transY, PlotOrientation orientation)
      Evaluates a data point and if it is the closest to the anchor point it becomes the new crosshair point.

      To understand this method, you need to know the context in which it will be called. An instance of this class is passed to an XYItemRenderer as each data point is plotted. As the point is plotted, it is passed to this method to see if it should be the new crosshair point.

      Parameters:
      x - x coordinate (measured against the domain axis).
      y - y coordinate (measured against the range axis).
      domainAxisIndex - the index of the domain axis for this point.
      rangeAxisIndex - the index of the range axis for this point.
      transX - x translated into Java2D space.
      transY - y translated into Java2D space.
      orientation - the plot orientation.
      Since:
      1.0.4
    • updateCrosshairX

      public void updateCrosshairX(double candidateX)
      Deprecated.
      Use updateCrosshairX(double, int). See bug report 1086307.
      Evaluates an x-value and if it is the closest to the anchor x-value it becomes the new crosshair value.

      Used in cases where only the x-axis is numerical.

      Parameters:
      candidateX - x position of the candidate for the new crosshair point.
    • updateCrosshairX

      public void updateCrosshairX(double candidateX, int domainAxisIndex)
      Evaluates an x-value and if it is the closest to the anchor x-value it becomes the new crosshair value.

      Used in cases where only the x-axis is numerical.

      Parameters:
      candidateX - x position of the candidate for the new crosshair point.
      domainAxisIndex - the index of the domain axis for this x-value.
      Since:
      1.0.4
    • updateCrosshairY

      public void updateCrosshairY(double candidateY)
      Deprecated.
      Use updateCrosshairY(double, int). See bug report 1086307.
      Evaluates a y-value and if it is the closest to the anchor y-value it becomes the new crosshair value.

      Used in cases where only the y-axis is numerical.

      Parameters:
      candidateY - y position of the candidate for the new crosshair point.
    • updateCrosshairY

      public void updateCrosshairY(double candidateY, int rangeAxisIndex)
      Evaluates a y-value and if it is the closest to the anchor y-value it becomes the new crosshair value.

      Used in cases where only the y-axis is numerical.

      Parameters:
      candidateY - y position of the candidate for the new crosshair point.
      rangeAxisIndex - the index of the range axis for this y-value.
      Since:
      1.0.4
    • getAnchor

      public Point2D getAnchor()
      Returns the anchor point.
      Returns:
      The anchor point.
      Since:
      1.0.3
      See Also:
    • setAnchor

      public void setAnchor(Point2D anchor)
      Sets the anchor point. This is usually the mouse click point in a chart panel, and the crosshair point will often be the data item that is closest to the anchor point.

      Note that the x and y coordinates (in data space) are not updated by this method - the caller is responsible for ensuring that this happens in sync.
      Parameters:
      anchor - the anchor point (null permitted).
      See Also:
    • getAnchorX

      public double getAnchorX()
      Returns the x-coordinate (in data space) for the anchor point.
      Returns:
      The x-coordinate of the anchor point.
      Since:
      1.0.3
    • setAnchorX

      public void setAnchorX(double x)
      Sets the x-coordinate (in data space) for the anchor point. Note that this does NOT update the anchor itself - the caller is responsible for ensuring this is done in sync.
      Parameters:
      x - the x-coordinate.
      Since:
      1.0.3
    • getAnchorY

      public double getAnchorY()
      Returns the y-coordinate (in data space) for the anchor point.
      Returns:
      The y-coordinate of teh anchor point.
      Since:
      1.0.3
    • setAnchorY

      public void setAnchorY(double y)
      Sets the y-coordinate (in data space) for the anchor point. Note that this does NOT update the anchor itself - the caller is responsible for ensuring this is done in sync.
      Parameters:
      y - the y-coordinate.
      Since:
      1.0.3
    • getCrosshairX

      public double getCrosshairX()
      Get the x-value for the crosshair point.
      Returns:
      The x position of the crosshair point.
      See Also:
    • setCrosshairX

      public void setCrosshairX(double x)
      Sets the x coordinate for the crosshair. This is the coordinate in data space measured against the domain axis.
      Parameters:
      x - the coordinate.
      See Also:
    • getCrosshairY

      public double getCrosshairY()
      Get the y-value for the crosshair point. This is the coordinate in data space measured against the range axis.
      Returns:
      The y position of the crosshair point.
      See Also:
    • setCrosshairY

      public void setCrosshairY(double y)
      Sets the y coordinate for the crosshair.
      Parameters:
      y - the y coordinate.
      See Also:
    • getDatasetIndex

      public int getDatasetIndex()
      Returns the dataset index that the crosshair values relate to. The dataset is mapped to specific axes, and this is how the crosshairs are mapped also.
      Returns:
      The dataset index.
      Since:
      1.0.11
      See Also:
    • setDatasetIndex

      public void setDatasetIndex(int index)
      Sets the dataset index that the current crosshair values relate to.
      Parameters:
      index - the dataset index.
      Since:
      1.0.11
      See Also:
    • getDomainAxisIndex

      public int getDomainAxisIndex()
      Deprecated.
      As of version 1.0.11, the domain axis should be determined using the dataset index.
      Returns the domain axis index for the crosshair x-value.
      Returns:
      The domain axis index.
      Since:
      1.0.4
    • getRangeAxisIndex

      public int getRangeAxisIndex()
      Deprecated.
      As of version 1.0.11, the domain axis should be determined using the dataset index.
      Returns the range axis index for the crosshair y-value.
      Returns:
      The range axis index.
      Since:
      1.0.4