-
Notifications
You must be signed in to change notification settings - Fork 18
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
General Layer Rasteriser #17
Conversation
version 0.1.9
fix vignettes URL
Thanks for this I should have clarified: it's best to create PRs against develop.
I actually think it's fine to add them as dependencies (and change the code to reflect this). They're both CRAN packages. |
Alright, I moved ragg/png from suggests to import and dropped the |
Thanks for this @teunbrand @VPetukhov and I will review the PR within a few days. Naturally, we'll have to update the vignettes as well. |
Thanks so much, @teunbrand ! This is so elegant, that I need to think more about it :) Sorry for reacting slow. |
Sure, no worries, I'm not in a hurry. Thanks for the kind words. If there are pieces of code that are unclear to you, feel free to ask :) |
@evanbiederstedt , I'm merging the PR. Could you please then do the changes that we discussed over e-mail? |
Yes, apologies for the delays on this front.
Will do. I'll keep you both informed of the PR. |
Thanks so much! |
Hi everyone,
TL;DR: The scope of this PR is to add one user facing function
rasterise()
, which goal is to convert any ggplot2 layer into a layer that produces rasterised output.However, the only thing
rasterise()
does is to wrap thedraw_panel()
method of the input layer to catch the produced grob and attach relevant attributes to the grob. The important bit is that the grob gains an extra class that we can use as a hook to render the grob differently.The rendering of the grob is done in
makeContext.rasteriser()
, which is an S3 method for thegrid::makeContext()
generic. When grid renders graphics it callsmakeContext()
on the graphical object, which we have overwritten here to have the rasterisation take place.The main advantage of this strategy over rasterising in the
draw_panel()
method is that the final dimensions of the plot are known at this step in the drawing process. Therefore we can use these dimensions to get absolute width/height information (rather than relative) about the drawing panel, and thus rasterise the graphical object without distortions (see for example #4).Here are a couple of features:
ragg_png
option to work around the alpha blending.I know it is not good programming etiquette to change things in the description, but I did and because of the following reasons. I imported the grid package, which was already being used in for example
geom_point_rast()
but I needed ggrastr's namespace to see themakeContext()
generic in the grid package. In order for this to happen I needed to add grid to the imports. Also I've included ragg and png to the suggests, as they are not required to run the functions but offer extra functionality. To avoid adding a hard dependency, they've been put into the suggests.Anyway, I think that is most of the things I should probably explain. Let me know if you have any questions, what you think, particularly if you're okay with the changes I made to the description and whether these functions can find a good fit here in the package. Also feel free to take the function for a spin and review the code yourself.
Best,
Teun