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