Skip to content

Do not change order of positive and negative values in PositionStack #3471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2019
Merged
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
2 changes: 1 addition & 1 deletion R/position-stack.r
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ PositionStack <- ggproto("PositionStack", Position,
)
}

rbind(neg, pos)
rbind(neg, pos)[match(seq_len(nrow(data)), c(which(negative), which(!negative))),]
Copy link
Member

Choose a reason for hiding this comment

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

I don't see immediately that this is always correct. Can there be problems with NAs? Or will NAs never reach this point?

Copy link
Member Author

Choose a reason for hiding this comment

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

An NA value in ymax is pretty nonsensical and would also have broken the previous code. I can put in some guarding if you’d like nonetheless

Copy link
Member

Choose a reason for hiding this comment

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

No strong opinion either way. Just make sure to look into why the CI builds fail.

Copy link
Member Author

Choose a reason for hiding this comment

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

The failures are due to the downstream changes in sf, which have been fixed in master but not yet merged into the v3.2.1-rc branch

}
)

Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-position-stack.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ test_that("negative and positive values are handled separately", {
p <- ggplot(df, aes(x, y, fill = factor(g))) + geom_col()
dat <- layer_data(p)

expect_equal(dat$ymin[dat$x == 1], c(-1, 0, 1))
expect_equal(dat$ymax[dat$x == 1], c(0, 1, 2))
expect_equal(dat$ymin[dat$x == 1], c(0, -1, 1))
expect_equal(dat$ymax[dat$x == 1], c(1, 0, 2))

expect_equal(dat$ymin[dat$x == 2], c(-3, 0))
expect_equal(dat$ymax[dat$x == 2], c(0, 2))
expect_equal(dat$ymin[dat$x == 2], c(0, -3))
expect_equal(dat$ymax[dat$x == 2], c(2, 0))
})

test_that("can request reverse stacking", {
Expand All @@ -36,7 +36,7 @@ test_that("can request reverse stacking", {
p <- ggplot(df, aes(1, y, fill = g)) +
geom_col(position = position_stack(reverse = TRUE))
dat <- layer_data(p)
expect_equal(dat$ymin, c(-2, -3, 0, 2))
expect_equal(dat$ymin, c(-2, 0, -3, 2))
})

test_that("data with no extent is stacked correctly", {
Expand Down