Skip to content

Commit

Permalink
Merge pull request #4 from olivroy/AaronGullickson-floating-table
Browse files Browse the repository at this point in the history
Merge main branch
  • Loading branch information
AaronGullickson authored Jul 15, 2024
2 parents 7faf1de + d9dadcf commit c331d3b
Show file tree
Hide file tree
Showing 43 changed files with 2,086 additions and 1,875 deletions.
20 changes: 10 additions & 10 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ tests/testthat/test-cols_label_with.R
tests/testthat/test-cols_merge.R
tests/testthat/_snaps/cols_merge.md

tests/testthat/test-cols_width_rtf.R
tests/testthat/_snaps/cols_width_rtf.md

tests/testthat/test-cols_width.R
tests/testthat/_snaps/cols_width.md

Expand Down Expand Up @@ -110,6 +107,9 @@ tests/testthat/_snaps/image.md
tests/testthat/test-info_tables.R
tests/testthat/test-input_data_validation.R

tests/testthat/test-l_summary_rows.R
tests/testthat/_snaps/l_summary_rows.md

tests/testthat/test-l_table_parts.R
tests/testthat/_snaps/l_table_parts.md

Expand All @@ -124,20 +124,18 @@ tests/testthat/_snaps/removal_functions.md
tests/testthat/test-rows_add.R
tests/testthat/_snaps/rows_add.md

tests/testthat/test-rtf_column_widths.R
tests/testthat/test-rtf_cols_width.R
tests/testthat/_snaps/rtf_cols_width.md

tests/testthat/test-rtf_page_options.R
tests/testthat/_snaps/rtf_page_options.md

tests/testthat/test-rtf_summary_rows.R
tests/testthat/_snaps/rtf_summary_rows.md

tests/testthat/test-stub.R
tests/testthat/test-substitution.R

tests/testthat/test-summary_rows_latex.R
tests/testthat/_snaps/summary_rows_latex.md

tests/testthat/test-summary_rows_rtf.R
tests/testthat/_snaps/summary_rows_rtf.md

tests/testthat/test-summary_rows.R
tests/testthat/_snaps/summary_rows.md

Expand Down Expand Up @@ -171,6 +169,8 @@ tests/testthat/test-table_parts.R
tests/testthat/_snaps/table_parts.md

tests/testthat/test-text_transform.R
tests/testthat/_snaps/text_transform.md

tests/testthat/test-util_functions.R
tests/testthat/test-utils_formatters.R
tests/testthat/test-utils_plots.R
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

* PDF output now defaults to a full-width floating environment using `tabular*` (@AronGullickson, #1588). Float position can be controlled by the `latex.tbl.pos` argument in `tab_options`. Quarto users can alternatively use the `tbl-pos` argument to control positioning. To use a `longtable` environment instead, use `tab_option(latex.use.longtable = TRUE)`.

* Improved error messages for the `text_transform()` function if `locations` couldn't be resolved. (@olivroy, #1774)

* `tab_row_group()` gives a more precise error message when `rows` can't be resolved correctly (#1535). (@olivroy, #1770)

* Fixed an issue where `md("")` would fail in Quarto. (@olivroy, #1769)

* Fixed a bug in using `pct()` column widths with `as_gtable()` (@teunbrand, #1771)

# gt 0.11.0

## New features
Expand Down
4 changes: 0 additions & 4 deletions R/dt_cols_merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ dt_col_merge_set <- function(data, col_merge) {
dt__set(data, .dt_col_merge_key, col_merge)
}

dt_col_merge_init <- function(data) {
dt_col_merge_set(data = data, col_merge = list())
}

dt_col_merge_add <- function(data, col_merge) {
added <- append(dt_col_merge_get(data = data), list(col_merge))
dt_col_merge_set(data = data, col_merge = added)
Expand Down
33 changes: 24 additions & 9 deletions R/export.R
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ grid_align_gtable <- function(gtable, data) {

} else {

right <- grid::unit(grid::unit(parse_px_to_pt(left), "pt"))
right <- grid::unit(parse_px_to_pt(left), "pt")
}

gtable <- gtable::gtable_add_cols(gtable, left, pos = 0)
Expand All @@ -1461,13 +1461,20 @@ grid_layout_widths <- function(layout, data) {

# Enlarge columns if fixed column widths have been set
column_width <- unlist(dt_boxhead_get(data)$column_width)
fixed <- integer(0L)
fixed <- integer(0)
relative <- rep(NA_real_, length(widths))

if (any(nzchar(column_width)) && length(column_width) == length(widths)) {

fixed <- which(nzchar(column_width))
widths[fixed] <- pmax(parse_px_to_pt(column_width[fixed]), widths[fixed])
fixed <- which(endsWith(column_width, "px"))
if (length(fixed) > 0) {
widths[fixed] <- pmax(parse_px_to_pt(column_width[fixed]), widths[fixed])
}
pct <- which(endsWith(column_width, "%"))
if (length(pct) > 0) {
relative[pct] <- as.numeric(gsub("\\%$", "", column_width[pct])) / 100
}
}
pct <- which(!is.na(relative))

spanner <- spanner[order(spanner$key$left, spanner$key$right), ]

Expand Down Expand Up @@ -1498,8 +1505,11 @@ grid_layout_widths <- function(layout, data) {

change <- setdiff(seq_along(widths), fixed)
widths[change] <- widths[change] + extra_width / (length(widths[change]))

return(grid::unit(widths, .grid_unit))
widths <- grid::unit(widths, .grid_unit)
if (length(pct) > 0) {
widths[pct] <- grid::unit(relative[pct], "npc")
}
return(widths)
}

if (grepl("\\%$", total_width)) {
Expand All @@ -1517,10 +1527,15 @@ grid_layout_widths <- function(layout, data) {

# Take pairwise max between minimal size and relative size
widths <- grid::unit.pmax(grid::unit(widths, .grid_unit), extra_width)
if (length(pct) > 0) {
widths[pct] <- grid::unit(relative[pct], "npc")
}
return(widths)
}

grid::unit(widths, .grid_unit)
grid::unit(
ifelse(is.na(relative), widths, relative),
ifelse(is.na(relative), .grid_unit, "npc")
)
}

#' Extract the table body from a **gt** object
Expand Down
Loading

0 comments on commit c331d3b

Please sign in to comment.