Search in sources :

Example 6 with LMargin

use of org.eclipse.elk.alg.layered.graph.LMargin in project elk by eclipse.

the class EndLabelPreprocessor method placeLabels.

/**
 * Places the edge end labels that are to be placed near the given port.
 */
private void placeLabels(final LPort port, final LabelCell labelCell, final double edgeLabelSpacing) {
    // Some necessary position information
    ElkRectangle labelCellRect = labelCell.getCellRectangle();
    KVector nodeSize = port.getNode().getSize();
    LMargin nodeMargin = port.getNode().getMargin();
    KVector portPos = port.getPosition();
    KVector portAnchor = KVector.sum(portPos, port.getAnchor());
    // Calculate cell position depending on port side
    switch(port.getSide()) {
        case NORTH:
            labelCell.setVerticalAlignment(VerticalLabelAlignment.BOTTOM);
            labelCellRect.y = -nodeMargin.top - edgeLabelSpacing - labelCellRect.height;
            if (getLabelSide(labelCell) == LabelSide.ABOVE) {
                labelCell.setHorizontalAlignment(HorizontalLabelAlignment.RIGHT);
                labelCellRect.x = portAnchor.x - maxEdgeThickness(port) - edgeLabelSpacing - labelCellRect.width;
            } else {
                labelCell.setHorizontalAlignment(HorizontalLabelAlignment.LEFT);
                labelCellRect.x = portAnchor.x + maxEdgeThickness(port) + edgeLabelSpacing;
            }
            break;
        case EAST:
            labelCell.setHorizontalAlignment(HorizontalLabelAlignment.LEFT);
            labelCellRect.x = nodeSize.x + nodeMargin.right + edgeLabelSpacing;
            if (getLabelSide(labelCell) == LabelSide.ABOVE) {
                labelCell.setVerticalAlignment(VerticalLabelAlignment.BOTTOM);
                labelCellRect.y = portAnchor.y - maxEdgeThickness(port) - edgeLabelSpacing - labelCellRect.height;
            } else {
                labelCell.setVerticalAlignment(VerticalLabelAlignment.TOP);
                labelCellRect.y = portAnchor.y + maxEdgeThickness(port) + edgeLabelSpacing;
            }
            break;
        case SOUTH:
            labelCell.setVerticalAlignment(VerticalLabelAlignment.TOP);
            labelCellRect.y = nodeSize.y + nodeMargin.bottom + edgeLabelSpacing;
            if (getLabelSide(labelCell) == LabelSide.ABOVE) {
                labelCell.setHorizontalAlignment(HorizontalLabelAlignment.RIGHT);
                labelCellRect.x = portAnchor.x - maxEdgeThickness(port) - edgeLabelSpacing - labelCellRect.width;
            } else {
                labelCell.setHorizontalAlignment(HorizontalLabelAlignment.LEFT);
                labelCellRect.x = portAnchor.x + maxEdgeThickness(port) + edgeLabelSpacing;
            }
            break;
        case WEST:
            labelCell.setHorizontalAlignment(HorizontalLabelAlignment.RIGHT);
            labelCellRect.x = -nodeMargin.left - edgeLabelSpacing - labelCellRect.width;
            if (getLabelSide(labelCell) == LabelSide.ABOVE) {
                labelCell.setVerticalAlignment(VerticalLabelAlignment.BOTTOM);
                labelCellRect.y = portAnchor.y - maxEdgeThickness(port) - edgeLabelSpacing - labelCellRect.height;
            } else {
                labelCell.setVerticalAlignment(VerticalLabelAlignment.TOP);
                labelCellRect.y = portAnchor.y + maxEdgeThickness(port) + edgeLabelSpacing;
            }
            break;
    }
}
Also used : LMargin(org.eclipse.elk.alg.layered.graph.LMargin) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) KVector(org.eclipse.elk.core.math.KVector)

Example 7 with LMargin

use of org.eclipse.elk.alg.layered.graph.LMargin in project elk by eclipse.

the class EndLabelPreprocessor method calculateOverlapStartCoordinate.

/**
 * Calculates the start coordinate to use for overlap removal on the given port side.
 */
private double calculateOverlapStartCoordinate(final LNode node, final PortSide portSide, final double edgeLabelSpacing) {
    KVector nodeSize = node.getSize();
    LMargin nodeMargin = node.getMargin();
    switch(portSide) {
        case NORTH:
            return -nodeMargin.top - edgeLabelSpacing;
        case SOUTH:
            return nodeSize.y + nodeMargin.bottom + edgeLabelSpacing;
        case EAST:
            return nodeSize.x + nodeMargin.right + edgeLabelSpacing;
        case WEST:
            return -nodeMargin.left - edgeLabelSpacing;
        default:
            // Should never happen
            assert false;
            return 0;
    }
}
Also used : LMargin(org.eclipse.elk.alg.layered.graph.LMargin) KVector(org.eclipse.elk.core.math.KVector)

Example 8 with LMargin

use of org.eclipse.elk.alg.layered.graph.LMargin in project elk by eclipse.

the class LayerSizeAndGraphHeightCalculator method process.

@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Layer size calculation", 1);
    // Remember the lowest and the highest y coordinates
    double minY = Double.POSITIVE_INFINITY;
    double maxY = Double.NEGATIVE_INFINITY;
    boolean foundNodes = false;
    for (Layer layer : layeredGraph) {
        // Retrieve and reset layer size (just to be sure...)
        KVector layerSize = layer.getSize();
        layerSize.x = 0.0;
        layerSize.y = 0.0;
        // If the layer is empty, skip the rest (should not usually happen)
        if (layer.getNodes().isEmpty()) {
            continue;
        }
        foundNodes = true;
        // Calculate the layer's width
        for (LNode node : layer) {
            KVector nodeSize = node.getSize();
            LMargin nodeMargin = node.getMargin();
            layerSize.x = Math.max(layerSize.x, nodeSize.x + nodeMargin.left + nodeMargin.right);
        }
        // Calculate the layer's height
        LNode firstNode = layer.getNodes().get(0);
        double top = firstNode.getPosition().y - firstNode.getMargin().top;
        if (firstNode.getType() == NodeType.EXTERNAL_PORT) {
            // Consider port spacing options for first node
            top -= layeredGraph.getProperty(LayeredOptions.SPACING_PORTS_SURROUNDING).getTop();
        }
        LNode lastNode = layer.getNodes().get(layer.getNodes().size() - 1);
        double bottom = lastNode.getPosition().y + lastNode.getSize().y + lastNode.getMargin().bottom;
        if (lastNode.getType() == NodeType.EXTERNAL_PORT) {
            // Consider port spacing options for last node
            bottom += layeredGraph.getProperty(LayeredOptions.SPACING_PORTS_SURROUNDING).getBottom();
        }
        layerSize.y = bottom - top;
        // Update the lowest and highest encountered Y coordinate
        minY = Math.min(minY, top);
        maxY = Math.max(maxY, bottom);
    }
    // component only contains external ports.
    if (!foundNodes) {
        minY = 0;
        maxY = 0;
    }
    // Set the graph's height
    layeredGraph.getSize().y = maxY - minY;
    layeredGraph.getOffset().y -= minY;
    monitor.done();
}
Also used : LMargin(org.eclipse.elk.alg.layered.graph.LMargin) LNode(org.eclipse.elk.alg.layered.graph.LNode) KVector(org.eclipse.elk.core.math.KVector) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 9 with LMargin

use of org.eclipse.elk.alg.layered.graph.LMargin in project elk by eclipse.

the class OrthogonalSelfLoopRouter method computeBaselinePosition.

/**
 * Based on the margin area, this computes the offset from the node origin to add to escape the area occupied by
 * ports.
 */
