spgarbet / tangram

Table Grammar package for R
66 stars 3 forks source link

Setting rowspan / colspan #41

Closed c4f3a0ce closed 5 years ago

c4f3a0ce commented 5 years ago

Is it possible to set rowspan / colspan for a particular cell?

spgarbet commented 5 years ago

Right now no. It's something I'd like to tackle, but it's a difficult problem. So far, I've not encountered a use case where it's really needed. If you have a simple example, i.e. how you would specify this in a simple consistent manner I might be able to prototype a solution in a branch.

spgarbet commented 5 years ago

I think I have a method that might work figured out.

c4f3a0ce commented 5 years ago

Thank your for your prompt response @spgarbet

I was thinking about expressing groups of columns / rows while without sacrificing semantic aspects (primarily with HTML output).

spgarbet commented 5 years ago

I think what I can do is just add colspan and rowspan as attributes on the tangram object. Then have the cells in the grid they overlap be a class that denotes to not render.

spgarbet commented 5 years ago

I'm currently swamped with high priority items, but on the walk in this morning it struck me. All the things I've done to make this library extensible and pluggable make this problem trivial. Any attribute you want to attach to a cell is automatic.

> library(tangram)
> x <- cell("joe", colspan=2)
> str(x)
 'cell' chr "joe"
 - attr(*, "colspan")= num 2

Thus the only thing necessary is how to denote non-renderable cells and create rendering. To that end, I propose that an NA become a non-renderable cell. it's a cell, but it denotes to not render it. Then modify the html5 renderer to respect these two things and I think it's mostly done.

spgarbet commented 5 years ago

All the table_builder helpers will need modified to respect it for a robust solution, but that can be done later.

spgarbet commented 5 years ago

I wrote a quick version of this with html5 and pushed it up in be8305ea06196dbad5cb9d3b57d9de2a80f69770

library(tangram)

tbl <- tangram(1, 1, id="joe")
tbl[[1]][[1]] <- cell_header("A", colspan = 2)
tbl[[1]][[2]] <- NA
tbl[[1]][[3]] <- cell_header("B", colspan = 2)
tbl[[1]][[4]] <- NA

tbl[[2]] <- list()
tbl[[2]][[1]] <- cell_subheader("Red")
tbl[[2]][[2]] <- cell_subheader("Black")
tbl[[2]][[3]] <- cell_subheader("Red")
tbl[[2]][[4]] <- cell_subheader("Black")

tbl[[3]] <- list()
tbl[[3]][[1]] <- cell("1")
tbl[[3]][[2]] <- cell("Rowspan 2", rowspan=2)
tbl[[3]][[3]] <- cell("3")
tbl[[3]][[4]] <- cell("4")

tbl[[4]] <- list()
tbl[[4]][[1]] <- cell("5")
tbl[[4]][[2]] <- NA
tbl[[4]][[3]] <- cell("7")
tbl[[4]][[4]] <- cell("8")
html5(tbl)

Note text display of a tbl like this at the command prompt is broken. I will have to add this to both text and table. I'll probably open those as separate tickets if this works for you.

What I'd like back is to kick the tires on this and let me know how well this worked for you. Also, if there are some operators on a table that would make what you're doing easier I'm open to suggestions.

c4f3a0ce commented 5 years ago

Thank you so much. It looks promising!

Let me take it for a spin.

spgarbet commented 5 years ago

And now a bunch of stuff is broken. Ugh. Working through fixing example.Rmd