var container = new JTopo.Container('边界自动变化');
scene.add(container);
for(var i=0; i<5; i++){
var node = new JTopo.Node("A_"+i);
node.textPosition = "Middle_Center";
node.setLocation(300+ Math.random() * 300, 200+ Math.random() * 200);
scene.add(node);
container.add(node);
}
scene.add(new JTopo.Link(container.childs[0], container.childs[1]));
scene.add(new JTopo.Link(container.childs[2], container.childs[3]));
// 流式布局(水平、垂直间隔均为10)
var flowLayout = JTopo.layout.FlowLayout(10, 10);
// 网格布局(4行3列)
var gridLayout = JTopo.layout.GridLayout(4, 3);
container.layout = flowLayout;
container2.click(function(){
if(container2.layout === flowLayout){
container2.layout = gridLayout;
}else{
container2.layout = flowLayout;
}
});复制代码
node.layout = {type: 'circle', radius: 80}; 圆形布局 半径80
JTopo.layout.layoutNode(scene, cloudNode, true); // scene 场景 cloudNode 定位目标
cloudNode.layout = {type: 'tree', direction: 'top',width:180, height: 100} 树形布局 子元素间距180 距离定位点高度100
direction: 'top','left','right','bottom'