Search in sources :

Example 6 with Direction

use of org.eclipse.elk.core.options.Direction in project elk by eclipse.

the class InteractiveLayeredGraphVisitor method setCoordinates.

/**
 * Sets the coordinates of the nodes in the graph {@code root} according to the set constraints.
 *
 * @param root
 *            The root of the graph that should be layouted.
 */
private void setCoordinates(final ElkNode root) {
    List<List<ElkNode>> layers = calcLayerNodes(root.getChildren());
    Direction direction = root.getProperty(LayeredOptions.DIRECTION);
    setCoordinateInLayoutDirection(layers, direction);
    int layerId = 0;
    for (List<ElkNode> layer : layers) {
        if (layer.size() > 0) {
            setCoordinatesOrthogonalToLayoutDirection(layer, layerId, direction);
            layerId++;
        }
    }
    return;
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ArrayList(java.util.ArrayList) List(java.util.List) Direction(org.eclipse.elk.core.options.Direction) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint)

Example 7 with Direction

use of org.eclipse.elk.core.options.Direction in project elk by eclipse.

the class OneDimensionalComponentsCompaction method updatePlaceholders.

private void updatePlaceholders(final Dir dir) {
    Set<Direction> dirs = (dir == Dir.VERT) ? UP_DOWN : LEFT_RIGHT;
    for (Direction d : dirs) {
        for (Pair<CGroup, CNode> pair : transformer.getExternalPlaceholder().get(d)) {
            CNode cNode = pair.getSecond();
            CGroup parentComponentGroup = pair.getFirst();
            // deltaNormalized is negative if a group was moved to the left,
            // positive if the group was moved to the right
            // the size of each component stays the same!
            double adelta = parentComponentGroup.deltaNormalized;
            switch(d) {
                case LEFT:
                case RIGHT:
                    cNode.hitbox.y += adelta;
                    break;
                case UP:
                case DOWN:
                    // y sticks to the top of the diagram
                    cNode.hitbox.x += adelta;
                    break;
            }
        }
    }
}
Also used : CNode(org.eclipse.elk.alg.layered.compaction.oned.CNode) Direction(org.eclipse.elk.core.options.Direction) CGroup(org.eclipse.elk.alg.layered.compaction.oned.CGroup)

Example 8 with Direction

use of org.eclipse.elk.core.options.Direction in project elk by eclipse.

the class OneDimensionalComponentsCompaction method addPlaceholders.

private void addPlaceholders(final Dir dir) {
    Set<Direction> dirs = (dir == Dir.VERT) ? UP_DOWN : LEFT_RIGHT;
    for (Direction d : dirs) {
        for (Pair<CGroup, CNode> pair : transformer.getExternalPlaceholder().get(d)) {
            compactionGraph.cNodes.add(pair.getSecond());
            compactionGraph.cGroups.add(pair.getSecond().cGroup);
        }
    }
}
Also used : CNode(org.eclipse.elk.alg.layered.compaction.oned.CNode) Direction(org.eclipse.elk.core.options.Direction) CGroup(org.eclipse.elk.alg.layered.compaction.oned.CGroup)

Example 9 with Direction

use of org.eclipse.elk.core.options.Direction in project elk by eclipse.

the class OneDimensionalComponentsCompaction method compact.

/**
 * Internal compaction method, performs 3 compactions into each direction (horizontal first,
 * then vertical). The first compaction is unconstrained, the latter two consider the node locks.
 */
