Daniel Kornhauser
2008-Oct-23 19:26 UTC
[Rd] Getting the panel location of a xyplot matrix using a mouse click in a GDCanvas
Hi:
I would like to find out the panel of a xyplot matrix where a mouse clicked.
I know this functionality is already bundled in trellis.focus but I can't
use it because I am coding a stand alone application in Java using with
GDCanvas as a graphics device.
I tried calling trellis.focus from Java with:
re.eval("t = trellis.focus()"));
However it did not work for an embedded GDCanvas. The above call to the
trellis.focus() returns null no matter where I click.
(Side note: the functionality must be implemented in the GDCanvas because
trellis.focus does work correctly in JGR)
I wish to handle all the user GUI events in Java to evaluate different
commands in an Rengine.
With a GDCanvas, it's straightforward to get the x y position of a mouse
click with the standard e.getX() and e.getY()
So my handler would look like:
public void mouseClicked(MouseEvent e) {
System.out.println("Clicked" + e.getX() + " " +
e.getY());
System.out.println(re.eval("t = trellis.focus()"));
System.out.println(re.eval("t"));
// I would update the panel here ...
}
I am only using Java because:
- I am proficient in Java GUI programmer
- It is multiplatform
Another way of posing the question is:
Given the coordinates from grid.location how can I find out the plane of an
xyplot matrix where the user clicked.
I have tried to figure out how to do it from code using trellis.clickFocus,
but I have have only been playing with R for a week, so I am quite lost
reading R code.
I tried to look up to in the code of JGR and came out emplty handed.
This is my first post so I hope I did not break any rules ...
Thanks !
Daniel
[[alternative HTML version deleted]]
Deepayan Sarkar
2008-Oct-23 19:55 UTC
[Rd] Getting the panel location of a xyplot matrix using a mouse click in a GDCanvas
On Thu, Oct 23, 2008 at 12:26 PM, Daniel Kornhauser <dkor at northwestern.edu> wrote:> Hi: > > I would like to find out the panel of a xyplot matrix where a mouse clicked. > > I know this functionality is already bundled in trellis.focus but I can't > use it because I am coding a stand alone application in Java using with > GDCanvas as a graphics device. > > I tried calling trellis.focus from Java with: > re.eval("t = trellis.focus()")); > However it did not work for an embedded GDCanvas. The above call to the > trellis.focus() returns null no matter where I click. > > (Side note: the functionality must be implemented in the GDCanvas because > trellis.focus does work correctly in JGR) > > I wish to handle all the user GUI events in Java to evaluate different > commands in an Rengine. > With a GDCanvas, it's straightforward to get the x y position of a mouse > click with the standard e.getX() and e.getY() > So my handler would look like: > public void mouseClicked(MouseEvent e) { > System.out.println("Clicked" + e.getX() + " " + e.getY()); > System.out.println(re.eval("t = trellis.focus()")); > System.out.println(re.eval("t")); > // I would update the panel here ... > } > > I am only using Java because: > - I am proficient in Java GUI programmer > - It is multiplatform > > Another way of posing the question is: > Given the coordinates from grid.location how can I find out the plane of an > xyplot matrix where the user clicked. > > I have tried to figure out how to do it from code using trellis.clickFocus, > but I have have only been playing with R for a week, so I am quite lost > reading R code.The approach in trellis.clickFocus should get you close. One important point is that clickLoc <- grid.locator("npc") returns the location in NPC, whereas your e.getX() and e.getY() would be in device coordinates. help(grconvertX) should tell you how to make the conversion. -Deepayan