在 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);
}
}