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

(HTML) Indices are changed after cells are merged with rowspan #355

Open
J-Moravec opened this issue Oct 4, 2024 · 3 comments
Open

(HTML) Indices are changed after cells are merged with rowspan #355

J-Moravec opened this issue Oct 4, 2024 · 3 comments

Comments

@J-Moravec
Copy link
Contributor

This could perhaps be emphasized in documentation because it took me quite a bit to understand what is going on.

  1. style_tt(rowspan = ...) to merge rows
  2. style_tt(j = ... , i = which(...)) -- suddenly columns are styled (e.g., coloured) in weird ragged way.

Switching order of operations doesn't help (likely they are evaluating lazily in a particular order)

This makes conditional styling together with rowspan essentially impossible (without adding a bunch of dummy column).

@vincentarelbundock
Copy link
Owner

Interesting. I think this may be HTML-specific. In LaTeX, all entries stay in the table and we use a tabularray argument to stretch cells. Since all cells stay in place, we can still refer and style them using the same indices.

In HTML, I believe that we "drop" cells, so indexing probably changes. This may require us to store a new S4 slot with information about spans, so that we can adjust indices appropriately. That's an interesting problem I had not considered before.

Super busy at work these days, but I'll take a look when I find some time. Thanks for the report!

@J-Moravec J-Moravec changed the title Indices are changed after cells are merged with rowspan (HTML) Indices are changed after cells are merged with rowspan Oct 7, 2024
@J-Moravec
Copy link
Contributor Author

MRE:

d = data.frame(1:2, 3:4)

# text output works well
tt(d) |> style_tt(j = 1, i = 1, rowspan = 2) |> style_tt(j = 1, color = "orange", italic = TRUE)

# +------+------+
# | X1.2 | X3.4 |
# +======+======+
# | *1*  | 3    |
# +------+------+
# | **   | 4    |
# +------+------+ 

# HTML output doesn't(t
tt(d) |> style_tt(j = 1, i = 1, rowspan = 2) |> style_tt(j = 1, color = "orange", italic = TRUE) |> save_tt("test.html")

image

We wanted to highlight first column. Instead, the first cell in a row is always highlighted, since the actual first cell was deleted by rowspan. For complex HTML tables. So to fix that, an empty dummy column needs to be inserted, or any conditional highlighting needs to compensate indexing for this,

@vincentarelbundock
Copy link
Owner

This PR is a proof of concept to handle the rowspan issue reported here.

#374

Problems:

  1. Ugly
  2. Does not handle colspan

Orange works despite rowspan. Blue does not work because of colspan

pkgload::load_all()
tt(head(iris)) |> 
    style_tt(j = 1, i = 1, rowspan = 2, colspan = 2) |> 
    style_tt(i = 1, color = "blue") |> 
    style_tt(j = 1, color = "orange", italic = TRUE)
    save_tt("example.html", overwrite = TRUE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants