Skip to content

Commit

Permalink
probably breaking everything
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Oct 22, 2024
1 parent 3581ae2 commit 1515322
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 27 deletions.
1 change: 1 addition & 0 deletions R/class.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ setClass(
ncol = "numeric",
nhead = "numeric",
ngroupi = "numeric",
group_i_idx = "numeric",
names = "NULLorCharacter",
output = "character",
output_dir = "character",
Expand Down
3 changes: 2 additions & 1 deletion R/group_bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ group_bootstrap_row <- function(x, i, j, indent = 1, ...) {
i[g] + x@nhead - 1,
ncol(x),
names(i)[g])
out <- bootstrap_setting(out, new = js, component = "cell")
out <- lines_insert(out, js, "tinytable span after", "after")
# out <- bootstrap_setting(out, new = js, component = "cell")
}

# need unique function names in case there are
Expand Down
1 change: 1 addition & 0 deletions R/group_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ group_tt <- function(x, i = NULL, j = NULL, indent = 1, ...) {
}

x@ngroupi <- x@ngroupi + length(i)
x@group_i_idx <- as.numeric(unlist(i))

cal <- call("group_eval", i = i, j = j, indent = indent)

Expand Down
9 changes: 1 addition & 8 deletions R/sanity.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ usepackage_latex <- function(name, options = NULL, extra_lines = NULL) {

sanitize_i <- function(i, x, pre_group_i = FALSE) {
if (is.null(i)) {
if (pre_group_i && inherits(x, "tinytable")) {
out <- seq_len(nrow(x) - x@ngroupi)
} else {
out <- seq_len(nrow(x))
}
if (inherits(x, "tinytable") && x@nhead > 0) {
out <- c(-1 * (1:x@nhead - 1), out)
}
out <- NA
} else {
out <- i
}
Expand Down
29 changes: 25 additions & 4 deletions R/style_bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,33 @@ setMethod(
style_apply_bootstrap <- function(x) {
sty <- x@style

x@ngroupi

# bootstrap classes and rules
if (length(x@bootstrap_css_rule) == 1) {
x@table_string <- bootstrap_setting(x@table_string, x@bootstrap_css_rule, component = "css")
}

# i=NULL includes groups
idx <- is.na(sty$i)
styna <- sty[idx, -1, drop = FALSE]
if (nrow(styna) > 0) {
idx_i <- seq_len(x@nrow + x@ngroupi)
if (x@nhead > 0) idx_i <- sort(unique(c(-(0:(x@nhead - 1)), idx_i)))
idx_i <- data.frame(i = idx_i)
idx_i <- merge(idx_i, styna, all = TRUE)
sty <- rbind(idx_i, sty[!idx,, drop = FALSE])
}

# if (pre_group_i && inherits(x, "tinytable")) {
# out <- seq_len(nrow(x) - x@ngroupi)
# } else {
# out <- seq_len(nrow(x))
# }
# if (inherits(x, "tinytable") && x@nhead > 0) {
# out <- c(-1 * (1:x@nhead - 1), out)
# }

sty$alignv[which(sty$alignv == "t")] <- "top"
sty$alignv[which(sty$alignv == "b")] <- "bottom"
sty$alignv[which(sty$alignv == "m")] <- "middle"
Expand Down Expand Up @@ -80,8 +102,6 @@ style_apply_bootstrap <- function(x) {
idx <- which(!is.na(sty$bootstrap_css))
css_arguments[idx] <- paste(css_arguments[idx], sty$bootstrap_css[idx])

browser()

lincol <- ifelse(is.na(sty$line_color),
sprintf("solid %sem; border-color: black;", sty$line_width),
sprintf("solid %s %sem", sty$line_color, sty$line_width))
Expand Down Expand Up @@ -149,9 +169,10 @@ style_apply_bootstrap <- function(x) {
colspan <- if (!is.na(sty$colspan[row])) sty$colspan[row] else 1
if (rowspan > 1 || colspan > 1) {
id <- get_id(stem = "spanCell_")
listener <- "window.addEventListener('load', function () { %s(%s, %s, %s, %s) })"
listener <- " window.addEventListener('load', function () { %s(%s, %s, %s, %s) })"
listener <- sprintf(listener, id, sty$i[row], sty$j[row], rowspan, colspan)
x@table_string <- bootstrap_setting(x@table_string, listener, component = "cell")
x@table_string <- lines_insert(x@table_string, listener, "tinytable span after", "after")
# x@table_string <- bootstrap_setting(x@table_string, listener, component = "cell")
}
}

Expand Down
5 changes: 5 additions & 0 deletions R/style_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ style_tt <- function (x,
settings[["align"]] <- NA
}

empty <- settings[, 4:ncol(settings)]
empty <- sapply(empty, function(x) is.na(x) | (is.logical(x) && !any(x)))
empty <- apply(empty, 1, all)
settings <- settings[!empty, , drop = FALSE]

if (nrow(out@style) > 0 && nrow(settings) > 0 && ncol(out@style) != ncol(settings)) {
a <- out@style
b <- settings
Expand Down
36 changes: 22 additions & 14 deletions inst/templates/bootstrap.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,17 @@
<!-- tinytable mathjax end -->

<script>

function styleCell(i, j, css_id) {
var table = document.getElementById("$tinytable_TABLE_ID");
table.rows[i].cells[j].classList.add(css_id);
var table = document.getElementById("$tinytable_TABLE_ID");
var cell = table.rows[i]?.cells[j]; // Safe navigation to avoid errors
if (cell) {
console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
cell.classList.add(css_id);
} else {
console.warn(`Cell at (${i}, ${j}) not found.`);
}
}
window.addEventListener('load', function () {
var cellsToStyle = [
// tinytable style arrays after
];

// Loop over the arrays to style the cells
cellsToStyle.forEach(function (group) {
group.positions.forEach(function (cell) {
styleCell_xsjwx284ljc2lem7zsd2(cell.i, cell.j, group.css_id);
});
});
});
function insertSpanRow(i, colspan, content) {
var table = document.getElementById('$tinytable_TABLE_ID');
var newRow = table.insertRow(i);
Expand Down Expand Up @@ -77,6 +72,19 @@
targetCell.rowSpan = rowspan;
targetCell.colSpan = colspan;
}
// tinytable span after
window.addEventListener('load', function () {
var cellsToStyle = [
// tinytable style arrays after
];

// Loop over the arrays to style the cells
cellsToStyle.forEach(function (group) {
group.positions.forEach(function (cell) {
styleCell_xsjwx284ljc2lem7zsd2(cell.i, cell.j, group.css_id);
});
});
});
</script>

<style>
Expand Down

0 comments on commit 1515322

Please sign in to comment.