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.