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

Add support for grob as image #19

Open
jonocarroll opened this issue Nov 13, 2024 · 0 comments
Open

Add support for grob as image #19

jonocarroll opened this issue Nov 13, 2024 · 0 comments

Comments

@jonocarroll
Copy link
Owner

get_image_path currently lacks a logic branch for an input which is not a ggplot or a string

ntfy/R/ntfy.R

Lines 17 to 28 in 125a3bf

get_image_path <- function(image) {
if (inherits(image, "ggplot")) {
requireNamespace("ggplot2", quietly = FALSE)
filename <- tempfile(pattern = "gg", fileext = ".png")
ggplot2::ggsave(filename, image)
} else if (is.character(image)) {
stopifnot(file.exists(image))
filename <- image
}
return(filename)
}

so a grob produces an uninformative error. A default case should be added, but specific support for grob would also be good, see also #18.

An example grob for testing would be

library(grid)

rect_grob <- rectGrob(
  x = 0.5, y = 0.5,
  width = 0.3, height = 0.3,
  gp = gpar(fill = "lightblue", col = "navy")
)

circle_grob <- circleGrob(
  x = 0.5, y = 0.5, r = 0.15,
  gp = gpar(fill = "pink", col = "red")
)

text_grob <- textGrob(
  "Hello Grid!",
  x = 0.5, y = 0.8,
  gp = gpar(fontsize = 16, fontface = "bold")
)

# Combine all grobs into a single grob object
my_grob <- gTree(children = gList(rect_grob, circle_grob, text_grob))

grid.newpage()
grid.draw(my_grob)

class(my_grob)
# [1] "gTree" "grob"  "gDesc"

image

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