1

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

1 回答 1

1

在 JGraphX 的分层布局中(我是它的作者),很难考虑在布局中不能移动的顶点。如果这些顶点的位置固定而不易被分配等级,那么所使用的算法将无法正常工作。

可以忽略布局中的顶点,但与不使它们可移动相比,这是非常不同的事情。

所以简短的回答是,在这个布局中使用所使用的算法是不可能考虑可移动标志的。如果此功能的特定情况不会使普通读者受益,我建议在github 项目问题跟踪器上提出问题,而不是在此处进行扩展讨论

于 2013-08-31T12:38:57.963 回答