jxxcarlson/elm-cell-grid/1.0.0

NOTE: the latest version is 8.0.1

CellGrid

This library is just a test. I repeat: a test!

Main API

type CellGrid a
= CellGrid ( Int, Int ) (Array a)

A value of type CellGrid a is a rectangular array of values of type a.

= Corner
| Edge
| Interior

A cell can be in the interior of the grid, on an edge, on in a cornder

type alias CellRenderer a =
{ cellSize : Float
, cellColorizer : a -> ColorValue
, defaultColor : ColorValue
}

CellRenderer is a record that provides the information -- cellSize, defaultColor, and the function cellColorizer -- that are needed to render a cell to SVG.

renderAsHtml : CellRenderer a -> CellGrid a -> Html msg

Render a cell grid as Html

Work with cells

mapWithIndex : (( Int, Int ) -> a -> a) -> CellGrid a -> CellGrid a

Transform a CellGrid a with a function ((Int, Int) -> a -> a)

classifyCell : CellGrid a -> ( Int, Int ) -> CellType

return the type of the cell at location (i,j). Thus classifyCell grid (0,0) = Corner

cellAtIndex : ( Int, Int ) -> CellGrid a -> Maybe a

Return the Maybe value of the cell at (i,j) from grid

setValue : CellGrid a -> ( Int, Int ) -> a -> CellGrid a

Set the value of the cell at location (i,j)

location : Int -> ( Int, Int ) -> Int

Consider a 1D array of elements which represents a 2D array with n rows. Then location n (i,j) is the index in the 1D array of the correspondng element in the 2D array at location (i,j)`

index : ( Int, Int ) -> Int -> ( Int, Int )

Conversely, index (nRows, nCols) k is the 2D array index (i,j) of the element al address k

indices : CellGrid a -> List ( Int, Int )

Return a list of all indices (i,j) of a grid. Useful for mapping.