@@ -147,7 +147,7 @@ element_nfl_headshot <- S7::new_class(
147147# ' @importFrom ggpath element_path
148148ggpath :: element_path
149149
150- S7 :: method(draw_element , element_nfl_logo ) <- function (
150+ S7 :: method(element_grob , element_nfl_logo ) <- function (
151151 element ,
152152 label = " " ,
153153 x = NULL ,
@@ -171,22 +171,47 @@ S7::method(draw_element, element_nfl_logo) <- function(
171171 )
172172 }
173173
174- S7 :: method(draw_element , ggpath :: element_path )(
174+ # This will likely break in a future ggplot2 release as they
175+ # currently work with a weird mix of S3 and S7. element_grob is a S3 generic
176+ # but the methods are S7. However, I can't call the method from ggpath with
177+ # S7::method(element_grob, ggpath::element_path)(...)
178+ # I think this should work and probably will work at some point in the future
179+ # in the meantime I change the class of element to dispatch to the ggpath
180+ # method for further processing.
181+ class(element ) <- c(
182+ " ggpath::element_path" ,
183+ " ggplot2::element_text" ,
184+ " ggplot2::element" ,
185+ " S7_object"
186+ )
187+
188+ ggplot2 :: element_grob(
175189 element = element ,
176190 label = image_list ,
177191 x = x ,
178192 y = y
179193 )
180194}
181195
182- S7 :: method(draw_element , element_nfl_wordmark ) <- function (
196+ S7 :: method(element_grob , element_nfl_wordmark ) <- function (
183197 element ,
184198 label = " " ,
185199 x = NULL ,
186200 y = NULL ,
187201 ...
188202) {
189- S7 :: method(draw_element , element_nfl_logo )(
203+ # see comment on weird S3/S7 mix in the above method
204+ # Note that I dispatch to the nflplotR method here before we move on
205+ # to ggpath
206+ class(element ) <- c(
207+ " nflplotR::element_nfl_logo" ,
208+ " ggpath::element_path" ,
209+ " ggplot2::element_text" ,
210+ " ggplot2::element" ,
211+ " S7_object"
212+ )
213+
214+ ggplot2 :: element_grob(
190215 element = element ,
191216 label = label ,
192217 x = x ,
@@ -196,7 +221,7 @@ S7::method(draw_element, element_nfl_wordmark) <- function(
196221 )
197222}
198223
199- S7 :: method(draw_element , element_nfl_headshot ) <- function (
224+ S7 :: method(element_grob , element_nfl_headshot ) <- function (
200225 element ,
201226 label = " " ,
202227 x = NULL ,
@@ -217,7 +242,15 @@ S7::method(draw_element, element_nfl_headshot) <- function(
217242 image_urls [is.na(image_urls )] <- na_headshot()
218243 }
219244
220- S7 :: method(draw_element , ggpath :: element_path )(
245+ # see comment on weird S3/S7 mix in the above method
246+ class(element ) <- c(
247+ " ggpath::element_path" ,
248+ " ggplot2::element_text" ,
249+ " ggplot2::element" ,
250+ " S7_object"
251+ )
252+
253+ ggplot2 :: element_grob(
221254 element = element ,
222255 label = image_urls ,
223256 x = x ,
0 commit comments