Skip to content
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

generic device support #319

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

coolbutuseless
Copy link

This is a rough implementation of code to allow for more output devices (See Issue #318).

The user already specifies the character string for the 'device'. Rather than the existing 'switch()' statement to pick the device, use 'get()'.

Also allow the user to explicitly specify the file suffix if wanted, but by default choose the natural suffix for the devices that it knows about already.

@MilesMcBain
Copy link

Nice one @coolbutuseless!

One comment: I tried to test this branch and found I couldn't use Cairo::CairoPNG as a device because device is converted to lower case here in prepare.args:

args$device <- tolower(device %?% chunk_args$device %||% getOption('gganimate.device', 'png'))
and thus get can't find 'cairopng'.

Move that into the switch maybe?

@thomasp85, I'm not sure if you're aware but R graphics look pretty awful out of box on Windows due to lack of anti-aliasing on devices that are supported there. One way around this is to use the devices in the Cairo package.

It would be really sweet to be able to set this as my device with gganimate and get anti-aliasing in my animations. Here's a quick example I made that's looking pretty retro:
anim_no_anti_alias

@MilesMcBain
Copy link

MilesMcBain commented Aug 5, 2019

I made a quick change to @coolbutuseless's branch to show you the difference, rendering with Cairo::CairoPNG on Windows:
anim_with_anti_aliasing

In doing so I noticed one additional flaw this implementation which is you need have the library loaded that contains the device i.e. get("Cairo::CairoPNG") doesn't work while get("CairoPNG") does.

Edit: ragg::agg_png also looking very spiffy 👍

@jonspring
Copy link

jonspring commented Aug 5, 2019 via email

@MilesMcBain
Copy link

@jonspring that's an interesting suggestion I didn't know you could instantiate a Cairo device on Windows using an arg to dev().

I think this PR still stands regardless and the bugs I found still need to be addressed.

Also maybe using type this way should make it into the documentation? An example in animate()?

@thomasp85
Copy link
Owner

Yeah, the type argument is def the way to go - I also think that is how most people use Cairo in general (I could be wrong).

I’m pretty sure I’m not going to accept this PR. Searching for functions passed as strings is really not a good idea IMO. I’ll have to think about a good way to allow arbitrary devices though

@MilesMcBain
Copy link

Maybe you're right about type, I'm still new to the pain of R on Windows.

When I said I think this PR still stands I meant the concept. The implementation has issues for sure.

Could we not just pass a function? If you can create a function that would return the 'current' device for which you use a string now, I think it could work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants