Title: | Implement 'tableGrob' Object as a Clickable Image Map |
---|---|
Description: | Implement 'tableGrob' object as a clickable image map. The 'clickableImageMap' package is designed to be more convenient and more configurable than the edit() function. Limitations that I have encountered with edit() are cannot control (1) positioning (2) size (3) appearance and formatting of fonts In contrast, when the table is implemented as a 'tableGrob', all of these features are controllable. In particular, the 'ggplot2' grid system allows exact positioning of the table relative to other graphics etc. |
Authors: | Barry Zeeberg [aut, cre] |
Maintainer: | Barry Zeeberg <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0 |
Built: | 2025-03-11 03:15:10 UTC |
Source: | https://github.com/cran/clickableImageMap |
post a message in the annunciator grob of gtab
annunciator(gtab, row, message, name)
annunciator(gtab, row, message, name)
gtab |
return value of gtable_replace_grob() |
row |
integer the row number of the annunciator grob in gtab |
message |
character string message to be posted |
name |
character string value of name field in gtab layout matrix |
returns the return value of gtable_add_grob()
if(interactive()){ load("data/x_rows.RData") annunciatorRow<-which(names(x_rows)=="annunciatorRow") load("data/x_gtab.RData") annunciator(x_gtab,annunciatorRow,"message","annunciator") }
if(interactive()){ load("data/x_rows.RData") annunciatorRow<-which(names(x_rows)=="annunciatorRow") load("data/x_gtab.RData") annunciator(x_gtab,annunciatorRow,"message","annunciator") }
use coordinates of upper left and bottom right of matrix to construct mapping between viewport coordinates and matrix cells
calibrate(m, rows, pullDownRow)
calibrate(m, rows, pullDownRow)
m |
matrix |
rows |
list of row heights in the gtable object |
pullDownRow |
integer number of the target row in the gtable object |
returns a list whose components are matrices representing the upper and lower coordinates of the row and column cells
if(interactive()){ m<-matrix(1:20 * .05,nrow=2,ncol=10) load("data/x_rows.RData") pullDownRow<-which(names(x_rows)=="pullDownRow") load("data/x_m.RData") cal<-calibrate(x_m,x_rows,pullDownRow) }
if(interactive()){ m<-matrix(1:20 * .05,nrow=2,ncol=10) load("data/x_rows.RData") pullDownRow<-which(names(x_rows)=="pullDownRow") load("data/x_m.RData") cal<-calibrate(x_m,x_rows,pullDownRow) }
demo to illustrate how to implement calibrate() and grid.locator() for a numerical matrix. This is just a stub to be replaced by the user's actual program.
clickableImageMapDemo( n = 3, bounds = list(xmin = 0.534, xmax = 0.553, ymin = 0.057, ymax = 0.067), sleepTime = 0.5 )
clickableImageMapDemo( n = 3, bounds = list(xmin = 0.534, xmax = 0.553, ymin = 0.057, ymax = 0.067), sleepTime = 0.5 )
n |
integer number of values to be edited in matrix m |
bounds |
list of 4 numerical values xmin, xmax, ymin, ymax |
sleepTime |
numeric number of seconds to sleep to avoid potential race condition |
this package emulates edit() but allows full control
over formatting and management of the edited matrix.
sleepTime parameter can be set to nonzero (suggest trying sleepTime=0.5) in case a complicated
graphic causes a race condition evidenced by incomplete redrawing of the window. Too large a value
might cause a noticeable annoying delay in redrawing the window.
returns the updated numerical matrix
if(interactive()){ m<-clickableImageMapDemo(2,bounds=list(xmin=.534,xmax=.553,ymin=.057,ymax=.067)) }
if(interactive()){ m<-clickableImageMapDemo(2,bounds=list(xmin=.534,xmax=.553,ymin=.057,ymax=.067)) }
construct the main gtable into which grobs will be inserted
construct_entire_gtab(m, rows, message, clickCoord)
construct_entire_gtab(m, rows, message, clickCoord)
m |
a matrix |
rows |
numerical vector defining rows for inserting grobs into main gtable |
message |
character string message to display in annunciator grob of gtable |
clickCoord |
numerical matrix of 2 columns, each row contains x and y coords of a mouse click |
returns a list whose components are
m.pullDown component m of return value of pullDown()
cal.pullDown return value of calibrate()
cal.m return value of calibrate()
gtab return value of annunciator()
if(interactive()){ load("data/x_m.RData") load("data/x_rows.RData") load("data/x_clickCoord.RData") gtab<-construct_entire_gtab(x_m,x_rows,"x_message",x_clickCoord) }
if(interactive()){ load("data/x_m.RData") load("data/x_rows.RData") load("data/x_clickCoord.RData") gtab<-construct_entire_gtab(x_m,x_rows,"x_message",x_clickCoord) }
map the screen coordinates to a cell of a matrix
decode(y, cal, rcnames)
decode(y, cal, rcnames)
y |
parsed return value of grid.locator() |
cal |
return value of calibrate() |
rcnames |
Boolean if TRUE matrix has row names and col names |
returns an integer vector of the index of a cell in a matrix or returns -1 if rcnames is TRUE and vector y is not within valid range
if(interactive()){ load("data/x_y.RData") load("data/x_rcnames.RData") load("data/x_cal2.RData") decode(x_y,x_cal2,x_rcnames) }
if(interactive()){ load("data/x_y.RData") load("data/x_rcnames.RData") load("data/x_cal2.RData") decode(x_y,x_cal2,x_rcnames) }
use mouse clicks to define bounding box
defineBounds()
defineBounds()
use in conjunction with exitClick()
returns a list of numeric xmin xmax ymin ymax defining screen target for exit
if(interactive()){ defineBounds() }
if(interactive()){ defineBounds() }
detect a (left) double click (without moving cursor position)
doubleClick(tol = 0.001)
doubleClick(tol = 0.001)
tol |
numeric tolerance for detecting same position |
I realized this is not very useful, as processing is stopped until 2 clicks are detected
returns TRUE if a double click was detected
if(interactive()){ doubleClick() }
if(interactive()){ doubleClick() }
test position of mouse click to see if user wants to exit
exitClick(bounds, y)
exitClick(bounds, y)
bounds |
list of numeric xmin xmax ymin ymax defining screen target for exit |
y |
numeric vector of x and y cursor position |
use in conjunction with defineBounds()
Boolean TRUE if y is within bounds
if(interactive()){ load("data/x_bounds.RData") load("data/x_y.RData") exitClick(x_bounds,x_y) }
if(interactive()){ load("data/x_bounds.RData") load("data/x_y.RData") exitClick(x_bounds,x_y) }
replace an existing grob (in a row of a gtable) with an updated version
gtable_replace_grob(gtab, row, new_grob, name)
gtable_replace_grob(gtab, row, new_grob, name)
gtab |
a gtable object |
row |
integer target row number within the gtable |
new_grob |
update grob to insert into gtable |
name |
character string entry in the "name" field of gtable$layout |
returns the updated gtable object
if(interactive()){ load("data/x_gtab.RData") load("data/x_tab.RData") load("data/x_rows.RData") ptabRow<-which(names(x_rows)=="ptabRow") gtab<-gtable_replace_grob(x_gtab,ptabRow,x_tab,name="ptab") }
if(interactive()){ load("data/x_gtab.RData") load("data/x_tab.RData") load("data/x_rows.RData") ptabRow<-which(names(x_rows)=="ptabRow") gtab<-gtable_replace_grob(x_gtab,ptabRow,x_tab,name="ptab") }
invoke highlight() to set highlight font color and size
highlight(gtab, color, fontsize)
highlight(gtab, color, fontsize)
gtab |
a gtable object |
color |
character string representing a color |
fontsize |
integer font size |
returns gtab
if(interactive()){ load("data/x_gtab.RData") highlight(x_gtab,"red",16) }
if(interactive()){ load("data/x_gtab.RData") highlight(x_gtab,"red",16) }
highlight one cell of grob matrix in gtab
highlightOneCell(gtab, row, col, currentPick)
highlightOneCell(gtab, row, col, currentPick)
gtab |
a gtable object |
row |
integer row number of cell to highlight |
col |
integer col number of cell to highlight |
currentPick |
Boolean TRUE if this is the most recently chosen cell and we are to apply special highlighting |
returns gtab, a gtable object
if(interactive()){ load("data/x_mtab.RData") load("data/x_clickCoord.RData") highlightOneCell(x_mtab,x_clickCoord[1,"x"],x_clickCoord[1,"y"],FALSE) }
if(interactive()){ load("data/x_mtab.RData") load("data/x_clickCoord.RData") highlightOneCell(x_mtab,x_clickCoord[1,"x"],x_clickCoord[1,"y"],FALSE) }
generate and insert a matrix, acting as a pull down menu, into a gtable object
pullDown(gtab, row, focus)
pullDown(gtab, row, focus)
gtab |
a gtable object |
row |
integer target row number within the gtable |
focus |
Boolean if TRUE add emphasis to matrix cell |
returns a list whose components are the generated matrix and the gtable object
if(interactive()){ load("data/x_gtab.RData") load("data/x_rows.RData") pullDownRow<-which(names(x_rows)=="pullDownRow") message<-"select a new value from the pull down menu: " pd<-pullDown(x_gtab,pullDownRow,grepl("pull down",message)) }
if(interactive()){ load("data/x_gtab.RData") load("data/x_rows.RData") pullDownRow<-which(names(x_rows)=="pullDownRow") message<-"select a new value from the pull down menu: " pd<-pullDown(x_gtab,pullDownRow,grepl("pull down",message)) }
adjust the width and height of a matrix to exactly fill the grob
tabify(m, focus = FALSE, clickCoord = NULL)
tabify(m, focus = FALSE, clickCoord = NULL)
m |
a matrix |
focus |
Boolean if TRUE add emphasis to matrix cell |
clickCoord |
param for highlightOneCell() |
returns the grob containing the matrix
if(interactive()){ load("data/x_m.RData") t<-tabify(x_m,FALSE,NULL) }
if(interactive()){ load("data/x_m.RData") t<-tabify(x_m,FALSE,NULL) }
invoke highlight() to set font color and size to default
unhighlight(gtab)
unhighlight(gtab)
gtab |
a gtable object |
returns the return value of highlight()
if(interactive()){ load("data/x_gtab.RData") unhighlight(x_gtab) }
if(interactive()){ load("data/x_gtab.RData") unhighlight(x_gtab) }
clickableImageMap data sets
data(x_bounds)
data(x_bounds)
clickableImageMap data sets
data(x_cal.m)
data(x_cal.m)
clickableImageMap data sets
data(x_cal.pullDown)
data(x_cal.pullDown)
clickableImageMap data sets
data(x_clickCoord)
data(x_clickCoord)
clickableImageMap data sets
data(x_mtab2)
data(x_mtab2)
clickableImageMap data sets
data(x_rcnames)
data(x_rcnames)
wrapper to perform and decode grid.locator()
zlocator(cal, rcnames, bounds)
zlocator(cal, rcnames, bounds)
cal |
return value of calibrate() |
rcnames |
parameter passed to decode() |
bounds |
parameter passed to exitClick() |
keeps looping until a valid click is detected
returns the return value of decode()
if(interactive()){ load("data/x_cal.m.RData") load("data/x_rcnames.RData") load("data/x_bounds.RData") zlocator(x_cal.m,x_rcnames,x_bounds) }
if(interactive()){ load("data/x_cal.m.RData") load("data/x_rcnames.RData") load("data/x_bounds.RData") zlocator(x_cal.m,x_rcnames,x_bounds) }