Search in sources :

Example 1 with NodeLabelPositionProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider in project sirius-components by eclipse-sirius.

the class IncrementalLayoutEngine method layout.

public void layout(Optional<IDiagramEvent> optionalDiagramElementEvent, DiagramLayoutData diagram, ISiriusWebLayoutConfigurator layoutConfigurator) {
    this.borderNodeLabelPositionProvider = new BorderNodeLabelPositionProvider();
    this.nodeLabelPositionProvider = new NodeLabelPositionProvider(layoutConfigurator);
    this.edgeLabelPositionProvider = new EdgeLabelPositionProvider(layoutConfigurator);
    // first we layout all the nodes
    for (NodeLayoutData node : diagram.getChildrenNodes()) {
        this.layoutNode(optionalDiagramElementEvent, node, layoutConfigurator);
    }
    // resolve overlaps due to previous changes
    new OverlapsUpdater().update(diagram);
    // resize according to the content
    new ContainmentUpdater().update(diagram);
    // finally we recompute the edges that needs to
    for (EdgeLayoutData edge : diagram.getEdges()) {
        if (this.hasChanged(edge.getSource()) || this.hasChanged(edge.getTarget()) || !this.isLabelPositioned(edge) || !this.isEdgePositioned(edge)) {
            this.layoutEdge(optionalDiagramElementEvent, edge);
        }
    }
}
Also used : EdgeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData) ContainmentUpdater(org.eclipse.sirius.components.diagrams.layout.incremental.updater.ContainmentUpdater) BorderNodeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.BorderNodeLabelPositionProvider) EdgeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.EdgeLabelPositionProvider) NodeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider) BorderNodeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.BorderNodeLabelPositionProvider) OverlapsUpdater(org.eclipse.sirius.components.diagrams.layout.incremental.updater.OverlapsUpdater) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)

Example 2 with NodeLabelPositionProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider in project sirius-components by eclipse-sirius.

the class NodeLabelPositionProviderTests method testNodeRectangleLabelBoundsPosition.

@Test
public void testNodeRectangleLabelBoundsPosition() {
    DiagramLayoutData createDiagramLayoutData = this.createDiagramLayoutData();
    NodeLayoutData nodeLayoutData = this.createNodeLayoutData(Position.at(0, 0), DEFAULT_NODE_SIZE, createDiagramLayoutData, NodeType.NODE_RECTANGLE);
    NodeLabelPositionProvider labelBoundsProvider = new NodeLabelPositionProvider(new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator());
    LabelLayoutData labelLayoutData = this.createLabelLayoutData();
    Position position = labelBoundsProvider.getPosition(nodeLayoutData, labelLayoutData, new ArrayList<>());
    assertThat(position).extracting(Position::getX).isEqualTo(Double.valueOf(DEFAULT_NODE_SIZE.getWidth() / 2));
    assertThat(position).extracting(Position::getY).isEqualTo(Double.valueOf(5));
}
Also used : DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) Position(org.eclipse.sirius.components.diagrams.Position) LabelLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData) NodeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider) LayoutConfiguratorRegistry(org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Test(org.junit.jupiter.api.Test)

Example 3 with NodeLabelPositionProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider in project sirius-components by eclipse-sirius.

the class NodeLabelPositionProviderTests method testNodeImageLabelBoundsPosition.

@Test
public void testNodeImageLabelBoundsPosition() {
    DiagramLayoutData createDiagramLayoutData = this.createDiagramLayoutData();
    NodeLayoutData nodeLayoutData = this.createNodeLayoutData(Position.at(0, 0), DEFAULT_NODE_SIZE, createDiagramLayoutData, NodeType.NODE_IMAGE);
    NodeLabelPositionProvider labelBoundsProvider = new NodeLabelPositionProvider(new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator());
    LabelLayoutData labelLayoutData = this.createLabelLayoutData();
    Position position = labelBoundsProvider.getPosition(nodeLayoutData, labelLayoutData, new ArrayList<>());
    assertThat(position).extracting(Position::getX).isEqualTo(Double.valueOf(DEFAULT_NODE_SIZE.getWidth() / 2));
    assertThat(position).extracting(Position::getY).isEqualTo(Double.valueOf(-23.3984375));
}
Also used : DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) Position(org.eclipse.sirius.components.diagrams.Position) LabelLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData) NodeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider) LayoutConfiguratorRegistry(org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Test(org.junit.jupiter.api.Test)

Aggregations

NodeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)3 NodeLabelPositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider)3 Position (org.eclipse.sirius.components.diagrams.Position)2 LayoutConfiguratorRegistry (org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry)2 DiagramLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData)2 LabelLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData)2 Test (org.junit.jupiter.api.Test)2 EdgeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData)1 BorderNodeLabelPositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.BorderNodeLabelPositionProvider)1 EdgeLabelPositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.EdgeLabelPositionProvider)1 ContainmentUpdater (org.eclipse.sirius.components.diagrams.layout.incremental.updater.ContainmentUpdater)1 OverlapsUpdater (org.eclipse.sirius.components.diagrams.layout.incremental.updater.OverlapsUpdater)1