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

Copy Markdown View Source

A layer's inline label (spec/04 §1.8): anchors, fit and contrast ink, copied from visualize's Visualize.Chart.Mark.Label and Visualize.Chart.Label.Polar (the polar rotation is Macaw.Frame.Labels.rotation/4's).

A layer's label labels each element from its own row: text (with {:field, f} holes), anchor, style (label by default, never the layer's), dx, dy, dr, rotate (degrees, :tangent or :radial) and fit (:none, :truncate, :hide). One text per element with an anchor point, drawn in the labels group.

Anchors (§1.8.1), from the element's anchor point (px, py):

AnchorPositiontext-anchor
top(px, py − 4)middle
bottom(px, py + 4), dy 0.71emmiddle
left, right(px ∓ 4, py), dy 0.32emend, start
start, middle, end(px, py), dy 0.32emas named
x0, x1the bounds' left or right edge midpoint, 4 outsideend, start
y1, y0the top or bottom edge midpoint, 4 outside (y0 with dy 0.71em)middle
outward, inward4 + dr along the ray from the center, beyond the rim or inside itby side

The edge anchors read an element's bounds (a rect's or a band's); without them they fall back to the side of the same name. A text-anchor in the label's style replaces the anchor's.

Fit (§1.8.2): :truncate cuts the text to the characters that fit and …, nothing when not one fits; :hide draws nothing unless the whole text fits. The element's width is its extent (a rect's width, a circle's diameter, an arc's length at the label's radius; :none fits everything); a label on a rectangle also needs the rectangle as tall as its font under any fit but :none. The text's width is the Frame's resolved measurer's (Macaw.Draw.Text.width/3, macaw_layers#63): by the estimate :truncate keeps capacity/2 characters, by another measurer the longest prefix whose width with the … fits.

Ink (§1.8.3): a label color of {:contrast, :under} is resolved per label against the color under it, composited over the theme's background, as the theme's ink of it, written as the role it is (text or background).

Summary

Functions

One label text at an anchor point (§1.8): nil when its fit draws nothing. child gives the element's bounds, extent, radii and the color under it.

The label texts of a layer's children (§1.8), in their order: one for each child with an anchor, placed, fitted and inked; rows the children's rows by index.

The fields a label reads of each row: its text's holes and its style's bindings.

The ink a contrast label takes over under (§1.8.3): the theme's ink of that literal color, written as the theme role it is (text or background) in the layer's mode; nil under is the background's ink.

A label's text for a row (§1.8): its parts with each {:field, f} hole read from the row, a nil reading as nothing.

The color under a label (§1.8.3): the element's own fill once its bindings are read, else the layer's paint when the kind is filled, a translucent fill composited over the background, a gradient by its first stop; nil with nothing under it (a stroked element, a text).

Functions

element(ctx, child, arg, content)

@spec element(map(), map(), {number(), number()}, String.t()) ::
  Macaw.Draw.IR.Element.t() | nil

One label text at an anchor point (§1.8): nil when its fit draws nothing. child gives the element's bounds, extent, radii and the color under it.

elements(children, ctx, rows)

@spec elements([map()], map(), map()) :: [Macaw.Draw.IR.Element.t()]

The label texts of a layer's children (§1.8), in their order: one for each child with an anchor, placed, fitted and inked; rows the children's rows by index.

fields(label)

@spec fields(map() | nil) :: [String.t()]

The fields a label reads of each row: its text's holes and its style's bindings.

ink(map, under)

@spec ink(map(), Macaw.Layers.Color.t() | nil) :: term()

The ink a contrast label takes over under (§1.8.3): the theme's ink of that literal color, written as the theme role it is (text or background) in the layer's mode; nil under is the background's ink.

text(text, row)

@spec text(term(), map()) :: String.t()

A label's text for a row (§1.8): its parts with each {:field, f} hole read from the row, a nil reading as nothing.

iex> Macaw.Frame.Layer.Label.text("load #{field(v)}%", %{"v" => 42})
"load 42%"

under(arg1, arg2)

@spec under(map(), map()) :: Macaw.Layers.Color.t() | nil

The color under a label (§1.8.3): the element's own fill once its bindings are read, else the layer's paint when the kind is filled, a translucent fill composited over the background, a gradient by its first stop; nil with nothing under it (a stroked element, a text).