use of org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram 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();
}
use of org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram 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);
}
Aggregations