【问题标题】:d3js create a force layout with fixed nodes [closed]d3js 创建具有固定节点的强制布局 [关闭]
【发布时间】:2013-07-15 14:20:19
【问题描述】:

我已经实现了这个http://jsbin.com/omokap/3/edit:

但是,我想取消图形的动态行为(例如在 dragend 状态下,但这仅适用于单个节点)并将节点放置在从 json 获取的设置点中。

我已经看到这个问题Moving fixed nodes in D3Fix Node Position in D3 Force-Directed Layout。 我不明白如何在我的示例中使用它们。

有人可以帮我吗?

【问题讨论】:

  • 对于不想移动的节点,将fixed属性设置为true
  • 我已经阅读了其他问题和相关回复,并且我已经做出:for (i=0;i<nodes.length nodes true function return d.cx d.cy> 这是结果<a href="/default/index/tourl?u=aHR0cDovL2pzYmluLmNvbS9vbW9rYXAvNC9lZGl0" rel="nofollow" target="_blank">jsbin.com/omokap/4/edit</a></nodes.length>
  • @LarsKotthoff 我哪里出错了?
  • 你的例子对我不起作用。原则上,您的代码应该实现您想要的。
  • Excuse me example 不起作用,因为我的 IPS 有问题,如果添加 D3js 库则无法保存。我自己解决了。感谢您的宝贵时间。

标签: d3.js force-layout


【解决方案1】:

解决方案是简单地插入节点对象 x,y 坐标和固定:像这样

{ name: "Sara", id:"1", x:239.31191418045182, y:296.78520431471384, fixed:true},
{ name: "Raul", id:"2", x:261.1651006560272, y:200.78448049334696, fixed:true},
{ name: "Stefano", id:"3", fixed:false},
{ name: "Michele", id:"4", fixed:false}

这是一个工作示例 http://jsbin.com/omokap/8/edit 请添加您自己的 d3js 库。

就我的目的而言工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-14
    相关资源
    最近更新 更多