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