在jgraph中结合树和层次结构布局

时间:2014-07-23 09:54:24

标签: layout treeview hierarchical jgraphx

我正在尝试组合水平树和层次结构布局。我希望我的图形的上半部分是树形布局,并且水平绘制和下半部分层次布局。 我尝试在同一个beginUpdate块中添加树布局和层次结构布局,但我观察到层次结构布局优先并覆盖图形的树布局。

有没有办法克服这个问题?以下是我所拥有的 -

graph.getModel().beginUpdate();
try
{
Object v1 = graph.insertVertex(parent, null, "Hello", 1, 1, 80,
                30);
Object v2 = graph.insertVertex(parent, null, "World!", 1, 1,
                80, 30,"shape=rhombus;perimeter=rhombusPerimeter");

graph.insertEdge(parent, null, "Edge", v1, v2);
/* Apply tree Layout*/
mxCompactTreeLayout layout = new mxCompactTreeLayout(graph,true); 
layout.execute(graph.getDefaultParent());

Object v3 = graph.insertVertex(parent, null, "Bye", 1, 1,80, 30,"shape=ellipse;perimeter=ellipsePerimeter");
Object v4 = graph.insertVertex(parent, null, "NoBye", 1, 1,80, 30,"shape=ellipse;perimeter=ellipsePerimeter");

//Object v5 = graph.insertVertex(parent, null, "Desc", 1, 1,
//  80, 30,"shape=ellipse;perimeter=ellipsePerimeter");

Object v6 = graph.insertVertex(parent, null, "World2!", 1, 1,80, 30,"shape=rhombus;perimeter=rhombusPerimeter");

graph.insertEdge(parent, null, "Yes", v2, v3);
graph.insertEdge(parent, null, "No", v2, v4);
graph.insertEdge(parent, null, "", v1, v6);

//Apply Hierarchial layout now
mxHierarchicalLayout layout1 = new mxHierarchicalLayout(graph ); 
layout1.setDisableEdgeStyle(false);
layout1.setFineTuning(true);
layout1.setIntraCellSpacing(50);
layout1.execute(graph.getDefaultParent());
}
finally
{
graph.getModel().endUpdate();
}

0 个答案:

没有答案