Macaw.Frame.Render (macaw_frame v0.1.0)

Copy Markdown View Source

The Frame's render per mode (spec/01 §3.7, §4; spec/10 §2.6, §3.6; spec/11 §1, §3, §4), copied from visualize's Visualize.Components.Chart markup and Visualize.Backend.Hybrid's layering, without the hybrid's inline-styled container.

render(assigns, module, opts) writes assigns.value's held drawing in assigns.context.mode under the drawn state, one root element holding the drawing, its drawn state's notice and its accessible text (§4.1):

<div class="mw-frame" id="<instance>-frame" data-mw-token="…" …client attributes…>
  <!-- a drawn state other than live: its notice, a banner before the drawing -->
  <div class="mw-frame-drawing" id="<instance>-drawing" tabindex="0" role="group" aria-label="…">
    <svg role="img" aria-label="<name>" aria-describedby="<instance>-desc" data-mw-token="…">
      <desc id="<instance>-desc">…description, then the summary's sentences…</desc>
      …
    </svg>
  </div>
  <table class="mw-frame-table mw-frame-hidden" id="<instance>-table-1">…</table>
</div>
  • The client attributes (Macaw.Component.Client.attributes/2) are on the root in the modes that allow hooks, so every hook inside reads its announcements, local keys, instance, events and requests from the nearest element carrying them.
  • The accessible root (spec/11 §3) is the drawing's <svg>: role="img", the Frame's name as its aria-label (the title: option, else the title setting, else Macaw.Frame.Summary's name) and aria-describedby naming its <desc>, which holds the description (the description: option, else the description setting, else the design's meta.description) followed by the summary's sentences, a full stop between them when the description has none. The summary: option is true by default, a string replaces the generated sentences, false leaves the description alone. It carries no <title>, which a browser shows as a tooltip. The description's id is Context.id(context, "desc"), unique to the instance and stable across renders.
  • The data table (spec/11 §4, Macaw.Frame.Summary.table/2) is beside the root, never inside it, visually hidden by the stylesheet's mw-frame-hidden class.
  • The keyboard is one tab stop, and needs a socket (spec/11 §1, §5.6): in :live only, the drawing element takes tabindex="0", role="group" and its aria-label, and the keyboard's attributes (Macaw.Frame.Keyboard.attrs/2); a hook this Frame's module declares in hooks: (spec/10 §7) is written as its phx-hook, and one it does not declare is never named. In :socketless the drawing element is there with none of them, and the summary and the table are the accessible path.
  • Ids come from Macaw.Component.Context.id/2, so two Frames on a page share none and one Frame's are stable across renders.
  • Nothing inline: no style attribute, no <style> element, no script. Every class written has its rule in the static stylesheet, priv/static/macaw_frame/frame.css (stylesheet/0), declared in the Frame's assets:; the motion classes are the generated sheet's, declared in stylesheets (spec/10 §3.6, §5).

The four modes (§4.2): :live and :socketless write the client attributes and the token (data-mw-token, on the root and on the image the visual check set reads it from); :neutral and :print write none of them, no hook element, no event wire and no token, so the SVG alone is drawn, in the context's theme and size, with its accessible root and its table. The layers (spec/10 §2.6, §2.7): each layer's target is Macaw.Frame.Render.Target's, chosen at compile; a frame whose layers are all SVG, every frame outside live mode among them, is one <svg> and has no layer container. A live frame with a layer on a canvas is the container <div class="mw-frame-layers">, named and described as the root is (its description a visually hidden paragraph), its canvases first, each the hook's element holding its <canvas>: a commands canvas its stream (<i data-c="…" data-k="…"> in a hidden <div data-mw-stream>), a binary or incremental canvas the prefix of its segments (data-mw-segments), whose raw bytes segments/1 hands the runtime (spec/10 §6, macaw_live spec/05 §9); then the SVG layer, then the text layer, a binary canvas's texts as SVG (the stream carries none, §4.6), every layer aria-hidden. A drawing made with canvases rendered outside live mode is one <svg> again, its canvases' layers written as SVG beneath the rest (svg/1). A :socketless render, the first render of a live page, carries the drawing segments/1 answers in its hidden stream element (macaw_component spec/02 §7.6), so the runtime has every segment before a socket joins.

Drawn states (§4.3) are Macaw.Frame.Drawn's: the higher of the assigned state and the value's own; its notice a banner before a held drawing, in the drawing's place with none.

A render computes nothing a transition could have: no data step, no realization, no compilation and no summary, which the realization made; it writes the drawing's SVG as the value holds it, and reads only the held tables' shown rows for the data table. Two renders of equal assigns are byte for byte equal.

Summary

Functions

The hooks module declares (spec/10 §7): their names, sorted; [] for a module that is no component or declares none.

The Frame's markup for assigns (Macaw.Component.Assigns: context, settings, declarations, drawn and value), as the Frame module renders it (§4): the hooks it writes are those module declares. Options (spec/11 §3): title:, description: and summary: (true, a string, or false).

The Frame's static stylesheet in this package, relative to its root (spec/10 §3.6).

The drawing's accessible name (spec/11 §3): the title: option, else the title setting, else the summary's name (the design's meta.name, else its first frame's kind).

Functions

hooks(module)

@spec hooks(module()) :: [String.t()]

The hooks module declares (spec/10 §7): their names, sorted; [] for a module that is no component or declares none.

render(assigns, module \\ Macaw.Frame, opts \\ [])

@spec render(map(), module(), keyword()) :: Phoenix.HTML.safe()

The Frame's markup for assigns (Macaw.Component.Assigns: context, settings, declarations, drawn and value), as the Frame module renders it (§4): the hooks it writes are those module declares. Options (spec/11 §3): title:, description: and summary: (true, a string, or false).

stylesheet()

@spec stylesheet() :: String.t()

The Frame's static stylesheet in this package, relative to its root (spec/10 §3.6).

title(assigns, value, opts \\ [])

@spec title(map(), Macaw.Frame.Value.t(), keyword()) :: String.t()

The drawing's accessible name (spec/11 §3): the title: option, else the title setting, else the summary's name (the design's meta.name, else its first frame's kind).