Skip to main content

What are entities?

Drawing entities are interactive overlays on the chart canvas - Lines, Boxes, Labels, Markers, and LineFills. Unlike plot() which renders a value per bar, entities are keyed objects that persist across bars and can be mutated in place.

The slot model

1 key = 1 slot. Each unique key string occupies exactly one slot in the entity registry. Calling the same factory with the same key overwrites the slot:
  • Last call wins.
  • The slot’s content (position, color, style) reflects the most recent call.
  • Persistent across bars - you do not need to recreate the entity every bar.

Generation tokens

Every time you call a factory (Line, Box, etc.) for a key, a new generation is allocated. The returned handle carries the key + generation pair internally as { __key, __gen, __kind }.
If you call Line("my-line", opts) twice, the second call allocates a fresh generation. Any handle returned from the first call will silently no-op on .set() or .delete() - its generation no longer matches the slot. Always use the return value from the most recent call.

Handle API

All entity factories return a handle with three methods:
void
Mutate the entity in place. Only the provided keys are updated; others remain unchanged. No-ops silently if the generation is stale.
handle
Copy the entity to a new key with a fresh generation. Returns a handle to the clone.
void
Remove the entity from the chart. No-ops silently if the generation is stale.

Entity budgets

Exceeding the per-type limit truncates silently with a warning in the console. See API limits for all budget values.

Entity types

Line

Anchored line segment between two bar/price coordinates.

Box

Rectangular zone with fill, border, text, and extend options.

Label

Text label pinned to a bar/price coordinate.

Marker

Icon shape (circle, diamond, arrow, etc.) at a point.

LineFill

Filled area between two Line entities.

Constants

linestyle, shape, size, extend, text.align enums.