Search in sources :

Example 11 with Layer

use of org.eclipse.elk.alg.layered.graph.Layer in project elk by eclipse.

the class GraphTransformer method process.

@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Graph transformation (" + mode + ")", 1);
    // We need to add all layerless nodes as well as all nodes in layers since this processor
    // is run twice -- once before layering, and once afterwards
    List<LNode> nodes = Lists.newArrayList(layeredGraph.getLayerlessNodes());
    for (Layer layer : layeredGraph.getLayers()) {
        nodes.addAll(layer.getNodes());
    }
    // graph transformations for unusual layout directions
    DirectionCongruency congruency = layeredGraph.getProperty(LayeredOptions.DIRECTION_CONGRUENCY);
    if (congruency == DirectionCongruency.READING_DIRECTION) {
        // --------------------------------------------------------------
        switch(layeredGraph.getProperty(LayeredOptions.DIRECTION)) {
            case LEFT:
                mirrorAllX(layeredGraph, nodes);
                break;
            case DOWN:
                transposeAll(layeredGraph, nodes);
                break;
            case UP:
                if (mode == Mode.TO_INTERNAL_LTR) {
                    transposeAll(layeredGraph, nodes);
                    mirrorAllY(layeredGraph, nodes);
                } else {
                    mirrorAllY(layeredGraph, nodes);
                    transposeAll(layeredGraph, nodes);
                }
                break;
        }
    } else {
        if (mode == Mode.TO_INTERNAL_LTR) {
            // --------------------------------------------------------------
            switch(layeredGraph.getProperty(LayeredOptions.DIRECTION)) {
                case LEFT:
                    mirrorAllX(layeredGraph, nodes);
                    mirrorAllY(layeredGraph, nodes);
                    break;
                case DOWN:
                    rotate90Clockwise(layeredGraph, nodes);
                    break;
                case UP:
                    rotate90CounterClockwise(layeredGraph, nodes);
                    break;
            }
        } else {
            // --------------------------------------------------------------
            switch(layeredGraph.getProperty(LayeredOptions.DIRECTION)) {
                case LEFT:
                    mirrorAllX(layeredGraph, nodes);
                    mirrorAllY(layeredGraph, nodes);
                    break;
                case DOWN:
                    rotate90CounterClockwise(layeredGraph, nodes);
                    break;
                case UP:
                    rotate90Clockwise(layeredGraph, nodes);
                    break;
            }
        }
    }
    monitor.done();
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode) DirectionCongruency(org.eclipse.elk.alg.layered.options.DirectionCongruency) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 12 with Layer

use of org.eclipse.elk.alg.layered.graph.Layer in project elk by eclipse.

the class HierarchicalNodeResizingProcessor method process.

@Override
public void process(final LGraph graph, final IElkProgressMonitor progressMonitor) {
    progressMonitor.begin("Resize child graph to fit parent.", 1);
    for (Layer layer : graph) {
        graph.getLayerlessNodes().addAll(layer.getNodes());
        layer.getNodes().clear();
    }
    for (LNode node : graph.getLayerlessNodes()) {
        node.setLayer(null);
    }
    graph.getLayers().clear();
    resizeGraph(graph);
    if (isNested(graph)) {
        graphLayoutToNode(graph.getParentNode(), graph);
    }
    progressMonitor.done();
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 13 with Layer

use of org.eclipse.elk.alg.layered.graph.Layer in project elk by eclipse.

the class InLayerConstraintProcessorTest method testValidNodeOrder.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
@TestAfterProcessor(InLayerConstraintProcessor.class)
public void testValidNodeOrder(final Object graph) {
    LGraph lGraph = (LGraph) graph;
    for (Layer layer : lGraph) {
        InLayerConstraint lastConstraint = null;
        for (LNode node : layer) {
            InLayerConstraint currentConstraint = node.getProperty(InternalProperties.IN_LAYER_CONSTRAINT);
            if (lastConstraint != null && currentConstraint != lastConstraint) {
                // if the value changes check valid transitions
                String error = "Invalid constraint transition: " + lastConstraint.name() + " -> " + currentConstraint.name();
                if (currentConstraint == InLayerConstraint.NONE) {
                    assertTrue(error, lastConstraint == InLayerConstraint.TOP);
                } else if (currentConstraint == InLayerConstraint.BOTTOM) {
                    assertTrue(error, lastConstraint == InLayerConstraint.TOP || lastConstraint == InLayerConstraint.NONE);
                }
                lastConstraint = currentConstraint;
            }
            lastConstraint = currentConstraint;
        }
    }
}
Also used : InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Layer(org.eclipse.elk.alg.layered.graph.Layer) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)

