Search in sources :

Example 51 with ElkRectangle

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

the class LabelCell method applyHorizontalModeLabelLayout.

/**
 * Implementation of {@link #applyLabelLayout()} for horizontal layout mode.
 */
private void applyHorizontalModeLabelLayout() {
    ElkRectangle cellRect = getCellRectangle();
    ElkPadding cellPadding = getPadding();
    // Calculate our starting y coordinate
    double yPos = cellRect.y;
    if (verticalAlignment == VerticalLabelAlignment.CENTER) {
        yPos += (cellRect.height - minimumContentAreaSize.y) / 2;
    } else if (verticalAlignment == VerticalLabelAlignment.BOTTOM) {
        yPos += cellRect.height - minimumContentAreaSize.y;
    }
    // Place them labels, I say!
    for (LabelAdapter<?> label : labels) {
        KVector labelSize = label.getSize();
        KVector labelPos = new KVector();
        // Y coordinate
        labelPos.y = yPos;
        yPos += labelSize.y + gap;
        // X coordinate
        switch(horizontalAlignment) {
            case LEFT:
                labelPos.x = cellRect.x + cellPadding.left;
                break;
            case CENTER:
                labelPos.x = cellRect.x + cellPadding.left + (cellRect.width - labelSize.x) / 2;
                break;
            case RIGHT:
                labelPos.x = cellRect.x + cellRect.width - cellPadding.right - labelSize.x;
                break;
        }
        // Apply position
        label.setPosition(labelPos);
    }
}
Also used : ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 52 with ElkRectangle

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

the class StripContainerCell method layoutChildrenVertically.

/* (non-Javadoc)
     * @see org.eclipse.elk.core.util.nodespacing.internal.cells.ContainerCell#layoutChildrenVertically()
     */
@Override
public void layoutChildrenVertically() {
    ElkRectangle cellRectangle = getCellRectangle();
    ElkPadding cellPadding = getPadding();
    if (containerMode == Strip.VERTICAL) {
        double[] cellHeights = minCellHeights(false);
        // Top cell is top-aligned with our content area, bottom cell is bottom-aligned
        applyVerticalLayout(cells[0], cellRectangle.y + cellPadding.top, cellHeights[0]);
        applyVerticalLayout(cells[2], cellRectangle.y + cellRectangle.height - cellPadding.bottom - cellHeights[2], cellHeights[2]);
        // Size of the content area and size of the available space in the content area
        double contentAreaHeight = cellRectangle.height - cellPadding.top - cellPadding.bottom;
        double contentAreaFreeHeight = contentAreaHeight;
        if (cellHeights[0] > 0) {
            // We add the gap here because that will spare us to check if cellHeights[0] is zero later on
            cellHeights[0] += gap;
            contentAreaFreeHeight -= cellHeights[0];
        }
        if (cellHeights[2] > 0) {
            contentAreaFreeHeight -= cellHeights[2] + gap;
        }
        // If the available space is larger than the current size of the center cell, enlarge that thing
        cellHeights[1] = Math.max(cellHeights[1], contentAreaFreeHeight);
        // Place the center cell, possibly enlarging it in the process
        applyVerticalLayout(cells[1], cellRectangle.y + cellPadding.top + cellHeights[0] - (cellHeights[1] - contentAreaFreeHeight) / 2, cellHeights[1]);
    } else {
        // Each child cell begins at our top border (plus padding) and is as large as our content area
        double yPos = cellRectangle.y + cellPadding.top;
        double height = cellRectangle.height - cellPadding.top - cellPadding.bottom;
        for (Cell childCell : cells) {
            applyVerticalLayout(childCell, yPos, height);
        }
    }
    // Layout container cells recursively
    for (Cell childCell : cells) {
        if (childCell instanceof ContainerCell) {
            ((ContainerCell) childCell).layoutChildrenVertically();
        }
    }
}
Also used : ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 53 with ElkRectangle

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

the class StripContainerCell method layoutChildrenHorizontally.

/* (non-Javadoc)
     * @see org.eclipse.elk.core.util.nodespacing.internal.cells.ContainerCell#layoutChildrenHorizontally()
     */
