This package provides a pivot table view function with which you can analyze and visualize your data by grouping various fields.
In this package, a field is defined as a function from row to something.
A function to create a table.
Since the Table is an opaque type, all user of this package must use this
function to create a Table value.
A function to get values from a table.
With the example appeared in the Table doc,
each field can be accessed like:
nameField = .name
ageField = .age
genderField = .gender
myTable : MyTable
myTable = makeTable
[ { name = "Alice", age = 17, gender = Female }
, { name = "Bob", age = 8, gender = Male }
, { name = "Charlie", age = 35, gender = Male }
]
getField nameField myTable -- ["Alice", "Bob", "Charlie"]
getField ageField myTable -- [17, 8, 35]
getField genderField myTable -- [Female, Male, Male]Note: Notice that a field does not have to be a record element. This is a valid code:
nameInitialLetterField = .name >> String.left 1
getField nameInitialLetterField myTable -- ["A", "B", "C"]In this package, a pivot table is a table to show values grouped by some fields.
genderToString : Gender -> String
genderToString gender =
case gender of
Male -> "Male"
Female -> "Female"
pivotTable
{ rowGroupFields = []
, colGroupFields = [ genderField ]
, aggregator = List.length
, viewRow = always Element.none
, viewCol = Element.text
, viewAgg = String.fromInt >> Element.text
}
myTableThe code above produces a table:
|Male |Female |
|-----|-------|
|2 |1 |The pivot table groups table rows.
After that, the Aggregator aggregates
the list of rows into a single value (of any type).
Draws a pivot table.
rowGroupFields is a list of Field's to group and generates grouped rows.colGroupFields is a list of Field's to group and generates grouped columns.aggregator aggregates each grouped set of table data into a single value.viewRow, viewCol and viewAgg are view functions to show each headers and cells.Draws a pivot table of Html type.
This view makes use of colspan and rowspan attributes of html table.
Use this view function when you want to avoid using elm-ui.
In this package, a table is defined as a list of rows.
In the most naive case, a table may be represented by a list of records like:
Note: Notice that rows can be any type.