Skip to content

Commit 3fcfbe3

Browse files
committed
For backward compatibility, zeroGrob() returns a nullGrob() subclass
1 parent 59dc42e commit 3fcfbe3

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

NAMESPACE

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ S3method(as.list,ggproto)
1919
S3method(autolayer,default)
2020
S3method(autoplot,default)
2121
S3method(c,mapped_discrete)
22-
S3method(drawDetails,zeroGrob)
2322
S3method(element_grob,element_blank)
2423
S3method(element_grob,element_line)
2524
S3method(element_grob,element_point)
@@ -76,9 +75,7 @@ S3method(ggplot_gtable,ggplot_built)
7675
S3method(grid.draw,absoluteGrob)
7776
S3method(grid.draw,ggplot)
7877
S3method(grobHeight,absoluteGrob)
79-
S3method(grobHeight,zeroGrob)
8078
S3method(grobWidth,absoluteGrob)
81-
S3method(grobWidth,zeroGrob)
8279
S3method(grobX,absoluteGrob)
8380
S3method(grobY,absoluteGrob)
8481
S3method(guide_gengrob,default)
@@ -87,7 +84,6 @@ S3method(guide_merge,default)
8784
S3method(guide_train,default)
8885
S3method(guide_transform,default)
8986
S3method(heightDetails,titleGrob)
90-
S3method(heightDetails,zeroGrob)
9187
S3method(limits,Date)
9288
S3method(limits,POSIXct)
9389
S3method(limits,POSIXlt)
@@ -149,7 +145,6 @@ S3method(vec_ptype2,mapped_discrete.factor)
149145
S3method(vec_ptype2,mapped_discrete.integer)
150146
S3method(vec_ptype2,mapped_discrete.mapped_discrete)
151147
S3method(widthDetails,titleGrob)
152-
S3method(widthDetails,zeroGrob)
153148
export("%+%")
154149
export("%+replace%")
155150
export(.data)

R/grob-null.R

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,6 @@
55
zeroGrob <- function() .zeroGrob
66

77
.zeroGrob <- NULL
8-
on_load(.zeroGrob <- grob(cl = "zeroGrob", name = "NULL"))
8+
on_load(.zeroGrob <- add_class(nullGrob(), "zeroGrob"))
99

10-
#' @export
11-
#' @method widthDetails zeroGrob
12-
widthDetails.zeroGrob <- function(x) unit(0, "cm")
13-
#' @export
14-
#' @method heightDetails zeroGrob
15-
heightDetails.zeroGrob <- function(x) unit(0, "cm")
16-
#' @export
17-
#' @method grobWidth zeroGrob
18-
grobWidth.zeroGrob <- function(x) unit(0, "cm")
19-
#' @export
20-
#' @method grobHeight zeroGrob
21-
grobHeight.zeroGrob <- function(x) unit(0, "cm")
22-
#' @export
23-
#' @method drawDetails zeroGrob
24-
drawDetails.zeroGrob <- function(x, recording) {}
25-
26-
is.zero <- function(x) is.null(x) || inherits(x, "zeroGrob")
10+
is.zero <- function(x) is.null(x) || inherits(x, "null")

R/utilities.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,3 +959,12 @@ compute_data_size <- function(data, size, default = 0.9,
959959
data[[target]] <- res * (default %||% 0.9)
960960
data
961961
}
962+
963+
add_class <- function(x, new_class) {
964+
new_class <- setdiff(new_class, class(x))
965+
if (length(new_class) < 1) {
966+
return(x)
967+
}
968+
class(x) <- union(new_class, class(x))
969+
x
970+
}

0 commit comments

Comments
 (0)