Macaw.Frame.Summary (macaw_frame v0.1.0)

Copy Markdown View Source

The text summary of a realized Frame (spec/11 §2, §3, §10): what a screen reader says for it, generated rather than written, so every Frame has one and it follows the data. Copied from visualize's Visualize.Chart.Summary, reading the Frame's drawing and its layers' contributions (Macaw.Frame.Layer.Summary, spec/04 §1.11) in place of an applied chart and a list of mark types.

new/1 reads a realized Frame (its Macaw.Frame.Value over its latest deliveries) into %Macaw.Frame.Summary{name, frames}, each of the design's frames in drawing order (z, ties by name) as %{name, kind, series, rows, noun, axes, extremes, panels, network, walk}:

  • The name is the design's meta.name, else the first frame's kind with its first letter capitalized ("Line chart").
  • The kind is the first rule that holds (§2.2): a "geographic" model is a "map"; a data layer whose kind contributes "gauge" makes a gauge; a layout step's phrase (each spatial step declares its own, phrase/0; a partition under an arc is a "sunburst"; a bin operation names a "histogram", a spectrum a "spectrum"); the first data layer's phrase, which in a polar model is its polar phrase; otherwise "chart". Nothing here lists layer kinds: a registered kind summarizes itself.
  • The series, rows, axes, extremes and panels are §2.3's, every value written as its axis writes it (§2.4), a category value by its declared name.
  • A network (a tree's, a cluster's, a sankey's or a force layout's, spec/13 §5) says its nodes and links as its layers' layout steps answer them, a tree's depth and a flow diagram's total value, in a sentence after the kind's.
  • A diagram (spec/13 §7.3) is walked after its kind (walk): a layered graph by its entry nodes and the paths from them, a sequence diagram by its messages in order, a Gantt chart by its sections and tasks with their dates, a timeline by its periods and events. A layered step's diagram option names a state, class or ER diagram, and a Gantt step of milestones alone a timeline.

text/1 writes it as sentences (§2.5). table/2 is the data-table fallback (Macaw.Frame.Summary.Table, §4), and attrs/2 and description/2 name the element that stands for the Frame (§3). The value's drawing holds its summary, made once per realization (Macaw.Frame.Value), so a render reads it and a hover or a move never re-derives it.

Every column is read through Macaw.Frame.Columns; no row is read through Macaw.Data.Table.get/2.

Summary

Types

An axis as the summary says it: its scale's range, or its categories.

The highest and the lowest value one value name draws, each with where it is; rows is how many readings there were, and a value of one row says that row alone.

One frame of the summary.

t()

Functions

The attributes that make an element stand for the Frame (§3): role="img", the name as aria-label and aria-describedby the id of description/2's element. A keyword list. A summary with no name is labeled "Chart".

The element attrs/2 points at (§3): the summary's sentences in a visually hidden paragraph with the id id, the Frame's stylesheet's mw-frame-hidden class, never a style attribute. Its text is escaped.

The summary of a realized Frame (§2.1): its name and, per frame in drawing order, its kind, series, rows, axes, extremes and panels. A value with no drawing is a summary of no frame, named "Chart" or by its design's meta.name.

The data-table fallback (§4): {:ok, html}, one <table> per data layer, beside the root and visually hidden. Options: hidden: (true), caption:, limit: (1000), context: (the render's, for the tables' ids and the schemas' labels).

The summary as sentences (§2.5): per frame, the kind with its series, one sentence per axis, then the extremes; a design of several frames says each frame's name first. A realized Frame is summarized first.

Types

axis()

@type axis() :: %{
  scale: String.t(),
  side: atom(),
  title: String.t(),
  range: {String.t(), String.t()} | nil,
  categories: [String.t()] | nil
}

An axis as the summary says it: its scale's range, or its categories.

extreme()

@type extreme() :: %{
  field: String.t(),
  rows: non_neg_integer(),
  high: {String.t(), String.t() | nil},
  low: {String.t(), String.t() | nil}
}

The highest and the lowest value one value name draws, each with where it is; rows is how many readings there were, and a value of one row says that row alone.

frame()

@type frame() :: %{
  name: String.t(),
  kind: String.t(),
  series: [String.t()],
  rows: non_neg_integer(),
  noun: String.t(),
  axes: [axis()],
  extremes: [extreme()],
  panels: %{count: non_neg_integer(), by: String.t() | nil} | nil,
  network: map() | nil,
  walk: String.t() | nil
}

One frame of the summary.

t()

@type t() :: %Macaw.Frame.Summary{frames: [frame()], name: String.t()}

Functions

attrs(value, id)

@spec attrs(term(), term()) :: keyword()

The attributes that make an element stand for the Frame (§3): role="img", the name as aria-label and aria-describedby the id of description/2's element. A keyword list. A summary with no name is labeled "Chart".

description(summary, id)

@spec description(term(), term()) :: String.t()

The element attrs/2 points at (§3): the summary's sentences in a visually hidden paragraph with the id id, the Frame's stylesheet's mw-frame-hidden class, never a style attribute. Its text is escaped.

new(value)

@spec new(term()) :: t()

The summary of a realized Frame (§2.1): its name and, per frame in drawing order, its kind, series, rows, axes, extremes and panels. A value with no drawing is a summary of no frame, named "Chart" or by its design's meta.name.

table(realized, opts \\ [])

@spec table(term(), term()) :: {:ok, iodata()} | {:error, [{list(), term()}, ...]}

The data-table fallback (§4): {:ok, html}, one <table> per data layer, beside the root and visually hidden. Options: hidden: (true), caption:, limit: (1000), context: (the render's, for the tables' ids and the schemas' labels).

text(value)

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

The summary as sentences (§2.5): per frame, the kind with its series, one sentence per axis, then the extremes; a design of several frames says each frame's name first. A realized Frame is summarized first.