Skip to content

Commit 924b8b6

Browse files
committed
add linejoins
1 parent fcfdc69 commit 924b8b6

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

R/theme-defaults.R

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ theme_grey <- function(base_size = 11, base_family = "",
127127
# by others
128128
line = element_line(
129129
colour = ink, linewidth = base_line_size,
130-
linetype = 1, lineend = "butt"
130+
linetype = 1, lineend = "butt", linejoin = "round"
131131
),
132132
rect = element_rect(
133133
fill = paper, colour = ink,
134-
linewidth = base_rect_size, linetype = 1
134+
linewidth = base_rect_size, linetype = 1,
135+
linejoin = "round"
135136
),
136137
text = element_text(
137138
family = base_family, face = "plain",
@@ -153,7 +154,7 @@ theme_grey <- function(base_size = 11, base_family = "",
153154

154155
polygon = element_polygon(
155156
fill = paper, colour = ink,
156-
linewidth = base_rect_size, linetype = 1
157+
linewidth = base_rect_size, linetype = 1, linejoin = "round"
157158
),
158159

159160
geom = element_geom(
@@ -525,7 +526,7 @@ theme_void <- function(base_size = 11, base_family = "",
525526
line = element_blank(),
526527
rect = element_rect(
527528
fill = paper, colour = NA, linewidth = 0, linetype = 1,
528-
inherit.blank = FALSE
529+
inherit.blank = FALSE, linejoin = "round"
529530
),
530531
polygon = element_blank(),
531532
point = element_blank(),
@@ -614,11 +615,11 @@ theme_test <- function(base_size = 11, base_family = "",
614615
t <- theme(
615616
line = element_line(
616617
colour = ink, linewidth = base_line_size,
617-
linetype = 1, lineend = "butt"
618+
linetype = 1, lineend = "butt", linejoin = "round"
618619
),
619620
rect = element_rect(
620621
fill = paper, colour = ink,
621-
linewidth = base_rect_size, linetype = 1
622+
linewidth = base_rect_size, linetype = 1, linejoin = "round"
622623
),
623624
text = element_text(
624625
family = base_family, face = "plain",
@@ -633,7 +634,7 @@ theme_test <- function(base_size = 11, base_family = "",
633634
),
634635
polygon = element_polygon(
635636
fill = paper, colour = ink,
636-
linewidth = base_rect_size, linetype = 1
637+
linewidth = base_rect_size, linetype = 1, linejoin = "round"
637638
),
638639
title = element_text(family = header_family),
639640
spacing = unit(half_line, "pt"),

R/theme-elements.R

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ element_props <- list(
105105
linewidth = property_nullable(S7::class_numeric),
106106
linetype = property_nullable(S7::class_numeric | S7::class_character),
107107
lineend = property_choice(c("round", "butt", "square"), allow_null = TRUE),
108+
linejoin = property_choice(c("round", "mitre", "bevel"), allow_null = TRUE),
108109
shape = property_nullable(S7::class_numeric | S7::class_character),
109110
arrow = property_nullable(S7::new_S3_class("arrow") | S7::class_logical),
110111
arrow.fill = property_nullable(S7::class_character | S7::class_logical),
@@ -116,18 +117,20 @@ element_props <- list(
116117
#' @rdname element
117118
element_rect <- S7::new_class(
118119
"element_rect", parent = element,
119-
properties = element_props[c("fill", "colour", "linewidth", "linetype", "inherit.blank")],
120+
properties = element_props[c("fill", "colour",
121+
"linewidth", "linetype", "linejoin",
122+
"inherit.blank")],
120123
constructor = function(fill = NULL, colour = NULL, linewidth = NULL,
121-
linetype = NULL, color = NULL, inherit.blank = FALSE,
122-
size = deprecated()){
124+
linetype = NULL, color = NULL, linejoin = NULL,
125+
inherit.blank = FALSE, size = deprecated()){
123126
if (lifecycle::is_present(size)) {
124127
deprecate_warn0("3.4.0", "element_rect(size)", "element_rect(linewidth)")
125128
linewidth <- size
126129
}
127130
S7::new_object(
128131
S7::S7_object(),
129132
fill = fill, colour = color %||% colour,
130-
linewidth = linewidth, linetype = linetype,
133+
linewidth = linewidth, linetype = linetype, linejoin = linejoin,
131134
inherit.blank = inherit.blank
132135
)
133136
}
@@ -140,12 +143,14 @@ element_rect <- S7::new_class(
140143
element_line <- S7::new_class(
141144
"element_line", parent = element,
142145
properties = element_props[c(
143-
"colour", "linewidth", "linetype", "lineend", "arrow", "arrow.fill",
146+
"colour", "linewidth", "linetype", "lineend", "linejoin",
147+
"arrow", "arrow.fill",
144148
"inherit.blank"
145149
)],
146150
constructor = function(colour = NULL, linewidth = NULL, linetype = NULL,
147-
lineend = NULL, color = NULL, arrow = NULL,
148-
arrow.fill = NULL, inherit.blank = FALSE, size = deprecated()) {
151+
lineend = NULL, color = NULL, linejoin = NULL,
152+
arrow = NULL, arrow.fill = NULL,
153+
inherit.blank = FALSE, size = deprecated()) {
149154
if (lifecycle::is_present(size)) {
150155
deprecate_warn0("3.4.0", "element_line(size)", "element_line(linewidth)")
151156
linewidth <- size
@@ -155,6 +160,7 @@ element_line <- S7::new_class(
155160
S7::S7_object(),
156161
colour = colour,
157162
linewidth = linewidth, linetype = linetype, lineend = lineend,
163+
linejoin = linejoin,
158164
arrow = arrow %||% FALSE,
159165
arrow.fill = arrow.fill %||% colour,
160166
inherit.blank = inherit.blank
@@ -212,15 +218,16 @@ element_text <- S7::new_class(
212218
element_polygon <- S7::new_class(
213219
"element_polygon", parent = element,
214220
properties = element_props[c(
215-
"fill", "colour", "linewidth", "linetype", "inherit.blank"
221+
"fill", "colour", "linewidth", "linetype", "linejoin", "inherit.blank"
216222
)],
217223
constructor = function(fill = NULL, colour = NULL, linewidth = NULL,
218-
linetype = NULL, color = NULL, inherit.blank = FALSE) {
224+
linetype = NULL, color = NULL, linejoin = NULL,
225+
inherit.blank = FALSE) {
219226
colour <- color %||% colour
220227
S7::new_object(
221228
S7::S7_object(),
222229
fill = fill, colour = color %||% colour, linewidth = linewidth,
223-
linetype = linetype, inherit.blank = inherit.blank
230+
linetype = linetype, linejoin = linejoin, inherit.blank = inherit.blank
224231
)
225232
}
226233
)
@@ -412,17 +419,19 @@ S7::method(element_grob, element_blank) <- function(element, ...) zeroGrob()
412419

413420
S7::method(element_grob, element_rect) <-
414421
function(element, x = 0.5, y = 0.5, width = 1, height = 1,
415-
fill = NULL, colour = NULL, linewidth = NULL, linetype = NULL,
422+
fill = NULL, colour = NULL,
423+
linewidth = NULL, linetype = NULL, linejoin = NULL,
416424
..., size = deprecated()) {
417425

418426
if (lifecycle::is_present(size)) {
419427
deprecate_warn0("3.4.0", "element_grob.element_rect(size)", "element_grob.element_rect(linewidth)")
420428
linewidth <- size
421429
}
422430

423-
gp <- gg_par(lwd = linewidth, col = colour, fill = fill, lty = linetype)
431+
gp <- gg_par(lwd = linewidth, col = colour, fill = fill, lty = linetype, linejoin = linejoin)
424432
element_gp <- gg_par(lwd = element@linewidth, col = element@colour,
425-
fill = element@fill, lty = element@linetype)
433+
fill = element@fill, lty = element@linetype,
434+
linejoin = element@linejoin)
426435

427436
rectGrob(x, y, width, height, gp = modify_list(element_gp, gp), ...)
428437
}
@@ -458,7 +467,7 @@ S7::method(element_grob, element_text) <-
458467
S7::method(element_grob, element_line) <-
459468
function(element, x = 0:1, y = 0:1,
460469
colour = NULL, linewidth = NULL, linetype = NULL, lineend = NULL,
461-
arrow.fill = NULL,
470+
linejoin = NULL, arrow.fill = NULL,
462471
default.units = "npc", id.lengths = NULL, ..., size = deprecated()) {
463472

464473
if (lifecycle::is_present(size)) {
@@ -479,12 +488,12 @@ S7::method(element_grob, element_line) <-
479488
# The gp settings can override element_gp
480489
gp <- gg_par(
481490
col = colour, fill = arrow.fill %||% colour,
482-
lwd = linewidth, lty = linetype, lineend = lineend
491+
lwd = linewidth, lty = linetype, lineend = lineend, linejoin = linejoin
483492
)
484493
element_gp <- gg_par(
485494
col = element@colour, fill = element@arrow.fill %||% element@colour,
486495
lwd = element@linewidth, lty = element@linetype,
487-
lineend = element@lineend
496+
lineend = element@lineend, linejoin = element@linejoin
488497
)
489498

490499
polylineGrob(
@@ -498,13 +507,15 @@ S7::method(element_grob, element_polygon) <-
498507
function(element, x = c(0, 0.5, 1, 0.5),
499508
y = c(0.5, 1, 0.5, 0), fill = NULL,
500509
colour = NULL, linewidth = NULL,
501-
linetype = NULL, ...,
510+
linetype = NULL, linejoin = NULL, ...,
502511
id = NULL, id.lengths = NULL,
503512
pathId = NULL, pathId.lengths = NULL) {
504513

505-
gp <- gg_par(lwd = linewidth, col = colour, fill = fill, lty = linetype)
514+
gp <- gg_par(lwd = linewidth, col = colour, fill = fill,
515+
lty = linetype, linejoin = linejoin)
506516
element_gp <- gg_par(lwd = element@linewidth, col = element@colour,
507-
fill = element@fill, lty = element@linetype)
517+
fill = element@fill, lty = element@linetype,
518+
linejoin = element@linejoin)
508519
pathGrob(
509520
x = x, y = y, gp = modify_list(element_gp, gp), ...,
510521
# We swap the id logic so that `id` is always the (super)group id

0 commit comments

Comments
 (0)