Skip to content

Instantly share code, notes, and snippets.

@nsdevaraj
Created May 14, 2020 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsdevaraj/265a4c40e4f955e0cc6629a17e067567 to your computer and use it in GitHub Desktop.
Save nsdevaraj/265a4c40e4f955e0cc6629a17e067567 to your computer and use it in GitHub Desktop.
/*
* Mark rows which have cells in the row header columns with text that's longer than the cell width
*
* Notes:
*
* - See https://wiki.wdf.sap.corp/wiki/display/zen/Crosstab+span+cells for span cell position reference.
* - Representation of default cell width /maxTextWidthPx in the ASCII tables below: +--------------+ = 16 chars
* - The actual modification of the crosstab data is done in expandHeaderRowsAndWrapText - this function
* adds flags to record what needs to be done later
*
* 5 cases:
*
* 1. There are no span cells in the row headers - if there is text to be wrapped, the row height will be expanded --> "exp"
*
* +--------------------------+--------------+--------------+
* | Col Header 1 | Col Header 2 | Col Header 3 |
* +--------------------------+--------------+--------------+
* | Col Header 4 | Col Header 5 | Col Header 6 |
* +--------------------------+--------------+--------------+
* | Really Long Row Header 1 | A | B |
* +--------------------------+--------------+--------------+
* | Row Header 2 | C | D |
* +--------------------------+--------------+--------------+
*
* Becomes:
*
* +--------------+--------------+--------------+
* | Col Header 1 | Col Header 2 | Col Header 3 |
* +--------------+--------------+--------------+
* | Col Header 4 | Col Header 5 | Col Header 6 |
* +--------------+--------------+--------------+
* | Really Long | A | B |
* | | | |
* | Row Header 1 | | | Insert a new row in the table
* +--------------+--------------+--------------+
* | Row Header 2 | C | D |
* +--------------+--------------+--------------+
*
* 2. There are span cells in the row headers, and there is text to be wrapped in non-span cells of the row headers (row height will be expanded) --> "exp"
*
* +--------------------------+--------------+--------------+
* | Col Header 1 | Col Header 2 | Col Header 3 |
* +--------------------------+--------------+--------------+
* | Col Header 4 | Col Header 5 | Col Header 6 |
* +--------------------------+--------------+--------------+
* | Row Header 1 | A | B |
* | +--------------+--------------+
* | | C | D |
* +--------------------------+--------------+--------------+
* | Really Long Row Header 2 | E | F |
* +--------------------------+--------------+--------------+
*
* Becomes:
*
* +--------------+--------------+--------------+
* | Col Header 1 | Col Header 2 | Col Header 3 |
* +--------------+--------------+--------------+
* | Col Header 4 | Col Header 5 | Col Header 6 |
* +--------------+--------------+--------------+
* | Row Header 1 | A | B |
* | +--------------+--------------+
* | | C | D |
* +--------------+--------------+--------------+
* | Really Long | E | F |
* | | | |
* | Row Header 2 | | | Insert a new row in the table
* +--------------+--------------+--------------+
*
* 3. There are span cells in the row headers, but there is text to be wrapped ONLY in NS and SS cells - do nothing, as the text will overflow into the adjacent NM/NE/SM/SE cell.
*
* +--------------------------+-----------------------------+--------------+
* | Col Header 1 | Really Long Col Header 2 | Col Header 3 |
* +--------------------------+-----------------------------+--------------+
* | Col Header 4 | Col Header 5 | Col Header 6 | Col Header 7 |
* +--------------------------+-----------------------------+--------------+
* | Really Long Row Header 1 | A | B | NS NE - Doesn't need to be wrapped
* +--------------------------+-----------------------------+--------------+
* | Row Header 2 | C | D |
* +--------------------------+-----------------------------+--------------+
*
* +--------------------------+-----------------------------+
* | Col Header 1 | Col Header 2 | Col Header 3 |
* +--------------------------+--------------+--------------+
* | Col Header 4 | Col Header 5 | Col Header 6 |
* +--------------------------+--------------+--------------+
* | Really Long Row Header 1 | A | B | SS SE - Doesn't need to be wrapped
* | +--------------+--------------+
* | | C | D |
* +--------------------------+--------------+--------------+
* | Row Header 2 | E | F |
* +--------------------------+--------------+--------------+
*
* 4. There are span cells, but there is text to be wrapped ONLY in SN, SM, and SE span cells (no need to expand row height - just wrap into rowspan M/E cells where needed) --> "wrap"
*
* +--------------------------+--------------+--------------+
* | Col Header 1 | Col Header 2 | Col Header 3 |
* +--------------------------+--------------+--------------+
* | Col Header 4 | Col Header 5 | Col Header 6 |
* +--------------------------+--------------+--------------+
* | Really Long Row Header 1 | A | B |
* | +--------------+--------------+
* | | C | D |
* |--------------------------+--------------+--------------+
* | Row Header 2 | E | F |
* +--------------------------+--------------+--------------+
*
* Becomes:
*
* +--------------+--------------+--------------+
* | Col Header 1 | Col Header 2 | Col Header 3 |
* +--------------+--------------+--------------+
* | Col Header 4 | Col Header 5 | Col Header 6 |
* +--------------+--------------+--------------+
* | Really Long | A | B |
* | +--------------+--------------+
* | Row Header 1 | C | D |
* |--------------+--------------+--------------+
* | Row Header 2 | E | F |
* +--------------+--------------+--------------+
*
* 5. No text to be wrapped --> no flag inserted
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment