如何使用d3力布局显示图形,初始位置设置和没有运动? [英] How can I show a graph using d3 force layout with initial positions set and no movement at all?

查看:390
本文介绍了如何使用d3力布局显示图形,初始位置设置和没有运动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用d3 force layout来构造一个图形,然后在数据库中存储节点的位置。

I use d3 force layout to construct a graph, and then store the positions of the nodes in a database.

下一次我想显示图形时,我从数据库读取位置到节点,然后开始强制布局。

The next time I want to show the graph, I read the positions from the database into the nodes and then I start the force layout.

这会导致布局稍微移动。

That causes the layout to move slightly.

有没有办法在没有调用force.start()的情况下显示存储节点位置的图?

Is there I way to show the graph with the stored node positions without calling force.start() at all?

我想要的是一个

/ Hans

推荐答案

我建议您阅读强制布局的文档。这真的很好。

I recommend you to read the documentation of the force layout. It is really good.

如前所述,您必须设置 px py 每个节点的属性。然后,可以在每个节点中将属性固定设置为 true

As you mentioned, you have to set the px and py attributes for each node. Then, you can set the attribute fixed to true in each node.

这将意味着计算force.start()不会有任何效果。

This will imply that computing force.start() won't have any effect.

您可以尝试的另一件事是将alpha值设置为0,然后开始模拟:

Another thing you can try is to set the alpha value to 0, and then start the simulation:

force.alpha(0)
    .start()

我不知道这个方法是否有效。如果没有,发布一个jsFiddle。

I am not sure whether this method works. Post a jsFiddle if it does not.

这篇关于如何使用d3力布局显示图形,初始位置设置和没有运动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