printing protovis output (programmatically)
-
29-09-2019 - |
문제
I'm pondering switching to protovis for visualizations. One thing that keeps me skeptical however - since protovis creates its output as a div in a browser, I wonder if there is any at least semi-automatic way for me to create a bunch of images at once without opening each one and pressing "print" manually.
So the question would be:
- do you think I can use a browserless JS engine like V8 to execute the code and print the result?
- can I automate opening and printing within a browser?
- is there another way to get automated images from protovis?
Thanks, Nicolas
해결책
Have a look at this Google Groups thread about this very topic.
다른 팁
Check out http://www.phantomjs.org/
It is a headless browser.
It can do exactly what you want : http://code.google.com/p/phantomjs/wiki/QuickStart#Rendering
rasterize.js:
if (phantom.state.length === 0) {
if (phantom.args.length !== 2) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
var address = phantom.args[0];
phantom.state = 'rasterize';
phantom.viewportSize = { width: 600, height: 600 };
phantom.open(address);
}
} else {
var output = phantom.args[1];
phantom.sleep(200);
phantom.render(output);
phantom.exit();
}
An example to produce the rendering of the famous Tiger (from SVG):
phantomjs rasterize.js http://ariya.github.com/svg/tiger.svg tiger.png
제휴하지 않습니다 StackOverflow