本文介绍了缩放到D3 Force Directed Graph上的点击节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将范例应用于D3强制导向图我正在工作,已经有功能。然而,我不知道如何获得我的当前位置,以使其成为变换的起点。我也有同样的问题,试图使用正常的变换。

I am trying to apply the van Wijk Smooth Zooming example to a D3 force-directed graph I am working that already has the drag+zoom functioning on it. However, I don't know how to get my current position in order to make that the starting point of the transform. The I have the same issue with trying to use a normal transform.

我也试过看看,但我不知道如何将其应用于力导向图。

I also tried looking at the click-to-zoom-transform but I wasn't sure how to apply that to a force-directed graph.

我想应用它的几个东西,包括当我点击链接时能够缩放和跳转到链接的目标节点。有没有办法得到当前屏幕的位置,所以我可以用它作为起点,跳到我想去的地方。

There are a couple things I want to apply it to, including being able to zoom and jump to a link's target node when I click on the link. Is there a way to get the current screen screen position so I could use it as a starting point to jump to where I want to go?

推荐答案

实际上,我只是根据中的点击功能来确定。我的方程是错误的我的规模和翻译数字。我需要以这种方式获取我的翻译数字:

Actually, I just figured it out based on the clicked function in this example. My equation was wrong for my scale and translate numbers. I needed to get my translate numbers this way:

translate = [width / 2 - scale * x, height / 2 - scale * y]

然后我需要调用放大行为如下面的.event在结束时使它发火:

Then I needed to call() the zoom behavior with the transition on the zoom behavior itself like below with the ".event" at the end to make it fire:

svg.transition().duration(750)
   .call(zoom.translate(translate).scale(scale).event);

而不是以错误的方式通过翻译svg像我之前做的

and not doing it the wrong way by translating the svg like I was doing before:

svg.transition().duration(750)
   .attr("transform", translate(translate).scale(scale));

这篇关于缩放到D3 Force Directed Graph上的点击节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 15:43