English 中文(简体)
printing protovis output (programmatically)
原标题:

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 

enter image description here





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签