D3 sankey图-强制节点位置 [英] D3 sankey diagram - enforce node position

查看:335
本文介绍了D3 sankey图-强制节点位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用D3 Sankey插件,我用新值更新了Sankey图(更改数据时,为节点和链接传递了新值-保持所有这些保持一致).是否具有d3.treemap的粘性之类的功能,以维护节点和链接顺序这一页?如果没有,是否有构建此方法的方法?

Using the D3 Sankey plugin, I'm updating a Sankey diagram with new values (on changing the data, passing new values for the nodes and links -- keeping all of them consistent). Is there functionality like d3.treemap's sticky to maintain node and link orders on the page? If not, is there an approach to building this?

var sankey = d3.sankey()
    .nodeWidth(15)
    .nodePadding(10)
    .size([width, height]);
    .sticky(true)

我在这里遵循以下模式: http://bost.ocks.org/mike/sankey/

I'm following the pattern here: http://bost.ocks.org/mike/sankey/

推荐答案

不,没有.如果您想深入了解版式,请在此处查看:

No, there isn't. If you want to dive into the layout, here's where you want to look:

function computeNodeDepths(iterations) {
 var nodesByBreadth = d3.nest()
    .key(function(d) { return d.x; })
    .sortKeys(d3.ascending)
    .entries(nodes)
    .map(function(d) { return d.values; });

initializeNodeDepth();
...

请注意sortKeys指向d3.ascending.您希望它指向某种硬连接的值,您需要在第一次迭代或数据准备中进行计算.当运行碰撞检测功能时,它仍然会进行调整,因此您可能会看到节点被推到位,但这将为您提供最佳的机会来保持某些控制.

Notice that sortKeys points at d3.ascending. You'd want this to point to some kind of hard-wired value, which you'd need to compute either in the first iteration or in your data preparation. It will still get adjusted when the collision detection function is run, so you might see your nodes pushed out of position but this will give you the best chance to maintain some control.

这篇关于D3 sankey图-强制节点位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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