Search in sources :

Example 6 with Bounds

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

the class CanvasLayoutUtilsTest method getNextFromRootWithParent.

@Test
@SuppressWarnings("unchecked")
public void getNextFromRootWithParent() {
    this.graphTestHandlerParent = new TestingGraphMockHandler();
    graphInstanceParent = TestingGraphInstanceBuilder.newGraph2(graphTestHandlerParent);
    Node node = mock(Node.class);
    Bounds boundsNode = new BoundsImpl(new BoundImpl(100d, 100d), new BoundImpl(300d, 200d));
    View viewNode = mock(View.class);
    when(node.getContent()).thenReturn(viewNode);
    when(viewNode.getBounds()).thenReturn(boundsNode);
    when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstanceParent.graph);
    Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstanceParent.startNode, node);
    Node<View<?>, Edge> start = (Node<View<?>, Edge>) graphInstanceParent.startNode;
    double[] size = GraphUtils.getNodeSize(start.getContent());
    assertTrue(next.getX() == CanvasLayoutUtils.getPaddingX());
    assertTrue(next.getY() > size[1]);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 7 with Bounds

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

the class CanvasLayoutUtilsTest method getNextNewTaskWithNonEmptyPosition.

// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextNewTaskWithNonEmptyPosition() {
    when(ruleManager.evaluate(eq(ruleSet), any(RuleEvaluationContext.class))).thenReturn(ruleViolations);
    when(ruleViolations.violations(Violation.Type.ERROR)).thenReturn(ruleViolationIterable);
    when(ruleViolations.violations(Violation.Type.ERROR).iterator()).thenReturn(ruleViolationIterator);
    when(ruleViolations.violations(Violation.Type.ERROR).iterator().hasNext()).thenReturn(true);
    this.graphTestHandler = new TestingGraphMockHandler();
    graphInstance = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
    Node newNode = mock(Node.class);
    Bounds boundsNewNode = new BoundsImpl(new BoundImpl(200d, 300d), new BoundImpl(300d, 400d));
    View viewNewNode = mock(View.class);
    when(newNode.getContent()).thenReturn(viewNewNode);
    when(viewNewNode.getBounds()).thenReturn(boundsNewNode);
    when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstance.graph);
    when(graphBoundsIndexer.getAt(140.0, 0.0, 100.0, 100.0, null)).thenReturn(graphInstance.intermNode);
    graphInstance.startNode.getOutEdges().clear();
    Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstance.startNode, newNode);
    Node<View<?>, Edge> startNode = (Node<View<?>, Edge>) graphInstance.startNode;
    double[] sizeStartNode = GraphUtils.getNodeSize(startNode.getContent());
    Node<View<?>, Edge> intermNode = (Node<View<?>, Edge>) graphInstance.intermNode;
    double[] sizeIntermNode = GraphUtils.getNodeSize(intermNode.getContent());
    assertTrue(next.getX() == sizeStartNode[0] + CanvasLayoutUtils.getPaddingX());
    assertTrue(next.getY() > sizeIntermNode[1]);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Bounds

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

the class AbstractGraphCommandTest method mockBounds.

public static Bounds mockBounds(final double x, final double y, final double w, final double h) {
    Bounds bounds = mock(Bounds.class);
    Bounds.Bound boundUL = mock(Bounds.Bound.class);
    Bounds.Bound boundLR = mock(Bounds.Bound.class);
    when(boundUL.getX()).thenReturn(x);
    when(boundUL.getY()).thenReturn(y);
    when(boundLR.getX()).thenReturn(x + w);
    when(boundLR.getY()).thenReturn(y + h);
    when(bounds.getLowerRight()).thenReturn(boundLR);
    when(bounds.getUpperLeft()).thenReturn(boundUL);
    return bounds;
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds)

Example 9 with Bounds

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

the class UpdateElementPositionCommandTest method testExecute.

@Test
public void testExecute() {
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    ArgumentCaptor<Bounds> bounds = ArgumentCaptor.forClass(Bounds.class);
    verify(content, times(1)).setBounds(bounds.capture());
    assertEquals(CommandResult.Type.INFO, result.getType());
    Bounds b = bounds.getValue();
    assertEquals(UUID, tested.getUuid());
    assertEquals(LOCATION, tested.getLocation());
    assertEquals(PREVIOUS_LOCATION, tested.getPreviousLocation());
    assertEquals(PREVIOUS_LOCATION.getY(), tested.getPreviousLocation().getY(), 0d);
    assertEquals(Double.valueOf(LOCATION.getX() + W), b.getLowerRight().getX());
    assertEquals(Double.valueOf(LOCATION.getY() + H), b.getLowerRight().getY());
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 10 with Bounds

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

the class GraphUtilsTest method checkBoundsExceededTest.

@Test
public void checkBoundsExceededTest() {
    Bounds parentBounds = new BoundsImpl(new BoundImpl(50d, 50d), new BoundImpl(200d, 200d));
    Bounds childBounds = new BoundsImpl(new BoundImpl(51d, 51d), new BoundImpl(199d, 199d));
    assertTrue(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(51d, 51d), new BoundImpl(200d, 200d));
    assertTrue(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(50d, 50d), new BoundImpl(199d, 199d));
    assertTrue(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(50d, 50d), new BoundImpl(200d, 200d));
    assertTrue(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(49d, 49d), new BoundImpl(201d, 201d));
    assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(49d, 49d), new BoundImpl(200d, 200d));
    assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(49d, 49d), new BoundImpl(199d, 199d));
    assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(49d, 49d), new BoundImpl(201d, 201d));
    assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(50d, 49d), new BoundImpl(201d, 201d));
    assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
    childBounds = new BoundsImpl(new BoundImpl(51d, 49d), new BoundImpl(201d, 201d));
    assertFalse(GraphUtils.checkBoundsExceeded(parentBounds, childBounds));
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Test(org.junit.Test)

Aggregations

Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)34 View (org.kie.workbench.common.stunner.core.graph.content.view.View)18 Test (org.junit.Test)16 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)13 Node (org.kie.workbench.common.stunner.core.graph.Node)13 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)12 Graph (org.kie.workbench.common.stunner.core.graph.Graph)7 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)6 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)6 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)5 Ignore (org.junit.Ignore)4 TestingGraphMockHandler (org.kie.workbench.common.stunner.core.TestingGraphMockHandler)4 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)4 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)4 Consumer (java.util.function.Consumer)2 Before (org.junit.Before)2 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel)2 Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)2 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)2