@@ -425,15 +425,63 @@ draw_key_timeseries <- function(data, params, size) {
425
425
data $ linetype <- 0
426
426
}
427
427
428
- grid :: linesGrob(
429
- x = c(0 , 0.4 , 0.6 , 1 ),
430
- y = c(0.1 , 0.6 , 0.4 , 0.9 ),
428
+ upper_x <- c(0 , 0.4 , 0.6 , 1 )
429
+ upper_y <- c(0.1 , 0.6 , 0.4 , 0.9 )
430
+
431
+ common_gp <- list (
432
+ lwd = data $ linewidth %|| % 0.5 ,
433
+ lty = data $ linetype %|| % 1 ,
434
+ lineend = params $ lineend %|| % " butt" ,
435
+ linejoin = params $ linejoin %|| % " round"
436
+ )
437
+
438
+ outline_type <- params $ outline.type
439
+ if (is.null(outline_type )) {
440
+ grob <- grid :: linesGrob(
441
+ x = upper_x ,
442
+ y = upper_y ,
443
+ gp = gg_par(
444
+ col = alpha(data $ colour %|| % data $ fill %|| % " black" , data $ alpha ),
445
+ !!! common_gp
446
+ )
447
+ )
448
+ return (grob )
449
+ }
450
+
451
+ colour <- if (identical(outline_type , " full" )) data $ colour else NA
452
+
453
+ grob <- grid :: polygonGrob(
454
+ x = c(0 , upper_x , 1 ),
455
+ y = c(0 , upper_y , 0 ),
431
456
gp = gg_par(
432
- col = alpha(data $ colour %|| % data $ fill %|| % " black" , data $ alpha ),
433
- lwd = data $ linewidth %|| % 0.5 ,
434
- lty = data $ linetype %|| % 1 ,
435
- lineend = params $ lineend %|| % " butt" ,
436
- linejoin = params $ linejoin %|| % " round"
457
+ col = colour %|| % NA ,
458
+ fill = alpha(data $ fill %|| % " black" , data $ alpha ),
459
+ !!! common_gp
437
460
)
438
461
)
462
+
463
+ draw_partial_outline <-
464
+ (outline_type %|| % " full" ) %in% c(" upper" , " lower" , " both" ) &&
465
+ ! is.null(data $ colour ) &&
466
+ ! all(is.na(data $ colour )) &&
467
+ ! all(data $ linewidth < = 0 ) &&
468
+ ! all((data $ linetype %|| % 1 ) %in% c(0 , " none" ))
469
+
470
+ if (draw_partial_outline ) {
471
+ gp <- gg_par(col = data $ colour , !!! common_gp )
472
+ args <- switch (
473
+ params $ outline.type ,
474
+ upper = list (x = upper_x , y = upper_y ),
475
+ lower = list (x = c(0 , 1 ), y = c(0 , 0 )),
476
+ both = list (
477
+ x = c(upper_x , 0 , 1 ),
478
+ y = c(upper_y , 0 , 0 ),
479
+ id.lengths = c(length(upper_x ), 2 )
480
+ )
481
+ )
482
+ lines <- inject(grid :: polylineGrob(!!! args , gp = gp ))
483
+ grob <- grobTree(grob , lines )
484
+ }
485
+
486
+ return (grob )
439
487
}
0 commit comments