Skip to content

Commit 870e5f8

Browse files
committed
clarify retrace.first.points only when basic polygon
1 parent 8b03e90 commit 870e5f8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

R/trace_generation.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,17 +428,21 @@ group2NA <- function(g, geom) {
428428
is.group <- names(g$data) == "group"
429429
poly.na.list <- list()
430430
forward.i <- seq_along(poly.list)
431+
## When group2NA is called on geom_polygon (or geom_rect, which is
432+
## treated as a basic polygon), we need to retrace the first points
433+
## of each group, see https://github.com/ropensci/plotly/pull/178
434+
retrace.first.points <- g$geom == "polygon"
431435
for (i in forward.i) {
432436
no.group <- poly.list[[i]][, !is.group, drop=FALSE]
433437
na.row <- no.group[1, ]
434438
na.row[, c("x", "y")] <- NA
435-
retrace.first <- if(g$geom %in% c("polygon", "rect")){
439+
retrace.first <- if(retrace.first.points){
436440
no.group[1,]
437441
}
438442
poly.na.list[[paste(i, "forward")]] <-
439443
rbind(no.group, retrace.first, na.row)
440444
}
441-
if(g$geom %in% c("polygon", "rect")){
445+
if(retrace.first.points)){
442446
backward.i <- rev(forward.i[-1])[-1]
443447
for(i in backward.i){
444448
no.group <- poly.list[[i]][1, !is.group, drop=FALSE]

0 commit comments

Comments
 (0)