[翻译]  Can D3 library be used with the Electron (Atom shell)?

[CHINESE]  D3库可以与Electron(Atom shell)一起使用吗?


Electron's website says that the applications made with electron can have access to node modules. Can they have access to the D3 library? If so, how can it be set up?

Electron的网站称,用电子制作的应用程序可以访问节点模块。他们可以访问D3库吗?如果是这样,怎么设置?

3 个解决方案

#1


7  

D3 is available as a Node.js module that can be imported into the JavaScript code you want to use to render your visualisation application.

D3可用作Node.js模块,可以将其导入到要用于呈现可视化应用程序的JavaScript代码中。

As an example of how to integrate D3 into an Electron application, have a look at my D3 Space Filler Explorer application on GitHub. This application visualises disk space use with multiple D3 pie charts and a D3 treemap.

作为如何将D3集成到Electron应用程序的示例,请查看我在GitHub上的D3 Space Filler Explorer应用程序。此应用程序使用多个D3饼图和D3树图可视化磁盘空间。

One pattern I found useful was to inject the SVG element into the D3 visualisation, which differs from the usual approach in D3 examples which creates the SVG element in the visualisation. See examples of this dependency injection in the /app/js/pie-chart.js and /app/js/treemap-chart.js files.

我发现有用的一种模式是将SVG元素注入到D3可视化中,这与D3示例中的常规方法不同,后者在可视化中创建了SVG元素。请参阅/app/js/pie-chart.js和/app/js/treemap-chart.js文件中的此依赖项注入示例。

#2


1  

All (at least theoretically) pure JS modules are compatible with electron, since it also provides a (CommonJS) javascript runtime environment (io.js).

所有(至少在理论上)纯JS模块都与​​电子兼容,因为它还提供了一个(CommonJS)javascript运行时环境(io.js)。

The only important thing is that electron doesn't automatically sets the NODE_PATH variable and doesn't look in system/global modules path for required modules. So you just have to make sure that you have the path to d3.js on your NODE_PATH:

唯一重要的是电子不会自动设置NODE_PATH变量,也不会查找所需模块的系统/全局模块路径。所以你必须确保你的NODE_PATH上有d3.js的路径:

NODE_PATH="/PATH/TO/d3.js" electron /PATH/TO/APP

#3


1  

We solved this in our workteam installing d3 with Npm:

我们在使用Npm安装d3的工作团队中解决了这个问题:

npm install d3 --save

npm install d3 --save

and in index.html we put this:

在index.html中我们把这个:

<script>var d3 = require("d3")</script>

We were getting this issue from nv.d3.js line 18, there is a little function requiring d3 as a node module and in our app we were using it in bower_components, so installing it with npm and requesting in your index directly from node_modules like as I said will probably solve this issue as it did with us.

我们从nv.d3.js第18行得到了这个问题,有一个小函数需要d3作为节点模块,在我们的应用程序中我们在bower_components中使用它,所以用npm安装它并直接从node_modules请求你的索引正如我所说,可能会像我们一样解决这个问题。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号