Search in sources :

Example 6 with LGraph

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

the class TestGraphCreator method getCrossWithManySelfLoopsGraph.

/**
 * Cross formed graph, but each node has three extra self loop edges.
 *
 * <pre>
 * *  *
 *  \/
 *  /\
 * *  *
 * .
 * </pre>
 *
 * @return Graph of the form above.
 */
public LGraph getCrossWithManySelfLoopsGraph() {
    LGraph selfLoopCrossGraph = getCrossFormedGraph();
    for (Layer layer : selfLoopCrossGraph) {
        for (LNode node : layer) {
            selfLoopOn(node, PortSide.EAST);
            selfLoopOn(node, PortSide.EAST);
            selfLoopOn(node, PortSide.EAST);
            selfLoopOn(node, PortSide.WEST);
            selfLoopOn(node, PortSide.WEST);
            selfLoopOn(node, PortSide.WEST);
        }
    }
    return selfLoopCrossGraph;
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 7 with LGraph

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

the class SortByInputModelProcessorTest method preserveNodeAndEdgeOrder.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
@TestAfterProcessor(LayerSweepCrossingMinimizer.class)
public void preserveNodeAndEdgeOrder(final Object graph) {
    LGraph lgraph = (LGraph) graph;
    int layerIndex = 0;
    for (Layer layer : lgraph) {
        int nodeIndex = 0;
        for (LNode node : layer.getNodes()) {
            if (node.getType() == NodeType.NORMAL) {
                assertEquals("A node is on an unexpected position.", "n_l" + layerIndex + "p" + nodeIndex, node.toString());
            }
            nodeIndex++;
        }
        layerIndex++;
    }
}
Also used : 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 8 with LGraph

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

the class LayerConstraintProcessorTest method noEmptyLayers.

/**
 * All labels on ports and edges have an assigned {@link LabelSide}.
 */
@TestAfterProcessor(LayerConstraintPostprocessor.class)
public void noEmptyLayers(Object graph) {
    LGraph lGraph = (LGraph) graph;
    lGraph.getLayers().stream().forEach(layer -> assertTrue(!layer.getNodes().isEmpty()));
}
Also used : LGraph(org.eclipse.elk.alg.layered.graph.LGraph) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)

Example 9 with LGraph

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

the class NodeMarginCalculatorTest method testNodeMargins.

private void testNodeMargins(final Object graph) {
    LGraph lGraph = (LGraph) graph;
    for (Layer layer : lGraph) {
        for (LNode node : layer) {
            assertTrue(node.getMargin() != null);
            assertTrue(node.getMargin().top >= 0);
            assertTrue(node.getMargin().right >= 0);
            assertTrue(node.getMargin().bottom >= 0);
            assertTrue(node.getMargin().left >= 0);
        }
    }
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 10 with LGraph

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

the class GreedySwitchProcessorTest method selfLoops.

@Test
public void selfLoops() {
    Layer leftLayer = makeLayer(getGraph());
    Layer rightLayer = makeLayer(getGraph());
    LNode topLeft = addNodeToLayer(leftLayer);
    LNode bottomLeft = addNodeToLayer(leftLayer);
    LNode topRight = addNodeToLayer(rightLayer);
    LNode bottomRight = addNodeToLayer(rightLayer);
    LPort topLeftPort = addPortOnSide(topLeft, PortSide.EAST);
    LPort bottomLeftPort = addPortOnSide(bottomLeft, PortSide.EAST);
    setUpIds();
    LGraph selfLoopCrossGraph = getGraph();
    for (Layer layer : selfLoopCrossGraph) {
        for (LNode node : layer) {
            selfLoopOn(node, PortSide.EAST);
            selfLoopOn(node, PortSide.EAST);
            selfLoopOn(node, PortSide.EAST);
            selfLoopOn(node, PortSide.WEST);
            selfLoopOn(node, PortSide.WEST);
            selfLoopOn(node, PortSide.WEST);
        }
    }
    LPort topRightPort = addPortOnSide(topRight, PortSide.WEST);
    LPort bottomRightPort = addPortOnSide(bottomRight, PortSide.WEST);
    addEdgeBetweenPorts(topLeftPort, bottomRightPort);
    addEdgeBetweenPorts(bottomLeftPort, topRightPort);
    List<LNode> expectedOrderLayerOne;
    List<LNode> expectedOrderLayerTwo;
    if (greedyType == CrossMinType.ONE_SIDED_GREEDY_SWITCH) {
        expectedOrderLayerOne = copyOfNodesInLayer(0);
        expectedOrderLayerTwo = copyOfSwitchOrderOfNodesInLayer(0, 1, 1);
    } else {
        expectedOrderLayerOne = copyOfSwitchOrderOfNodesInLayer(0, 1, 0);
        expectedOrderLayerTwo = copyOfNodesInLayer(1);
    }
    startGreedySwitcherWithCurrentType();
    assertThat("Layer one", copyOfNodesInLayer(0), is(expectedOrderLayerOne));
    assertThat("Layer two", copyOfNodesInLayer(1), is(expectedOrderLayerTwo));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Layer(org.eclipse.elk.alg.layered.graph.Layer) Test(org.junit.Test)

Aggregations

LGraph (org.eclipse.elk.alg.layered.graph.LGraph)115 LNode (org.eclipse.elk.alg.layered.graph.LNode)90 LPort (org.eclipse.elk.alg.layered.graph.LPort)49 Layer (org.eclipse.elk.alg.layered.graph.Layer)38 Test (org.junit.Test)36 TestAfterProcessor (org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)19 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)17 KVector (org.eclipse.elk.core.math.KVector)15 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)14 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)13 List (java.util.List)11 ILayoutProcessor (org.eclipse.elk.core.alg.ILayoutProcessor)11 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)10 NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)9 Lists (com.google.common.collect.Lists)7 Set (java.util.Set)7 GraphProperties (org.eclipse.elk.alg.layered.options.GraphProperties)7 GraphInfoHolder (org.eclipse.elk.alg.layered.p3order.GraphInfoHolder)7 PortSide (org.eclipse.elk.core.options.PortSide)7 ElkNode (org.eclipse.elk.graph.ElkNode)7