Visualize.Chart.Mark (Visualize v0.2.35)

Copy Markdown View Source

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 colour 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"

Summary

Types

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, colour}, 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).

Functions

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

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

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.

Types

context()

@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()) => pos_integer()} | 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, colour}, 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).

Functions

generate(frame, mark)

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

generate(frame, mark, opts)

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(frame, mark, sources)

@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.