我正在使用 D3.js 尝试强制定向布局。我需要的是按根(或其他选定的节点)将布局居中,并在刻度函数完成后将此节点返回到 svg(例如画布)中心(图形 alpha 较低)。是否可以?我找到了一个例子
http://bl.ocks.org/1080941
但我无法使根(当使用 alpha 或其他自定义刻度函数计算时)返回到中心(按此特定节点将布局居中)。
任何帮助,将不胜感激。
实际上我是这样解决的(与之前的类似但更复杂):
force.on("tick", function(e) {
node.attr("transform", function(d) {
//TODO move these constants to the header section
//center the center (root) node when graph is cooling down
if(d.index==0){
damper = 0.1;
d.x = d.x + (w/2 - d.x) * (damper + 0.71) * e.alpha;
d.y = d.y + (h/2 - d.y) * (damper + 0.71) * e.alpha;
}
//start is initiated when importing nodes from XML
if(d.start === true){
d.x = w/2;
d.y = h/2;
d.start = false;
}
r = d.name.length;
//these setting are used for bounding box, see [http://blockses.appspot.com/1129492][1]
d.x = Math.max(r, Math.min(w - r, d.x));
d.y = Math.max(r, Math.min(h - r, d.y));
return "translate("+d.x+","+d.y+")";
}
);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)