Search in sources :

Example 1 with VertexPosition

use of org.kie.workbench.common.stunner.core.graph.processing.layout.VertexPosition in project kie-wb-common by kiegroup.

the class OpenDiagramLayoutExecutor method applyLayout.

@Override
public void applyLayout(final Layout layout, final Graph graph) {
    if (layout.getNodePositions().size() == 0) {
        return;
    }
    final HashMap<String, Node> indexByUuid = new HashMap<>();
    for (final Object n : graph.nodes()) {
        if (n instanceof Node) {
            final Node node = (Node) n;
            indexByUuid.put(node.getUUID(), node);
        }
    }
    for (final VertexPosition position : layout.getNodePositions()) {
        final Node indexed = indexByUuid.get(position.getId());
        if (indexed.getContent() instanceof HasBounds) {
            ((HasBounds) indexed.getContent()).setBounds(Bounds.create(position.getUpperLeft().getX(), position.getUpperLeft().getY(), position.getBottomRight().getX(), position.getBottomRight().getY()));
        }
    }
    notifyUser();
}
Also used : HashMap(java.util.HashMap) Node(org.kie.workbench.common.stunner.core.graph.Node) VertexPosition(org.kie.workbench.common.stunner.core.graph.processing.layout.VertexPosition) HasBounds(org.kie.workbench.common.stunner.core.graph.content.HasBounds)

Example 2 with VertexPosition

use of org.kie.workbench.common.stunner.core.graph.processing.layout.VertexPosition in project kie-wb-common by kiegroup.

the class UndoableLayoutExecutor method createCommand.

CompositeCommand createCommand(final Layout layout, final Graph graph) {
    final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<>();
    for (int i = 0; i < layout.getNodePositions().size(); i++) {
        final VertexPosition position = layout.getNodePositions().get(i);
        final Node node = graph.getNode(position.getId());
        commandBuilder.addCommand(new UpdateElementPositionCommand(node, position.getUpperLeft()));
    }
    return commandBuilder.build();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) VertexPosition(org.kie.workbench.common.stunner.core.graph.processing.layout.VertexPosition) Node(org.kie.workbench.common.stunner.core.graph.Node) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)

Example 3 with VertexPosition

use of org.kie.workbench.common.stunner.core.graph.processing.layout.VertexPosition 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)3 VertexPosition (org.kie.workbench.common.stunner.core.graph.processing.layout.VertexPosition)3 HasBounds (org.kie.workbench.common.stunner.core.graph.content.HasBounds)2 HashMap (java.util.HashMap)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)1 Bound (org.kie.workbench.common.stunner.core.graph.content.Bound)1 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)1 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)1 Layout (org.kie.workbench.common.stunner.core.graph.processing.layout.Layout)1 Vertex (org.kie.workbench.common.stunner.core.graph.processing.layout.Vertex)1 VertexPositionImpl (org.kie.workbench.common.stunner.core.graph.processing.layout.VertexPositionImpl)1