- 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.
-
-
Constructor Summary
Constructors Constructor Description CrosshairState()Creates a newcrosshairStateinstance that calculates distance in Java2D space.CrosshairState(boolean calculateDistanceInDataSpace)Creates a newcrosshairStateinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Point2DgetAnchor()Returns the anchor point.doublegetAnchorX()Returns the x-coordinate (in data space) for the anchor point.doublegetAnchorY()Returns the y-coordinate (in data space) for the anchor point.doublegetCrosshairDistance()Returns the distance between the anchor point and the current crosshair point.doublegetCrosshairX()Get the x-value for the crosshair point.doublegetCrosshairY()Get the y-value for the crosshair point.intgetDatasetIndex()Returns the dataset index that the crosshair values relate to.voidsetAnchor(Point2D anchor)Sets the anchor point.voidsetAnchorX(double x)Sets the x-coordinate (in data space) for the anchor point.voidsetAnchorY(double y)Sets the y-coordinate (in data space) for the anchor point.voidsetCrosshairDistance(double distance)Sets the distance between the anchor point and the current crosshair point.voidsetCrosshairX(double x)Sets the x coordinate for the crosshair.voidsetCrosshairY(double y)Sets the y coordinate for the crosshair.voidsetDatasetIndex(int index)Sets the dataset index that the current crosshair values relate to.voidupdateCrosshairPoint(double x, double y, int datasetIndex, double transX, double transY, PlotOrientation orientation)Updates the crosshair point.voidupdateCrosshairX(double x, double transX, int datasetIndex)Checks to see if the specified data point is the closest to the anchor point and, if yes, updates the current state.voidupdateCrosshairY(double candidateY, double transY, int datasetIndex)Evaluates a y-value and if it is the closest to the anchor y-value it becomes the new crosshair value.
-
-
-
Constructor Detail
-
CrosshairState
public CrosshairState()
Creates a newcrosshairStateinstance that calculates distance in Java2D space.
-
CrosshairState
public CrosshairState(boolean calculateDistanceInDataSpace)
Creates a newcrosshairStateinstance. Determination of the data point nearest the anchor point can be calculated in either dataspace or Java2D space. The former should only be used for charts with a single set of axes.- Parameters:
calculateDistanceInDataSpace- a flag that controls whether the distance is calculated in data space or Java2D space.
-
-
Method Detail
-
getCrosshairDistance
public double getCrosshairDistance()
Returns the distance between the anchor point and the current crosshair point.- Returns:
- The distance.
- See Also:
setCrosshairDistance(double)
-
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:
getCrosshairDistance()
-
updateCrosshairPoint
public void updateCrosshairPoint(double x, double y, int datasetIndex, double transX, double transY, PlotOrientation orientation)
Updates the crosshair point.- Parameters:
x- the x-value.y- the y-value.datasetIndex- the dataset index.transX- the x-value in Java2D space.transY- the y-value in Java2D space.orientation- the plot orientation (nullnot permitted).
-
updateCrosshairX
public void updateCrosshairX(double x, double transX, int datasetIndex)
Checks to see if the specified data point is the closest to the anchor point and, if yes, updates the current state.- Parameters:
x- the x-value.transX- the x-value in Java2D space.datasetIndex- the dataset index.
-
updateCrosshairY
public void updateCrosshairY(double candidateY, double transY, int datasetIndex)
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.transY- the y-value in Java2D space.datasetIndex- the index of the range axis for this y-value.
-
getAnchor
public Point2D getAnchor()
Returns the anchor point.- Returns:
- The anchor point.
- See Also:
setAnchor(Point2D)
-
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 (nullpermitted).- See Also:
getAnchor()
-
getAnchorX
public double getAnchorX()
Returns the x-coordinate (in data space) for the anchor point.- Returns:
- The x-coordinate of the anchor point.
-
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.
-
getAnchorY
public double getAnchorY()
Returns the y-coordinate (in data space) for the anchor point.- Returns:
- The y-coordinate of teh anchor point.
-
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.
-
getCrosshairX
public double getCrosshairX()
Get the x-value for the crosshair point.- Returns:
- The x position of the crosshair point.
- See Also:
setCrosshairX(double)
-
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:
getCrosshairX(),setCrosshairY(double),updateCrosshairPoint(double, double, int, double, double, PlotOrientation)
-
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(double)
-
setCrosshairY
public void setCrosshairY(double y)
Sets the y coordinate for the crosshair.- Parameters:
y- the y coordinate.- See Also:
getCrosshairY(),setCrosshairX(double),updateCrosshairPoint(double, double, int, double, double, PlotOrientation)
-
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.
- See Also:
setDatasetIndex(int)
-
setDatasetIndex
public void setDatasetIndex(int index)
Sets the dataset index that the current crosshair values relate to.- Parameters:
index- the dataset index.- See Also:
getDatasetIndex()
-
-