Search in sources :

Example 26 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class Issue682Test method testGraph.

public Triple<ElkNode, ElkNode, ElkLabel> testGraph() {
    ElkNode graph = ElkGraphUtil.createGraph();
    graph.setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
    graph.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
    graph.setProperty(LayeredOptions.DIRECTION, layoutDirection);
    graph.setProperty(LayeredOptions.NODE_LABELS_PADDING, new ElkPadding(21, 32, 43, 54));
    ElkNode parent = ElkGraphUtil.createNode(graph);
    parent.setProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.NODE_LABELS));
    parent.setProperty(LayeredOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.insideTopCenter());
    ElkLabel label = ElkGraphUtil.createLabel("foobar", parent);
    // Arbitrary
    label.setWidth(23);
    label.setHeight(22);
    return new Triple<>(graph, parent, label);
}
Also used : Triple(org.eclipse.elk.core.util.Triple) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 27 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class Issue701Test method testMixInsideAndOutsideLabels.

/**
 * Check behavior for port labels that is forced to be inside or outside the node according to
 * {@link PortLabelPlacement} property, with more complex cases that {@link #testInsideLabels(ElkNode)} and
 * {@link #testOutsideLabels(ElkNode)}.
 */
@Test
public void testMixInsideAndOutsideLabels(final ElkNode graph) {
    ElkNode containerForMixInsideOutsideLabels = GraphTestUtils.getChild(graph, "ContainerWithLabelsInsideAndOutside", "Container_SeveralBorderNodes_LabelInsideAndOutside");
    // Ensure there is no label overlaps
    if (GraphTestUtils.haveOverlaps(assembleLabels(containerForMixInsideOutsideLabels))) {
    // TODO: Check deactivated because it fails for "MyCont2": case with 2 border nodes without edges. Maybe to
    // review for https://github.com/eclipse/elk/issues/638.
    // fail("Overlaps between labels detected in \"Container_SeveralBorderNodes_LabelInsideAndOutside\"!");
    }
    // Ports on north and on south sides
    ElkNode node1 = GraphTestUtils.getChild(containerForMixInsideOutsideLabels, "MyNode1");
    ElkPort node1Port1 = GraphTestUtils.getPort(node1, "P1");
    ElkPort node1Port2 = GraphTestUtils.getPort(node1, "P2");
    assertNodeWidthAccordingToPortWidth(node1, node1Port1, node1Port2, false);
    assertNodeHeightAccordingToPortHeight(node1, node1Port1, node1Port2, false);
    // Ports on east and on west sides
    ElkNode node2 = GraphTestUtils.getChild(containerForMixInsideOutsideLabels, "MyNode2");
    ElkPort node2Port1 = GraphTestUtils.getPort(node2, "P1");
    ElkPort node2Port2 = GraphTestUtils.getPort(node2, "P2");
    assertNodeWidthAccordingToPortWidth(node2, node2Port1, node2Port2, true);
    assertNodeHeightAccordingToPortHeight(node2, node2Port1, node2Port2, true);
    // Ports on east and on west sides with a node inside the container without edge
    // TODO: Ignored. The behavior seems KO. Maybe to review for https://github.com/eclipse/elk/issues/638.
    // ElkNode cont2 = GraphTestUtils.getChild(containerForMixInsideOutsideLabels, "MyCont2");
    // Ports on east and on west sides with a node inside the container and linked to the ports, check width of the
    // container
    ElkNode cont3 = GraphTestUtils.getChild(containerForMixInsideOutsideLabels, "MyCont3");
    ElkNode cont3Node2 = GraphTestUtils.getChild(cont3, "MyNode2");
    ElkPort cont3Port1 = GraphTestUtils.getPort(cont3, "P1");
    ElkLabel cont3Port1Label = cont3Port1.getLabels().get(0);
    ElkPort cont3Port2 = GraphTestUtils.getPort(cont3, "P2");
    ElkLabel cont3Port2Label = cont3Port2.getLabels().get(0);
    double spacingLabelCont3Port1 = cont3Port1.getProperty(CoreOptions.SPACING_LABEL_PORT);
    double spacingLabelCont3Port2 = cont3Port2.getProperty(CoreOptions.SPACING_LABEL_PORT);
    double cont3Port1BorderOffset = cont3Port1.getProperty(CoreOptions.PORT_BORDER_OFFSET);
    double cont3Port2BorderOffset = cont3Port2.getProperty(CoreOptions.PORT_BORDER_OFFSET);
    ElkPadding cont3Padding = cont3.getProperty(CoreOptions.PADDING);
    // Compute expected width
    double expectedCont3Width = cont3Padding.getLeft();
    // TODO: It seems to be a bug here. There is only 4 pixels instead of 12
    expectedCont3Width -= 8;
    expectedCont3Width += cont3Node2.getWidth();
    expectedCont3Width += -cont3Port2BorderOffset;
    expectedCont3Width += spacingLabelCont3Port2;
    expectedCont3Width += cont3Port2Label.getWidth();
    expectedCont3Width += cont3Port1Label.getWidth();
    expectedCont3Width += spacingLabelCont3Port1;
    expectedCont3Width += -cont3Port1BorderOffset;
    expectedCont3Width += cont3Padding.getRight();
    assertEquals("Wrong node width according to ports label width.", expectedCont3Width, cont3.getWidth(), 0);
    // Port on east side on a node in container, port on west side of the container, and with edge between ports,
    // check width of the container
    ElkNode cont4 = GraphTestUtils.getChild(containerForMixInsideOutsideLabels, "MyCont4");
    ElkNode cont4Node1 = GraphTestUtils.getChild(cont4, "MyNode1");
    ElkPort cont4Node1Port1 = GraphTestUtils.getPort(cont4Node1, "P1");
    ElkLabel cont4Node1Port1Label = cont4Node1Port1.getLabels().get(0);
    ElkPort cont4Port1 = GraphTestUtils.getPort(cont4, "P1");
    ElkLabel cont4Port1Label = cont4Port1.getLabels().get(0);
    double spacingLabelCont4Node1Port1 = cont4Node1Port1.getProperty(CoreOptions.SPACING_LABEL_PORT);
    double spacingLabelCont4Port1 = cont4Port1.getProperty(CoreOptions.SPACING_LABEL_PORT);
    double cont4Node1Port1BorderOffset = cont4Node1Port1.getProperty(CoreOptions.PORT_BORDER_OFFSET);
    double cont4Port1BorderOffset = cont4Port1.getProperty(CoreOptions.PORT_BORDER_OFFSET);
    ElkPadding cont4Padding = cont4.getProperty(CoreOptions.PADDING);
    // Compute expected width
    double expectedCont4Width = cont4Padding.getLeft();
    expectedCont4Width += cont4Node1.getWidth();
    // TODO: ElkUtil.calcPortOffset(cont4Node1Port1, PortSide.EAST); is supposed to do the same computing as below
    // but it is not the case
    expectedCont4Width += cont4Node1Port1.getWidth() + cont4Node1Port1BorderOffset;
    expectedCont4Width += spacingLabelCont4Node1Port1;
    expectedCont4Width += cont4Node1Port1Label.getWidth();
    expectedCont4Width += cont4Port1Label.getWidth();
    expectedCont4Width += spacingLabelCont4Port1;
    expectedCont4Width += -cont4Port1BorderOffset;
    expectedCont4Width += cont4Padding.getRight();
    assertEquals("Wrong node width according to ports label width.", expectedCont4Width, cont4.getWidth(), 0);
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) ElkPadding(org.eclipse.elk.core.math.ElkPadding) Test(org.junit.Test)

Example 28 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class Issue405Test method testPortAndLabelPositionsEqual.

@Test
public void testPortAndLabelPositionsEqual(final ElkNode graph) {
    // There are four (non-hierarchical) nodes within the diagram for which different layout directions are used.
    // Each node has a number of ports, each of which has a single label.
    // While we do not know in which "order" the ports are placed, we expect the collective of port positions
    // (and port label positions) to match each other for all of the various layout directions.
    final List<String> topNodes = Lists.newArrayList("Right", "Down", "Left", "Up");
    // Now check for each subsequent pair of these "layout-direction nodes" that their ports and labels match.
    topNodes.stream().map(name -> getRelevantPortsAndPortLabels(graph, name)).reduce((previous, current) -> {
        for (ElkPort port : previous.getFirst()) {
            // For the previous node's port, find all of the current node's ports that match its position
            List<ElkPort> matchingPorts = current.getFirst().stream().filter(other -> checkPositionEquals(port, other)).collect(Collectors.toList());
            if (matchingPorts.size() != 1) {
                // We expected there to be exactly one such port!
                fail(positionsDontMatchErrorMessage(port, current.getFirst()));
            }
        }
        for (ElkLabel label : previous.getSecond()) {
            // For the previous node's label, find all of the current node's ports that match its position
            List<ElkLabel> matchingLabels = current.getSecond().stream().filter(other -> checkPositionEquals(label, other)).collect(Collectors.toList());
            if (matchingLabels.size() != 1) {
                // We expected there to be exactly one such label!
                fail(positionsDontMatchErrorMessage(label, current.getSecond()));
            }
        }
        return current;
    });
}
Also used : DoubleMath(com.google.common.math.DoubleMath) LayoutTestRunner(org.eclipse.elk.alg.test.framework.LayoutTestRunner) ModelResourcePath(org.eclipse.elk.alg.test.framework.io.ModelResourcePath) Algorithm(org.eclipse.elk.alg.test.framework.annotations.Algorithm) ElkLabel(org.eclipse.elk.graph.ElkLabel) Collection(java.util.Collection) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) DefaultConfiguration(org.eclipse.elk.alg.test.framework.annotations.DefaultConfiguration) ElkShape(org.eclipse.elk.graph.ElkShape) Collectors(java.util.stream.Collectors) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) List(java.util.List) AbstractResourcePath(org.eclipse.elk.alg.test.framework.io.AbstractResourcePath) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) Lists(com.google.common.collect.Lists) Assert.fail(org.junit.Assert.fail) Pair(org.eclipse.elk.core.util.Pair) ElkGraphUtil(org.eclipse.elk.graph.util.ElkGraphUtil) Assert.assertEquals(org.junit.Assert.assertEquals) GraphResourceProvider(org.eclipse.elk.alg.test.framework.annotations.GraphResourceProvider) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) Test(org.junit.Test)

Example 29 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class Issue405_2Test method testPortAndLabelPositionsEqual.

@Test
public void testPortAndLabelPositionsEqual(final ElkNode graph) {
    // There are four (non-hierarchical) nodes within the diagram for which different layout directions are used.
    // Each node has a number of ports, each of which has a single label.
    // While we do not know in which "order" the ports are placed, we expect the collective of port positions
    // (and port label positions) to match each other for all of the various layout directions.
    final List<String> topNodes = Lists.newArrayList("Right", "Down", "Left", "Up");
    // Now check for each subsequent pair of these "layout-direction nodes" that their ports and labels match.
    topNodes.stream().map(name -> Issue405Test.getRelevantPortsAndPortLabels(graph, name)).reduce((previous, current) -> {
        for (ElkPort port : previous.getFirst()) {
            boolean foundExactlyOneMatch = current.getFirst().stream().map(other -> checkPositionEquals(port, other)).reduce(false, (a, b) -> a ^ b);
            assertTrue("Unexpected port position " + port, foundExactlyOneMatch);
        }
        for (ElkLabel label : previous.getSecond()) {
            boolean foundExactlyOneMatch = current.getSecond().stream().map(other -> checkPositionEquals(label, other)).reduce(false, (a, b) -> a ^ b);
            assertTrue("Unexpected port label position " + label, foundExactlyOneMatch);
        }
        return current;
    });
}
Also used : DoubleMath(com.google.common.math.DoubleMath) LayoutTestRunner(org.eclipse.elk.alg.test.framework.LayoutTestRunner) ModelResourcePath(org.eclipse.elk.alg.test.framework.io.ModelResourcePath) Algorithm(org.eclipse.elk.alg.test.framework.annotations.Algorithm) PortSide(org.eclipse.elk.core.options.PortSide) ElkLabel(org.eclipse.elk.graph.ElkLabel) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) DefaultConfiguration(org.eclipse.elk.alg.test.framework.annotations.DefaultConfiguration) ElkShape(org.eclipse.elk.graph.ElkShape) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) List(java.util.List) AbstractResourcePath(org.eclipse.elk.alg.test.framework.io.AbstractResourcePath) Lists(com.google.common.collect.Lists) GraphResourceProvider(org.eclipse.elk.alg.test.framework.annotations.GraphResourceProvider) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) Test(org.junit.Test)

Example 30 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class Issue471Test method testLabels.

private void testLabels(final ElkEdge edge) {
    double minX = Double.MAX_VALUE;
    double maxWidth = 0;
    for (ElkLabel label : edge.getLabels()) {
        minX = Math.min(minX, label.getX());
        maxWidth = Math.max(maxWidth, label.getWidth());
    }
    // Each label must be centered
    for (ElkLabel label : edge.getLabels()) {
        assertEquals(minX + (maxWidth - label.getWidth()) / 2, label.getX(), COORDINATE_FUZZYNESS);
    }
}
Also used : ElkLabel(org.eclipse.elk.graph.ElkLabel)

Aggregations

ElkLabel (org.eclipse.elk.graph.ElkLabel)64 ElkNode (org.eclipse.elk.graph.ElkNode)33 KVector (org.eclipse.elk.core.math.KVector)25 ElkPort (org.eclipse.elk.graph.ElkPort)23 ElkEdge (org.eclipse.elk.graph.ElkEdge)20 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)14 KVectorChain (org.eclipse.elk.core.math.KVectorChain)12 ElkPadding (org.eclipse.elk.core.math.ElkPadding)10 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)9 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)7 PortSide (org.eclipse.elk.core.options.PortSide)6 List (java.util.List)5 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)5 LPort (org.eclipse.elk.alg.layered.graph.LPort)5 ElkBendPoint (org.eclipse.elk.graph.ElkBendPoint)5 ElkConnectableShape (org.eclipse.elk.graph.ElkConnectableShape)5 Test (org.junit.Test)5 Lists (com.google.common.collect.Lists)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)4 DCElement (org.eclipse.elk.alg.disco.graph.DCElement)4