Search in sources :

Example 1 with CGroup

use of org.eclipse.elk.alg.layered.compaction.oned.CGroup in project elk by eclipse.

the class CompactionTest method testDownGroupCompaction.

/**
 * The connection indicates a grouping, not an edge.
 *
 *   +--+         
 *   |  |     
 *   +--+-----+--+
 *            |  |
 *     +--+   +--+ 
 *     |  |  
 *     +--+ 
 */
@Test
public void testDownGroupCompaction() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    CTestNode upperLeft = new CTestNode(new ElkRectangle(0, 0, 20, 20));
    graph.cNodes.add(upperLeft);
    CTestNode lowerLeft = new CTestNode(new ElkRectangle(5, 40, 10, 20));
    graph.cNodes.add(lowerLeft);
    CTestNode right = new CTestNode(new ElkRectangle(25, 10, 20, 20));
    graph.cNodes.add(right);
    CGroup group = new CGroup(upperLeft, right);
    graph.cGroups.add(group);
    compacter(graph).changeDirection(Direction.DOWN).compact().finish();
    assertEquals(15, upperLeft.hitbox.y, EPSILON);
    assertEquals(40, lowerLeft.hitbox.y, EPSILON);
    assertEquals(25, right.hitbox.y, EPSILON);
}
Also used : CGraph(org.eclipse.elk.alg.layered.compaction.oned.CGraph) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Direction(org.eclipse.elk.core.options.Direction) CGroup(org.eclipse.elk.alg.layered.compaction.oned.CGroup) Test(org.junit.Test)

Example 2 with CGroup

use of org.eclipse.elk.alg.layered.compaction.oned.CGroup in project elk by eclipse.

the class CompactionTest method testRightGroupCompaction.

/**
 * The connection indicates a grouping, not an edge.
 *
 *   +--+         
 *   |  |     +--+
 *   +--+     |  |
 *     |      +--+
 *     |          
 *     +--+  
 *     |  |  
 *     +--+ 
 */
@Test
public void testRightGroupCompaction() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    CTestNode left = new CTestNode(new ElkRectangle(0, 5, 20, 20));
    graph.cNodes.add(left);
    CTestNode upperRight = new CTestNode(new ElkRectangle(40, 0, 20, 20));
    graph.cNodes.add(upperRight);
    CTestNode lowerRight = new CTestNode(new ElkRectangle(10, 25, 20, 20));
    graph.cNodes.add(lowerRight);
    CGroup group = new CGroup(left, lowerRight);
    graph.cGroups.add(group);
    compacter(graph).changeDirection(Direction.RIGHT).compact().finish();
    assertEquals(15, left.hitbox.x, EPSILON);
    assertEquals(40, upperRight.hitbox.x, EPSILON);
    assertEquals(25, lowerRight.hitbox.x, EPSILON);
}
Also used : CGraph(org.eclipse.elk.alg.layered.compaction.oned.CGraph) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Direction(org.eclipse.elk.core.options.Direction) CGroup(org.eclipse.elk.alg.layered.compaction.oned.CGroup) Test(org.junit.Test)

Example 3 with CGroup

use of org.eclipse.elk.alg.layered.compaction.oned.CGroup in project elk by eclipse.

the class ComponentsToCGraphTransformer method transform.

/* -----------------------------------------------------------
     *                    Graph Transformation
     * ----------------------------------------------------------- */
@Override
public CGraph transform(final IConnectedComponents<N, E> ccs) {
    cGraph = new CGraph(EnumSet.allOf(Direction.class));
    for (IComponent<N, E> comp : ccs.getComponents()) {
        CGroup group = new CGroup();
        cGraph.cGroups.add(group);
        // convert the hull of the graph's elements without external edges
        for (ElkRectangle rect : comp.getHull()) {
            CRectNode rectNode = new CRectNode(rect);
            setLock(rectNode, comp.getExternalExtensionSides());
            if (!oldPosition.containsKey(comp)) {
                oldPosition.put(comp, new KVector(rect.x, rect.y));
                offsets.put(comp, rectNode);
            }
            cGraph.cNodes.add(rectNode);
            group.addCNode(rectNode);
        }
        // they can be added to the CGraph on demand later on
        for (IExternalExtension<E> ee : comp.getExternalExtensions()) {
            CRectNode rectNode = new CRectNode(ee.getRepresentor());
            externalExtensions.put(ee, Pair.of(group, rectNode));
            setLock(rectNode, comp.getExternalExtensionSides());
            // placeholder
            if (ee.getPlaceholder() != null) {
                CRectNode rectPlaceholder = new CRectNode(ee.getPlaceholder(), 1d);
                setLock(rectPlaceholder, comp.getExternalExtensionSides());
                CGroup dummyGroup = new CGroup();
                dummyGroup.addCNode(rectPlaceholder);
                externalPlaceholder.put(ee.getDirection(), Pair.of(group, rectPlaceholder));
            }
        }
    }
    return cGraph;
}
Also used : CGraph(org.eclipse.elk.alg.layered.compaction.oned.CGraph) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) KVector(org.eclipse.elk.core.math.KVector) CGroup(org.eclipse.elk.alg.layered.compaction.oned.CGroup)

Example 4 with CGroup

use of org.eclipse.elk.alg.layered.compaction.oned.CGroup 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 5 with CGroup

use of org.eclipse.elk.alg.layered.compaction.oned.CGroup 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)

Aggregations

CGroup (org.eclipse.elk.alg.layered.compaction.oned.CGroup)13 Direction (org.eclipse.elk.core.options.Direction)9 CGraph (org.eclipse.elk.alg.layered.compaction.oned.CGraph)6 CNode (org.eclipse.elk.alg.layered.compaction.oned.CNode)6 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)6 Test (org.junit.Test)5 KVector (org.eclipse.elk.core.math.KVector)2 Pair (org.eclipse.elk.core.util.Pair)1