Macaw.Frame.Reach (macaw_frame v0.1.0)

Copy Markdown View Source

A Frame's keyboard points held on the server, answered one at a time (spec/11 §5.4), copied from visualize's Visualize.Chart.Reach (#1070, #1071, D-278).

new/2 reads each series' value, series and key columns once from the delivery's packed columns and keeps them indexed (Macaw.Frame.Summary.Points), none built. The series, their order and every readout are the summary's, and nothing is sampled: a 50,000-row series has 50,000 points. A point is built only when asked for (point/2), its position read by index from the placements (Macaw.Frame.Placements) and its readout written for it alone, so an answer costs one point wherever it is.

FunctionContract
new/2the Frame's points indexed, none built; placements the same realization's, or nil
series/1, count/1each series' name, count and whether it is a grid; how many points in all
point/2%{series, index, text, x, y, row, layer, key, cell}, or nil where there is none
move/3the moves folded from a point, or from none, as pressing the keys one after another would
identity/2, find/2what names a point's row, and the same row in a later realization's reach
nearest/2the point a click at a position picks
keyed/2the point whose key names that layer and row

A Frame indexes its reach only while its keyboard is armed (§5.6, Macaw.Frame.Keyboard): an unarmed Frame holds none.

Summary

Types

A point by its series and its index in it, both from zero.

A move: within the series, across series at the same index, to the series' ends; a pointer's {:at, {x, y}}, the point a click there picks; {:keyed, key}, the point a drawn item's key names.

t()

A Frame's keyboard points, indexed.

Functions

How many points the series hold.

The point of identity's row in this reach: the series of the same name, else the first; in it, the row with the same position reading, found by halving when the series is ordered by it, else its nearest neighbor in that order; a point read by identity by its identity; else the same index, clamped. nil for a Frame with no points.

What names the row behind the point at at, for find/2 in a later realization's reach: the series' name, the index, and the point's position reading (the x of a line, a bar's category), or its declared identity for a point read by identity. nil where there is no point.

The point whose key names a drawn item: its key's item, <frame>.<layer>.<row> as the drawing writes it (data-mw-item), given as the string or as a key map; nil where no point carries it.

Where moves land from from (nil for no point yet), folded as pressing their keys one after another would: next and previous within the series, the next and previous series at the same index clamped to its points, the ends, each stopping at the ends; the first move from none lands on the first point of the first series; in a grid, next and previous by column and the series moves by row, each to the nearest cell holding a point; {:at, xy} the point a click there picks, {:keyed, key} the point a key names, each keeping the point where none is. nil for a Frame with no points, or a from or move it cannot read.

The point a click at {x, y}, in the Frame's pixels, picks: the least horizontal distance, then of points within half a unit of it the least vertical, as the crosshair snaps; nil where no point is placed.

The Frame's keyboard points of a realized value, indexed and none built; placements the same realization's (Macaw.Frame.Placements.new/1), whose pixels each point's position is read from, or nil to place what it reads.

The point at {series, index}, built alone; nil where there is none.

Each series as %{name, count, grid}, in the summary's order.

Types

at()

@type at() :: {non_neg_integer(), non_neg_integer()}

A point by its series and its index in it, both from zero.

move()

@type move() ::
  :next
  | :previous
  | :next_series
  | :previous_series
  | :first
  | :last
  | {:at, {number(), number()}}
  | {:keyed, term()}

A move: within the series, across series at the same index, to the series' ends; a pointer's {:at, {x, y}}, the point a click there picks; {:keyed, key}, the point a drawn item's key names.

t()

@type t() :: %Macaw.Frame.Reach{points: Macaw.Frame.Summary.Points.t()}

A Frame's keyboard points, indexed.

Functions

count(reach)

@spec count(term()) :: non_neg_integer()

How many points the series hold.

find(reach, arg2)

@spec find(term(), term()) :: at() | nil

The point of identity's row in this reach: the series of the same name, else the first; in it, the row with the same position reading, found by halving when the series is ordered by it, else its nearest neighbor in that order; a point read by identity by its identity; else the same index, clamped. nil for a Frame with no points.

identity(reach, at)

@spec identity(term(), term()) :: term()

What names the row behind the point at at, for find/2 in a later realization's reach: the series' name, the index, and the point's position reading (the x of a line, a bar's category), or its declared identity for a point read by identity. nil where there is no point.

keyed(reach, item)

@spec keyed(term(), term()) :: at() | nil

The point whose key names a drawn item: its key's item, <frame>.<layer>.<row> as the drawing writes it (data-mw-item), given as the string or as a key map; nil where no point carries it.

move(reach, from, moves)

@spec move(term(), term(), term()) :: at() | nil

Where moves land from from (nil for no point yet), folded as pressing their keys one after another would: next and previous within the series, the next and previous series at the same index clamped to its points, the ends, each stopping at the ends; the first move from none lands on the first point of the first series; in a grid, next and previous by column and the series moves by row, each to the nearest cell holding a point; {:at, xy} the point a click there picks, {:keyed, key} the point a key names, each keeping the point where none is. nil for a Frame with no points, or a from or move it cannot read.

nearest(reach, arg2)

@spec nearest(term(), term()) :: at() | nil

The point a click at {x, y}, in the Frame's pixels, picks: the least horizontal distance, then of points within half a unit of it the least vertical, as the crosshair snaps; nil where no point is placed.

new(realized, placements \\ nil)

@spec new(term(), Macaw.Frame.Placements.t() | nil) :: t()

The Frame's keyboard points of a realized value, indexed and none built; placements the same realization's (Macaw.Frame.Placements.new/1), whose pixels each point's position is read from, or nil to place what it reads.

point(reach, arg2)

@spec point(term(), term()) :: map() | nil

The point at {series, index}, built alone; nil where there is none.

series(reach)

@spec series(term()) :: [
  %{name: String.t(), count: non_neg_integer(), grid: boolean()}
]

Each series as %{name, count, grid}, in the summary's order.