Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
10 changes: 6 additions & 4 deletions R/geom-curve.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
GeomCurve <- ggproto(
"GeomCurve", GeomSegment,

draw_panel = function(data, panel_params, coord, curvature = 0.5, angle = 90,
ncp = 5, arrow = NULL, arrow.fill = NULL, lineend = "butt", na.rm = FALSE) {
draw_panel = function(data, panel_params, coord, curvature = 0.5, angle = 90, ncp = 5, shape = 0.5,
arrow = NULL, arrow.fill = NULL, lineend = "butt", na.rm = FALSE) {

if (!coord$is_linear()) {
cli::cli_warn("{.fn geom_curve} is not implemented for non-linear coordinates")
Expand All @@ -31,11 +31,13 @@ GeomCurve <- ggproto(

arrow.fill <- arrow.fill %||% trans$colour

square <- (ncp == 1 && angle == 90)

curveGrob(
trans$x, trans$y, trans$xend, trans$yend,
default.units = "native",
curvature = curvature, angle = angle, ncp = ncp,
square = FALSE, squareShape = 1, inflect = FALSE, open = TRUE,
curvature = curvature, angle = angle, ncp = ncp, shape = shape,
square = square, squareShape = 1, inflect = FALSE, open = TRUE,
gp = gg_par(
col = alpha(trans$colour, trans$alpha),
fill = alpha(arrow.fill, trans$alpha),
Expand Down
5 changes: 5 additions & 0 deletions man/geom_segment.Rd

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

24 changes: 24 additions & 0 deletions tests/testthat/test-geom-curve.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,27 @@ test_that("geom_curve flipping works", {
expect_doppelganger("flipped geom_curve", p + scale_y_reverse())

})

test_that("geom_curve shape works", {

df <- data.frame(x = c(1, 3), xend = c(2, 4), y = c(0, 1), yend = c(2, 1.5))

p_0 <- ggplot(df, aes(x, y, xend = xend, yend = yend)) +
geom_curve(arrow = arrow(), shape = 0, ncp = 1, curvature = 1)

# This will use `square = FALSE` in curveGrob because angle != 90
p_0_not_square <- ggplot(df, aes(x, y, xend = xend, yend = yend)) +
geom_curve(arrow = arrow(), shape = 0, ncp = 1, curvature = 1, angle = 60)

p_1 <- ggplot(df, aes(x, y, xend = xend, yend = yend)) +
geom_curve(arrow = arrow(), shape = 1)

p_m1 <- ggplot(df, aes(x, y, xend = xend, yend = yend)) +
geom_curve(arrow = arrow(), shape = -1, angle = 40)

expect_doppelganger("shape=0 geom_curve", p_0)
expect_doppelganger("shape=0 geom_curve", p_0_not_square)
expect_doppelganger("shape=1 geom_curve", p_1)
expect_doppelganger("shape=-1 geom_curve", p_m1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this 1 plot with 4 geom_curve() layers, each with something like aes(colour = "not square") that is indicative of the setting, so that it sort of becomes self-descriptive?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the tests indicate that the snapshot would need updating. Did you have an older svglite/vdiffr version when you generated the snapshots?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this 1 plot with 4 geom_curve() layers, each with something like aes(colour = "not square") that is indicative of the setting, so that it sort of becomes self-descriptive?

Done!

Also the tests indicate that the snapshot would need updating. Did you have an older svglite/vdiffr version when you generated the snapshots?

My bad, I forgot to add the snapshot entirely.


})
Loading