D3 Pre-Rendering

前端 未结 2 1559
滥情空心
滥情空心 2021-01-25 21:30

I\'m still a beginner with JS + Python and I\'d be really happy to get your help on one problem. What I basically need to to is to pre-render a d3js visualizati

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-25 22:06

    You can satisfy both requirements with CasperJS. Casper is a library that will use a headless browser to request a web page, which it can also programmatically interact with. A simple snippet of how to grab a screen shot goes something like this:

    casper.start('http://ninjaPixel.io/', function() {
      this.capture('page.png', undefined, {
          format: 'png'
      });
    });
    

    You can add a delay to this, to make sure that your force diagram is in a stable state when you take the screen shot. Casper can grab anything off the page, so if you display your computed node values in a html table, for example, tell Casper the id of that table and it can then grab it and save the values for you. You could even save the SVG object generated by your d3.js code.

提交回复
热议问题