thomasp85 / ggforce

Accelerating ggplot2
https://ggforce.data-imaginist.com
Other
916 stars 105 forks source link

Possible bug in makeContent.shape when expand, radius= 0 #318

Open hughjonesd opened 7 months ago

hughjonesd commented 7 months ago

I'm trying to use the new shapeGrob export on the "experiment-rounded-rect" branch of hughjonesd/ggmagnify. I ran into an error, which I now can't reproduce, like this:

library(ggplot2)
library(ggmagnify)

ggp <- ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species, shape = Species))
ggp2 <- ggp + geom_point()

from <- c(2.5, 3.0, 5.5, 6.0)
to <- c(3.5, 4.5, 4.5, 5.5)
ggp2 + geom_magnify(from = from, to = to, corners = 0.05)

corners is passed into the radius argument to shapeGrob.

This did give the error:

Error in p$x : $ operator is invalid for atomic vectors

though now it seems to be ok :-/

Anyway, it seemed to happen when the radius and expand variables in makeContent.shape evaluated to 0 via the code in convertWidth (perhaps because of a small viewport?) If so, then the various polyoffset functions in makeContent.shape aren't called, and then the polygons variable ends up not set up correctly for some reason.

I'm sorry, this isn't a very useful bug report! But you might be able to understand what's happened better than me and work out a test case for this code path.

thomasp85 commented 7 months ago

While there may be an issue buried somewhere in there I'm unsure whether the shapeGrob is the right tool for it. Any reason why you aren't using the grid::roundrectGrob?

hughjonesd commented 7 months ago

Hmm. Maybe I hadn't heard of it... though maybe there was another reason. I'll take the hint and look at it, thanks!