Macaw.Frame.Labels (macaw_frame v0.1.0)

Copy Markdown View Source

The frame's labels (spec/03 §3.4): one text at its anchor, placed by the model.

AnchorPositiontext-anchorDefault style
:title(w / 2, −m.top / 2), dy 0.32emmiddletitle
:subtitle(w / 2, −4)middlelabel
:caption(0, h + m.bottom − 4)startlabel
{:axis, s}the title of the first axis naming s, by its sidemiddlelabel
{:frame, corner}4 in from the corner (dy 0.71em at the top)start, endlabel
{:frame, :center}the plot's middle, the polar origin in a polar framemiddlelabel
{:data, point}the model's place/2 of the point; nothing when it cannot place itstartlabel

A label's style may set vertical_align, margin_x, margin_y and text_angle, applied along the anchor's outward direction (position/4); rotate turns the text about its point, :tangent and :radial about the model's center with the upright flip (rotation/4). Copied from visualize's Visualize.Chart.Frame.Labels, Visualize.Chart.Frame.Position and Visualize.Chart.Label.Polar.

A text's rotation is its node's Macaw.Draw.IR.Transform (spec/10 §1.3): the anchor's turn, then the label's own rotate about its point, then the style's text_angle.

Summary

Types

Where a label's text goes: its point, dy, text anchor and rotation.

Functions

An axis's title (§3.2): the text placed as a label anchored at the axis's side is.

The center a frame's labels turn about and its center anchor sits at: the plot's middle, which is the polar origin in a polar frame.

One text per label of opts[:labels] (the frame's label nodes) that has a place (§3.4), in its style resolved through opts[:styles] and the theme.

The outward direction of an anchor (§3.4): away from the plot for titles and captions, into the plot for corners, none for the center and data points.

Where an anchor puts a label in the model (§3.4), nil for a point it cannot place.

A placed text with its style node's position keys applied (§3.4; spec/02 §6.3): the text part's baseline (or vertical_align) sets its dy; its offset [x, y] (or margin_x and margin_y) moves it along outward; its angle (or text_angle) turns it about its own point. box is {width, height} an offset in pct is of.

The rotation of a text at point about center and the text anchor it leaves (visualize Visualize.Chart.Label.Polar): nil none; a number as it is; :radial the ray's angle anchored :start, flipped a half turn on the left and anchored :end; :tangent a quarter turn from the ray, flipped on the lower half, anchored :middle.

The labels a design draws (spec/02 §6.1): every label node but one whose show is false, in order; anything that is no list of labels draws none.

Types

placement()

@type placement() :: %{
  :x => number(),
  :y => number(),
  :anchor => :start | :middle | :end,
  optional(:dy) => String.t(),
  optional(:rotate) => number()
}

Where a label's text goes: its point, dy, text anchor and rotation.

Functions

axis_title(model, side, text, opts)

An axis's title (§3.2): the text placed as a label anchored at the axis's side is.

center(model)

@spec center(Macaw.Frame.Coordinates.Model.t()) :: {number(), number()}

The center a frame's labels turn about and its center anchor sits at: the plot's middle, which is the polar origin in a polar frame.

generate(model, opts)

@spec generate(term(), term()) :: [Macaw.Draw.IR.Element.t()]

One text per label of opts[:labels] (the frame's label nodes) that has a place (§3.4), in its style resolved through opts[:styles] and the theme.

outward(model, anchor)

@spec outward(term(), term()) :: {-1 | 0 | 1, -1 | 0 | 1} | nil

The outward direction of an anchor (§3.4): away from the plot for titles and captions, into the plot for corners, none for the center and data points.

place(model, arg2)

@spec place(term(), term()) :: placement() | nil

Where an anchor puts a label in the model (§3.4), nil for a point it cannot place.

position(text, node, outward, arg4)

@spec position(Macaw.Draw.IR.Element.t(), map(), term(), {number(), number()}) ::
  Macaw.Draw.IR.Element.t()

A placed text with its style node's position keys applied (§3.4; spec/02 §6.3): the text part's baseline (or vertical_align) sets its dy; its offset [x, y] (or margin_x and margin_y) moves it along outward; its angle (or text_angle) turns it about its own point. box is {width, height} an offset in pct is of.

rotation(degrees, arg2, arg3, anchor)

@spec rotation(term(), {number(), number()}, {number(), number()}, atom()) ::
  {number() | nil, atom()}

The rotation of a text at point about center and the text anchor it leaves (visualize Visualize.Chart.Label.Polar): nil none; a number as it is; :radial the ray's angle anchored :start, flipped a half turn on the left and anchored :end; :tangent a quarter turn from the ray, flipped on the lower half, anchored :middle.

iex> Macaw.Frame.Labels.rotation(:radial, {-10, 0}, {0, 0}, :start)
{0.0, :end}
iex> Macaw.Frame.Labels.rotation(:tangent, {0, 10}, {0, 0}, :start)
{0.0, :middle}

shown(labels)

@spec shown(term()) :: [map()]

The labels a design draws (spec/02 §6.1): every label node but one whose show is false, in order; anything that is no list of labels draws none.

iex> Macaw.Frame.Labels.shown([%{text: "a", show: false}, %{text: "b"}])
[%{text: "b"}]