Last active
April 12, 2023 19:14
-
-
Save te-lang-wakker/1382d9df802ceb865475f2feae756429 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "tablex.typ": * | |
#let groupedx(data, results-start: none, gutter: auto, column-gutter: auto, row-gutter: auto, fill: none, align: horizon, stroke: black, inset: 5pt) = { | |
let datax = data.map(x => x.map(y => ())) | |
let number-of-columns = data.at(0).len() | |
let number-of-rows = data.len() | |
let skip = () | |
for row in range(number-of-rows) { | |
for column in range(number-of-columns) { | |
if skip.find(it => it.at(0) == column and it.at(1) == row) != none { | |
continue | |
} | |
let entry = data.at(row).at(column) | |
let xspan = 1 | |
let yspan = 1 | |
if results-start == none or column < results-start.at(0) { | |
while column + xspan < number-of-columns and data.at(row).at(column + xspan) == entry { | |
xspan += 1 | |
} | |
while row + yspan < number-of-rows and data.at(row + yspan).at(column) == entry { | |
yspan += 1 | |
} | |
for x in range(xspan) { | |
for y in range(yspan) { | |
skip.push((column + x, row + y)) | |
} | |
} | |
} | |
datax.at(row).at(column) = cellx( | |
colspan: xspan, | |
rowspan: yspan | |
)[ | |
#if results-start != none and (column < results-start.at(0) or row < results-start.at(1)) { | |
text(weight: "bold", entry) | |
} | |
else { | |
entry | |
} | |
] | |
} | |
} | |
tablex( | |
columns: number-of-columns, | |
rows: number-of-rows, | |
gutter: gutter, | |
row-gutter: row-gutter, | |
fill: fill, | |
align: align, | |
stroke: stroke, | |
inset: inset, | |
..datax.flatten() | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment