use of org.eclipse.elk.graph.ElkNode in project sirius-components by eclipse-sirius.
the class DiagramConverterTests method testDiagramOneNodeAndOneBorderNode.
@Test
public void testDiagramOneNodeAndOneBorderNode() {
ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
ELKDiagramConverter diagramConverter = new ELKDiagramConverter(this.textBoundsService, imageSizeProvider);
// @formatter:off
TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
Node borderNode = Node.newNode(diagramBuilder.getNode(FIRST_NODE_ID)).style(diagramBuilder.getRectangularNodeStyle()).build();
Node node = Node.newNode(diagramBuilder.getNode(SECOND_NODE_ID)).style(diagramBuilder.getImageNodeStyle()).borderNodes(List.of(borderNode)).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);
ElkNode elkNode = elkDiagram.getChildren().get(0);
assertThat(elkNode.getPorts().size()).isEqualTo(1);
ElkPort elkPort = elkNode.getPorts().get(0);
assertThat(elkPort.getIdentifier()).isEqualTo(borderNode.getId().toString());
imageSizeProvider.dispose();
}
use of org.eclipse.elk.graph.ElkNode in project sirius-components by eclipse-sirius.
the class DiagramConverterTests method testDiagramOneEdgeBetweenTwoBorderNodes.
@Test
public void testDiagramOneEdgeBetweenTwoBorderNodes() {
ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
ELKDiagramConverter diagramConverter = new ELKDiagramConverter(this.textBoundsService, imageSizeProvider);
// @formatter:off
TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
Node firstBorderNode = Node.newNode(diagramBuilder.getNode(FIRST_NODE_ID)).style(diagramBuilder.getRectangularNodeStyle()).build();
Node secondBorderNode = Node.newNode(diagramBuilder.getNode(SECOND_NODE_ID)).style(diagramBuilder.getRectangularNodeStyle()).build();
Node node = Node.newNode(diagramBuilder.getNode(THIRD_NODE_ID)).style(diagramBuilder.getImageNodeStyle()).borderNodes(List.of(firstBorderNode, secondBorderNode)).build();
Edge edge = Edge.newEdge(diagramBuilder.getEdge(FIRST_EDGE_ID, firstBorderNode.getId(), secondBorderNode.getId())).build();
Diagram diagram = Diagram.newDiagram(diagramBuilder.getDiagram(DIAGRAM_ID)).nodes(List.of(node)).edges(List.of(edge)).build();
// @formatter:on
ELKConvertedDiagram convertedDiagram = diagramConverter.convert(diagram);
ElkNode elkDiagram = convertedDiagram.getElkDiagram();
assertThat(elkDiagram.getChildren().size()).isEqualTo(1);
assertThat(elkDiagram.getChildren().get(0)).isInstanceOf(ElkNode.class);
assertThat(elkDiagram.getContainedEdges().size()).isEqualTo(1);
assertThat(elkDiagram.getContainedEdges().get(0)).isInstanceOf(ElkEdge.class);
ElkEdge elkEdge = elkDiagram.getContainedEdges().get(0);
assertThat(elkEdge.getSources().size()).isEqualTo(1);
assertThat(elkEdge.getSources().get(0).getIdentifier()).isEqualTo(firstBorderNode.getId().toString());
assertThat(elkEdge.getTargets().size()).isEqualTo(1);
assertThat(elkEdge.getTargets().get(0).getIdentifier()).isEqualTo(secondBorderNode.getId().toString());
imageSizeProvider.dispose();
}
use of org.eclipse.elk.graph.ElkNode in project sirius-components by eclipse-sirius.
the class DiagramConverterTests method testDiagramOneNodeAndOneEdge.
@Test
public void testDiagramOneNodeAndOneEdge() {
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();
Edge edge = Edge.newEdge(diagramBuilder.getEdge(FIRST_EDGE_ID, node.getId(), node.getId())).build();
Diagram diagram = Diagram.newDiagram(diagramBuilder.getDiagram(DIAGRAM_ID)).nodes(List.of(node)).edges(List.of(edge)).build();
// @formatter:on
ELKConvertedDiagram convertedDiagram = diagramConverter.convert(diagram);
ElkNode elkDiagram = convertedDiagram.getElkDiagram();
assertThat(elkDiagram.getContainedEdges().size()).isEqualTo(1);
ElkEdge elkEdge = elkDiagram.getContainedEdges().get(0);
assertThat(elkEdge.getIdentifier()).isEqualTo(edge.getId().toString());
imageSizeProvider.dispose();
}
use of org.eclipse.elk.graph.ElkNode in project sirius-components by eclipse-sirius.
the class LayoutService method layout.
@Override
public Diagram layout(IEditingContext editingContext, Diagram diagram) {
ELKConvertedDiagram convertedDiagram = this.elkDiagramConverter.convert(diagram);
ElkNode elkDiagram = convertedDiagram.getElkDiagram();
// @formatter:off
var optionalDiagramDescription = this.representationDescriptionSearchService.findById(editingContext, diagram.getDescriptionId()).filter(DiagramDescription.class::isInstance).map(DiagramDescription.class::cast);
// @formatter:on
ISiriusWebLayoutConfigurator layoutConfigurator;
if (optionalDiagramDescription.isPresent()) {
var diagramDescription = optionalDiagramDescription.get();
elkDiagram = this.layoutConfiguratorRegistry.applyBeforeLayout(elkDiagram, editingContext, diagram, diagramDescription);
layoutConfigurator = this.layoutConfiguratorRegistry.getLayoutConfigurator(diagram, diagramDescription);
} else {
layoutConfigurator = this.layoutConfiguratorRegistry.getDefaultLayoutConfigurator();
}
ElkUtil.applyVisitors(elkDiagram, layoutConfigurator);
IGraphLayoutEngine engine = new RecursiveGraphLayoutEngine();
engine.layout(elkDiagram, new BasicProgressMonitor());
if (optionalDiagramDescription.isPresent()) {
var diagramDescription = optionalDiagramDescription.get();
elkDiagram = this.layoutConfiguratorRegistry.applyAfterLayout(elkDiagram, editingContext, diagram, diagramDescription);
}
Map<String, ElkGraphElement> id2ElkGraphElements = convertedDiagram.getId2ElkGraphElements();
Diagram layoutedDiagram = this.elkLayoutedDiagramProvider.getLayoutedDiagram(diagram, elkDiagram, id2ElkGraphElements);
if (this.logger.isDebugEnabled()) {
// @formatter:off
String json = ElkGraphJson.forGraph(elkDiagram).omitLayout(true).omitZeroDimension(true).omitZeroPositions(true).shortLayoutOptionKeys(false).prettyPrint(true).toJson();
// @formatter:on
this.logger.debug(json);
}
return layoutedDiagram;
}
use of org.eclipse.elk.graph.ElkNode in project sirius-components by eclipse-sirius.
the class ELKDiagramConverter method convert.
@Override
public ELKConvertedDiagram convert(Diagram diagram) {
Diagram initializedDiagram = this.initializeDiagram(diagram);
ElkNode elkDiagram = this.convertDiagram(initializedDiagram);
Map<String, ElkGraphElement> id2ElkGraphElements = new HashMap<>();
Map<String, ElkConnectableShape> connectableShapeIndex = new LinkedHashMap<>();
initializedDiagram.getNodes().stream().forEach(node -> this.convertNode(node, elkDiagram, connectableShapeIndex, id2ElkGraphElements));
initializedDiagram.getEdges().stream().forEach(edge -> this.convertEdge(edge, elkDiagram, connectableShapeIndex, id2ElkGraphElements));
return new ELKConvertedDiagram(elkDiagram, id2ElkGraphElements);
}
Aggregations