I have implemented the ChartMouseListener for my ChartPanel. However, the method chartMouseEvent.getEntity() is not always returning an XYItemEntity. Sometimes the mouse cursor will be directly on top of a point in the line, yet getEntity() will return NULL. Here is my code:
public void chartMouseMoved(ChartMouseEvent event) {
final ChartEntity entity = event.getEntity();
if (entity instanceof XYItemEntity) {
chartPanel.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));
} else {
chartPanel.setCursor(null);
}
}
I notified that if I change the ItemRendered to StandardXYItemRenderer.SHAPES, getEntity() will correctly return an XYItemEntity everytime the mouse moves over a point. However, it does not always work for StandardXYItemRenderer.LINES.
chartMouseMoved bug?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
It is sort-of a bug. The XYLineAndShapeRenderer only creates entities for the data points, not the lines connecting them. If shapes are visible, the shape area is used as the hotspot. If shapes are not visible, a small circle (or rectangle, I forget) is generated and used as the hotspot for the data point (i.e. where two lines meet).
We could generate entities for the lines also...the only complication is that you probably would need to split the line in two, and assign one half to the data point at the start of the line, and the other half to the data point at the other end of the line (unless you prefer to define an entity that described the two data points that are connected by the line).
We could generate entities for the lines also...the only complication is that you probably would need to split the line in two, and assign one half to the data point at the start of the line, and the other half to the data point at the other end of the line (unless you prefer to define an entity that described the two data points that are connected by the line).
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
-
- Posts: 6
- Joined: Thu Mar 20, 2008 5:38 pm
Hi,
I am using this to highlight curves under the mouse cursor (just using a thicker paint for the line paint). Currently this works only at the places where data points are available, but not on the lines conneting them. So I don't require the complete XYEntity, but only the dataset and series it belongs to. Just getting an entity providing the dataset/series the line
belongs to, I would be happy. By the side I could distinguish if "only" the connecing line or a real data point was hit.
I have the following suggestion:
Having something like a ConnetitionEntity (as a subclass of ChartEntity) with the dataset/series and the count of the hit line segment (0 for line between the 0. and the 1. point, 1 for the line between the 1. and the 2. point and so on would be nice. If splines instead of lines are used to connect the data points, this would also be a more intuitive, cause not only two points would define the spline.
Finding coordinates (if required) for the line segment is simple (by dataset.getX/Y(series, segmentNumber resp. segmentNumber+1). Getting the Items is just a call to findEntity with this coordinates.
What do you think about this idear?
Greetings
Tom
I am using this to highlight curves under the mouse cursor (just using a thicker paint for the line paint). Currently this works only at the places where data points are available, but not on the lines conneting them. So I don't require the complete XYEntity, but only the dataset and series it belongs to. Just getting an entity providing the dataset/series the line
belongs to, I would be happy. By the side I could distinguish if "only" the connecing line or a real data point was hit.
I have the following suggestion:
Having something like a ConnetitionEntity (as a subclass of ChartEntity) with the dataset/series and the count of the hit line segment (0 for line between the 0. and the 1. point, 1 for the line between the 1. and the 2. point and so on would be nice. If splines instead of lines are used to connect the data points, this would also be a more intuitive, cause not only two points would define the spline.
Finding coordinates (if required) for the line segment is simple (by dataset.getX/Y(series, segmentNumber resp. segmentNumber+1). Getting the Items is just a call to findEntity with this coordinates.
What do you think about this idear?
Greetings
Tom
Just found a simple bug in SWT Chart Composite, that might be related to your problems:
If I use a ChartComposite with buffering disabled, like
new ChartComposite(parent, SWT.NONE, chart)
the chart mouse event fails to find the correct entity, if the chart window gets to big or too small and exceeds the default bounds where it begins to scale.
If I use enabled buffering, like
new ChartComposite(parent, SWT.NONE, chart, true)
the mouse event works perfectly.
Looking at the ChartComposite code, the scaling is applied to the chart only, if the buffing is used. Therefore the mouse coordinates do not fit anymore, if the ChartComposite computes a scale, but the JFreechart does not.
Hope that my examination is correct, helps and gets fixed somehow (maybe a simple sg2.scale(this.scaleX, this.scaleY) within paintControl is enough, I didn't try).
Regards,
N
If I use a ChartComposite with buffering disabled, like
new ChartComposite(parent, SWT.NONE, chart)
the chart mouse event fails to find the correct entity, if the chart window gets to big or too small and exceeds the default bounds where it begins to scale.
If I use enabled buffering, like
new ChartComposite(parent, SWT.NONE, chart, true)
the mouse event works perfectly.
Looking at the ChartComposite code, the scaling is applied to the chart only, if the buffing is used. Therefore the mouse coordinates do not fit anymore, if the ChartComposite computes a scale, but the JFreechart does not.
Hope that my examination is correct, helps and gets fixed somehow (maybe a simple sg2.scale(this.scaleX, this.scaleY) within paintControl is enough, I didn't try).
Regards,
N
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
I think it sounds reasonable. Would you be interested in putting together a patch for this? I'll have a go at some point, but I'm so short of time that it could be a long time before I get to it.unknownfrog wrote:I have the following suggestion:
Having something like a ConnetitionEntity (as a subclass of ChartEntity) with the dataset/series and the count of the hit line segment (0 for line between the 0. and the 1. point, 1 for the line between the 1. and the 2. point and so on would be nice. If splines instead of lines are used to connect the data points, this would also be a more intuitive, cause not only two points would define the spline.
Finding coordinates (if required) for the line segment is simple (by dataset.getX/Y(series, segmentNumber resp. segmentNumber+1). Getting the Items is just a call to findEntity with this coordinates.
What do you think about this idear?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
-
- Posts: 6
- Joined: Thu Mar 20, 2008 5:38 pm
That's correct. It is not a big prolem here, just would be nice to have.converge wrote:Thanks for the replies as I understand the problem. So there is no current way of detecting when the mouse passes over a line, if it doesn't also pass over where a point (shape) is?
Currently I am also short of time to implement my suggestion mentioned above .