Resolves every keyed mark in a scene to device-pixel geometry, a paint and its key, packed as compact columnar tables. vellumwidget ships this to the browser to draw and hit-test big plots (F-5 stage 1).
Usage
scene_display_list(
scene,
what = "keyed",
panels = NULL,
version = 1L,
keys = NULL,
precision = "f32"
)Arguments
- scene
A
vl_scene(), or anything with anas_vellum_scene()method.- what
Which marks to list. Only
"keyed"for now.- panels
NULL(the default) to list keyed marks wherever they are, or a character vector of panel names to list only those whose innermost named panel (scene_model()$elements$panel) is one of them, the same rule asscene_png(layer = "keyed", panels = ). vellumwidget passes its data panels, which leaves out a legend's keyed swatches.- version
The format version,
1(the default) or2(see the Version 2 section).- keys
NULL(the default), or a character vector of keys forrecord$keyto index, so the list need not repeat them (VR-22). Keys it lacks are listed inkeysas usual, after it;NAmatches nothing.- precision
How to encode the geometry columns (see Compact coordinates):
"f32"(the default) for 32-bit floats;"u16"or"u24"to quantise each column to 16 or 24 bits within its range; or a positive number, the largest rounding error allowed in device px, to use the fewest of 8, 16 or 24 bits that keeps each column within it (f32when none does).0.005, half the 0.01 px gridscene_svg()writes coordinates on, takes 16 bits for a column spanning up to 655 px.
Details
This is a private vellum to vellumwidget payload, not a public format. Its fields and encodings may change in any release, in step with vellumwidget. Do not build on it.
Format
A list with format = "vellum-display-list", version (1 or 2), the page
width and height in device px, the record count n, and:
record: one row per keyed primitive, in paint order.kind(0 point, 1 rect, 2 path),paint(0-based row ofpaints),key(0-based index intokeys),flags(bitfield, see below),clip(1-based row ofclips, 0 = unclipped) andpanel(1-based intopanels: the innermost named panel the mark is drawn in, as inscene_model()$elements$panel; 0 = none). The i-th record of a kind is the i-th row of that kind's table.point:cx,cy,r(device px) andshape(0 circle, else thepoints_grob()marker code: 1 square, 2 triangle, 3 diamond, 4 plus, 5 cross, 6 triangle down, 7 star).rect: axis-aligned rectangles, top-leftx,yand sizew,h.path: polygons and polylines.xyholds interleaved vertices,run_offsetthe start of each run in vertices (one more entry than runs),path_offsetthe start of each path in runs (one more than paths),closed(1 = closed rings, 0 = open polylines) andevenodd(fill rule). Curves are flattened.paints: a data-frame-like list withfillandstroke("#rrggbbaa"orNAfor none),stroke_width(device px),dash(comma-separated device px, orNAfor solid),linecapandlinejoin.clips: rectanglesx0,y0,x1,y1(device px).keys: the distinct keys in first-use order, as a character vector, or as an integer column (see below) when every key is a plain non-negative integer. With thekeysargument, only the keys it lacks (see below).keys_given: only with thekeysargument, its length.record$keythen indexesc(<the keys argument>, keys): a key found in the argument is its first position there, and the rest follow in first-use order. A client that already has the keys (vellumwidget's element table) ships them once.panels: the names of the panels marks are drawn in.
Every numeric column except those in paints and clips is a list
list(type, n, ...). type is "f32", "u8", "u16" or "u32" (or
"u24", see below), and n is the length. The values come as exactly one
of data (base64, little-endian, typed), const (every value equal),
seq = c(start, step) (an arithmetic sequence) or
rle = list(values, lengths) (runs of equal values, used when there are
few).
Compact coordinates
With precision other than "f32" (VR-18), the geometry columns (point
cx, cy, r; rect x, y, w, h; path xy) are quantised
within their own range: such a column is list(type, n, lo, step, data)
with type "u8", "u16" or "u24" (three bytes per value) and value i
lo + u[i] * step, where u are the little-endian unsigned integers in
data, lo is the column's minimum and step its range over
2^bits - 1. The rounding error is at most step / 2. A column that is empty,
collapses to const or rle or holds a non-finite value stays f32,
as do the clip_paths coordinates. Points come in paint order, not in
space, so their coordinates are not delta-coded: neighbouring records are
as far apart as any two.
Version 2
version = 2 lists three more cases exactly, which version 1 flags, and
adds the tables they need. A reader that knows only version 1 must not be
handed a version-2 list: their records are no longer flagged.
Gradient fills: linear and radial gradients with
padextension.paints$fill_gradientis the 1-based row ofgradients(0 = none; thenfillisNA).gradientshastype("linear"or"radial"), the geometry in the shape's local px (linear:x1, y1tox2, y2; radial: the focal circlex1, y1, r1at offset 0 to the outer circlex2, y2, r2at offset 1), the transform placing it in device px asa,b,c,d,e,f(the SVG / canvasmatrix(a, b, c, d, e, f)), and its stops: gradient i's are rowsstop_offset[i] + 1tostop_offset[i + 1]ofstop_pos(0 to 1) andstop_color("#rrggbbaa").Path clips: a clip by a path or a rotated rectangle.
clipsgainspath_startandpath_n: a clip's paths are shapespath_start + 1topath_start + path_nofclip_paths(0 = the rect alone), and a record is clipped to the rect and to each of them. Its rect is then also bounded by the paths' boxes.clip_pathsis a path table likepath:xy,run_offset,path_offset(one shape per entry) andevenodd.Opacity groups: a group whose only effect is an opacity below 1.
record$groupis the 1-based row ofgroups(the innermost such group the record is drawn in, 0 = none).groupshasalphaandparent(1-based, 0 = top level). A client draws a group's records into their own layer and composites it atalpha.
Masks, blend modes, blur and shadow effects, hatches, patterns, repeating or reflecting gradients and gradient strokes stay flagged.
Flagged runs (VW-30):
record$runis the run of flagged marks a record belongs to (1-based, 0 = none) andrunstheir count. A run is a stretch of flagged marks in paint order that no exactly drawn mark interrupts; every record of a node with a flagged record, and of an opacity group holding one, is in it.scene_png(layer = "keyed_flagged", run = k)draws runk, so a client can draw the exact records itself and composite each run's raster where the run starts.Blend modes in runs (VW-32):
run_blendgives, per run, how its raster composites onto what is beneath it:"normal", or a CSSmix-blend-modekeyword ("multiply","screen", ...) when the run is exactly the marks of one group with that blend mode drawn onto the page, directly or inside groups with no opacity, mask, blend or effect, which isolate nothing (a blend root; a run ends where the blend root changes). Rendered on its own, such a run's raster is its marks unblended, and compositing it with that mode reproduces the blend. A blend nested inside a mask, an effect or an opacity group happens within that group's raster, so its run is"normal".""would mark a run that cannot be composited from its raster; current lists have none.
What stage 1 does not reproduce
Such marks are still listed, so they can be hit-tested, but flags marks
them and a client should fall back to its approximate path for them:
1 a gradient, pattern or hatch paint (the paint's colour is NA); 2 a
clip that is not an axis-aligned rectangle (the clip is not listed); 4 a
mark inside a group with opacity, blend mode, mask or effect; 8 a text
label (the geometry is its box); 16 pick-only: a keyed mark that paints
nothing (an invisible hover target such as a fill = NA rect, circle,
marker or polygon). Its geometry is listed and its paint has fill and
stroke NA, so a client hit-tests it but draws nothing; 32 inside a
group with a blend mode (with 4): the mark mixes with what is painted
beneath it, so its run's raster reproduces it only when composited with
the run's run_blend mode. Images do not appear at all.
