Skip to content

Instantly share code, notes, and snippets.

@ashgillman
Created September 9, 2015 13:00
Show Gist options
  • Save ashgillman/150331a78a3c34727e8b to your computer and use it in GitHub Desktop.
Save ashgillman/150331a78a3c34727e8b to your computer and use it in GitHub Desktop.
Static D3 Visualisation
{
"name": "Static-D3-Visualisation",
"version": "1.0.0",
"description": "Template to make visualisations with D3 locally",
"dependencies": {
"jsdom": "^3.1.2"
},
"devDependencies": {
"coffee-script": "^1.10.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Ashley Gillman",
"license": "MIT"
}
#!/usr/bin/sh
npm install
./node_modules/.bin/coffee -c visualisation.coffee
node visualisation.js > visualisation.svg
convert visualisation.svg visualisation.png
jsdom = require 'jsdom'
jsdom.env '<html><body></body></html>',
[ 'http://d3js.org/d3.v3.min.js' ],
(err, window) ->
svg = window.d3.select 'body'
.append 'svg'
.attr 'width', 100
.attr 'height', 100
svg.append 'rect'
.attr 'x', 10
.attr 'y', 10
.attr 'width', 80
.attr 'height', 80
.style 'fill', 'orange'
console.log(window.d3.select("body").html());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment