D3-Node

Server-side D3 with ease Â
Tested on Nodejs v10 & up
see examples >

Why?
Basic usage:

Create a SVG
const D3Node = require('d3-node')
const d3n = new D3Node()
d3n.createSVG(10,20).append('g')
d3n.svgString()
Advanced usage
Setting container & insertion point via selector
const options = { selector: '#chart', container: '<div id="container"><div id="chart"></div></div>' }
const d3n = new D3Node(options)
const d3 = d3n.d3
d3.select(d3n.document.querySelector('#chart')).append('span')
d3n.html()
d3n.chartHTML()
Inline SVG styles
const d3n = new D3Node({styles:'.test {fill:#000;}'})
d3n.createSVG().append('g')
d3n.svgString()
Output
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<style type="text/css"><![CDATA[ .test{fill:#000;} ]]></style>
</defs>
<g></g>
<svg>
Create a canvas (for generating a png)
const canvasModule = require('canvas');
const d3n = new D3Node({ canvasModule });
const canvas = d3n.createCanvas(960, 500);
const context = canvas.getContext('2d');
canvas.pngStream().pipe(fs.createWriteStream('output.png'));
Run Tests:
$ npm test
TODOs:
- Add more examples: (remote data, world map)
- Create Gulp task
- Add option to inject css/js into html output