XYGraph - suggested way for user interaction [message #1708458] |
Wed, 16 September 2015 18:01  |
Eclipse User |
|
|
|
Hallo,
I created an RCP application with a Nebula XYGraph chart, and now I am adding clickable squares.
The idea is to add a clickable square centered on a data point, and to react to user clicks by executing arbitrary code.

For now I draw few squares. Each one is a RectangleFigure, added on top of the XYGraph figure, and each one has an attached Mouse listener.
RectangleFigure nodeRect = new RectangleFigure();
nodeRect.setForegroundColor(COLOR_RED);
nodeRect.setBackgroundColor(COLOR_YELLOW);
for(int i=0; i<3; i++){
int xVal = 100*(1+i);
int yVal = 100*(1+i);
nodeRect.setBounds(new Rectangle(xVal, yVal, 30, 30));
xyGraph.add(nodeRect);
// listener prints the click
nodeRect.addMouseListener( myMouseClickListener );
}
In this case, the clickable squares (Draw2D Figure) are on a layer external to XYGraph, and this brings two issues:
- The clickable squares are not linked to data points in the XYGraph chart, so I will have to "rescale" their x and y relatively to the graph. I don't know how to scale data from XYGraph space to Draw2d space.
- When resizing the XYGraph container, my squares are cut off, and I have to explicitly move them. So I think I need to intercept the XYGraph resize event. I don't know how to intercept the XYGraph resize events.

I already checked the XYGraph source code and examples. But I found no examples on this, and I found a little bit difficult to interact with XYGraph.
( I tried using annotations, but the mouse events are intercepted and canceled by the XYGraph listening system)
So, I would like to know if someone could point me to some example / best practices on how to add and interactive layer on XYGraph.
Any advice or suggestion it would be extremely useful.
Kind Regards
[Updated on: Thu, 17 September 2015 10:07] by Moderator Report message to a moderator
|
|
|
|
Re: XYGraph - suggested way for user interaction [message #1708805 is a reply to message #1708802] |
Mon, 21 September 2015 11:48   |
Eclipse User |
|
|
|
Wim,
Thank you very much for the response.
I found the behavior of annotations was limiting. In particular I think annotations are linked to a specific trace or axis, then they can not listen on "arbitrary areas of the chart".
So I decided to go with a specialized solution: Adding figures on top of the XYGraph.
With this solution I can add RectangleFigures on arbitrary areas of the Chart, and I can listen to the mouse events.
The only drawbacks are:
- I had to implement myself a scaling/conversion mechanism from data points to pixel space.
- I am reacting to XYGraph#postLayout() to redraw the interactive points each time the Canvas area is resized.
- my system is not working when zooming on the chart.
I think it would be interesting adding this kind of mechanism to XYGraph, but taking into account also the chart zooming.
Met vriendelijk groet.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03301 seconds