private double compact(final int run) {
    double delta = 0;
    // reset all groups' deltas
    for (CGroup g : compactionGraph.cGroups) {
        g.delta = 0;
        g.deltaNormalized = 0;
    }
    // ----------------------------------------------------
    // #1 We want to perform horizontal compaction first.
    // For this we have to add the vertical external
    // edges to the hulls to prevent edge node overlaps
    // ----------------------------------------------------
    addPlaceholders(Dir.HORZ);
    addExternalEdgeRepresentations(verticalExternalExtensions);
    compactor.calculateGroupOffsets();
    // there are new nodes in the compaction graph, we have to update the constraints
    compactor.forceConstraintsRecalculation();
    Direction direction = Direction.LEFT;
    // compact horizontally
    compactor.changeDirection(direction).compact().changeDirection(direction.opposite()).applyLockingStrategy().compact().changeDirection(direction).applyLockingStrategy().compact();
    // very important to transform back to LEFT
    // because the hitboxes representing external edges
    // that will be added in a second have not been transformed yet
    compactor.changeDirection(Direction.LEFT);
    // remove the vertical external edges again
    removeExternalEdgeRepresentations(verticalExternalExtensions);
    removePlaceholders(Dir.HORZ);
    // .. and offset the horizontal external edges (that will be added next)
    // according to the just finished horizontal compaction
    updateExternalExtensionDimensions(Dir.HORZ);
    updatePlaceholders(Dir.VERT);
    // ----------------------------------------------------
    // #2 We want to perform vertical compaction.
    // ----------------------------------------------------
    // now add them
    addPlaceholders(Dir.VERT);
    addExternalEdgeRepresentations(horizontalExternalExtensions);
    compactor.calculateGroupOffsets();
    // remember delta from horizontal compaction
    for (CGroup g : compactionGraph.cGroups) {
        delta += Math.abs(g.deltaNormalized);
    }
    // reset all groups' deltas
    for (CGroup g : compactionGraph.cGroups) {
        g.delta = 0;
        g.deltaNormalized = 0;
    }
    direction = Direction.UP;
    // compact vertically
    compactor.changeDirection(direction).forceConstraintsRecalculation().compact().changeDirection(direction.opposite()).applyLockingStrategy().compact().changeDirection(direction).applyLockingStrategy().compact();
    // transform back to LEFT
    compactor.changeDirection(Direction.LEFT);
    // remove the horizontal external edges
    removeExternalEdgeRepresentations(horizontalExternalExtensions);
    removePlaceholders(Dir.VERT);
    // ... offset the vertical external edges
    // (which have been excluded during the last compaction)
    updateExternalExtensionDimensions(Dir.VERT);
    updatePlaceholders(Dir.HORZ);
    compactor.forceConstraintsRecalculation();
    // ... and the delta from vertical compaction
    for (CGroup g : compactionGraph.cGroups) {
        delta += Math.abs(g.deltaNormalized);
    }
    return delta;
}
Also used : Direction(org.eclipse.elk.core.options.Direction) CGroup(org.eclipse.elk.alg.layered.compaction.oned.CGroup)

Example 10 with Direction

use of org.eclipse.elk.core.options.Direction in project elk by eclipse.

the class OneDimensionalComponentsCompaction method removePlaceholders.

private void removePlaceholders(final Dir dir) {
    Set<Direction> dirs = (dir == Dir.VERT) ? UP_DOWN : LEFT_RIGHT;
    for (Direction d : dirs) {
        for (Pair<CGroup, CNode> pair : transformer.getExternalPlaceholder().get(d)) {
            compactionGraph.cNodes.remove(pair.getSecond());
            compactionGraph.cGroups.remove(pair.getSecond().cGroup);
        }
    }
}
Also used : CNode(org.eclipse.elk.alg.layered.compaction.oned.CNode) Direction(org.eclipse.elk.core.options.Direction) CGroup(org.eclipse.elk.alg.layered.compaction.oned.CGroup)

Aggregations

Direction (org.eclipse.elk.core.options.Direction)30 LNode (org.eclipse.elk.alg.layered.graph.LNode)9 KVector (org.eclipse.elk.core.math.KVector)7 PortSide (org.eclipse.elk.core.options.PortSide)7 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)6 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)5 PortConstraints (org.eclipse.elk.core.options.PortConstraints)5 ElkNode (org.eclipse.elk.graph.ElkNode)5 CGroup (org.eclipse.elk.alg.layered.compaction.oned.CGroup)4 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)4 GraphProperties (org.eclipse.elk.alg.layered.options.GraphProperties)4 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)4 ElkEdge (org.eclipse.elk.graph.ElkEdge)4 ElkPort (org.eclipse.elk.graph.ElkPort)4 Test (org.junit.Test)4 CGraph (org.eclipse.elk.alg.layered.compaction.oned.CGraph)3 CNode (org.eclipse.elk.alg.layered.compaction.oned.CNode)3 LPort (org.eclipse.elk.alg.layered.graph.LPort)3 ElkLabel (org.eclipse.elk.graph.ElkLabel)3 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)2