gajus / table

Formats data into a string table.
Other
893 stars 77 forks source link

feat: Support spanning cell over rows/columns #188

Closed nam-hle closed 2 years ago

nam-hle commented 2 years ago

Fix #187, #12.

API

type SpanningCellConfig = CellUserConfig // the same config as column's to overwrite the default config
& {
  readonly row: number, // row index of the top-left cell in the spanning cell
  readonly col: number, // column index of the top-left cell in the spanning cell
  readonly rowSpan?: number, // number of rows in the spanning cell
  readonly colSpan?: number, // number of columns in the spanning cell
};

type BaseUserConfig = {
   // other configs
   readonly spanningCells?: SpanningCellConfig[]
}

Algorithm

Width calculation

The width of the spanning cell (SC) is the sum of all column widths, padding, border (hidden borders has been considered) that it spans.

Height calculation

The raw content of the top-left cell will be used as SC's content. After calculating the width above, we can determine the total height that needs to be used to render the cell. The table row height calculation will skip the cells that belong to SCs, except those cells are belongs to the last row of SC since we need all the remaining content of SC to be placed in them.

Spanning cell config

We will use the config of the first column of SC as the SC's config, except the padding-right will be inherited from the last column's (for better alignment). The user can also overwrite those configs on demand.

Drawing border

We also need other kinds of border characters to be placed around SC. The logic should be straightforward but many cases need to be considered.

Header

The header content and config will be transferred into spanning cell config

Validation

row, col, rowSpan (min 1), colSpan (min 1) need to be specified such as all cells inside spanning cells are also contained inside the table, and do not overlap other spanning cells.

coveralls commented 2 years ago

Pull Request Test Coverage Report for Build 1537893299


Totals Coverage Status
Change from base Build 1526258228: 0.0%
Covered Lines: 641
Relevant Lines: 641

💛 - Coveralls
github-actions[bot] commented 2 years ago

:tada: This PR is included in version 6.8.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: