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

Change default clip settings in gtable_col() and gtable_row()? #56

Open
clauswilke opened this issue Jul 29, 2017 · 0 comments
Open

Change default clip settings in gtable_col() and gtable_row()? #56

clauswilke opened this issue Jul 29, 2017 · 0 comments

Comments

@clauswilke
Copy link

Both gtable_col() and gtable_row() have no clip parameter and set clip = "off" in the layout they generate. This clip setting switches off any clip settings that might have been chosen higher up:

# a circle grob
circ <- grid::circleGrob(gp = gpar(fill = "blue"))

# a function that scales a grob and clips it
scale_and_clip <- function(grob, size = .8, scale = 1.2) {
  vp_outer <- viewport(x = .5, y = .5,
                       width = size, height = size,
                       just = c("center", "center"),
                       clip = "on")

  vp_inner <- viewport(width = scale, height = scale,
                       just = c("center", "center"))

  inner_grob <- grobTree(grob, vp = vp_inner, name = "inner")
  outer_grob <- grobTree(inner_grob, vp = vp_outer, name = "outer")

  grid.newpage()
  grid.draw(outer_grob)
}

# this works correctly, top and bottom of the circle are cut off
circ <- grid::circleGrob(gp = gpar(fill = "blue"))
scale_and_clip(circ, .8, 1.2)

rplot1

# this doesn't work correctly, because gtable overrides the clip settings
u <- grid::unit(1, "null")
ct <- gtable::gtable_col(NULL, list(circ), u, u)
scale_and_clip(ct, .8, 1.2)

rplot2

# this fixes it
ct$layout$clip <- "inherit"
scale_and_clip(ct, .8, 1.2)
# output like the first image

# this breaks it again, because grid cannot nest clipping areas :-(
ct$layout$clip <- "on"
scale_and_clip(ct, .8, 1.2)
# output like the second image

I think both functions should have a clip parameter, and I also think the default should be "inherit" so that it is possible to clip gtables. I'm happy to generate a pull request if you agree. Not sure how this might interact with ggplot2, though. And it's frustrating that grid doesn't nest clipping areas, that really limits some of the more advanced applications of clipping.

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

1 participant