private double computeBaselinePosition(final SelfLoopHolder slHolder, final PortSide portSide, final double nodeSelfLoopDistance) {
    LNode lNode = slHolder.getLNode();
    LMargin lMargins = lNode.getMargin();
    switch(portSide) {
        case NORTH:
            return -lMargins.top - nodeSelfLoopDistance;
        case EAST:
            return lNode.getSize().x + lMargins.right + nodeSelfLoopDistance;
        case SOUTH:
            return lNode.getSize().y + lMargins.bottom + nodeSelfLoopDistance;
        case WEST:
            return -lMargins.left - nodeSelfLoopDistance;
        default:
            assert false;
            return -1;
    }
}
Also used : LMargin(org.eclipse.elk.alg.layered.graph.LMargin) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Example 10 with LMargin

use of org.eclipse.elk.alg.layered.graph.LMargin in project elk by eclipse.

the class CommentNodeMarginCalculator method processComments.

/**
 * Make some extra space for comment boxes that are placed near the given node.
 */
private void processComments(final LNode node) {
    LMargin margin = node.getMargin();
    List<LNode> topBoxes = node.getProperty(InternalProperties.TOP_COMMENTS);
    List<LNode> bottomBoxes = node.getProperty(InternalProperties.BOTTOM_COMMENTS);
    if (topBoxes == null && bottomBoxes == null) {
        // Shortcut if there are no attached comments
        return;
    }
    // Retrieve the spacings that apply to this node
    double commentCommentSpacing = Spacings.getIndividualOrDefault(node, LayeredOptions.SPACING_COMMENT_COMMENT);
    double commentNodeSpacing = Spacings.getIndividualOrDefault(node, LayeredOptions.SPACING_COMMENT_NODE);
    // Consider comment boxes that are put on top of the node
    double topWidth = 0;
    if (topBoxes != null) {
        double maxHeight = 0;
        for (LNode commentBox : topBoxes) {
            maxHeight = Math.max(maxHeight, commentBox.getSize().y);
            topWidth += commentBox.getSize().x;
        }
        topWidth += commentCommentSpacing * (topBoxes.size() - 1);
        margin.top += maxHeight + commentNodeSpacing;
    }
    // Consider comment boxes that are put in the bottom of the node
    double bottomWidth = 0;
    if (bottomBoxes != null) {
        double maxHeight = 0;
        for (LNode commentBox : bottomBoxes) {
            maxHeight = Math.max(maxHeight, commentBox.getSize().y);
            bottomWidth += commentBox.getSize().x;
        }
        bottomWidth += commentCommentSpacing * (bottomBoxes.size() - 1);
        margin.bottom += maxHeight + commentNodeSpacing;
    }
    // Check if the maximum width of the comments is wider than the node itself, which the comments
    // are centered on
    double maxCommentWidth = Math.max(topWidth, bottomWidth);
    if (maxCommentWidth > node.getSize().x) {
        double protrusion = (maxCommentWidth - node.getSize().x) / 2;
        margin.left = Math.max(margin.left, protrusion);
        margin.right = Math.max(margin.right, protrusion);
    }
}
Also used : LMargin(org.eclipse.elk.alg.layered.graph.LMargin) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Aggregations

LMargin (org.eclipse.elk.alg.layered.graph.LMargin)14 KVector (org.eclipse.elk.core.math.KVector)11 LNode (org.eclipse.elk.alg.layered.graph.LNode)7 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)4 LPort (org.eclipse.elk.alg.layered.graph.LPort)2 SelfHyperLoopLabels (org.eclipse.elk.alg.layered.intermediate.loops.SelfHyperLoopLabels)2 LabelCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell)1 Point (org.eclipse.elk.alg.layered.compaction.recthull.Point)1 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)1 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)1 Layer (org.eclipse.elk.alg.layered.graph.Layer)1 SelfHyperLoop (org.eclipse.elk.alg.layered.intermediate.loops.SelfHyperLoop)1 SelfLoopEdge (org.eclipse.elk.alg.layered.intermediate.loops.SelfLoopEdge)1 SelfLoopPort (org.eclipse.elk.alg.layered.intermediate.loops.SelfLoopPort)1 KVectorChain (org.eclipse.elk.core.math.KVectorChain)1 PortSide (org.eclipse.elk.core.options.PortSide)1 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)1