AshReports.Layout.IR.Cell (ash_reports v0.1.0)

Intermediate Representation for a cell in a layout.

The CellIR represents a single cell with its calculated position, span information, properties, and content.

Position

Position is represented as a {x, y} tuple where:

  • x is the column index (0-indexed)
  • y is the row index (0-indexed)

Span

Span is represented as a {colspan, rowspan} tuple where:

  • colspan is the number of columns the cell spans (default: 1)
  • rowspan is the number of rows the cell spans (default: 1)

Examples

# Cell at position (0, 0) with default span
cell = AshReports.Layout.IR.Cell.new(
  position: {0, 0},
  content: [label_ir]
)

# Cell with colspan of 2
cell = AshReports.Layout.IR.Cell.new(
  position: {1, 0},
  span: {2, 1},
  content: [field_ir]
)

Summary

Functions

Adds content to the cell.

Returns the colspan of the cell.

Gets a property from the cell.

Creates a new CellIR struct with the given options.

Returns all positions occupied by this cell (including spans).

Sets a property on the cell.

Returns the rowspan of the cell.

Returns the x (column) coordinate of the cell.

Returns the y (row) coordinate of the cell.

Types

position()

@type position() :: {non_neg_integer(), non_neg_integer()}

span()

@type span() :: {pos_integer(), pos_integer()}

t()

@type t() :: %AshReports.Layout.IR.Cell{
  content: [AshReports.Layout.IR.Content.t()],
  position: position(),
  properties: map(),
  span: span()
}

Functions

add_content(cell, content)

@spec add_content(t(), AshReports.Layout.IR.Content.t()) :: t()

Adds content to the cell.

colspan(cell)

@spec colspan(t()) :: pos_integer()

Returns the colspan of the cell.

get_property(cell, key, default \\ nil)

@spec get_property(t(), atom(), any()) :: any()

Gets a property from the cell.

new(opts \\ [])

@spec new(Keyword.t()) :: t()

Creates a new CellIR struct with the given options.

Options

  • :position - {x, y} tuple for cell position (default: {0, 0})
  • :span - {colspan, rowspan} tuple (default: {1, 1})
  • :properties - Map of cell properties (align, inset, fill, etc.)
  • :content - List of ContentIR items

Examples

iex> AshReports.Layout.IR.Cell.new(position: {1, 2}, span: {2, 1})
%AshReports.Layout.IR.Cell{position: {1, 2}, span: {2, 1}, ...}

occupied_positions(cell)

@spec occupied_positions(t()) :: [position()]

Returns all positions occupied by this cell (including spans).

Examples

iex> cell = AshReports.Layout.IR.Cell.new(position: {1, 0}, span: {2, 2})
iex> AshReports.Layout.IR.Cell.occupied_positions(cell)
[{1, 0}, {2, 0}, {1, 1}, {2, 1}]

put_property(cell, key, value)

@spec put_property(t(), atom(), any()) :: t()

Sets a property on the cell.

rowspan(cell)

@spec rowspan(t()) :: pos_integer()

Returns the rowspan of the cell.

x(cell)

@spec x(t()) :: non_neg_integer()

Returns the x (column) coordinate of the cell.

y(cell)

@spec y(t()) :: non_neg_integer()

Returns the y (row) coordinate of the cell.