Skip to content

Binary Packing

deckgl_marimo.pack_binary

pack_binary(n, attributes, start_indices=None)

Pack layer data into an aligned binary buffer for deck.gl.

Parameters:

Name Type Description Default
n int

Number of data items (rows/features).

required
attributes dict[str, tuple[Any, str, int]]

Mapping of attribute name to (array, dtype, size) where: - array: numpy array (flat, raveled) - dtype: numpy dtype string ("float32", "uint8", etc.) - size: components per element (e.g. 2 for [lon, lat], 4 for RGBA)

required
start_indices Any | None

Optional uint32 array for variable-length data (polygons, paths).

None

Returns:

Type Description
tuple[dict, bytes]

(metadata, buffer) ready for the JS applyBinaryData() function.

deckgl_marimo.pack_polygon_binary

pack_polygon_binary(data, get_polygon='polygon', get_fill_color=None, per_polygon_colors=None)

Pack polygon data into a binary buffer for deck.gl.

Convenience wrapper around :func:pack_binary for polygon data.

Parameters:

Name Type Description Default
data list[dict] | Any

List of dicts, or a dict with pre-built numpy arrays::

{"polygon_coords": np.ndarray,   # (total_verts, 2) float32
 "start_indices": np.ndarray,     # (n_polygons,) uint32
 "colors": np.ndarray | None}     # (total_verts, 4) uint8
required
get_polygon str

Key in each dict for the polygon coordinates.

'polygon'
get_fill_color Any

If a string, key for per-polygon [r, g, b, a] color.

None
per_polygon_colors Any | None

Pre-resolved per-polygon RGBA colors as a (n_polygons, 4) uint8 array (e.g. from a ColorScale or callable accessor). Expanded to per-vertex colors here. Ignored on the pre-built-arrays fast path and when get_fill_color is a column name.

None

Returns:

Type Description
tuple[dict, bytes]