D3力的导向图在变焦上断裂

发布于 2025-01-18 05:44:48 字数 1027 浏览 2 评论 0原文

我正在使用 d3 7.3.0 版本,并且我的代码基于此示例。我的问题是,当我放大(或缩小)时,圆圈的布局会中断并变为

在此处输入图像描述

最初是这样的

在此处输入图像描述

实现缩放的代码是

    const zoomed = d3.zoom()
      .scaleExtent([0, 3])
      .on('zoom', event => {
        graph.selectAll('g').attr('transform', event.transform);
      });

我注意到,如果我添加以下代码行,那么它可以防止它中断。

    const zoomed = d3.zoom()
      .scaleExtent([0, 3])
      .on('zoom', event => {
        graph.selectAll('g').attr('transform', event.transform);

        // This line prevents zoom from breaking
        simulation.restart();
      });

但缺点是速度明显变慢。有没有更有效的方法来防止它像这样破裂?

任何帮助将不胜感激。谢谢

I'm using version 7.3.0 of d3 and I have based my code on this example. My problem is that when I'm zooming in (or out) the layout of the circles breaks and becomes

enter image description here

while initially was like this

enter image description here

The code that implements the zoom is

    const zoomed = d3.zoom()
      .scaleExtent([0, 3])
      .on('zoom', event => {
        graph.selectAll('g').attr('transform', event.transform);
      });

I have noticed that if I add the following line of code, then it prevents it from breaking.

    const zoomed = d3.zoom()
      .scaleExtent([0, 3])
      .on('zoom', event => {
        graph.selectAll('g').attr('transform', event.transform);

        // This line prevents zoom from breaking
        simulation.restart();
      });

But the downside is that it becomes noticeably slower. Is there a more efficient way to prevent it from breaking like that?

Any help would be appreciated. Thank you

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文