scene_model() walks a rendered scene and returns one row per drawn element of
the keyable marks, pairing each element's grammar-supplied identity — its data key, free-form
meta, grob id/name, and enclosing panel — with its resolved device-pixel
bounding box. It is the host-agnostic bridge underlying interactivity: a host
renders the SVG (each element tagged with data-key, see scene_svg()) and
uses this table to map an event back to the originating datum.
Usage
scene_model(scene, meta = c("records", "columns"))Arguments
- scene
A
vl_scene()(or anything coercible viaas_vellum_scene()).- meta
The form of the elements'
metacolumn."records"(the default) is a list-column with one record per element."columns"is a data-frame column instead, with one row per element and one column per field. In it a field is a plain vector when every element that carries it holds one atomic value of one type (NAfor the elements without it), and a list-column (NULLwhere absent) otherwise. The columnar form skips the per-element records, so a host reading many elements should ask for it.
Value
A list with two data frames:
elements— one row per element:key,mark,id,name,panel, the device-px bboxx0,y0,x1,y1, its centre/sizex,y,w,h, and ametacolumn (see themetaargument).panels— one row per named panel that encloses at least one element, plus any named viewport carryingmeta(a declared data panel, whose element bbox isNAwhen it holds no element):name, its elements' bounding boxx0,y0,x1,y1, the panel viewport's device-px rectanglepx0,py0,px1,py1, its native rangesxscale_lo,xscale_hi,yscale_lo,yscale_hi, and ametalist-column.
Details
Elements are returned in paint order. Batched marks (points, circles, rects,
hexagons, sectors, segments) always emit one row per element, with
key/meta NA/NULL when drawn without them, so a plain scene still
yields a geometry table. Round rects and text emit a row only for keyed
elements, and paths, lines and polygons one row per grob only when keyed.
vignette("scene-contract") is the full contract.
