如何在新版本的D3中获取节点?

发布于 2025-02-03 07:29:51 字数 99 浏览 2 评论 0原文

我看到的D3示例使用tree..nodes(root).reverse()检索节点数组的D3旧版本。 它不适用于最新版本的D3。如何在新版本中获得节点阵列?

The D3 examples I've seen use an old version of D3 with tree.nodes(root).reverse() to retrieve nodes array.
It does not work with the latest version of D3. How do I get nodes array in the new version?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救星 2025-02-10 07:29:51

创建一个树布局对象:

const layout = d3.tree();

从数据中构建根对象:

const root = d3.hierarchy(data, d => d.children);

从树中提取节点:

const tree = layout(root);
const nodes = tree.descendants();

应该适用于 d3 v7 (请参见工作示例在这里

Create a tree layout object:

const layout = d3.tree();

Build a root object from your data:

const root = d3.hierarchy(data, d => d.children);

Extract nodes from the tree:

const tree = layout(root);
const nodes = tree.descendants();

Should work for D3 V7 (see a working example here)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文