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
6 changes: 6 additions & 0 deletions R/geom_edge_bundle_force.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ StatEdgeBundleForce2 <- ggproto(
threshold = 0.6,
eps = 1e-8
) {
if (empty(data)) {
return(data_frame0())
}
data <- data[order(data$group), ]
edges <- cbind(
data$x[c(TRUE, FALSE)],
Expand Down Expand Up @@ -382,6 +385,9 @@ StatEdgeBundleForce0 <- ggproto(
threshold = 0.6,
eps = 1e-8
) {
if (empty(data)) {
return(data_frame0())
}
edges <- cbind(data$x, data$y, data$xend, data$yend)
edges <- force_bundle_mem(
edges,
Expand Down
6 changes: 6 additions & 0 deletions R/geom_edge_bundle_minimal.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ StatEdgeBundleMinimal2 <- ggproto(
weight_fac = 2,
tension = 1
) {
if (empty(data)) {
return(data_frame0())
}
graph <- .G()
nodes <- data_frame0(x = .N()$.ggraph_layout_x, y = .N()$.ggraph_layout_y)
data <- data[order(data$group), ]
Expand Down Expand Up @@ -321,6 +324,9 @@ StatEdgeBundleMinimal0 <- ggproto(
weight_fac = 2,
tension = 1
) {
if (empty(data)) {
return(data_frame0())
}
graph <- .G()
nodes <- data_frame0(x = .N()$.ggraph_layout_x, y = .N()$.ggraph_layout_y)
edges <- minimal_bundle_mem(
Expand Down
6 changes: 6 additions & 0 deletions R/geom_edge_bundle_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ StatEdgeBundlePath2 <- ggproto(
weight_fac = 2,
tension = 1
) {
if (empty(data)) {
return(data_frame0())
}
graph <- .G()
nodes <- data_frame0(x = .N()$.ggraph_layout_x, y = .N()$.ggraph_layout_y)
data <- data[order(data$group), ]
Expand Down Expand Up @@ -350,6 +353,9 @@ StatEdgeBundlePath0 <- ggproto(
weight_fac = 2,
tension = 1
) {
if (empty(data)) {
return(data_frame0())
}
graph <- .G()
nodes <- data_frame0(x = .N()$.ggraph_layout_x, y = .N()$.ggraph_layout_y)
from <- .E()$from[data$edge_id]
Expand Down
16 changes: 10 additions & 6 deletions R/geom_edge_elbow.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ StatEdgeElbow <- ggproto(
n = 100,
strength = 1
) {
if (empty(data)) {
return(data_frame0())
}

data$group <- make_unique(data$group)
if (data$circular[1] && n %% 2 == 1) {
n <- n + 1
Expand Down Expand Up @@ -234,9 +238,6 @@ StatEdgeElbow <- ggproto(
setup_data = function(data, params) {
data <- StatFilter$setup_data(data, params)
data <- remove_loop(data)
if (nrow(data) == 0) {
return(data)
}
Comment on lines -237 to -239

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Because data was returned regardless of the condition, I removed these.

data
},
default_aes = aes(filter = TRUE),
Expand Down Expand Up @@ -325,6 +326,9 @@ StatEdgeElbow2 <- ggproto(
n = 100,
strength = 1
) {
if (empty(data)) {
return(data_frame0())
}
pos_cols <- c('x', 'y', 'group', 'circular', 'direction', 'PANEL')
data <- data[order(data$group), ]
pos_data <- cbind(
Expand Down Expand Up @@ -359,9 +363,6 @@ StatEdgeElbow2 <- ggproto(
setup_data = function(data, params) {
data <- StatFilter$setup_data(data, params)
data <- remove_loop2(data)
if (nrow(data) == 0) {
return(data)
}
data
},
default_aes = aes(filter = TRUE),
Expand Down Expand Up @@ -442,6 +443,9 @@ StatEdgeElbow0 <- ggproto(
'StatEdgeElbow0',
Stat,
compute_panel = function(data, scales, flipped = FALSE, strength = 1) {
if (empty(data)) {
return(data_frame0())
}
data$group <- make_unique(data$group)
if (any(data$circular)) {
if (strength != 1) {
Expand Down
6 changes: 6 additions & 0 deletions R/geom_edge_link.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ StatEdgeLink2 <- ggproto(
}
StatLink2$setup_data(data, params)
},
compute_layer = function(data, params, layout) {
if (empty(data)) {
return(data)
}
StatLink2$compute_layer(data, params, layout)
},
Comment on lines +189 to +194

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Arguably it'd be better to handle this in ggforce::StatLink2.

default_aes = aes(filter = TRUE)
)
#' @rdname geom_edge_link
Expand Down
6 changes: 6 additions & 0 deletions R/geom_edge_parallel.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ StatEdgeParallel2 <- ggproto(
data$.position <- rep(edge_positions(data1, data2), each = 2)
StatLink2$setup_data(data, params)
},
compute_layer = function(data, params, layout) {
if (empty(data)) {
return(data)
}
StatEdgeLink2$compute_layer(data, params, layout)
},
required_aes = c('x', 'y', 'group', 'from', 'to'),
default_aes = aes(filter = TRUE),
extra_params = c('na.rm', 'n')
Expand Down
6 changes: 6 additions & 0 deletions R/geom_node_circle.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,11 @@ StatNodeCircle <- ggproto(
setup_data = function(data, params) {
StatFilter$setup_data(data, params)
},
compute_layer = function(data, params, layout) {
if (empty(data)) {
return(data)
}
StatCircle$compute_layer(data, params, layout)
},
default_aes = aes(filter = TRUE)
)
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,7 @@ snakeize <- function(x) {
snake_class <- function(x) {
snakeize(class(x)[1])
}

empty <- function(df) {
is.null(df) || nrow(df) == 0 || ncol(df) == 0 || inherits(df, "waiver")
}
Loading