Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lineend and linejoin params to geom_rect() and geom_tile() #3050

Merged
merged 18 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ core developer team.
* `geom_*()` and `stat_*()` now accepts purrr-style lambda notation
(@yutannihilation, #3138).

* `geom_tile()` and `geom_rect()` now draw rectangles without notches at the
corners. The style of the corner can be controlled by `linejoin` parameters
(@yutannihilation, #3050).

# ggplot2 3.1.0

## Breaking changes
Expand Down
14 changes: 11 additions & 3 deletions R/geom-rect.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
geom_rect <- function(mapping = NULL, data = NULL,
stat = "identity", position = "identity",
...,
linejoin = "mitre",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE) {
Expand All @@ -15,6 +16,7 @@ geom_rect <- function(mapping = NULL, data = NULL,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
linejoin = linejoin,
na.rm = na.rm,
...
)
Expand All @@ -31,7 +33,7 @@ GeomRect <- ggproto("GeomRect", Geom,

required_aes = c("xmin", "xmax", "ymin", "ymax"),

draw_panel = function(self, data, panel_params, coord) {
draw_panel = function(self, data, panel_params, coord, linejoin = "mitre") {
if (!coord$is_linear()) {
aesthetics <- setdiff(
names(data), c("x", "y", "xmin", "xmax", "ymin", "ymax")
Expand All @@ -58,7 +60,10 @@ GeomRect <- ggproto("GeomRect", Geom,
fill = alpha(coords$fill, coords$alpha),
lwd = coords$size * .pt,
lty = coords$linetype,
lineend = "butt"
linejoin = linejoin,
# `lineend` is a workaround for Windows and intentionally kept unexposed
# as an argument. (c.f. https://github.com/tidyverse/ggplot2/issues/3037#issuecomment-457504667)
lineend = if (identical(linejoin, "round")) "round" else "square"
)
))
}
Expand All @@ -69,7 +74,10 @@ GeomRect <- ggproto("GeomRect", Geom,


# Convert rectangle to polygon
# Useful for non-Cartesian coordinate systems where it's easy to work purely in terms of locations, rather than locations and dimensions.
# Useful for non-Cartesian coordinate systems where it's easy to work purely in
# terms of locations, rather than locations and dimensions. Note that, though
# `polygonGrob()` expects an open form, closed form is needed for correct
# munching (c.f. https://github.com/tidyverse/ggplot2/issues/3037#issuecomment-458406857).
#
# @keyword internal
rect_to_poly <- function(xmin, xmax, ymin, ymax) {
Expand Down
3 changes: 3 additions & 0 deletions R/geom-tile.r
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#' @eval rd_aesthetics("geom", "tile")
#' @inheritParams layer
#' @inheritParams geom_point
#' @inheritParams geom_segment
#' @export
#' @examples
#' # The most common use for rectangles is to draw a surface. You always want
Expand Down Expand Up @@ -57,6 +58,7 @@
geom_tile <- function(mapping = NULL, data = NULL,
stat = "identity", position = "identity",
...,
linejoin = "mitre",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE) {
Expand All @@ -69,6 +71,7 @@ geom_tile <- function(mapping = NULL, data = NULL,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
linejoin = linejoin,
na.rm = na.rm,
...
)
Expand Down
5 changes: 4 additions & 1 deletion R/legend-draw.r
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ draw_key_polygon <- function(data, params, size) {
fill = alpha(data$fill %||% "grey20", data$alpha),
lty = data$linetype %||% 1,
lwd = lwd * .pt,
linejoin = "mitre"
linejoin = params$linejoin %||% "mitre",
# `lineend` is a workaround for Windows and intentionally kept unexposed
# as an argument. (c.f. https://github.com/tidyverse/ggplot2/issues/3037#issuecomment-457504667)
lineend = if (identical(params$linejoin, "round")) "round" else "square"
))
}

Expand Down
10 changes: 6 additions & 4 deletions man/geom_tile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions tests/figs/creating-aesthetic-mappings/stat-count.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions tests/figs/creating-aesthetic-mappings/stat-identity.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions tests/figs/geom-violin/dodging-and-coord-flip.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading