# `Visualize.Chart.Mark`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/chart/mark.ex#L1)

The marks of a design drawn through the frame's scales (spec/14 §5, D-61).

`generate/3` is one mark node as one `Visualize.IR.Element` group in the plot area's
coordinates: its rows are the bound source through the mark's pipeline (`rows/3`,
spec/14 §5.4), each channel is read from the rows and mapped through the scale it
names in `Visualize.Chart.Frame.scales/1` — the frame kind's table, renamed by the
mark's `scales` node (spec/14 §5.1) — and every element is the generator's own —
`Visualize.Shape.Line`, `Visualize.Shape.Area`, `Visualize.Shape.Band`,
`Visualize.Shape.Rule`, `Visualize.Shape.XBand`, `Visualize.Shape.PercentileBand`,
`Visualize.Shape.Rose`, `Visualize.Shape.Symbol`, `Visualize.Shape.Pie` over
`Visualize.Shape.Arc` — fed the pixels the mark computed, so a mark is byte for byte
the direct call with the same numbers. The four generic marks (`path`, `rect`, `circle`,
`arc`) draw what a layout's rows carry. The mark's style resolves through
`Visualize.Chart.Style` in the mode of the render target, and its paint, when the style
gives none, is the theme's series color for its position (spec/14 §5.6).

## Examples

    iex> chart =
    ...>   Visualize.Chart.from_map!(%{
    ...>     version: 2,
    ...>     sources: %{primary: %{fields: [:t, :v]}},
    ...>     frames: %{main: %{
    ...>       kind: :cartesian,
    ...>       margin: %{top: 0, right: 0, bottom: 0, left: 0},
    ...>       scales: %{x: %{kind: :linear}, y: %{kind: :linear}}
    ...>     }},
    ...>     marks: [%{type: :line, data: :primary, channels: %{x: :t, y: :v}}]
    ...>   })
    iex> sources = %{primary: [%{t: 0, v: 0}, %{t: 1, v: 1}]}
    iex> frame = Visualize.Chart.Frame.new(chart, sources: sources, size: {300, 200})
    iex> group = Visualize.Chart.Mark.generate(frame, hd(chart.marks), sources: sources)
    iex> group.style
    %{class: "mark mark-line", fill: :none, stroke: "var(--vis-series-1, #3b6fa8)"}
    iex> [path] = group.children
    iex> Visualize.Backend.SVG.path_data(path.path)
    "M0,200L300,0"

# `context`

```elixir
@type context() :: %{
  frame: Visualize.Chart.Frame.t(),
  mark: map(),
  type: atom(),
  rows: [map()],
  mode: Visualize.Theme.mode(),
  style_node: map(),
  static: map(),
  bound: map(),
  paint: {:fill | :stroke, term()},
  options: map(),
  label: map() | nil,
  tooltip: map() | nil,
  series: %{required(term()) =&gt; pos_integer()} | nil,
  keys:
    %{
      frame: atom(),
      mark: non_neg_integer(),
      ordinals: %{required(map()) =&gt; non_neg_integer()}
    }
    | nil,
  index: pos_integer(),
  by_data:
    %{entries: [{:field, atom()}], names: map(), reach: map(), table: map()}
    | nil,
  generated: %{memo: map(), path: list()},
  placed: %{mark: map(), rows: [map()], pixels: [map()]} | nil
}
```

What the element builders see of a mark: the frame, the mark node, its rows, its
resolved style split into the static part and the `{:field, f}` bindings, its paint
as `{key, color}`, its options, inline label and tooltip node, the render mode, and
its series values by position when it has a `series` channel (spec/14 §5.2, D-126), the
keys a mark with an event writes on its elements (§5.7, D-170), its one-based position
among the marks, and the styles a stack's `{:field, f}` entries name by data (§3.6,
#644) and its generators compute (§3.13, #654), `nil` for a stack that names none and
reaches none, with the memo of the generators the mark's rows call, and the update's
placement of its rows when the caller made one (#811).

# `generate`

```elixir
@spec generate(Visualize.Chart.Frame.t(), map()) :: Visualize.IR.Element.t()
```

As `generate/3` with `[]` options: no source bound, an empty mark group.

# `generate`

```elixir
@spec generate(Visualize.Chart.Frame.t(), map(), keyword()) ::
  Visualize.IR.Element.t()
```

One mark as the `Visualize.IR.Element` group of spec/14 §5.6.

## Options

  * `:sources` - a map from source name to anything `Visualize.Data.Table.rows/1`
    reads, as `Visualize.Chart.Frame.new/2` takes (default `%{}`)
  * `:resolve` - the theme mode: `:css` (default) or `:literal`
  * `:index` - the mark's one-based position among the design's marks, for its paint;
    defaults to its position among the frame's marks, `1` when it is not one of them
  * `:panel` - in a `:facet` frame, the panel value the rows are restricted to

Raises `ArgumentError` for an unresolved variable, a `:path` row whose `path` is neither
a `Visualize.IR.Path` nor `nil` (a `nil` path, such as a row a `:projection` clips, draws
nothing — D-130), or a pipeline step it cannot run.

# `rows`

```elixir
@spec rows(Visualize.Chart.Frame.t(), map(), map()) :: [map()]
```

The rows a mark draws: its source's rows through its transforms with the frame's plot
area and projection as the pipeline's context (spec/14 §5.4), `[]` when the source is
not bound.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
