Skip to content

Commit

Permalink
Fix #314
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Jan 16, 2024
1 parent 5e7907d commit 5d70067
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Imports:
vctrs,
systemfonts
LinkingTo: Rcpp, RcppEigen
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
Suggests:
sessioninfo,
concaveman,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggforce (development version)

* Fixed a bug that would cause reordering of data in some geoms (#314)

# ggforce 0.4.1

* Fixed a sanitizer error in the decent calculations used for the mark geoms
Expand Down
12 changes: 12 additions & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ combine_aes <- function(aes1, aes2) {
empty_data <- function(x) {
length(x) == 0 || nrow(x) == 0
}

# This function is like base::make.unique, but it
# maintains the ordering of the original names if the values
# are sorted.
make_unique <- function(x, sep = '.') {
if (!anyDuplicated(x)) return(x)
groups <- match(x, unique(x))
suffix <- unsplit(lapply(split(x, groups), seq_along), groups)
max_chars <- nchar(max(suffix))
suffix_format <- paste0('%0', max_chars, 'd')
paste0(x, sep, sprintf(suffix_format, suffix))
}
14 changes: 1 addition & 13 deletions R/arc_bar.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,25 +184,13 @@ geom_arc_bar <- function(mapping = NULL, data = NULL, stat = 'arc_bar',
)
}

# This function is like base::make.unique, but it
# maintains the ordering of the original names if the values
# are sorted.
make_unique <- function(x, sep = '.') {
if (!anyDuplicated(x)) return(x)
groups <- match(x, unique(x))
suffix <- unsplit(lapply(split(x, groups), seq_along), groups)
max_chars <- nchar(max(suffix))
suffix_format <- paste0('%0', max_chars, 'd')
paste0(x, sep, sprintf(suffix_format, suffix))
}

arcPaths <- function(data, n) {
trans <- radial_trans(c(0, 1), c(0, 2 * pi), pad = 0)
data <- data[data$start != data$end, ]
data$nControl <- ceiling(n / (2 * pi) * abs(data$end - data$start))
data$nControl[data$nControl < 3] <- 3
extraData <- !names(data) %in% c('r0', 'r', 'start', 'end', 'group')
data$group <- make_unique(as.character(data$group))
data$group <- make_unique(data$group)
paths <- lapply(seq_len(nrow(data)), function(i) {
path <- data_frame0(
a = seq(data$start[i], data$end[i], length.out = data$nControl[i]),
Expand Down
4 changes: 2 additions & 2 deletions R/diagonal.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ StatDiagonal <- ggproto('StatDiagonal', Stat,
compute_panel = function(data, scales, n = 100, strength = 0.5, flipped_aes = FALSE) {
if (empty_data(data)) return(data)
data <- flip_data(data, flipped_aes)
data$group <- make_unique(as.character(data$group))
data$group <- make_unique(data$group)
end <- data
end$x <- end$xend
end$y <- end$yend
Expand Down Expand Up @@ -212,7 +212,7 @@ StatDiagonal0 <- ggproto('StatDiagonal0', Stat,
compute_panel = function(data, scales, strength = 0.5, flipped_aes = FALSE) {
if (empty_data(data)) return(data)
data <- flip_data(data, flipped_aes)
data$group <- make_unique(as.character(data$group))
data$group <- make_unique(data$group)
end <- data
end$x <- end$xend
end$y <- end$yend
Expand Down
2 changes: 1 addition & 1 deletion R/ellipse.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ StatEllip <- ggproto('StatEllip', Stat,
},
compute_panel = function(self, data, scales, n = 360) {
if (empty_data(data)) return(data)
data$group <- make_unique(as.character(data$group))
data$group <- make_unique(data$group)
n_ellipses <- nrow(data)
data <- data[rep(seq_len(n_ellipses), each = n), ]
points <- rep(seq(0, 2 * pi, length.out = n + 1)[seq_len(n)],
Expand Down
2 changes: 1 addition & 1 deletion R/link.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ NULL
StatLink <- ggproto('StatLink', Stat,
compute_panel = function(data, scales, n = 100) {
extraCols <- !names(data) %in% c('x', 'y', 'xend', 'yend', 'group', 'PANEL')
data$group <- make_unique(as.character(data$group))
data$group <- make_unique(data$group)
data <- lapply(seq_len(nrow(data)), function(i) {
path <- data_frame0(
x = seq(data$x[i], data$xend[i], length.out = n),
Expand Down
2 changes: 1 addition & 1 deletion R/regon.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ StatRegon <- ggproto('StatRegon', Stat,
if (n %% 2 == 0) p <- p + p[2] / 2
p * 2 * pi
}))
data$group <- make_unique(as.character(data$group))
data$group <- make_unique(data$group)
data <- data[rep(seq_len(nrow(data)), data$sides), ]
x_tmp <- sin(pos) * data$r
y_tmp <- cos(pos) * data$r
Expand Down
2 changes: 1 addition & 1 deletion R/spiro.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ StatSpiro <- ggproto('StatSpiro', Stat,
if (is.null(data$x0)) data$x0 <- 0
if (is.null(data$y0)) data$y0 <- 0
n_spiro <- nrow(data)
data$group <- make_unique(as.character(data$group))
data$group <- make_unique(data$group)
if (is.null(revolutions)) {
revo <- attr(fractions(data$r / data$R), 'fracs')
revo <- as.numeric(sub('/.*$', '', revo))
Expand Down
2 changes: 1 addition & 1 deletion man/facet_grid_paginate.Rd

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

1 change: 1 addition & 0 deletions man/gather_set_data.Rd

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

3 changes: 2 additions & 1 deletion man/geom_autohistogram.Rd

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

2 changes: 2 additions & 0 deletions man/geom_delvor.Rd

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

2 changes: 2 additions & 0 deletions man/geom_mark_hull.Rd

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

3 changes: 2 additions & 1 deletion man/geom_sina.Rd

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

2 changes: 1 addition & 1 deletion man/scale_unit.Rd

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

2 changes: 1 addition & 1 deletion man/trans_reverser.Rd

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

0 comments on commit 5d70067

Please sign in to comment.