-
Notifications
You must be signed in to change notification settings - Fork 794
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
Integrate vl-convert for saving to svg and png #2701
Conversation
This is exciting! My thoughts on your two questions:
|
Thanks for the notes @joelostblom.
|
I agree with you and personally I don't see much of a use for PDF when svg is working fine. I imagine that there might be some people relying on PDF export in altair since it still is a more familiar format, so we would just need to include a note in the docs/changelog about how to convert SVG to PDF or how to use SVG directly when in need of vector graphics for those not familiar with it (I'm sure there is some existing resource to link to). Especially if we decide to replace altair_saver with vl-convert as the recommend way to save images, which would have my vote based on what I have seen so far and that the repo is now officially part of the Vega org. |
I agree with @joelostblom that this should not rely on |
Ok, thanks for the feedback @joelostblom and @daylinmorgan! I'll fix the lint issue and add some tests soon. In the meantime, let me know if you have feedback on the patch itself. |
To make testing easier, I added an It defaults to If this approach looks good, I'll update the documentation |
Hi @jonmmease, nice work! I've a question. I saw this comment in another repo deeplook/svglib#207 (comment). It uses another approach to convert svg into png. It goes from svg to pdf and then from pdf to png.. Surely cumbersome, but it also has a few things that might be interesting here.
There are also disadvantages, which are working correctly with In no means I'm saying we should use that option, but are there things in there that we can benefit from? |
|
Lots of excellent info, thanks for sharing @daylinmorgan! |
Thanks for the notes @mattijn, I've played with svglib+reportlab a bit as an approach to generate PDFs. It worked well for simple figures, but I didn't pursue it further what I saw that it doesn't support gradients. This may be another good reason to introduce the |
Another option, that I'm totally fine with, would be to only expose the |
I'm fine with the current approach. No need to expose svg-only. Thanks for the clarifications! |
I fixed the flake8 lint and updated the image export documentation to include info on vl-convert and the new This is good to go from my side, let me know if there's anything else you'd like to see done here before merging. |
One thing to note, in 925ca3e I removed the installation of |
Do the docs currently use PNGs for the static figures? |
The gallery thumbnails are static images |
Will the changes in this PR results that the example-specs are tested against both |
The It looks like The vl-convert test suite does this for a handful of vega-lite specifications, and we could certainly do that here as well if we're comfortable committing the collection of baseline PNGs to the repository. |
If you can change the |
Thanks for the changes! Your branch is a bit behind with the main repo. Since this PR there have been 8 other commits that were merged. can you synchronise your branch with master? |
Branch updated in a163f8f |
Thanks! All tests are passing. Merging. While this is in master, you still have sufficient time to work on vega/vl-convert#29 to make it conda/mamba installable. This is great, thanks again! |
@jonmmease I noticed that there another test where we should probably add vl-convert as an alternative to altair-saver. Would you be able to put up a PR changing this file to also include the appropriate vl-convert test and I can review? |
sure! |
Done over in #2784 |
This is incredible! Thanks for all the hard work everyone! What release is this scheduled for? |
Thanks @mcp292, this will be included in Altair 5 (which doesn't have a firm release timeline unfortunately). But you can start using VlConvert directly in the meantime. See the Altair examples toward the end of https://github.com/vega/vl-convert/blob/main/vl-convert-python/notebooks/convert_vegalite.ipynb. |
Thanks for that @jonmmease, and thank you especially for moving this improvement forward! I noticed When it is included in Altair 5, will On a separate note, I found it interesting that the library is written in Rust. Is there a form of Altair for Rust? What does it replace pandas with? |
Hi @mcp292, the default of 1 for the scale parameter is applied in the Rust layer: Scale is optional in |
That answers all my questions! Thanks again @jonmmease! |
Really cool to see an implementation that is fully installed from pypi! I've finally gotten the node packages brought into my corporate firewalled VM environment for the node implementation of altair_saver, to find out the rendering is pretty slow compared to matplotlib. For my test example (large scatterplot) it was ~8s using altair_saver versus ~3s using matplotlib. I can't find a whole lot of discussion on it, but it seems that re-svg is quicker at rendering than node-canvas. Has anyone done a speed comparison between this vl-convert implementation and altair_saver? |
Hi @bodacious-bill, unfortunately I don't think resvg is faster that node canvas for the case of scatter plots (it may even be a bit slower). This is listed as a limitation in the vl-convert README. |
Thanks for the quick response! I suppose then I'll have to just stick to matplotlib for static chart generation. |
Alternative for saving PNG and SVG vega/altair#2701
Updated to Altair 5, this is working perfectly!! Thank you all for the hard work and the clever approach! Works seamlessly. |
Thanks for taking the time to let us know @mcp292, that's great to hear! |
This PR adds support for saving Altair charts to SVG and PNG static images using the VlConvert Python package.
See #2662 (opened by @mcp292) for some background on the need for a simpler method for exporting charts as static images.
See https://medium.com/@jonmmease/introducing-vlconvert-c763f0076e89 for background on how VlConvert works, and how it is able to avoid the need for external dependencies like selenium or Node.js.
Example:
Questions:
cc @joelostblom @mattijn @daylinmorgan