Skip to content

Commit 896666d

Browse files
committed
backwards compatibility for element_grob()
1 parent afadca1 commit 896666d

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ S3method(autolayer,default)
2929
S3method(autoplot,default)
3030
S3method(c,mapped_discrete)
3131
S3method(drawDetails,zeroGrob)
32+
S3method(element_grob,default)
3233
S3method(format,ggproto)
3334
S3method(format,ggproto_method)
3435
S3method(format,rd_section_aesthetics)
@@ -317,6 +318,7 @@ export(cut_width)
317318
export(datetime_scale)
318319
export(derive)
319320
export(discrete_scale)
321+
export(draw_element)
320322
export(draw_key_abline)
321323
export(draw_key_blank)
322324
export(draw_key_boxplot)

R/theme-elements.R

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,16 +436,19 @@ element_render <- function(theme, element, ..., name = NULL) {
436436

437437
#' Generate grid grob from theme element
438438
#'
439+
#' The `element_grob()` function is vestigial and `draw_element()` should
440+
#' be used instead.
441+
#'
439442
#' @param element Theme element, i.e. `element_rect` or similar.
440443
#' @param ... Other arguments to control specific of rendering. This is
441444
#' usually at least position. See the source code for individual methods.
442445
#' @keywords internal
443446
#' @export
444-
element_grob <- S7::new_generic("element_grob", "element")
447+
draw_element <- S7::new_generic("draw_element", "element")
445448

446-
S7::method(element_grob, element_blank) <- function(element, ...) zeroGrob()
449+
S7::method(draw_element, element_blank) <- function(element, ...) zeroGrob()
447450

448-
S7::method(element_grob, element_rect) <-
451+
S7::method(draw_element, element_rect) <-
449452
function(element, x = 0.5, y = 0.5, width = 1, height = 1,
450453
fill = NULL, colour = NULL,
451454
linewidth = NULL, linetype = NULL, linejoin = NULL,
@@ -464,7 +467,7 @@ S7::method(element_grob, element_rect) <-
464467
rectGrob(x, y, width, height, gp = modify_list(element_gp, gp), ...)
465468
}
466469

467-
S7::method(element_grob, element_text) <-
470+
S7::method(draw_element, element_text) <-
468471
function(element, label = "", x = NULL, y = NULL,
469472
family = NULL, face = NULL, colour = NULL, size = NULL,
470473
hjust = NULL, vjust = NULL, angle = NULL, lineheight = NULL,
@@ -492,7 +495,7 @@ S7::method(element_grob, element_text) <-
492495
margin_x = margin_x, margin_y = margin_y, debug = element@debug, ...)
493496
}
494497

495-
S7::method(element_grob, element_line) <-
498+
S7::method(draw_element, element_line) <-
496499
function(element, x = 0:1, y = 0:1,
497500
colour = NULL, linewidth = NULL, linetype = NULL, lineend = NULL,
498501
linejoin = NULL, arrow.fill = NULL,
@@ -531,7 +534,7 @@ S7::method(element_grob, element_line) <-
531534
)
532535
}
533536

534-
S7::method(element_grob, element_polygon) <-
537+
S7::method(draw_element, element_polygon) <-
535538
function(element, x = c(0, 0.5, 1, 0.5),
536539
y = c(0.5, 1, 0.5, 0), fill = NULL,
537540
colour = NULL, linewidth = NULL,
@@ -553,7 +556,7 @@ S7::method(element_grob, element_polygon) <-
553556
)
554557
}
555558

556-
S7::method(element_grob, element_point) <-
559+
S7::method(draw_element, element_point) <-
557560
function(element, x = 0.5, y = 0.5, colour = NULL,
558561
shape = NULL, fill = NULL, size = NULL,
559562
stroke = NULL, ...,
@@ -567,6 +570,18 @@ S7::method(element_grob, element_point) <-
567570
default.units = default.units, ...)
568571
}
569572

573+
# TODO: the S3 generic should be phased out once S7 is adopted more widely
574+
#' @rdname draw_element
575+
#' @export
576+
element_grob <- function(element, ...) {
577+
UseMethod("element_grob")
578+
}
579+
580+
#' @export
581+
element_grob.default <- function(element, ...) {
582+
draw_element(element, ...)
583+
}
584+
570585
#' Define and register new theme elements
571586
#'
572587
#' The underlying structure of a ggplot2 theme is defined via the element tree, which

man/element_grob.Rd renamed to man/draw_element.Rd

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)