Note that there are some explanatory texts on larger screens.

plurals
  1. POSVG to PNG Server side - using node.js
    primarykey
    data
    text
    <p>I'm trying to follow this tutorial on converting a d3.js SVG Vis to a PNG server-side (using Node.js) <a href="http://eng.wealthfront.com/2011/12/converting-dynamic-svg-to-png-with.html" rel="noreferrer">http://eng.wealthfront.com/2011/12/converting-dynamic-svg-to-png-with.html</a></p> <p><strong>Link to full code:</strong> <a href="https://gist.github.com/1509145" rel="noreferrer">https://gist.github.com/1509145</a></p> <p>However, I keep getting this <strong>error</strong> whenever I attempt to make a request to load my page </p> <pre><code> /Users/me/Node/node_modules/jsdom/lib/jsdom.js:171 features = JSON.parse(JSON.stringify(window.document.implementation._fea ^ TypeError: Cannot read property 'implementation' of undefined at exports.env.exports.jsdom.env.processHTML (/Users/dereklo/Node/node_modules/jsdom/lib/jsdom.js:171:59) at Object.exports.env.exports.jsdom.env (/Users/dereklo/Node/node_modules/jsdom/lib/jsdom.js:262:5) at Server.&lt;anonymous&gt; (/Users/dereklo/Node/Pie/pie_serv.js:26:9) at Server.EventEmitter.emit (events.js:91:17) at HTTPParser.parser.onIncoming (http.js:1785:12) at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23) at Socket.socket.ondata (http. </code></pre> <p>Does anybody know why this might be? I've installed the jsdom module fine, so I don't really know what's causing these issues...thanks in advance.</p> <p><strong>EDIT</strong></p> <p>This is the code I'm using to implement the node.js server. My latest issue is below this source...</p> <pre><code>var http = require('http'), url = require('url'), jsdom = require('jsdom'), child_proc = require('child_process'), w = 400, h = 400, __dirname = "Users/dereklo/Node/pie/" scripts = ["/Users/dereklo/Node/pie/d3.min.js", "/Users/dereklo/Node/pie/d3.layout.min.js", "/Users/dereklo/Node/pie/pie.js"], //scripts = ["./d3.v2.js", // "./d3.layout.min.js", // "./pie.js"] htmlStub = '&lt;!DOCTYPE html&gt;&lt;div id="pie" style="width:'+w+'px;height:'+h+'px;"&gt;&lt;/div&gt;'; http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'image/png'}); var convert = child_proc.spawn("convert", ["svg:", "png:-"]), values = (url.parse(req.url, true).query['values'] || ".5,.5") .split(",") .map(function(v){return parseFloat(v)}); convert.stdout.on('data', function (data) { res.write(data); }); convert.on('exit', function(code) { res.end(); }); jsdom.env({features:{QuerySelector:true}, html:htmlStub, scripts:scripts, done:function(errors, window) { var svgsrc = window.insertPie("#pie", w, h, values).innerHTML; console.log("svgsrc",svgsrc); //jsdom's domToHTML will lowercase element names svgsrc = svgsrc.replace(/radialgradient/g,'radialGradient'); convert.stdin.write(svgsrc); convert.stdin.end(); }}); }).listen(8888, "127.0.0.1"); console.log('Pie SVG server running at http://127.0.0.1:8888/'); console.log('ex. http://127.0.0.1:8888/?values=.4,.3,.2,.1'); </code></pre> <p><strong>Latest Issue</strong></p> <pre><code> events.js:66 throw arguments[1]; // Unhandled 'error' event ^ Error: This socket is closed. at Socket._write (net.js:519:19) at Socket.write (net.js:511:15) at http.createServer.jsdom.env.done (/Users/dereklo/Node/Pie/pie_serv.js:38:19) at exports.env.exports.jsdom.env.scriptComplete (/Users/dereklo/Node/node_modules/jsdom/lib/jsdom.js:199:39) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload