Search in sources :

Example 21 with LNode

use of org.eclipse.elk.alg.layered.graph.LNode 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 22 with LNode

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

the class HierarchicalNodeResizingProcessor method resizeGraphNoReallyIMeanIt.

/**
 * Applies a new effective size to a graph that previously had an old size calculated by the layout algorithm. This
 * method takes care of adjusting content alignments as well as external ports that would be misplaced if the new
 * size is larger than the old one.
 *
 * @param lgraph
 *            the graph to apply the size to.
 * @param oldSize
 *            old size as calculated by the layout algorithm.
 * @param newSize
 *            new size that may be larger than the old one.
 */
private void resizeGraphNoReallyIMeanIt(final LGraph lgraph, final KVector oldSize, final KVector newSize) {
    // obey to specified alignment constraints
    Set<ContentAlignment> contentAlignment = lgraph.getProperty(LayeredOptions.CONTENT_ALIGNMENT);
    // horizontal alignment
    if (newSize.x > oldSize.x) {
        if (contentAlignment.contains(ContentAlignment.H_CENTER)) {
            lgraph.getOffset().x += (newSize.x - oldSize.x) / 2f;
        } else if (contentAlignment.contains(ContentAlignment.H_RIGHT)) {
            lgraph.getOffset().x += newSize.x - oldSize.x;
        }
    }
    // vertical alignment
    if (newSize.y > oldSize.y) {
        if (contentAlignment.contains(ContentAlignment.V_CENTER)) {
            lgraph.getOffset().y += (newSize.y - oldSize.y) / 2f;
        } else if (contentAlignment.contains(ContentAlignment.V_BOTTOM)) {
            lgraph.getOffset().y += newSize.y - oldSize.y;
        }
    }
    // correct the position of eastern and southern hierarchical ports, if necessary
    if (lgraph.getProperty(InternalProperties.GRAPH_PROPERTIES).contains(GraphProperties.EXTERNAL_PORTS) && (newSize.x > oldSize.x || newSize.y > oldSize.y)) {
        // (at this point, the graph's nodes are not divided into layers anymore)
        for (LNode node : lgraph.getLayerlessNodes()) {
            // we're only looking for external port dummies
            if (node.getType() == NodeType.EXTERNAL_PORT) {
                // check which side the external port is on
                PortSide extPortSide = node.getProperty(InternalProperties.EXT_PORT_SIDE);
                if (extPortSide == PortSide.EAST) {
                    node.getPosition().x += newSize.x - oldSize.x;
                } else if (extPortSide == PortSide.SOUTH) {
                    node.getPosition().y += newSize.y - oldSize.y;
                }
            }
        }
    }
    // Actually apply the new size
    LPadding padding = lgraph.getPadding();
    lgraph.getSize().x = newSize.x - padding.left - padding.right;
    lgraph.getSize().y = newSize.y - padding.top - padding.bottom;
}
Also used : ContentAlignment(org.eclipse.elk.core.options.ContentAlignment) LPadding(org.eclipse.elk.alg.layered.graph.LPadding) LNode(org.eclipse.elk.alg.layered.graph.LNode) PortSide(org.eclipse.elk.core.options.PortSide)

Example 23 with LNode

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

the class EndLabelSorterTest method testNode.

private void testNode(final LNode node) {
    switch(node.getType()) {
        case NORMAL:
            // Build a list of label strings that we can check
            if (node.hasProperty(InternalProperties.END_LABELS)) {
                for (LabelCell labelCell : node.getProperty(InternalProperties.END_LABELS).values()) {
                    List<String> labelStrings = labelCell.getLabels().stream().map(label -> label.getText()).collect(Collectors.toList());
                    failIfUnsorted(labelStrings);
                }
            }
            break;
        case LABEL:
            List<LLabel> labels = node.getProperty(InternalProperties.REPRESENTED_LABELS);
            assertNotNull(labels);
            List<String> labelStrings = labels.stream().map(label -> label.getText()).collect(Collectors.toList());
            failIfUnsorted(labelStrings);
            break;
    }
}
Also used : LayoutTestRunner(org.eclipse.elk.alg.test.framework.LayoutTestRunner) ModelResourcePath(org.eclipse.elk.alg.test.framework.io.ModelResourcePath) Iterator(java.util.Iterator) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) Algorithm(org.eclipse.elk.alg.test.framework.annotations.Algorithm) Assert.assertNotNull(org.junit.Assert.assertNotNull) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) DefaultConfiguration(org.eclipse.elk.alg.test.framework.annotations.DefaultConfiguration) Collectors(java.util.stream.Collectors) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) LabelCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell) List(java.util.List) AbstractResourcePath(org.eclipse.elk.alg.test.framework.io.AbstractResourcePath) Lists(com.google.common.collect.Lists) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) LNode(org.eclipse.elk.alg.layered.graph.LNode) GraphResourceProvider(org.eclipse.elk.alg.test.framework.annotations.GraphResourceProvider) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LabelCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell)

Example 24 with LNode

use of org.eclipse.elk.alg.layered.graph.LNode 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 25 with LNode

use of org.eclipse.elk.alg.layered.graph.LNode 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)

Aggregations

LNode (org.eclipse.elk.alg.layered.graph.LNode)471 LPort (org.eclipse.elk.alg.layered.graph.LPort)189 Layer (org.eclipse.elk.alg.layered.graph.Layer)185 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)110 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)91 Test (org.junit.Test)85 KVector (org.eclipse.elk.core.math.KVector)38 PortSide (org.eclipse.elk.core.options.PortSide)28 List (java.util.List)23 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)22 GraphInfoHolder (org.eclipse.elk.alg.layered.p3order.GraphInfoHolder)16 TestAfterProcessor (org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)16 KVectorChain (org.eclipse.elk.core.math.KVectorChain)15 NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)14 ArrayList (java.util.ArrayList)13 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)13 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)13 PortConstraints (org.eclipse.elk.core.options.PortConstraints)13 Set (java.util.Set)12 CrossingsCounter (org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter)10