Skip to content

Commit 762cb1a

Browse files
committed
draw_key_polygon() observes outline.type
1 parent af6f4e8 commit 762cb1a

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

R/legend-draw.R

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,57 @@ draw_key_polygon <- function(data, params, size) {
6767

6868
lwd <- data$linewidth %||% 0
6969

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+
7080
grob <- rectGrob(
71-
width = unit(1, "npc") - unit(lwd, "mm"),
81+
width = unit(1, "npc") - unit(lwd, "mm"),
7282
height = unit(1, "npc") - unit(lwd, "mm"),
7383
gp = gg_par(
74-
col = data$colour %||% NA,
84+
col = colour %||% NA,
7585
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
8087
))
8188

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+
82121
# Magic number is 5 because we convert mm to cm (divide by 10) but we
83122
# draw two lines in each direction (times 2)
84123
attr(grob, "width") <- lwd / 5

tests/testthat/_snaps/stat-align/align-two-areas-with-cliff.svg

Lines changed: 4 additions & 2 deletions
Loading

tests/testthat/_snaps/stat-align/align-two-areas-with-pos-neg-y.svg

Lines changed: 4 additions & 2 deletions
Loading

tests/testthat/_snaps/stat-align/align-two-areas.svg

Lines changed: 4 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)