Skip to content
Open
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
13 changes: 8 additions & 5 deletions R/geom_edge.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @importFrom ggforce interpolateDataFrame
#' @export
GeomEdgePath <- ggproto('GeomEdgePath', GeomPath,
draw_panel = function(self, data, panel_scales, coord, arrow = NULL,
draw_panel = function(self, data, panel_scales, coord, arrow = NULL, arrow.fill = NULL,
lineend = 'butt', linejoin = 'round', linemitre = 1,
na.rm = FALSE, interpolate = TRUE,
label_colour = 'black', label_alpha = 1, label_parse = FALSE,
Expand Down Expand Up @@ -84,9 +84,11 @@ GeomEdgePath <- ggproto('GeomEdgePath', GeomPath,
cli::cli_abort("{.fn {snake_class(self)}} can't have varying {.field edge_colour}, {.field edge_width}, and/or {.field edge_alpha} along the line when {.field edge_linetype} isn't solid")
}

arrow.fill <- arrow.fill %||% data$edge_colour

gp <- gpar(
col = alpha(data$edge_colour, data$edge_alpha),
fill = alpha(data$edge_colour, data$edge_alpha),
fill = alpha(arrow.fill, data$edge_alpha),
lwd = data$edge_width * .pt, lty = data$edge_linetype,
lineend = lineend, linejoin = linejoin, linemitre = linemitre
)
Expand Down Expand Up @@ -237,17 +239,18 @@ GeomEdgeParallelPath <- ggproto('GeomEdgeParallelPath', GeomEdgePath,
#' @importFrom grid gpar segmentsGrob
#' @export
GeomEdgeSegment <- ggproto('GeomEdgeSegment', GeomSegment,
draw_panel = function(data, panel_scales, coord, arrow = NULL, lineend = 'butt',
na.rm = FALSE) {
draw_panel = function(data, panel_scales, coord, arrow = NULL, arrow.fill = NULL,
lineend = 'butt', na.rm = FALSE) {
if (empty_data(data)) {
return(zeroGrob())
}
coord <- coord$transform(data, panel_scales)
arrow.fill <- arrow.fill %||% coord$edge_colour
segmentsGrob(coord$x, coord$y, coord$xend, coord$yend,
default.units = 'native',
gp = gpar(
col = alpha(coord$edge_colour, coord$edge_alpha),
fill = alpha(coord$edge_colour, coord$edge_alpha),
fill = alpha(arrow.fill, coord$edge_alpha),
lwd = coord$edge_width * .pt,
lty = coord$edge_linetype,
lineend = lineend
Expand Down
19 changes: 13 additions & 6 deletions R/geom_edge_link.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
#' along the edge direction. If 'across' the label will be written across the
#' edge direction.
#'
#' @param arrow.fill fill color to use for the arrow head (if closed). `NULL`
#' means use `colour` aesthetic.
#'
#' @param force_flip Logical. If `angle_calc` is either 'along' or 'across'
#' should the label be flipped if it is on it's head. Default to `TRUE`.
#'
Expand Down Expand Up @@ -185,7 +188,8 @@ StatEdgeLink2 <- ggproto('StatEdgeLink2', StatLink2,
#' @importFrom ggforce StatLink
#' @export
geom_edge_link <- function(mapping = NULL, data = get_edges('short'),
position = 'identity', arrow = NULL, n = 100,
position = 'identity', arrow = NULL, arrow.fill = NULL,
n = 100,
lineend = 'butt', linejoin = 'round', linemitre = 1,
label_colour = 'black', label_alpha = 1,
label_parse = FALSE, check_overlap = FALSE,
Expand All @@ -202,7 +206,8 @@ geom_edge_link <- function(mapping = NULL, data = get_edges('short'),
inherit.aes = FALSE,
params = expand_edge_aes(
list(
arrow = arrow, lineend = lineend, linejoin = linejoin,
arrow = arrow, arrow.fill = arrow.fill,
lineend = lineend, linejoin = linejoin,
linemitre = linemitre, na.rm = FALSE, n = n,
interpolate = FALSE,
label_colour = label_colour, label_alpha = label_alpha,
Expand All @@ -218,7 +223,8 @@ geom_edge_link <- function(mapping = NULL, data = get_edges('short'),
#' @importFrom ggforce StatLink2
#' @export
geom_edge_link2 <- function(mapping = NULL, data = get_edges('long'),
position = 'identity', arrow = NULL, n = 100,
position = 'identity', arrow = NULL, arrow.fill = NULL,
n = 100,
lineend = 'butt', linejoin = 'round', linemitre = 1,
label_colour = 'black', label_alpha = 1,
label_parse = FALSE, check_overlap = FALSE,
Expand All @@ -234,7 +240,8 @@ geom_edge_link2 <- function(mapping = NULL, data = get_edges('long'),
inherit.aes = FALSE,
params = expand_edge_aes(
list(
arrow = arrow, lineend = lineend, linejoin = linejoin,
arrow = arrow, arrow.fill = arrow.fill,
lineend = lineend, linejoin = linejoin,
linemitre = linemitre, na.rm = FALSE, n = n,
interpolate = TRUE,
label_colour = label_colour, label_alpha = label_alpha,
Expand All @@ -250,7 +257,7 @@ geom_edge_link2 <- function(mapping = NULL, data = get_edges('long'),
#' @importFrom ggforce StatLink2
#' @export
geom_edge_link0 <- function(mapping = NULL, data = get_edges(),
position = 'identity', arrow = NULL,
position = 'identity', arrow = NULL, arrow.fill = NULL,
lineend = 'butt', show.legend = NA, ...) {
mapping <- complete_edge_aes(mapping)
mapping <- aes_intersect(mapping, aes(x = x, y = y,
Expand All @@ -260,7 +267,7 @@ geom_edge_link0 <- function(mapping = NULL, data = get_edges(),
geom = GeomEdgeSegment, position = position,
show.legend = show.legend, inherit.aes = FALSE,
params = expand_edge_aes(
list(arrow = arrow, lineend = lineend, na.rm = FALSE, ...)
list(arrow = arrow, arrow.fill = arrow.fill, lineend = lineend, na.rm = FALSE, ...)
)
)
}