强制定向布局附加在D3.js中 [英] NaN on Force-Directed Layout Append in D3.js

查看:150
本文介绍了强制定向布局附加在D3.js中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在D3中使用强制导向的布局,从JSON文件中获取数据,然后当双击其中一个节点时,查询数据库以查找到该节点的链接,并更新链接和节点数组尝试将新数据附加到viz。看来,当节点附加无链接,他们工作正常,但到xy坐标的链接最终是NaN。您可以在这里看到效果,只需双击其中一个节点:

I'm using a force-directed layout in D3 that grabs data from a JSON file and then, when one of the nodes is double-clicked, queries the database to find links to that node and updates the links and nodes arrays attempting to append the new data to the viz. It seems when the nodes are appended without links, they work fine, but the links to the xy coordinates end up being NaN. You can see the effect here, just double-click on one of the nodes:

http://blockses.appspot.com/2432083

推荐答案

我通过重写代码跟随强制导向与附加示例从Bostock。当你覆盖你的节点和链接数组,而不是推送数据到他们,如果任何人遇到类似的问题似乎发生了。

I fixed this by rewriting the code to follow the force-directed with append example from Bostock. The problem seems to occur when you overwrite your nodes and links arrays rather than pushing data to them, in case anyone runs into similar issues.

更新的代码是在原来的gist,可以在这里看到:

The updated code is in the original gist and can be seen here:

http:// blockses .appspot.com / 2432083

这篇关于强制定向布局附加在D3.js中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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