mxHierarchicalLayout ignores isVertexMovable

715 views Asked by At

in JGraphX the most layout algorithms don't move vertices which are not movable. Unfortunately mxHierarchicalLayout ignores, whether a vertex is movable or not. I found out, that this layout alogrithm dosen't use isVertexMovable at all. Where do I have to add the check if a vertex is movable or not.

The positions I tried, producing an endless loop or don't have any effect.

[Edit]

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

There are 1 answers

0
Frodo Baggins On BEST ANSWER

In the hierarchical layout in JGraphX (and I am the author of it) it is very difficult to take into account vertices that cannot be moved in the layout. If those vertices are fixed in position that do not lend themselves to easily being allocated a rank, the algorithms used just will not work.

It is possible to ignore vertices in the layout, but that is very different thing to do compared to not making them movable.

So the short answer is that it's not possible to take the movable flag into account in this layout with the algorithms used. If there is a specific case for this functionality that will not benefit the general reader, I suggest raising an issue on the github project issue tracker, rather than an extended discussion here