我正在看这个例子 http://mbostock.github.com/d3/ex/cluster.html使用簇布局将 X 和 Y 坐标分配给树状图上的节点。我怎么知道cluster https://github.com/mbostock/d3/wiki/Cluster-Layout#wiki-cluster垂直布局,从上到下,而不是默认的从左到右?
For the example http://mbostock.github.com/d3/ex/cluster.html您链接时,只需翻转 X 和 Y 坐标的使用即可。这可以通过改变来完成
var diagonal = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x]; });
and
var node = vis.selectAll("g.node")
.data(nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })
to
var diagonal = d3.svg.diagonal()
// Flip the values here.
.projection(function(d) { return [d.x, d.y]; });
and
var node = vis.selectAll("g.node")
.data(nodes)
.enter().append("g")
.attr("class", "node")
// Flip the values here.
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
这里有一个JSFiddle http://jsfiddle.net/brantolsen/Ld6Uz/显示上述动作的变化。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)