运行jsdom在Nashorn

问题描述:

我想在服务器上呈现d3图表。我有3个选项:Node,Phantom和Nashorn。

I want to render d3 charts on the server. I had 3 options: Node, Phantom, and Nashorn.

我更喜欢Nashorn,因为我的API是Scala Play,我不想管理另一个进程。 (部署,加载,队列等等)

I prefer Nashorn because my API is Scala Play and I don't want to manage another process. (deployment, load, queue, etc etc)

现在我需要让JSDom在Nashorn中工作,这样D3将有一些东西可以渲染。

So now I need to get JSDom working in Nashorn, so that D3 will have something to render to.

这到目前为止,但我不知道如何添加jsdom

This works so far but I can't figure out how to add jsdom

class Application @Inject() (val messagesApi: MessagesApi) extends api.ApiController {

  def test = ApiAction { implicit request =>
    ok("The API is ready")
  }

  def pptx = Action { implicit request =>
    val manager: ScriptEngineManager = new ScriptEngineManager
    val engine: ScriptEngine = manager.getEngineByName("nashorn")
    engine.eval(new FileReader(Play.getFile("/ext/lodash.js")))
    val output = engine.eval("function hello(){return _.join('Hello world nashorn does this thing'.split(' '), '-');} hello();")
    Ok(output.toString)
  }
}

https://github.com/jazdw/domino =nofollow> domino 在nashorn中运行d3。 Domino是基于Mozilla的dom.js的服务器端DOM实现。我使用r.js从require.js加载它。您可以使用此readlike 从nashorn中缺少的函数,以获得require.js工作。

I'm loading a fork of domino in nashorn to run d3. Domino is a server-side DOM implementation based on Mozilla's dom.js. I loaded it using r.js from require.js. You can use this readfully function that is missing from nashorn to get require.js working.