Search in sources :

Example 76 with Bounds

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

the class AbstractGraphCommandTest method mockView.

public static View mockView(final double x, final double y, final double w, final double h) {
    View view = mock(View.class);
    Bounds bounds = mockBounds(x, y, w, h);
    when(view.getBounds()).thenReturn(bounds);
    return view;
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 77 with Bounds

use of org.kie.workbench.common.stunner.core.graph.content.Bounds 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)

Example 78 with Bounds

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

the class NodeFactoryImpl method build.

@Override
@SuppressWarnings("unchecked")
public Node<Definition<Object>, Edge> build(final String uuid, final Object definition) {
    final NodeImpl node = new NodeImpl<>(uuid);
    final Bounds bounds = definitionUtils.buildBounds(definition, 0d, 0d);
    View<Object> content = new ViewImpl<>(definition, bounds);
    node.setContent(content);
    appendLabels(node.getLabels(), definition);
    return node;
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)

Example 79 with Bounds

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

the class BasePropertyWriter method absoluteBounds.

public static org.kie.workbench.common.stunner.core.graph.content.Bounds absoluteBounds(final Node<? extends View, ?> node) {
    final Point2D point2D = GraphUtils.getComputedPosition(node);
    final org.kie.workbench.common.stunner.core.graph.content.Bounds bounds = node.getContent().getBounds();
    return org.kie.workbench.common.stunner.core.graph.content.Bounds.create(point2D.getX(), point2D.getY(), point2D.getX() + bounds.getWidth(), point2D.getY() + bounds.getHeight());
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds)

Example 80 with Bounds

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

the class StunnerLienzoBoundsPanelTest method testLocationConstraints.

@Test
public void testLocationConstraints() {
    Bounds bounds = tested.getLocationConstraints();
    assertNotNull(bounds);
    assertTrue(bounds.hasUpperLeft());
    assertEquals(0d, bounds.getUpperLeft().getX(), 0d);
    assertEquals(0d, bounds.getUpperLeft().getY(), 0d);
    assertFalse(bounds.hasLowerRight());
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Test(org.junit.Test)

Aggregations

Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)95 Test (org.junit.Test)42 View (org.kie.workbench.common.stunner.core.graph.content.view.View)34 Bound (org.kie.workbench.common.stunner.core.graph.content.Bound)26 Node (org.kie.workbench.common.stunner.core.graph.Node)24 Edge (org.kie.workbench.common.stunner.core.graph.Edge)20 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)20 Graph (org.kie.workbench.common.stunner.core.graph.Graph)9 ArrayList (java.util.ArrayList)8 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)7 HasBounds (org.kie.workbench.common.stunner.core.graph.content.HasBounds)7 Connection (org.kie.workbench.common.stunner.core.graph.content.view.Connection)7 Dock (org.kie.workbench.common.stunner.core.graph.content.relationship.Dock)6 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)6 Before (org.junit.Before)5 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)5 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)5 List (java.util.List)4 Ignore (org.junit.Ignore)4 Lane (org.kie.workbench.common.stunner.bpmn.definition.Lane)4