Skip to content

Commit

Permalink
theme_placement
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Nov 3, 2024
1 parent d14c3a8 commit 94901f0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
9 changes: 6 additions & 3 deletions R/build_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ build_tt <- function(x, output = NULL) {

x@output <- output

# for (th in x@lazy_theme) {
# x <- do.call(th[[1]], th[2])
# }
for (th in x@lazy_theme) {
fn <- th[[1]]
args <- th[[2]]
args[["x"]] <- x
x <- do.call(fn, args)
}

# groups must increment indices here
for (idx in seq_along(x@lazy_group)) {
Expand Down
2 changes: 1 addition & 1 deletion R/class.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ setMethod("initialize", "tinytable", function(
.Object@portable <- FALSE
.Object@style <- data.frame()
.Object@group_tt_i <- FALSE
.Object@lazy_theme <- list(list(identity, list()))
.Object@lazy_theme <- list()
# conditional: allows NULL user input
if (!is.null(placement)) .Object@placement <- placement
if (!is.null(caption)) .Object@caption <- caption
Expand Down
1 change: 1 addition & 0 deletions R/style_typst.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ hlines <- function(k) {
ymax <- k$i[1] + 1
line <- k$line[1]
color <- if (is.na(k$line_color[1])) "black" else k$line_color[1]
if (grepl("^#", color)) color <- sprintf('rgb("%s")', color)
width <- if (is.na(k$line_width[1])) 0.1 else k$line_width[1]
width <- sprintf("%sem", width)
out <- ""
Expand Down
6 changes: 1 addition & 5 deletions R/theme_tt.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
theme_default <- function(x, ...) {
if (isTRUE(x@output == "html")) {
if (isTRUE(x@output %in% c("html", "typst"))) {
x <- style_tt(x,
bootstrap_class = "table table-borderless",
i = nrow(x),
Expand All @@ -13,7 +13,6 @@ theme_default <- function(x, ...) {
line_color = "#d3d8dc",
line_width = 0.1)
}
x <- theme_tt(x, "placement")
return(x)
}

Expand Down Expand Up @@ -109,7 +108,6 @@ theme_resize <- function(x,
}

x <- style_tt(x, finalize = fn)
x <- theme_tt(x, "placement")
return(x)
}

Expand Down Expand Up @@ -139,7 +137,6 @@ theme_void <- function(x, ...) {
}
x <- style_tt(x, finalize = fn,
bootstrap_class = "table table-borderless")
x <- theme_tt(x, "placement")
return(x)
}

Expand All @@ -163,7 +160,6 @@ theme_grid <- function(x, ...) {
}
x <- style_tt(x, tabularray_inner = "hlines, vlines,", finalize = fn,
bootstrap_class = "table table-bordered")
x <- theme_tt(x, "placement")
return(x)
}

Expand Down
4 changes: 1 addition & 3 deletions R/tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ tt <- function(x,


dots <- list(...)
if ("placement" %in% names(dots)) {
warning("The `placement` argument in `tt()` is deprecated. Please use this instead: `theme_tt(table, 'placement')`", call. = FALSE)
}

# sanity checks
assert_string(caption, null.ok = TRUE)
Expand Down Expand Up @@ -134,6 +131,7 @@ tt <- function(x,

if (is.null(theme)) {
out <- theme_tt(out, theme = "default")
out <- theme_tt(out, theme = "placement")
} else {
out <- theme_tt(out, theme = theme)
}
Expand Down

0 comments on commit 94901f0

Please sign in to comment.