Skip to content
Prev 14543 / 63424 Next

pausing between plots - waiting for graphics input

On Wed, 01 Dec 2004 08:55:27 +1300, Paul Murrell
<p.murrell@auckland.ac.nz> wrote :
You mean something like this?

The user sees a function 

 graphevents <- function(handler, events = c('mousedown', 'mouseup',
'mousemove', 'keydown', 'keyup') , prompt = 'Please do something')

which calls the handler function with a standard set of args
indicating what event just happened and keeps going until the handler
returns some non-NULL value.  So locating a single point could be
implemented as

 onmousedown <- function(event, button, x, y) {
      c(x,y)
 }

 graphevents(onmousedown, events='mousedown', prompt='Click on the
graph')

and waiting for the user to hit a key could be implemented as

 onkeyup <- function(event, key) {
   TRUE
 }

 graphevents(onkeyup, events='keyup', prompt='Hit any key')

If we wanted both, maybe we could have

 graphevents( list(onmousedown, onkeyup), c('mousedown', 'keyup'))

That would be fairly easy to implement in the windows() device, but I
have no idea if it would make sense in other interactive devices.
Issues would be defining what sort of values "key" would take, what
events to allow handlers for, what the event handler arg lists would
look like, and so on.  A test of whether it was good enough might be
whether locator() could be rewritten in R.
Yes, definitely harder.

Duncan