Visualize.Layout.Hexbin (Visualize v0.2.35)

Copy Markdown View Source

Hexagonal binning of points in the plane (spec/06 §9, #348): d3-hexbin's lattice of flat-topped hexagons, the columns 2 r sin(π/3) apart and the rows 1.5 r, every odd row offset by half a column. The lattice is in the coordinates of the points, so a chart bins pixels.

Examples

iex> [cell] = Visualize.Layout.Hexbin.bin([{1, 1}, {-1, 2}], 20)
iex> {cell.x, cell.y, cell.count}
{0.0, 0.0, 2}

Summary

Types

A non-empty cell: its centre, its count and its points in input order.

Functions

The non-empty cells of the lattice over points, in lattice order (row, then column).

The closed flat-topped hexagon of radius at the centre, its first vertex at bearing −30° (the upper right), then clockwise on screen.

Types

cell()

@type cell() :: %{
  x: float(),
  y: float(),
  count: pos_integer(),
  points: [{number(), number()}]
}

A non-empty cell: its centre, its count and its points in input order.

Functions

bin(points, radius)

@spec bin([{number(), number()}], number()) :: [cell()]

The non-empty cells of the lattice over points, in lattice order (row, then column).

hexagon(cx, cy, radius)

@spec hexagon(number(), number(), number()) :: Visualize.IR.Path.t()

The closed flat-topped hexagon of radius at the centre, its first vertex at bearing −30° (the upper right), then clockwise on screen.