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

Copy Markdown View Source

A layer's datum attributes, declared events and hover text (spec/04 §1.9), copied from visualize's Visualize.Chart.Mark tooltip part and the server half of Visualize.Hooks.Tooltip.

A layer's tooltip node (fields, template, event, context_event, show) asks it to carry each row's fields on its elements for the tooltip hook to show with no round trip:

  • each named field is written as a datum attribute (Macaw.Draw.IR.Element.datum/3, _ as -), to_string/1 of its value, with its declared name beside it where the slot's schema names the value; [] writes every column in sorted order (element/4);
  • the group carries data-tooltip-template and, when given, data-tooltip-event and data-tooltip-context-event (group/1);
  • show: false keeps the keys and events and shows nothing on hover; with it, only the named fields are written.

event and context_event are names the Frame declares as its events: a click on an element emits an event of that name (event/4), its identity the row's declared identity (or nil), its value the row's declared fields as [field, value] pairs, never a row ordinal. The two names may not be equal ({:same_name, :event} at context_event), and a name the runtime reserves is {:reserved, :event, name} (check/2).

Summary

Types

What writer/2 settles of a tooltip node, for write/3 to apply per row.

Functions

The faults of a tooltip node's event names at path (§1.9): a reserved name at its key, and a context_event equal to event.

An element with its row's datum attributes (§1.9): the tooltip's named fields read from row, or every column with a text form in sorted order where it names none and shows them; under show: false with no fields, none. schema names declared values.

The event a click on an element of a layer emits (§1.9): %{name, identity, value}, name the tooltip's event (or context_event with context: true), identity the row's declared identity by schema (or nil), value the row's declared fields as [field, value] pairs in the schema's field order. :none without such an event.

Whether the tooltip declares a click or a context event.

Whether a tooltip node writes every column of an element's row (§1.9): it names no fields and shows them. A declared event alone reads no row where the layer draws: the item's identity and value are written by column (Macaw.Frame.Events.write/3).

The group's tooltip attributes (§1.9): data-tooltip-template, data-tooltip-event, data-tooltip-context-event where given, and data-tooltip-show="false".

The event names the runtime reserves.

Whether a tooltip node needs each element's whole row: it names no fields and shows them, or it has an event (whose value is the row's declared fields).

An element with its row's datum attributes, as writer/2 settled them (§1.9).

A tooltip node's datum attributes settled for a whole layer (§1.9): the attribute names, the listing and each field's declared names, read once, so write/3 writes a row's attributes from its values alone. nil for no tooltip or none to write, :every for a node that writes every column. write(element, row, writer(tooltip, schema)) is element(element, row, tooltip, schema).

Types

writer()

@type writer() :: nil | :every | {:fields, String.t(), [tuple()]}

What writer/2 settles of a tooltip node, for write/3 to apply per row.

Functions

check(tooltip, path)

@spec check(term(), list()) :: [Macaw.Base.Fault.t()]

The faults of a tooltip node's event names at path (§1.9): a reserved name at its key, and a context_event equal to event.

iex> Macaw.Frame.Layer.Tooltip.check(%{"event" => "zoom", "context_event" => "zoom"}, [:tooltip])
[{[:tooltip, :event], {:reserved, :event, "zoom"}},
 {[:tooltip, :context_event], {:reserved, :event, "zoom"}},
 {[:tooltip, :context_event], {:same_name, :event}}]

element(element, row, tooltip, schema)

@spec element(
  Macaw.Draw.IR.Element.t(),
  map(),
  map() | nil,
  Macaw.Data.Schema.t() | nil
) ::
  Macaw.Draw.IR.Element.t()

An element with its row's datum attributes (§1.9): the tooltip's named fields read from row, or every column with a text form in sorted order where it names none and shows them; under show: false with no fields, none. schema names declared values.

event(tooltip, row, schema, opts \\ [])

@spec event(map() | nil, map(), Macaw.Data.Schema.t() | nil, keyword()) ::
  map() | :none

The event a click on an element of a layer emits (§1.9): %{name, identity, value}, name the tooltip's event (or context_event with context: true), identity the row's declared identity by schema (or nil), value the row's declared fields as [field, value] pairs in the schema's field order. :none without such an event.

events?(tooltip)

@spec events?(map() | nil) :: boolean()

Whether the tooltip declares a click or a context event.

every_column?(tooltip)

@spec every_column?(map() | nil) :: boolean()

Whether a tooltip node writes every column of an element's row (§1.9): it names no fields and shows them. A declared event alone reads no row where the layer draws: the item's identity and value are written by column (Macaw.Frame.Events.write/3).

group(tooltip)

@spec group(map() | nil) :: %{required(String.t()) => String.t()}

The group's tooltip attributes (§1.9): data-tooltip-template, data-tooltip-event, data-tooltip-context-event where given, and data-tooltip-show="false".

reserved()

@spec reserved() :: [String.t(), ...]

The event names the runtime reserves.

whole_row?(tooltip)

@spec whole_row?(map() | nil) :: boolean()

Whether a tooltip node needs each element's whole row: it names no fields and shows them, or it has an event (whose value is the row's declared fields).

write(element, row, arg3)

An element with its row's datum attributes, as writer/2 settled them (§1.9).

writer(tooltip, schema)

@spec writer(map() | nil, Macaw.Data.Schema.t() | nil) :: writer()

A tooltip node's datum attributes settled for a whole layer (§1.9): the attribute names, the listing and each field's declared names, read once, so write/3 writes a row's attributes from its values alone. nil for no tooltip or none to write, :every for a node that writes every column. write(element, row, writer(tooltip, schema)) is element(element, row, tooltip, schema).