In order to generate some svg with d3 in node.js, you need a dom. This is a bare bones example of using jsdom for said dom.
Last active
June 7, 2019 11:42
-
-
Save shancarter/e988a8a9576e2205af6e3f0e06c26e1a to your computer and use it in GitHub Desktop.
Using d3 to generate SVGs in node.js
This file contains 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 d3 = require("d3"), | |
jsdom = require("jsdom").jsdom; | |
var body = d3.select(jsdom().documentElement).select("body"); | |
var width = 1000, | |
height = 500; | |
var svg = body.append("svg"); | |
var svg = body.append("svg") | |
.attr("version", "1.1") | |
.attr("xmlns", d3.namespaces.svg) | |
.attr("xmlns:xlink", d3.namespaces.xlink) | |
.attr("width", width) | |
.attr("height", height) | |
.attr("viewBox", "0 0 " + width + " " + height); | |
process.stdout.write(body.node().innerHTML); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment