Created
July 1, 2019 23:03
-
-
Save kazusato/08da518bad2ac1122c6dd16a7c6b19db to your computer and use it in GitHub Desktop.
d3 with jsdom
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
/* | |
* 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