Skip to content

Commit 9736300

Browse files
committed
Make S7 generic of get_alt_text()
1 parent 5453b28 commit 9736300

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

NAMESPACE

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ S3method(fortify,sfg)
5555
S3method(fortify,summary.glht)
5656
S3method(fortify,tbl)
5757
S3method(fortify,tbl_df)
58-
S3method(get_alt_text,"ggplot2::ggplot")
59-
S3method(get_alt_text,"ggplot2::ggplot_built")
60-
S3method(get_alt_text,gtable)
6158
S3method(grid.draw,absoluteGrob)
6259
S3method(grobHeight,absoluteGrob)
6360
S3method(grobHeight,zeroGrob)

R/labels.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ get_labs <- function(plot = get_last_plot()) {
272272
#'
273273
#' get_alt_text(p)
274274
#'
275-
get_alt_text <- function(p, ...) {
275+
get_alt_text <- S7::new_generic("get_alt_text", "p", fun = function(p, ...) {
276276
warn_dots_used()
277-
UseMethod("get_alt_text")
278-
}
279-
#' @export
280-
`get_alt_text.ggplot2::ggplot` <- function(p, ...) {
277+
S7::S7_dispatch()
278+
})
279+
280+
S7::method(get_alt_text, class_ggplot) <- function(p, ...) {
281281
alt <- p@labels[["alt"]] %||% ""
282282
if (!is.function(alt)) {
283283
return(alt)
@@ -287,14 +287,14 @@ get_alt_text <- function(p, ...) {
287287
build@plot@labels[["alt"]] <- alt
288288
get_alt_text(build)
289289
}
290-
#' @export
291-
`get_alt_text.ggplot2::ggplot_built` <- function(p, ...) {
290+
291+
S7::method(get_alt_text, class_ggplot_built) <- function(p, ...) {
292292
alt <- p@plot@labels[["alt"]] %||% ""
293293
p@plot@labels[["alt"]] <- NULL
294294
if (is.function(alt)) alt(p@plot) else alt
295295
}
296-
#' @export
297-
get_alt_text.gtable <- function(p, ...) {
296+
297+
S7::method(get_alt_text, class_gtable) <- function(p, ...) {
298298
attr(p, "alt-label") %||% ""
299299
}
300300

0 commit comments

Comments
 (0)