This example shows how to use d3.geoPath with node-canvas and us-atlas.
Last active
February 1, 2020 08:27
-
-
Save mbostock/885fffe88d72b2a25c090e0bbbef382f to your computer and use it in GitHub Desktop.
d3.geoPath + node-canvas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: GPL-3.0 | |
height: 600 | |
border: no |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<img src="preview.png" width="960" height="600"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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