simplepanel {spatstat.geom} | R Documentation |
Simple Point-and-Click Interface Panels
Description
These functions enable the user to create a simple, robust, point-and-click interface to any R code.
Usage
simplepanel(title, B, boxes, clicks,
redraws=NULL, exit = NULL, env)
grow.simplepanel(P, side = c("right", "left", "top", "bottom"),
len = NULL, new.clicks, new.redraws=NULL, ..., aspect)
Arguments
title |
Character string giving the title of the interface panel. |
B |
Bounding box of the panel coordinates.
A rectangular window (object of class |
boxes |
A list of rectangular windows (objects of class |
clicks |
A list of R functions, of the same length as |
redraws |
Optional list of R functions, of the same length as |
exit |
An R function specifying actions to be taken when the interactive panel terminates. |
env |
An |
P |
An existing interaction panel (object of class |
side |
Character string identifying which side of the panel |
len |
Optional. Thickness of the new panel area that should be grown
to accommodate the new buttons. A single number in the same units
as the coordinate system of |
new.clicks |
List of R functions defining the operations to be performed when each of the new buttons is clicked. |
new.redraws |
Optional. List of R functions, of the same length as
|
... |
Arguments passed to |
aspect |
Optional. Aspect ratio (height/width) of the new buttons. |
Details
These functions enable the user to create a simple, robust, point-and-click interface to any R code.
The functions simplepanel
and grow.simplepanel
create an object of class "simplepanel"
. Such an object defines
the graphics to be displayed and the actions to be performed
when the user interacts with the panel.
The panel is activated by calling run.simplepanel
.
The function simplepanel
creates a panel object
from basic data.
The function grow.simplepanel
modifies an existing
panel object P
by growing an additional row or column
of buttons.
For simplepanel
,
-
The spatial layout of the panel is determined by the rectangles
B
andboxes
. -
The argument
clicks
must be a list of functions specifying the action to be taken when each button is clicked (orNULL
to indicate that no action should be taken). The list entries should have names (but there are sensible defaults). Each function should be of the formfunction(env, xy)
whereenv
is anenvironment
that may contain shared data, andxy
gives the coordinates of the mouse click, in the formatlist(x, y)
. The function returnsTRUE
if the panel should continue running, andFALSE
if the panel should terminate. -
The argument
redraws
, if given, must be a list of functions specifying the action to be taken when each button is to be redrawn. Each function should be of the formfunction(button, name, env)
wherebutton
is a rectangle specifying the location of the button in the current coordinate system;name
is a character string giving the name of the button; andenv
is theenvironment
that may contain shared data. The function returnsTRUE
if the panel should continue running, andFALSE
if the panel should terminate. Ifredraws
is not given (or if one of the entries inredraws
isNULL
), the default action is to draw a pink rectangle showing the button position, draw the name of the button in the middle of this rectangle, and returnTRUE
. -
The argument
exit
, if given, must be a function specifying the action to be taken when the panel terminates. (Termination occurs when one of theclicks
functions returnsFALSE
). Theexit
function should be of the formfunction(env)
whereenv
is theenvironment
that may contain shared data. Its return value will be used as the return value ofrun.simplepanel
. -
The argument
env
should be an R environment. The panel buttons will have access to this environment, and will be able to read and write data in it. This mechanism is used to exchange data between the panel and other R code.
For grow.simplepanel
,
the spatial layout of the new boxes is determined by the arguments
side
,len
,aspect
and by the additional...
arguments passed tolayout.boxes
.the argument
new.clicks
should have the same format asclicks
. It implicitly specifies the number of new buttons to be added, and the actions to be performed when they are clicked.the optional argument
new.redraws
, if given, should have the same format asredraws
. It specifies the actions to be performed when the new buttons are clicked.
Value
An object of class "simplepanel"
.
Author(s)
Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner rolfturner@posteo.net and Ege Rubak rubak@math.aau.dk.
See Also
Examples
# make boxes (alternatively use layout.boxes())
Bminus <- square(1)
Bvalue <- shift(Bminus, c(1.2, 0))
Bplus <- shift(Bvalue, c(1.2, 0))
Bdone <- shift(Bplus, c(1.2, 0))
myboxes <- list(Bminus, Bvalue, Bplus, Bdone)
myB <- do.call(boundingbox,myboxes)
# make environment containing an integer count
myenv <- new.env()
assign("answer", 0, envir=myenv)
# what to do when finished: return the count.
myexit <- function(e) { return(get("answer", envir=e)) }
# button clicks
# decrement the count
Cminus <- function(e, xy) {
ans <- get("answer", envir=e)
assign("answer", ans - 1, envir=e)
return(TRUE)
}
# display the count (clicking does nothing)
Cvalue <- function(...) { TRUE }
# increment the count
Cplus <- function(e, xy) {
ans <- get("answer", envir=e)
assign("answer", ans + 1, envir=e)
return(TRUE)
}
# 'Clear' button
Cclear <- function(e, xy) {
assign("answer", 0, envir=e)
return(TRUE)
}
# quit button
Cdone <- function(e, xy) { return(FALSE) }
myclicks <- list("-"=Cminus,
value=Cvalue,
"+"=Cplus,
done=Cdone)
# redraw the button that displays the current value of the count
Rvalue <- function(button, nam, e) {
plot(button, add=TRUE)
ans <- get("answer", envir=e)
text(centroid.owin(button), labels=ans)
return(TRUE)
}
# make the panel
P <- simplepanel("Counter",
B=myB, boxes=myboxes,
clicks=myclicks,
redraws = list(NULL, Rvalue, NULL, NULL),
exit=myexit, env=myenv)
# print it
P
# show what it looks like
redraw.simplepanel(P)
# ( type run.simplepanel(P) to run the panel interactively )
# add another button to right
Pplus <- grow.simplepanel(P, "right", new.clicks=list(clear=Cclear))