你可以在這裏找到我的解決方案: http://jsfiddle.net/5TK3d/
var numItems = Math.round(root.children.length /2);
var nodePositionDictionary = {};
var rootLeft = {children:[], name:root.name};
var rootRight = {children:[], name:root.name};
for(var i=0;i<root.children.length;i++)
{
var node = root.children[i];
if(!(i < numItems))
{
rootRight.children.push($.extend({}, node));
}else{
rootLeft.children.push($.extend({}, node));
}
}
var nodesRight = cluster.nodes(rootRight);
for (var i = 0; i < nodesRight.length; i++) {
var node = nodesRight[i];
node.right = true;
nodePositionDictionary[node.name + (node.parent?node.parent.name:"")] = node;
};
var nodesLeft = cluster.nodes(rootLeft);
for (var i = 0; i < nodesLeft.length; i++) {
var node = nodesLeft[i];
node.right = false;
nodePositionDictionary[node.name + (node.parent?node.parent.name:"")] = node;
};
// manually create nodes with their positions instead of doing cluster.nodes because
// i want them to be drawn left and right
var nodes = [];
updateNodePositions(root);
function updateNodePositions(n)
{
var nodePosition = nodePositionDictionary[n.name + (n.parent?n.parent.name:"")];
if(nodePosition){
n.x = nodePosition.x;
n.y = nodePosition.y;
n.depth = nodePosition.depth;
nodes.push(n);
}
for(var i=0; i< n.children.length;i++)
{
var node = n.children[i];
node.parent = n;
nodes.push(node);
var childNodePosition = nodePositionDictionary[node.name + (node.parent?node.parent.name:"")];
if(childNodePosition){
node.x = childNodePosition.x;
node.y = childNodePosition.y;
node.depth = childNodePosition.depth;
node.right = childNodePosition.right;
}
if(node.children){
updateNodePositions(node);
}
}
}
不知道你在找什麼? A [二分圖](https://github.com/bitliner/d3-bipartite-graph)? –
像這樣的東西http://intelligentheritage.files.wordpress.com/2011/11/mind-map.png?w=609&h=326 –
然後[這個問題](http://stackoverflow.com/questions/10232850/ js-library-for-creating-a-mindmap-like-interface)可能會有所幫助。 –