Example 14 with Layer

use of org.eclipse.elk.alg.layered.graph.Layer in project elk by eclipse.

the class TestGraphCreator method getNodesInDifferentLayoutUnitsPreventSwitch.

/**
 * <pre>
 *     * <-- this ...
 *    /
 * *-+-* <-- cannot switch with this
 *  / _|__
 * *  |  |
 *    |__|
 *
 * .
 * </pre>
 *
 * @return graph of the form above.
 */
public LGraph getNodesInDifferentLayoutUnitsPreventSwitch() {
    Layer[] layers = makeLayers(2);
    LNode[] leftNodes = addNodesToLayer(2, layers[0]);
    LNode[] rightNodes = addNodesToLayer(3, layers[1]);
    eastWestEdgeFromTo(leftNodes[0], rightNodes[1]);
    eastWestEdgeFromTo(leftNodes[1], rightNodes[0]);
    LPort southPort = addPortOnSide(rightNodes[1], PortSide.SOUTH);
    LPort northPort = addPortOnSide(rightNodes[2], PortSide.NORTH);
    addEdgeBetweenPorts(southPort, northPort);
    rightNodes[1].setProperty(InternalProperties.IN_LAYER_LAYOUT_UNIT, rightNodes[2]);
    rightNodes[2].setProperty(InternalProperties.IN_LAYER_LAYOUT_UNIT, rightNodes[2]);
    setUpIds();
    return graph;
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 15 with Layer

use of org.eclipse.elk.alg.layered.graph.Layer in project elk by eclipse.

the class TestGraphCreator method getCurrentOrder.

/**
 * Returns the nodes in the graph as two-dimensional array of LNodes.
 *
 * @return graph as LNode[][].
 */
public LNode[][] getCurrentOrder() {
    LNode[][] nodeOrder = new LNode[graph.getLayers().size()][];
    List<Layer> layers = graph.getLayers();
    for (int i = 0; i < layers.size(); i++) {
        Layer layer = layers.get(i);
        List<LNode> nodes = layer.getNodes();
        nodeOrder[i] = new LNode[nodes.size()];
        for (int j = 0; j < nodes.size(); j++) {
            nodeOrder[i][j] = nodes.get(j);
        }
    }
    return nodeOrder;
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Aggregations

Layer (org.eclipse.elk.alg.layered.graph.Layer)209 LNode (org.eclipse.elk.alg.layered.graph.LNode)185 LPort (org.eclipse.elk.alg.layered.graph.LPort)64 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)40 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)36 Test (org.junit.Test)25 TestAfterProcessor (org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)13 KVector (org.eclipse.elk.core.math.KVector)12 List (java.util.List)9 NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)6 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)6 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)5 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)5 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)5 BPInfo (org.eclipse.elk.alg.layered.intermediate.wrapping.BreakingPointInserter.BPInfo)4 GraphInfoHolder (org.eclipse.elk.alg.layered.p3order.GraphInfoHolder)4 ILayoutProcessor (org.eclipse.elk.core.alg.ILayoutProcessor)4 PortSide (org.eclipse.elk.core.options.PortSide)4 Pair (org.eclipse.elk.core.util.Pair)4 ArrayList (java.util.ArrayList)3