Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active February 1, 2020 08:27
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mbostock/885fffe88d72b2a25c090e0bbbef382f to your computer and use it in GitHub Desktop.
d3.geoPath + node-canvas
license: GPL-3.0
height: 600
border: no
<!DOCTYPE html>
<img src="preview.png" width="960" height="600">
{
"name": "d3-geoPath-canvas-example",
"version": "0.0.1",
"license": "GPL-3.0",
"scripts": {
"prepublish": "./rasterize"
},
"devDependencies": {
"canvas": "1",
"d3-geo": "1",
"topojson-client": "2",
"us-atlas": "1"
}
}
#!/usr/bin/env node
var fs = require("fs"),
d3 = require("d3-geo"),
topojson = require("topojson-client"),
Canvas = require("canvas"),
us = require("./node_modules/us-atlas/us/10m.json");
var canvas = new Canvas(960, 600),
context = canvas.getContext("2d"),
path = d3.geoPath().context(context);
context.beginPath();
path(topojson.mesh(us));
context.stroke();
canvas.pngStream().pipe(fs.createWriteStream("preview.png"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment