Search in sources :

Example 6 with HasBounds

use of org.kie.workbench.common.stunner.core.graph.content.HasBounds in project kie-wb-common by kiegroup.

the class SugiyamaLayoutServiceTest method testGetWidth.

@Test
public void testGetWidth() {
    final Node n = mock(Node.class);
    final HasBounds hasBounds = mock(HasBounds.class);
    final Bounds bounds = mock(Bounds.class);
    final double width = 17;
    final int expected = (int) width;
    when(bounds.getWidth()).thenReturn(width);
    when(hasBounds.getBounds()).thenReturn(bounds);
    when(n.getContent()).thenReturn(hasBounds);
    int actual = layoutService.getWidth(n);
    assertEquals(expected, actual);
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) HasBounds(org.kie.workbench.common.stunner.core.graph.content.HasBounds) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) HasBounds(org.kie.workbench.common.stunner.core.graph.content.HasBounds) Test(org.junit.Test)

Example 7 with HasBounds

use of org.kie.workbench.common.stunner.core.graph.content.HasBounds in project kie-wb-common by kiegroup.

the class SugiyamaLayoutServiceTest method createNode.

private Node createNode(final String uuid) {
    final Node node = mock(Node.class);
    final HasBounds hasBounds = mock(HasBounds.class);
    when(node.getUUID()).thenReturn(uuid);
    when(node.getContent()).thenReturn(hasBounds);
    return node;
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) HasBounds(org.kie.workbench.common.stunner.core.graph.content.HasBounds)

Example 8 with HasBounds

use of org.kie.workbench.common.stunner.core.graph.content.HasBounds in project kie-wb-common by kiegroup.

the class SugiyamaLayoutService method buildLayout.

Layout buildLayout(final HashMap<String, Node> indexByUuid, final List<GraphLayer> layers) {
    final Layout layout = new Layout();
    for (int i = layers.size() - 1; i >= 0; i--) {
        final GraphLayer layer = layers.get(i);
        for (final Vertex v : layer.getVertices()) {
            final Node n = indexByUuid.get(v.getId());
            final int x = v.getX();
            final int y = v.getY();
            final Bounds currentBounds = ((HasBounds) n.getContent()).getBounds();
            final Bound lowerRight = currentBounds.getLowerRight();
            final int x2;
            if (isCloseToZero(lowerRight.getX())) {
                x2 = x + VertexPositioning.DEFAULT_VERTEX_WIDTH;
            } else {
                x2 = (int) (x + lowerRight.getX());
            }
            final int y2;
            if (isCloseToZero(lowerRight.getY())) {
                y2 = y + VertexPositioning.DEFAULT_VERTEX_HEIGHT;
            } else {
                y2 = (int) (y + lowerRight.getY());
            }
            final VertexPosition position = new VertexPositionImpl(v.getId(), new Point2D(x, y), new Point2D(x2, y2));
            layout.getNodePositions().add(position);
        }
    }
    return layout;
}
Also used : Vertex(org.kie.workbench.common.stunner.core.graph.processing.layout.Vertex) Layout(org.kie.workbench.common.stunner.core.graph.processing.layout.Layout) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Node(org.kie.workbench.common.stunner.core.graph.Node) HasBounds(org.kie.workbench.common.stunner.core.graph.content.HasBounds) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) VertexPosition(org.kie.workbench.common.stunner.core.graph.processing.layout.VertexPosition) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) VertexPositionImpl(org.kie.workbench.common.stunner.core.graph.processing.layout.VertexPositionImpl) HasBounds(org.kie.workbench.common.stunner.core.graph.content.HasBounds)

Aggregations

Node (org.kie.workbench.common.stunner.core.graph.Node)8 HasBounds (org.kie.workbench.common.stunner.core.graph.content.HasBounds)8 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)4 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Bound (org.kie.workbench.common.stunner.core.graph.content.Bound)2 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)2 Layout (org.kie.workbench.common.stunner.core.graph.processing.layout.Layout)2 VertexPosition (org.kie.workbench.common.stunner.core.graph.processing.layout.VertexPosition)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1