{"id":16005792,"url":"https://github.com/thibaudcolas/chart-export-example","last_synced_at":"2026-05-05T23:32:40.742Z","repository":{"id":146980813,"uuid":"50963180","full_name":"thibaudcolas/chart-export-example","owner":"thibaudcolas","description":"An example of using various Node tools to create an SVG / PNG export from a D3 SVG+CSS chart","archived":false,"fork":false,"pushed_at":"2016-09-11T19:58:59.000Z","size":25,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-12T01:06:01.098Z","etag":null,"topics":["d3","electron","exporter","jsdom","svg"],"latest_commit_sha":null,"homepage":"https://thib.me/exporting-d3-charts-to-svg-and-png","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thibaudcolas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-03T00:51:50.000Z","updated_at":"2024-10-19T15:04:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"625d76ce-4e25-4174-905f-b48b1bf9463d","html_url":"https://github.com/thibaudcolas/chart-export-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thibaudcolas/chart-export-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thibaudcolas%2Fchart-export-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thibaudcolas%2Fchart-export-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thibaudcolas%2Fchart-export-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thibaudcolas%2Fchart-export-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thibaudcolas","download_url":"https://codeload.github.com/thibaudcolas/chart-export-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thibaudcolas%2Fchart-export-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32672640,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-05T11:29:49.557Z","status":"ssl_error","status_checked_at":"2026-05-05T11:29:48.587Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["d3","electron","exporter","jsdom","svg"],"created_at":"2024-10-08T11:21:45.526Z","updated_at":"2026-05-05T23:32:40.714Z","avatar_url":"https://github.com/thibaudcolas.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"chart-export-example\n====================\n\n\u003e An example of using various Node tools to create an SVG / PNG export from a D3 SVG+CSS chart\n\n/!\\ The most effective approach has been packaged into a library, available at https://github.com/thibaudcolas/export-svg-chart.\n\n## Example export\n\nhttp://bl.ocks.org/mbostock/raw/7341714/ becomes (PNG and SVG):\n\n![Example export PNG](test-nightmare.png)\n\n[SVG version](test-nightmare.svg)\n\n## Relevant links\n\n- https://github.com/exupero/saveSvgAsPng\n- https://github.com/tmpvar/jsdom\n- https://www.npmjs.com/package/svg2png\n- https://github.com/segmentio/nightmare\n- https://github.com/TooTallNate/node-data-uri-to-buffer\n- https://github.com/Automattic/node-canvas\n- http://fabricjs.com/\n- https://www.smashingmagazine.com/2014/05/love-generating-svg-javascript-move-to-server/\n- https://d3export.housegordon.org/\n- https://github.com/Baremetrics/barepng\n\n## With Nightmare / Electron\n\n\u003e TL;DR; More heavyweight than jsdom but works flawlessly. Uses http://www.chromium.org/developers/content-module.\n\n- Point the browser to the page with the chart to export.\n- Inject `saveSvgAsPng` onto the page.\n- Get the SVG \u0026 PNG data URIs.\n\n## With jsdom\n\n\u003eTL;DR; SVG exports work, PNG exports are more complicated.\n\n- Getting the SVG data uri with `saveSvgAsPng` works.\n- Getting the PNG data uri doesn't, because jsdom's implementation of images is just a stub at the moment.\n- To circumvent that, it is possible to use `node-canvas`'s implementation, however it relies on Cairo, which doesn't support loading SVG files.\n- This issue can apparently be overcome by using `fabric` (it has a SVG to canvas parser), however Fabric doesn't support Node 4+ yet (compilation errors). This means that it would be necessary to step back to jsdom 3. I haven't tried this yet.\n\nAnother option is to use something like `svg2png`, but this relies on `phantom`. It seems a bit weird to use both jsdom and phantom.\n\n## Caveats\n\n- The rendering is handled by [Electron](http://electron.atom.io/), if something isn't supported there isn't much to do about it.\n- The chart to SVG \u0026 SVG to PNG features are handled by [saveSvgAsPng](https://github.com/exupero/saveSvgAsPng). This codebase is easier to contribute to.\n- saveSvgAsPng doesn't support inlining of font face definitions ([yet](https://github.com/exupero/saveSvgAsPng/pull/29)).\n- If the chart is styled with ancestor selectors that are outside of it, the selectors need to be re-mapped when they are inlined.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthibaudcolas%2Fchart-export-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthibaudcolas%2Fchart-export-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthibaudcolas%2Fchart-export-example/lists"}