Visualize.Board.Budget (Visualize v0.8.0)

Copy Markdown View Source

Each bound slot's budget, derived from what its cell draws at its size, and each feed's, the largest of its slots' (spec/15 §8.2, #864, D-226).

A mark that reads a slot needs rows by its type at its plot width w — the width of its frame's box at the cell's size less the frame's left and right margins, in whole pixels:

MarksRows
:line, :area, :percentile_band4 × w, M4's lossless bound
:rect, :band, :roseceil(w / 2), a bar per two pixels
any other mark that draws rowsw
:tilesnone

A slot's budget is the largest of its marks' needs — marks on one slot read the same rows — or the design's budget where it declares one (spec/14 §2.10), and never more than the board's ceiling. A feed is asked the largest budget of the slots it fills.

Everything here is pure, read from the design without applying it, so the board process that holds the feeds never pays for a cell's chart.

Examples

iex> chart = Visualize.Chart.from_map!(%{
...>   version: 3,
...>   sources: %{primary: %{fields: [:t, :v]}},
...>   frames: %{main: %{kind: :cartesian, margin: %{left: 40, right: 20}}},
...>   marks: [%{type: :line, data: :primary, channels: %{x: :t, y: :v}}]
...> })
iex> Visualize.Board.Budget.slot(chart, %{}, "primary", {560, 200}, nil)
2000
iex> Visualize.Board.Budget.slot(chart, %{}, "primary", {560, 200}, 500)
500

Summary

Types

t()

A slot's or a feed's budget: rows, or nil for no bound.

Functions

Each feed's budget, the largest of the bound slots' it fills (nil, no bound, the largest of all): a feed of feeds that no slot binds, or that a virtual source reads (read), is asked the ceiling.

A slot's budget in a cell of size ({width, height}, pixels): the design's budget where it declares one, else the largest of the needs of the marks that read the slot, capped by ceiling. A slot no mark reads, with no integer declared, is the ceiling. vars are the cell's variables, which a frame's box, cell or margin may read.

Every bound slot's budget, by {cell, slot}: each slot of needs (a cell's slots by name) that slot_refs binds to a feed, in its cell's box of boxes (Visualize.Board.boxes/2), its component's chart and variables from components.

Types

t()

@type t() :: pos_integer() | nil

A slot's or a feed's budget: rows, or nil for no bound.

Functions

feeds(feeds, budgets, slot_refs, read, ceiling)

@spec feeds([term()], %{required({term(), String.t()}) => t()}, map(), [term()], t()) ::
  %{
    required(term()) => t()
  }

Each feed's budget, the largest of the bound slots' it fills (nil, no bound, the largest of all): a feed of feeds that no slot binds, or that a virtual source reads (read), is asked the ceiling.

slot(chart, vars, slot, size, ceiling)

@spec slot(Visualize.Chart.t(), map(), String.t(), {number(), number()}, t()) :: t()

A slot's budget in a cell of size ({width, height}, pixels): the design's budget where it declares one, else the largest of the needs of the marks that read the slot, capped by ceiling. A slot no mark reads, with no integer declared, is the ceiling. vars are the cell's variables, which a frame's box, cell or margin may read.

slots(components, needs, slot_refs, boxes, ceiling)

@spec slots(map(), %{required(term()) => [String.t()]}, map(), map(), t()) :: %{
  required({term(), String.t()}) => t()
}

Every bound slot's budget, by {cell, slot}: each slot of needs (a cell's slots by name) that slot_refs binds to a feed, in its cell's box of boxes (Visualize.Board.boxes/2), its component's chart and variables from components.