@@ -244,7 +244,7 @@ GuideLegend <- ggproto(
244
244
245
245
available_aes = " any" ,
246
246
247
- hashables = exprs(title , key $ .label , direction , name ),
247
+ hashables = exprs(title , key $ .label , name ),
248
248
249
249
elements = list (
250
250
background = " legend.background" ,
@@ -260,14 +260,10 @@ GuideLegend <- ggproto(
260
260
),
261
261
262
262
extract_params = function (scale , params ,
263
- title = waiver(), direction = NULL , ... ) {
263
+ title = waiver(), ... ) {
264
264
params $ title <- scale $ make_title(
265
265
params $ title %| W | % scale $ name %| W | % title
266
266
)
267
- params $ direction <- arg_match0(
268
- params $ direction %|| % direction ,
269
- c(" horizontal" , " vertical" ), arg_nm = " direction"
270
- )
271
267
if (isTRUE(params $ reverse %|| % FALSE )) {
272
268
params $ key <- params $ key [nrow(params $ key ): 1 , , drop = FALSE ]
273
269
}
@@ -291,17 +287,26 @@ GuideLegend <- ggproto(
291
287
},
292
288
293
289
# Arrange common data for vertical and horizontal legends
294
- get_layer_key = function (params , layers ) {
290
+ process_layers = function (self , params , layers , data = NULL ) {
291
+
292
+ include <- vapply(layers , function (layer ) {
293
+ aes <- matched_aes(layer , params )
294
+ include_layer_in_guide(layer , aes )
295
+ }, logical (1 ))
296
+
297
+ if (! any(include )) {
298
+ return (NULL )
299
+ }
300
+
301
+ self $ get_layer_key(params , layers [include ], data [include ])
302
+ },
303
+
304
+ get_layer_key = function (params , layers , data ) {
295
305
296
306
decor <- lapply(layers , function (layer ) {
297
307
298
308
matched_aes <- matched_aes(layer , params )
299
309
300
- # Check if this layer should be included
301
- if (! include_layer_in_guide(layer , matched_aes )) {
302
- return (NULL )
303
- }
304
-
305
310
if (length(matched_aes ) > 0 ) {
306
311
# Filter out aesthetics that can't be applied to the legend
307
312
n <- lengths(layer $ aes_params , use.names = FALSE )
@@ -338,14 +343,15 @@ GuideLegend <- ggproto(
338
343
339
344
# Remove NULL geoms
340
345
params $ decor <- compact(decor )
341
-
342
- if (length(params $ decor ) == 0 ) {
343
- return (NULL )
344
- }
345
346
return (params )
346
347
},
347
348
348
349
setup_params = function (params ) {
350
+ params $ direction <- arg_match0(
351
+ params $ direction %|| % direction ,
352
+ c(" horizontal" , " vertical" ), arg_nm = " direction"
353
+ )
354
+
349
355
if (" title.position" %in% names(params )) {
350
356
params $ title.position <- arg_match0(
351
357
params $ title.position %|| %
0 commit comments