What is the best way of detecting mouse-click events on plots? I would like to pop up a name that corresponds to a plot in a graph.
I can attach a mouse listener to a GJGraph, and I iterate through the plots in the graph calling plot.intersect(e.getX(), e.getY()) on each plot, but it seems to return true even if I click to a totally different part of the graph.
Thanks!
Tamas
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Tamas
This behaviour calls the intersects method in the java.awt.Shape implementations so what you describe is probably expected.
e.getX(), e.getY() specifies a 10 pixel-wide rectangle for the comparison.
Java doc for Shape:
"Tests if the interior of the Shape intersects the interior of a specified rectangular area. The rectangular area is considered to intersect the Shape if any point is contained in both the interior of the Shape and the specified rectangular area."
The area of a line e.g. is defined as the area under the curve using a specified "winding rule".
Your listener could refine that, e.g. by calculating the distance between any x,y point in the line and the e.getX(), e.getY() values.
M
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
What is the best way of detecting mouse-click events on plots? I would like to pop up a name that corresponds to a plot in a graph.
I can attach a mouse listener to a GJGraph, and I iterate through the plots in the graph calling plot.intersect(e.getX(), e.getY()) on each plot, but it seems to return true even if I click to a totally different part of the graph.
Thanks!
Tamas
Tamas
This behaviour calls the intersects method in the java.awt.Shape implementations so what you describe is probably expected.
e.getX(), e.getY() specifies a 10 pixel-wide rectangle for the comparison.
Java doc for Shape:
"Tests if the interior of the Shape intersects the interior of a specified rectangular area. The rectangular area is considered to intersect the Shape if any point is contained in both the interior of the Shape and the specified rectangular area."
The area of a line e.g. is defined as the area under the curve using a specified "winding rule".
Your listener could refine that, e.g. by calculating the distance between any x,y point in the line and the e.getX(), e.getY() values.
M
Hi,
Thanks for the info. I did as you said, and the following code seems to work for me:
It actually seems to work better than the logic that selects the plot in the graph. ;)
Tamas