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

Fix merging of cells with Multiline values #29

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

## [2.0.2] - 2024-09-16

- Fixed issue where cells would not merge if they stored a `Multiline` value [#29](https://github.com/PumasAI/SummaryTables.jl/pull/29).

## [2.0.1] - 2024-09-16

- Fixed incorrect order of column group keys in `summarytable` and `listingtable` when some row/col group combinations were missing [#25](https://github.com/PumasAI/SummaryTables.jl/pull/25).
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SummaryTables"
uuid = "6ce4ecf0-73a7-4ce3-9fb4-80ebfe887b60"
authors = ["Julius <[email protected]>", "Mike <[email protected]>"]
version = "2.0.1"
version = "2.0.2"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down
6 changes: 3 additions & 3 deletions src/cells.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ A `Multiline` value may only be used as the top-level value of a cell, so
`Cell(Multiline(...))` is allowed but `Cell(Concat(Multiline(...), ...))` is not.
"""
struct Multiline
values::Vector{Any}
values::Tuple
Multiline(args...) = new(args)
end
Multiline(args...) = Multiline(Any[args...])

"""
Concat(args...)
Expand Down Expand Up @@ -532,7 +532,7 @@ end
apply_rounder(x, r::Rounder) = x
apply_rounder(x::AbstractFloat, r::Rounder) = RoundedFloat(x, r.round_digits, r.round_mode, r.trailing_zeros)
apply_rounder(x::Concat, r::Rounder) = Concat(map(arg -> apply_rounder(arg, r), x.args)...)
apply_rounder(x::Multiline, r::Rounder) = Multiline(map(arg -> apply_rounder(arg, r), x.values))
apply_rounder(x::Multiline, r::Rounder) = Multiline(map(arg -> apply_rounder(arg, r), x.values)...)
apply_rounder(x::Annotated, r::Rounder) = Annotated(apply_rounder(x.value, r), x.annotation, x.label)

function postprocess_cell(cell::Cell, r::Rounder)
Expand Down
25 changes: 25 additions & 0 deletions test/references/merged_cells/custom_datatypes.latex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
\documentclass{article}
\usepackage{threeparttable}
\usepackage{multirow}
\usepackage{booktabs}
\begin{document}
\begin{table}[!ht]
\setlength\tabcolsep{0pt}
\centering
\begin{threeparttable}
\begin{tabular}{@{\extracolsep{2ex}}*{2}{cc}}
\toprule
\multicolumn{2}{c}{\begin{tabular}{@{}c@{}}A \\ B\end{tabular}} \\
\multicolumn{2}{c}{\textsuperscript{Sup}} \\
\multicolumn{2}{c}{\textsubscript{Sub}} \\
\multicolumn{2}{c}{AB} \\
\multicolumn{2}{c}{Label\tnote{1}} \\
\bottomrule
\end{tabular}
\begin{tablenotes}[flushleft,para]
\footnotesize
\item[1]Annotation
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
49 changes: 49 additions & 0 deletions test/references/merged_cells/custom_datatypes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<table class="st-0d1e8685">
<style>
.st-0d1e8685 {
border: none;
margin: 0 auto;
padding: 0.25rem;
border-collapse: separate;
border-spacing: 0.85em 0.2em;
line-height: 1.2em;
}

.st-0d1e8685 tr td {
vertical-align: top;
padding: 0;
border: none;
}

.st-0d1e8685 br {
line-height: 0em;
margin: 0;
}

.st-0d1e8685 sub {
line-height: 0;
}

.st-0d1e8685 sup {
line-height: 0;
}
</style>
<tr><td colspan="2" style="border-bottom: 1.5px solid black; padding: 0"></td></tr>
<tr>
<td colspan="2" style="text-align:center;">A<br>B</td>
</tr>
<tr>
<td colspan="2" style="text-align:center;"><sup>Sup</sup></td>
</tr>
<tr>
<td colspan="2" style="text-align:center;"><sub>Sub</sub></td>
</tr>
<tr>
<td colspan="2" style="text-align:center;">AB</td>
</tr>
<tr>
<td colspan="2" style="text-align:center;">Label<sup>1</sup></td>
</tr>
<tr><td colspan="2" style="border-bottom: 1.5px solid black; padding: 0"></td></tr>
<tr><td colspan="2" style="font-size: 0.8em;"><sup>1</sup> Annotation</td></tr>
</table>
16 changes: 16 additions & 0 deletions test/references/merged_cells/custom_datatypes.typ.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

#table(
rows: 5,
columns: 2,
column-gutter: 0.25em,
align: (center, center),
stroke: none,
table.hline(y: 0, stroke: 1pt),
table.cell(colspan: 2)[A #linebreak() B],
table.cell(colspan: 2)[#super[Sup]],
table.cell(colspan: 2)[#sub[Sub]],
table.cell(colspan: 2)[AB],
table.cell(colspan: 2)[Label#super[1]],
table.hline(y: 5, stroke: 1pt),
table.cell(align: left, colspan: 2)[#super[1]#text(size: 0.8em)[Annotation]],
)
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,19 @@ end
reftest(t, "references/character_escaping/problematic_characters")
end

@testset "Merged cells with special values" begin
contents = [
Multiline("A", "B"),
Superscript("Sup"),
Subscript("Sub"),
Concat("A", "B"),
Annotated("Label", "Annotation"),
]
cells = Cell.(contents, merge = true)
t = Table(hcat(cells, cells))
reftest(t, "references/merged_cells/custom_datatypes")
end

@testset "Styles" begin
cells = [
SpannedCell(1, 1, "Row 1"),
Expand Down
Loading