@Override
public void layoutChildrenHorizontally() {
    ElkRectangle cellRectangle = getCellRectangle();
    ElkPadding cellPadding = getPadding();
    if (containerMode == Strip.VERTICAL) {
        // Each child cell begins at our left border (plus padding) and is as large as our content area
        double xPos = cellRectangle.x + cellPadding.left;
        double width = cellRectangle.width - cellPadding.left - cellPadding.right;
        for (Cell childCell : cells) {
            applyHorizontalLayout(childCell, xPos, width);
        }
    } else {
        double[] cellWidths = minCellWidths(false);
        // Left cell is left-aligned with our content area, right cell is right-aligned
        applyHorizontalLayout(cells[0], cellRectangle.x + cellPadding.left, cellWidths[0]);
        applyHorizontalLayout(cells[2], cellRectangle.x + cellRectangle.width - cellPadding.right - cellWidths[2], cellWidths[2]);
        // Size of the content area and size of the available space in the content area
        double freeContentAreaWidth = cellRectangle.width - cellPadding.left - cellPadding.right;
        if (cellWidths[0] > 0) {
            freeContentAreaWidth -= cellWidths[0] + gap;
            // We add the gap here because that will spare us to check if cellWidths[0] is zero later on
            cellWidths[0] += gap;
        }
        if (cellWidths[2] > 0) {
            freeContentAreaWidth -= cellWidths[2] + gap;
        }
        // If the available space is larger than the current size of the center cell, enlarge that thing
        cellWidths[1] = Math.max(cellWidths[1], freeContentAreaWidth);
        // Place the center cell, possibly enlarging it in the process
        applyHorizontalLayout(cells[1], cellRectangle.x + cellPadding.left + cellWidths[0] - (cellWidths[1] - freeContentAreaWidth) / 2, cellWidths[1]);
    }
    // Layout container cells recursively
    for (Cell childCell : cells) {
        if (childCell instanceof ContainerCell) {
            ((ContainerCell) childCell).layoutChildrenHorizontally();
        }
    }
}
Also used : ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 54 with ElkRectangle

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

the class EndLabelPreprocessor method createConfiguredLabelCell.

/**
 * Creates label cell for the given port with the given labels, if any. If there are no labels, this method returns
 * {@code null}. The label cell will still have to have its alignment set up, but its size is already set to the
 * size required to place its labels.
 */
private LabelCell createConfiguredLabelCell(final List<LLabel> labels, final double labelLabelSpacing, final boolean verticalLayout) {
    if (labels == null || labels.isEmpty()) {
        return null;
    }
    // Create the new label cell and setup its alignments depending on the port's side
    LabelCell labelCell = new LabelCell(labelLabelSpacing, !verticalLayout);
    for (LLabel label : labels) {
        labelCell.addLabel(LGraphAdapters.adapt(label));
    }
    // Setup the label cell's size
    ElkRectangle labelCellRect = labelCell.getCellRectangle();
    labelCellRect.height = labelCell.getMinimumHeight();
    labelCellRect.width = labelCell.getMinimumWidth();
    return labelCell;
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LabelCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

Example 55 with ElkRectangle

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

the class EndLabelPreprocessor method removeLabelOverlaps.

/**
 * Calls the rectangle overlap removal code to remove overlaps between end labels of edges connected to ports on
 * the given sides.
 */
private void removeLabelOverlaps(final LNode node, final LabelCell[] portLabelCells, final PortSide portSide, final double labelLabelSpacing, final double edgeLabelSpacing) {
    RectangleStripOverlapRemover overlapRemover = RectangleStripOverlapRemover.createForDirection(portSideToOverlapRemovalDirection(portSide)).withGap(labelLabelSpacing).withStartCoordinate(calculateOverlapStartCoordinate(node, portSide, edgeLabelSpacing));
    // Gather the rectangles
    for (LPort port : node.getPorts(portSide)) {
        if (portLabelCells[port.id] != null) {
            ElkRectangle labelCellRect = portLabelCells[port.id].getCellRectangle();
            assert labelCellRect.height > 0 && labelCellRect.width > 0;
            overlapRemover.addRectangle(labelCellRect);
        }
    }
    // Remove overlaps. Since we have stuffed the original label cell rectangles into this thing, we won't evern
    // have to apply or post-process anything. The marvels of modern technology.
    overlapRemover.removeOverlaps();
}
Also used : RectangleStripOverlapRemover(org.eclipse.elk.alg.common.overlaps.RectangleStripOverlapRemover) LPort(org.eclipse.elk.alg.layered.graph.LPort) 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