Bosatsu packages

Yichus/Table

Builtin package (resource table.bosatsu). This is the complete package source used by this build. The export list names its public API; definitions below give the types and behavior.

New to the API? Start with Make a data app or Build an API, then use this page to look up a definition.

package Yichus/Table

from Bosatsu/Predef import List, String
from Yichus/Num/Float64 import Float64

export (
  FieldKind(),
  Role(),
  Field(),
  Layout(),
  TableShape(),
  Cell(),
  Record()
)

exposes Yichus/Num/Float64

# A table is records by typed fields, the way a spreadsheet model is laid
# out. A record table runs one record per row: the rows a sheet loads, with
# a column per field (a name, a role, a salary). A period grid runs one
# record per column: each month is a record, each line item (revenue,
# salaries, cash) a field down the side. They are one table drawn two ways.
#
# The calculator computes every cell, every total and the order of the
# records; the page draws them and computes nothing.

# What a field holds, and so how its cells are written: text as it is, a
# currency amount with its sign before the symbol, a percentage in
# percentage points (25.0 is 25%), or a plain number.
enum FieldKind:
  TextField
  CurrencyField
  PercentField
  NumberField

# A total (a subtotal line, a total column, a total row) is drawn with a
# rule and in bold. The calculator computes it like any other cell.
enum Role:
  Detail
  Total

# A field: its name as the reader reads it, what it holds, and its role.
struct Field(label: String, kind: FieldKind, role: Role)

# RecordPerRow: one record per row, the fields across (a record table).
# RecordPerColumn: one record per column, the fields down the side (a
# period grid).
enum Layout:
  RecordPerRow
  RecordPerColumn

# The fields every record has, in order, how they are laid out, and the
# words in the corner above the record labels.
struct TableShape(layout: Layout, corner: String, fields: List[Field])

# One cell: a number written in its field's kind, words for a text field,
# or nothing (a total that would mean nothing, such as the sum of cash
# balances). A Figure in a text field, or Text in a number field, is a
# table the page refuses.
enum Cell:
  Figure(value: Float64)
  Text(text: String)
  Empty

# One record: its label (a month, a person), its role, and one cell per
# field of the shape, in order. A record with a cell too many or too few
# is refused by name. Clicking a figure, a text cell or a record
# label opens Why on that part of the record itself: the page follows the
# record's place in the list, then the cell's place in `cells`, back to
# the call that made it.
struct Record(label: String, role: Role, cells: List[Cell])