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

2022-01-10 00:00:00 node.js d3.js electron javascript

Electron 的网站说,使用 electron 制作的应用程序可以访问节点模块.他们可以访问 D3 库吗?如果可以,如何设置?

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?

推荐答案

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

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 集成到 Electron 应用程序的示例,请查看我的 GitHub 上的 D3 Space Filler Explorer 应用程序.此应用程序通过多个 D3 饼图和 D3 树状图可视化磁盘空间使用情况.

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.

我发现一种有用的模式是将 SVG 元素注入到 D3 可视化中,这与 D3 示例中通常在可视化中创建 SVG 元素的方法不同.在/app/js/pie-chart.js 和/app/js/treemap-chart.js 文件中查看这种依赖注入的示例.

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.

相关文章