Search in sources :

Example 1 with Cell

use of org.eclipse.elk.alg.common.nodespacing.cellsystem.Cell in project elk by eclipse.

the class NodeLabelAndSizeCalculator method computeInsideNodeLabelPadding.

/**
 * Computes the padding required to place inside non-center node labels. This can be used to reserve space around
 * a hierarchical node while laying out its content. The layout direction is interesting here: usually, one would
 * probably either use the graph's layout direction, or the layout direction used to lay out the node's children.
 * However, the way the node's labels are placed may not have anything to do with either direction.
 *
 * @param graph
 *            the node's parent graph which may specify spacings inherited by the node.
 * @param node
 *            the node to process.
 * @param layoutDirection
 *            the layout direction to assume when computing the paddings.
 * @return the padding required for inside node labels.
 */
public static ElkPadding computeInsideNodeLabelPadding(final GraphAdapter<?> graph, final NodeAdapter<?> node, final Direction layoutDirection) {
    // Create a node context and fill it with all the inside node labels
    NodeContext nodeContext = new NodeContext(null, node);
    NodeLabelCellCreator.createNodeLabelCells(nodeContext, true, !layoutDirection.isVertical());
    GridContainerCell labelCellContainer = nodeContext.insideNodeLabelContainer;
    ElkPadding padding = new ElkPadding();
    // Top
    for (ContainerArea col : ContainerArea.values()) {
        Cell labelCell = labelCellContainer.getCell(ContainerArea.BEGIN, col);
        if (labelCell != null) {
            padding.top = Math.max(padding.top, labelCell.getMinimumHeight());
        }
    }
    // Bottom
    for (ContainerArea col : ContainerArea.values()) {
        Cell labelCell = labelCellContainer.getCell(ContainerArea.END, col);
        if (labelCell != null) {
            padding.bottom = Math.max(padding.bottom, labelCell.getMinimumHeight());
        }
    }
    // Left
    for (ContainerArea row : ContainerArea.values()) {
        Cell labelCell = labelCellContainer.getCell(row, ContainerArea.BEGIN);
        if (labelCell != null) {
            padding.left = Math.max(padding.left, labelCell.getMinimumWidth());
        }
    }
    // Right
    for (ContainerArea row : ContainerArea.values()) {
        Cell labelCell = labelCellContainer.getCell(row, ContainerArea.END);
        if (labelCell != null) {
            padding.right = Math.max(padding.right, labelCell.getMinimumWidth());
        }
    }
    // Apply insets and gap where necessary
    if (padding.top > 0) {
        padding.top += labelCellContainer.getPadding().top;
        padding.top += labelCellContainer.getGap();
    }
    if (padding.bottom > 0) {
        padding.bottom += labelCellContainer.getPadding().bottom;
        padding.bottom += labelCellContainer.getGap();
    }
    if (padding.left > 0) {
        padding.left += labelCellContainer.getPadding().left;
        padding.left += labelCellContainer.getGap();
    }
    if (padding.right > 0) {
        padding.right += labelCellContainer.getPadding().right;
        padding.right += labelCellContainer.getGap();
    }
    return padding;
}
Also used : NodeContext(org.eclipse.elk.alg.common.nodespacing.internal.NodeContext) GridContainerCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.GridContainerCell) ElkPadding(org.eclipse.elk.core.math.ElkPadding) ContainerArea(org.eclipse.elk.alg.common.nodespacing.cellsystem.ContainerArea) GridContainerCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.GridContainerCell) Cell(org.eclipse.elk.alg.common.nodespacing.cellsystem.Cell)

Aggregations

Cell (org.eclipse.elk.alg.common.nodespacing.cellsystem.Cell)1 ContainerArea (org.eclipse.elk.alg.common.nodespacing.cellsystem.ContainerArea)1 GridContainerCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.GridContainerCell)1 NodeContext (org.eclipse.elk.alg.common.nodespacing.internal.NodeContext)1 ElkPadding (org.eclipse.elk.core.math.ElkPadding)1