@@ -67,18 +67,57 @@ draw_key_polygon <- function(data, params, size) {
67
67
68
68
lwd <- data $ linewidth %|| % 0
69
69
70
+ outline_type <- params $ outline.type %|| % " full"
71
+ colour <- switch (outline_type , full = data $ colour , NA )
72
+
73
+ common_gp <- list (
74
+ lty = data $ linetype %|| % 1 ,
75
+ lwd = lwd ,
76
+ linejoin = params $ linejoin %|| % " mitre" ,
77
+ lineend = params $ lineend %|| % " butt"
78
+ )
79
+
70
80
grob <- rectGrob(
71
- width = unit(1 , " npc" ) - unit(lwd , " mm" ),
81
+ width = unit(1 , " npc" ) - unit(lwd , " mm" ),
72
82
height = unit(1 , " npc" ) - unit(lwd , " mm" ),
73
83
gp = gg_par(
74
- col = data $ colour %|| % NA ,
84
+ col = colour %|| % NA ,
75
85
fill = fill_alpha(data $ fill %|| % " grey20" , data $ alpha ),
76
- lty = data $ linetype %|| % 1 ,
77
- lwd = lwd ,
78
- linejoin = params $ linejoin %|| % " mitre" ,
79
- lineend = params $ lineend %|| % " butt"
86
+ !!! common_gp
80
87
))
81
88
89
+ draw_partial_outline <-
90
+ outline_type %in% c(" upper" , " lower" , " both" ) &&
91
+ ! is.null(data $ colour ) && ! all(is.na(data $ colour )) &&
92
+ ! all(lwd < = 0 ) &&
93
+ ! all((data $ linetype %|| % 1 ) %in% c(0 , " none" ))
94
+
95
+ if (draw_partial_outline ) {
96
+ gp <- gg_par(col = data $ colour , !!! common_gp )
97
+ low <- unit(0 , " npc" ) + unit(0.5 * lwd , " mm" )
98
+ high <- unit(1 , " npc" ) - unit(0.5 * lwd , " mm" )
99
+ args <- switch (
100
+ outline_type ,
101
+ upper = list (
102
+ x0 = low , x1 = high , y0 = high , y1 = high , gp = gp
103
+ ),
104
+ lower = list (
105
+ x0 = low , x1 = high , y0 = low , y1 = low , gp = gp
106
+ ),
107
+ both = list (
108
+ x0 = unit.c(low , low ), x1 = unit.c(high , high ),
109
+ y0 = unit.c(low , high ), y1 = unit.c(low , high ),
110
+ gp = gp
111
+ )
112
+ )
113
+ if (identical(params $ orientation , " y" )) {
114
+ args <- rename(args , c(x0 = " y0" , x1 = " y1" , y0 = " x0" , y1 = " x1" ))
115
+ }
116
+
117
+ segments <- inject(segmentsGrob(!!! args ))
118
+ grob <- grobTree(grob , segments )
119
+ }
120
+
82
121
# Magic number is 5 because we convert mm to cm (divide by 10) but we
83
122
# draw two lines in each direction (times 2)
84
123
attr(grob , " width" ) <- lwd / 5
0 commit comments