D3 sankey diagram - enforce node position

◇◆丶佛笑我妖孽 提交于 2019-12-13 06:59:24

问题


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)

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


回答1:


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();
...

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.



来源:https://stackoverflow.com/questions/27553793/d3-sankey-diagram-enforce-node-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!