Search in sources :

Example 31 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle 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 32 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.

the class CompactionTest method testHorizontalSpacingDuringVerticalCompaction.

/**
 * "Two" is "center node". Node "one" is supposed to be blocked by "two", while "three" can move freely.
 */
@Test
public void testHorizontalSpacingDuringVerticalCompaction() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    CTestNodeSpacing one = new CTestNodeSpacing(new ElkRectangle(16, 150, 20, 20), 5d, 0d);
    graph.cNodes.add(one);
    CTestNodeSpacing two = new CTestNodeSpacing(new ElkRectangle(40, 0, 20, 20), 10d, 0d);
    graph.cNodes.add(two);
    CTestNodeSpacing three = new CTestNodeSpacing(new ElkRectangle(76, 150, 20, 20), 15d, 0d);
    graph.cNodes.add(three);
    compacter(graph).changeDirection(Direction.UP).compact().finish();
    assertEquals(20, one.hitbox.y, EPSILON);
    assertEquals(0, two.hitbox.y, EPSILON);
    assertEquals(0, three.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) Test(org.junit.Test)

Example 33 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle 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 34 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.

the class ComponentsCompactor method transformLEdge.

/**
 * Converts an external edge to an external extension. While doing so, the the original edge
 * contributes three things as explained in the code.
 */
private IExternalExtension<LEdge> transformLEdge(final LEdge externalEdge, final Hullpoints hullPoints, final OuterSegments outerSegments) {
    InternalExternalExtension externalExtension = new InternalExternalExtension(externalEdge);
    // #1 convert the edge's path into a set of segments
    Segments segments = edgeToSegments(externalEdge, externalExtension);
    // #2 all 'inner' segments contribute to the hull (consider the edge's thickness)
    double thickness = Math.max(externalEdge.getProperty(LayeredOptions.EDGE_THICKNESS).doubleValue(), 1);
    for (Pair<KVector, KVector> segment : segments.innerSegments) {
        ElkRectangle rect = segmentToRectangle(segment.getFirst(), segment.getSecond(), thickness);
        hullPoints.add(rect);
    }
    // #3 the 'outer' segment, being the segment that actually connects to the external port,
    // contributes to the 'union external segment' that we create
    // for one direction of the component
    PortSide side = externalExtension.externalPortSide;
    ElkRectangle outerSegmentRect = segmentToRectangle(segments.outerSegment.getFirst(), segments.outerSegment.getSecond(), thickness);
    if (side == PortSide.WEST || side == PortSide.EAST) {
        outerSegments.min[side.ordinal()] = Math.min(outerSegments.min[side.ordinal()], outerSegmentRect.y);
        outerSegments.max[side.ordinal()] = Math.max(outerSegments.max[side.ordinal()], outerSegmentRect.y + outerSegmentRect.height);
    } else {
        outerSegments.min[side.ordinal()] = Math.min(outerSegments.min[side.ordinal()], outerSegmentRect.x);
        outerSegments.max[side.ordinal()] = Math.max(outerSegments.max[side.ordinal()], outerSegmentRect.x + outerSegmentRect.width);
    }
    // extent
    double extent = Double.NEGATIVE_INFINITY;
    LMargin margins = externalExtension.externalPort.getNode().getMargin();
    switch(side) {
        case WEST:
            extent = margins.right;
            break;
        case EAST:
            extent = margins.left;
            break;
        case NORTH:
            extent = margins.bottom;
            break;
        case SOUTH:
            extent = margins.top;
            break;
    }
    outerSegments.extent[side.ordinal()] = Math.max(outerSegments.extent[side.ordinal()], extent);
    return externalExtension;
}
Also used : LMargin(org.eclipse.elk.alg.layered.graph.LMargin) KVector(org.eclipse.elk.core.math.KVector) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) PortSide(org.eclipse.elk.core.options.PortSide)

Example 35 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.

the class EndLabelPreprocessor method updateNodeMargins.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Node Margins
/**
 * Updates the node's margins to account for its end labels.
 */
private void updateNodeMargins(final LNode node, final LabelCell[] labelCells) {
    LMargin nodeMargin = node.getMargin();
    KVector nodeSize = node.getSize();
    // Calculate the rectangle that describes the node's current margin
    ElkRectangle nodeMarginRectangle = new ElkRectangle(-nodeMargin.left, -nodeMargin.top, nodeMargin.left + nodeSize.x + nodeMargin.right, nodeMargin.top + nodeSize.y + nodeMargin.bottom);
    // Union the rectangle with each rectangle that describes a label cell
    for (LabelCell labelCell : labelCells) {
        if (labelCell != null) {
            nodeMarginRectangle.union(labelCell.getCellRectangle());
        }
    }
    // Reapply the new rectangle to the margin
    nodeMargin.left = -nodeMarginRectangle.x;
    nodeMargin.top = -nodeMarginRectangle.y;
    nodeMargin.right = nodeMarginRectangle.width - nodeMargin.left - nodeSize.x;
    nodeMargin.bottom = nodeMarginRectangle.height - nodeMargin.top - nodeSize.y;
}
Also used : LMargin(org.eclipse.elk.alg.layered.graph.LMargin) LabelCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell) KVector(org.eclipse.elk.core.math.KVector) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

Aggregations

ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)82 KVector (org.eclipse.elk.core.math.KVector)33 Test (org.junit.Test)27 Direction (org.eclipse.elk.core.options.Direction)18 CGraph (org.eclipse.elk.alg.layered.compaction.oned.CGraph)17 ElkPadding (org.eclipse.elk.core.math.ElkPadding)9 PortContext (org.eclipse.elk.alg.common.nodespacing.internal.PortContext)8 LabelCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell)7 CGroup (org.eclipse.elk.alg.layered.compaction.oned.CGroup)6 Point (org.eclipse.elk.alg.common.Point)4 LMargin (org.eclipse.elk.alg.layered.graph.LMargin)4 LPort (org.eclipse.elk.alg.layered.graph.LPort)4 ElkNode (org.eclipse.elk.graph.ElkNode)4 RectilinearConvexHull (org.eclipse.elk.alg.common.RectilinearConvexHull)3 AtomicCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.AtomicCell)3 RectangleStripOverlapRemover (org.eclipse.elk.alg.common.overlaps.RectangleStripOverlapRemover)3 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)3 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)3 LNode (org.eclipse.elk.alg.layered.graph.LNode)3 Random (java.util.Random)2