Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support spanning cell over rows/columns #188

Merged
merged 1 commit into from
Jan 5, 2022

Conversation

nam-hle
Copy link
Collaborator

@nam-hle nam-hle commented Nov 3, 2021

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
Copy link

coveralls commented Nov 16, 2021

Pull Request Test Coverage Report for Build 1537893299

  • 325 of 325 (100.0%) changed or added relevant lines in 22 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

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

💛 - Coveralls

@nam-hle nam-hle marked this pull request as ready for review November 19, 2021 13:54
@nam-hle nam-hle force-pushed the merge-cell branch 2 times, most recently from 55a69f6 to b9db077 Compare November 27, 2021 13:51
@nam-hle nam-hle requested a review from gajus December 1, 2021 14:22
@nam-hle nam-hle changed the title Support spanning cell over rows/columns feat: Support spanning cell over rows/columns Jan 5, 2022
@nam-hle nam-hle merged commit abcf625 into gajus:master Jan 5, 2022
@nam-hle nam-hle deleted the merge-cell branch January 5, 2022 13:07
@github-actions
Copy link

github-actions bot commented Jan 5, 2022

🎉 This PR is included in version 6.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merging cells
3 participants