Skip to content

Instantly share code, notes, and snippets.

@ningunaparte
ningunaparte / README.md
Last active December 14, 2015 12:33 — forked from mbostock/.block
Save SVG as PNG

Say you have an SVG built dynamically on the client by D3. Now say you want to save it to a static PNG as a fallback for old browsers. There are lots of ways to do this using alternative renderers (such as Batik and PhantomJS), but what if you want your browser to do it, so that you the static PNG matches the dynamic SVG exactly, down to the subpixel, including transparency?

Here’s how.

1. Save as SVG.

Use the SVG Crowbar bookmarklet to save the SVG to a file. Call this file “fallback.svg”. Open the SVG in your browser to verify that it looks right.

SVG Crowbar helpfully inlines any stylesheets you may have on the page, but you might find you need to edit a few of the styles by hand to get things to look right. For example, the font-family “sans-serif” won’t work in an SVG image, even though it works when the SVG is built client-side; you’ll have to make the font name explicit, s

@ningunaparte
ningunaparte / README.md
Last active August 29, 2015 14:25 — forked from mbostock/.block
Bubble Chart

Bubble charts encode data in the area of circles. Although less perceptually-accurate than bar charts, they can pack hundreds of values into a small space. Implementation based on work by Jeff Heer. Data shows the Flare class hierarchy, also courtesy Jeff Heer.