Macaw.Frame.Layer.Budget (macaw_frame v0.1.0)

Copy Markdown View Source

The budget hint and the slot's reducer (spec/04 §1.10).

A kind's budget/2 is the rows it needs at a plot width w in whole pixels, by its class (hint/2):

ClassKindsRows at width w
:continuousline, area, percentile_band, violin4 × w: M4's lossless bound
:barsrect, band, rose, boxceil(w / 2): a bar per two pixels
:candlescandleceil(w / 3): a candle per three pixels, its body and the gap beside it
:rowevery other kind that reads rowsw
:nonetilesnil: reads no rows

A hint is monotone non-decreasing in w and at least 1 for every w ≥ 1.

From its layers' hints the Frame answers macaw_component's budget/3 for each slot (slot/3): the largest need of the layers reading the slot, or the document's own budget where it declares one, a layer through a delaunay or voronoi step asking at most 2,000 rows (triangulation_cap/0); and the slot's reducer: whole when any reader passes its rows through a step that needs every row, "m4" when any reader is a continuous kind, the host's default "lttb" otherwise.

Summary

Functions

A delivery for a triangulating layer kept to the cap (§1.10): {table, capped?}, the first 2,000 rows in the slot's order when there are more.

The rows a kind of class needs at width w (§1.10).

A slot's budget and reducer from the checked layers reading it (§1.10): %{budget: rows | nil, reducer: :whole | "m4" | "lttb"} at plot width w. Options: budget: the document's own budget for the slot, which wins over the layers' needs.

Whether a layer's steps include a triangulating one (delaunay, voronoi).

The rows a layer through a triangulating step asks for at most: 2,000.

Types

class()

@type class() :: :continuous | :bars | :candles | :row | :none

Functions

capped(layer, table)

@spec capped(map(), Macaw.Data.Table.t()) :: {Macaw.Data.Table.t(), boolean()}

A delivery for a triangulating layer kept to the cap (§1.10): {table, capped?}, the first 2,000 rows in the slot's order when there are more.

hint(class, w)

@spec hint(class(), term()) :: pos_integer() | nil

The rows a kind of class needs at width w (§1.10).

iex> alias Macaw.Frame.Layer.Budget
iex> {Budget.hint(:continuous, 640), Budget.hint(:bars, 641), Budget.hint(:candles, 640), Budget.hint(:row, 640)}
{2560, 321, 214, 640}
iex> Budget.hint(:none, 640)
nil

slot(layers, w, opts \\ [])

@spec slot([map()], number(), keyword()) :: %{
  budget: pos_integer() | nil,
  reducer: term()
}

A slot's budget and reducer from the checked layers reading it (§1.10): %{budget: rows | nil, reducer: :whole | "m4" | "lttb"} at plot width w. Options: budget: the document's own budget for the slot, which wins over the layers' needs.

triangulates?(layer)

@spec triangulates?(map()) :: boolean()

Whether a layer's steps include a triangulating one (delaunay, voronoi).

triangulation_cap()

@spec triangulation_cap() :: 2000

The rows a layer through a triangulating step asks for at most: 2,000.