在 JGraphX 中,大多数布局算法不会移动不可移动的顶点。不幸的是,mxHierarchicalLayout 忽略了顶点是否可移动。我发现,这个布局算法根本不使用 isVertexMovable 。我必须在哪里添加顶点是否可移动的检查。
我尝试过的位置,产生无限循环或没有任何效果。
[编辑]
public void execute(Object parent, List<Object> roots)
{
super.execute(parent);
mxIGraphModel model = graph.getModel();
// If the roots are set and the parent is set, only
// use the roots that are some dependent of the that
// parent.
// If just the root are set, use them as-is
// If just the parent is set use it's immediate
// children as the initial set
if (roots == null && parent == null)
{
// TODO indicate the problem
return;
}
if (roots != null && parent != null)
{
for (Object root : roots)
{
if (!model.isAncestor(parent, root))
{
roots.remove(root);
}
}
}
this.roots = roots;
model.beginUpdate();
try
{
run(parent);
if (isResizeParent() && !graph.isCellCollapsed(parent))
{
graph.updateGroupBounds(new Object[] { parent }, getParentBorder(), isMoveParent());
}
}
finally
{
model.endUpdate();
}
}
/**
* The API method used to exercise the layout upon the graph description
* and produce a separate description of the vertex position and edge
* routing changes made.
*/
public void run(Object parent)
{
// Separate out unconnected hierarchies
List<Set<Object>> hierarchyVertices = new ArrayList<Set<Object>>();
Set<Object> allVertexSet = new LinkedHashSet<Object>();
if (this.roots == null && parent != null)
{
Set<Object> filledVertexSet = filterDescendants(parent);
this.roots = new ArrayList<Object>();
while (!filledVertexSet.isEmpty())
{
List<Object> candidateRoots = findRoots(parent, filledVertexSet);
for (Object root : candidateRoots)
{
Set<Object> vertexSet = new LinkedHashSet<Object>();
for (Object o : vertexSet)
{
vertexSet.remove(o);
}
hierarchyVertices.add(vertexSet);
traverse(root, true, null, allVertexSet, vertexSet, hierarchyVertices, filledVertexSet);
}
this.roots.addAll(candidateRoots);
}
}
else
{
// Find vertex set as directed traversal from roots
for (int i = 0; i < roots.size(); i++)
{
Set<Object> vertexSet = new LinkedHashSet<Object>();
for (Object o : vertexSet)
{
vertexSet.remove(o);
}
hierarchyVertices.add(vertexSet);
traverse(roots.get(i), true, null, allVertexSet, vertexSet, hierarchyVertices, null);
}
}
// Iterate through the result removing parents who have children in this layout
// Perform a layout for each separate hierarchy
// Track initial coordinate x-positioning
double initialX = 0;
Iterator<Set<Object>> iter = hierarchyVertices.iterator();
while (iter.hasNext())
{
Set<Object> vertexSet = iter.next();
this.model = new mxGraphHierarchyModel(this, vertexSet.toArray(), roots, parent);
cycleStage(parent);
layeringStage();
crossingStage(parent);
initialX = placementStage(initialX, parent);
}
}
在 JGraphX 的分层布局中(我是它的作者),很难考虑布局中无法移动的顶点。如果这些顶点固定在不适合轻松分配排名的位置,则所使用的算法将不起作用。
可以忽略布局中的顶点,但这与不使它们可移动相比是非常不同的事情。
所以简短的答案是,在使用所使用的算法的布局中不可能考虑可移动标志。如果此功能存在对普通读者没有好处的特定情况,我建议在 github project issue tracker 上提出问题,而不是在这里进行扩展讨论
我是一名优秀的程序员,十分优秀!