Skip to content

Instantly share code, notes, and snippets.

@kazusato
Created July 1, 2019 23:03
Show Gist options
  • Save kazusato/08da518bad2ac1122c6dd16a7c6b19db to your computer and use it in GitHub Desktop.
Save kazusato/08da518bad2ac1122c6dd16a7c6b19db to your computer and use it in GitHub Desktop.
d3 with jsdom
/*
* npm install -s d3
* npm install -s jsdom
* node start.js > work.svg
* chrome work.svg
*/
const d3 = require("d3")
const jsdom = require("jsdom")
const { JSDOM } = jsdom
const { document } = new JSDOM().window
const svg = d3.select(document.body)
.append("svg")
.attr("xmlns", "http://www.w3.org/2000/svg")
.attr("width", 1000)
.attr("height", 750)
svg.append("circle")
.attr("cx", 200)
.attr("cy", 300)
.attr("r", 150)
.attr("stroke", "#000000")
.attr("fill", "#ffaaaa")
.attr("stroke-width", 5)
svg.append("text")
.attr("x", 200)
.attr("y", 300)
.attr("text-anchor", "middle")
.attr("dominant-baseline", "central")
.style("font-size", "48px")
.text("日本語")
console.log(document.body.innerHTML)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment