Search in sources :

Example 61 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project sirius-components by eclipse-sirius.

the class DiagramConverterTests method testDiagramOneImageNode.

@Test
public void testDiagramOneImageNode() {
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    ELKDiagramConverter diagramConverter = new ELKDiagramConverter(this.textBoundsService, imageSizeProvider);
    // @formatter:off
    TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
    Node node = Node.newNode(diagramBuilder.getNode(FIRST_NODE_ID)).style(diagramBuilder.getImageNodeStyle()).build();
    Diagram diagram = Diagram.newDiagram(diagramBuilder.getDiagram(DIAGRAM_ID)).nodes(List.of(node)).build();
    // @formatter:on
    ELKConvertedDiagram convertedDiagram = diagramConverter.convert(diagram);
    ElkNode elkDiagram = convertedDiagram.getElkDiagram();
    assertThat(elkDiagram.getChildren().size()).isEqualTo(1);
    Map<String, ElkGraphElement> id2ElkGraphElements = convertedDiagram.getId2ElkGraphElements();
    assertThat(id2ElkGraphElements.get(node.getId().toString())).isInstanceOf(ElkNode.class);
    assertThat(id2ElkGraphElements.get(node.getLabel().getId().toString())).isInstanceOf(ElkLabel.class);
    ElkNode elkNode = (ElkNode) id2ElkGraphElements.get(node.getId().toString());
    this.assertSize(elkNode, TEXT_WIDTH, TEXT_HEIGHT);
    assertThat(elkNode.getChildren().size()).isEqualTo(1);
    ElkNode elkImage = elkNode.getChildren().get(0);
    this.assertSize(elkImage, IMAGE_WIDTH, IMAGE_HEIGHT);
    assertThat(elkNode.getLabels().size()).isEqualTo(1);
    ElkLabel elkLabel = elkNode.getLabels().get(0);
    this.assertSize(elkLabel, TEXT_WIDTH, TEXT_HEIGHT);
    imageSizeProvider.dispose();
}
Also used : ELKDiagramConverter(org.eclipse.sirius.components.diagrams.layout.ELKDiagramConverter) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) ElkNode(org.eclipse.elk.graph.ElkNode) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) ElkLabel(org.eclipse.elk.graph.ElkLabel) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 62 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project sirius-components by eclipse-sirius.

the class DiagramConverterTests method testDiagramOneRectangularNode.

@Test
public void testDiagramOneRectangularNode() {
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    ELKDiagramConverter diagramConverter = new ELKDiagramConverter(this.textBoundsService, imageSizeProvider);
    // @formatter:off
    TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
    Node node = diagramBuilder.getNode(FIRST_NODE_ID);
    Diagram diagram = Diagram.newDiagram(diagramBuilder.getDiagram(DIAGRAM_ID)).nodes(List.of(node)).build();
    // @formatter:on
    ELKConvertedDiagram convertedDiagram = diagramConverter.convert(diagram);
    ElkNode elkDiagram = convertedDiagram.getElkDiagram();
    assertThat(elkDiagram.getChildren().size()).isEqualTo(1);
    Map<String, ElkGraphElement> id2ElkGraphElements = convertedDiagram.getId2ElkGraphElements();
    assertThat(id2ElkGraphElements.get(node.getId().toString())).isInstanceOf(ElkNode.class);
    assertThat(id2ElkGraphElements.get(node.getLabel().getId().toString())).isInstanceOf(ElkLabel.class);
    ElkNode elkNode = (ElkNode) id2ElkGraphElements.get(node.getId().toString());
    this.assertSize(elkNode, TEXT_WIDTH, TEXT_HEIGHT);
    assertThat(elkNode.getLabels().size()).isEqualTo(1);
    ElkLabel elkLabel = elkNode.getLabels().get(0);
    this.assertSize(elkLabel, TEXT_WIDTH, TEXT_HEIGHT);
    imageSizeProvider.dispose();
}
Also used : ELKDiagramConverter(org.eclipse.sirius.components.diagrams.layout.ELKDiagramConverter) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) ElkNode(org.eclipse.elk.graph.ElkNode) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) ElkLabel(org.eclipse.elk.graph.ElkLabel) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 63 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project sirius-components by eclipse-sirius.

the class LayoutedDiagramProviderTests method getConvertedDiagram.

private ELKConvertedDiagram getConvertedDiagram(Diagram originalDiagram) {
    Map<String, ElkGraphElement> id2ElkGraphElements = new HashMap<>();
    ElkNode elkDiagram = ElkGraphFactory.eINSTANCE.createElkNode();
    elkDiagram.setIdentifier(originalDiagram.getId().toString());
    Node node = originalDiagram.getNodes().get(0);
    ElkNode elkNode = ElkGraphFactory.eINSTANCE.createElkNode();
    elkNode.setIdentifier(node.getId().toString());
    elkNode.setDimensions(NODE_WIDTH, NODE_HEIGHT);
    elkNode.setX(NODE_X);
    elkNode.setY(NODE_Y);
    elkNode.setParent(elkDiagram);
    ElkLabel elkLabel = ElkGraphFactory.eINSTANCE.createElkLabel();
    elkLabel.setIdentifier(node.getLabel().getId().toString());
    elkLabel.setDimensions(LABEL_WIDTH, LABEL_HEIGHT);
    elkLabel.setX(LABEL_X);
    elkLabel.setY(LABEL_Y);
    elkLabel.setParent(elkNode);
    id2ElkGraphElements.put(elkLabel.getIdentifier(), elkLabel);
    id2ElkGraphElements.put(elkNode.getIdentifier(), elkNode);
    String edgeId = originalDiagram.getEdges().get(0).getId();
    ElkEdge elkEdge = ElkGraphFactory.eINSTANCE.createElkEdge();
    elkEdge.setIdentifier(edgeId.toString());
    elkEdge.getSources().add(elkNode);
    elkEdge.getTargets().add(elkNode);
    elkEdge.setContainingNode(elkDiagram);
    ElkEdgeSection section = ElkGraphFactory.eINSTANCE.createElkEdgeSection();
    section.setStartX(NODE_X);
    section.setStartY(NODE_Y);
    ElkBendPoint bendPoint = ElkGraphFactory.eINSTANCE.createElkBendPoint();
    bendPoint.setX(EDGE_BENDPOINT_X);
    bendPoint.setY(EDGE_BENDPOINT_Y);
    section.getBendPoints().add(bendPoint);
    section.setEndX(NODE_X);
    section.setEndY(NODE_Y);
    elkEdge.getSections().add(section);
    id2ElkGraphElements.put(elkEdge.getIdentifier(), elkEdge);
    return new ELKConvertedDiagram(elkDiagram, id2ElkGraphElements);
}
Also used : ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) ElkNode(org.eclipse.elk.graph.ElkNode) HashMap(java.util.HashMap) ElkLabel(org.eclipse.elk.graph.ElkLabel) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ElkBendPoint(org.eclipse.elk.graph.ElkBendPoint) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 64 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project sirius-components by eclipse-sirius.

the class ELKLayoutedDiagramProvider method getLayoutedLabel.

private Label getLayoutedLabel(Label label, Map<String, ElkGraphElement> id2ElkGraphElements, double xOffset, double yOffset) {
    Label layoutedLabel = label;
    var optionalElkBeginLabel = Optional.of(id2ElkGraphElements.get(label.getId().toString())).filter(ElkLabel.class::isInstance).map(ElkLabel.class::cast);
    if (optionalElkBeginLabel.isPresent()) {
        ElkLabel elkLabel = optionalElkBeginLabel.get();
        Size size = Size.of(elkLabel.getWidth(), elkLabel.getHeight());
        Position position = Position.at(xOffset + elkLabel.getX(), yOffset + elkLabel.getY());
        // @formatter:off
        Position alignment = elkLabel.eAdapters().stream().findFirst().filter(AlignmentHolder.class::isInstance).map(AlignmentHolder.class::cast).map(AlignmentHolder::getAlignment).orElse(Position.UNDEFINED);
        layoutedLabel = Label.newLabel(label).size(size).position(position).alignment(alignment).build();
    // @formatter:on
    }
    return layoutedLabel;
}
Also used : ElkLabel(org.eclipse.elk.graph.ElkLabel) Position(org.eclipse.sirius.components.diagrams.Position) Size(org.eclipse.sirius.components.diagrams.Size) ElkLabel(org.eclipse.elk.graph.ElkLabel) Label(org.eclipse.sirius.components.diagrams.Label)

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