playwith (version 0.9-54)

convertFromDevicePixels: Utilities for working with grobs and viewports in device coordinates.

Description

Utilities for working with grobs and viewports in device coordinates.

Usage

convertFromDevicePixels(x.px, y.px, unitTo = "native", valueOnly = FALSE) convertToDevicePixels(x, y)
inViewport(x.px, y.px, viewport) grobBBDevicePixels(grob, viewport, pad = 2)
grobBoundingBoxes(draw = TRUE, gp.box = gpar(col = "yellow", lwd = 5, alpha = 0.2), gp.text = gpar(cex = 0.75, alpha = 0.5))

Arguments

x.px, y.px
locations in device coordinates (i.e. pixels, with origin at top-left corner of device). May be vectors.
unitTo
the unit to convert to.
valueOnly
to return values as numeric (native) rather than units.
x, y
locations in the current viewport (numeric native or units). May be vectors.
viewport
a viewport name or vpPath.
grob
a grob.
pad
number of pixels to expand bounding boxes.
draw
whether to draw bounding boxes and grob names.
gp.box
graphical parameters for bounding boxes.
gp.text
graphical parameters for grob name text.

Value

convertFromDevicePixels returns a list with x, y (units or numeric) locations in the current viewport.convertToDevicePixels returns a list with x, y (numeric) locations in pixels from the top-left corner of the device.inViewport returns a logical: whether the given pixel location is inside the given viewport.grobBBDevicePixels returns a list with x, y (numeric) locations in pixels giving the bounding box of the given grob. The grob must exist in the given viewport.grobBoundingBoxes returns a data.frame giving information about all grobs in the current scene.

Details

Not yet...

See Also

grid.convert, grobX, grid.ls, grid.show.layout

Examples

Run this code
print(xyplot(1:10 ~ 1:10 | c("a", "b")))

vpname <- trellis.vpname("panel", 1, 1)
downViewport(vpname)

convertToDevicePixels(x = 5:10, y = 5:10)
convertToDevicePixels(unit(0, "npc"), unit(0, "npc"))
convertFromDevicePixels(x = 100, y = 100)

inViewport(x = 100, y = 100, vpname)
inViewport(x = c(0, 100), y = c(0, 100), vpname)

myGrob <- grid.circle(r = 0.3, name = "myCircle")
grobBBDevicePixels(myGrob, vpname)

str(grobBoundingBoxes(draw = TRUE))

Run the code above in your browser using DataLab