Search in sources :

Example 1 with LMargin

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

the class FinalSplineBendpointsCalculator method nodeToBoundingBox.

private ElkRectangle nodeToBoundingBox(final LNode node) {
    KVector pos = node.getPosition();
    KVector size = node.getSize();
    LMargin m = node.getMargin();
    return new ElkRectangle(pos.x - m.left, pos.y - m.top, size.x + m.getHorizontal(), size.y + m.getVertical());
}
Also used : LMargin(org.eclipse.elk.alg.layered.graph.LMargin) KVector(org.eclipse.elk.core.math.KVector) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

Example 2 with LMargin

use of org.eclipse.elk.alg.layered.graph.LMargin 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 3 with LMargin

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

the class ComponentsCompactor method addLGraphElementBounds.

private void addLGraphElementBounds(final List<Point> pts, final LShape element, final KVector offset) {
    // extract the relevant margins object.
    // there's LayoutOptions.MARGINS as well,
    // however, this is only used outside of elk layered.
    LMargin margins = null;
    if (element instanceof LNode) {
        margins = ((LNode) element).getMargin();
    } else if (element instanceof LPort) {
        margins = ((LPort) element).getMargin();
    } else if (element instanceof LLabel) {
        margins = new LMargin();
    }
    // add bounding box of the node
    pts.add(new Point(element.getPosition().x - margins.left + offset.x, element.getPosition().y - margins.top + offset.y));
    pts.add(new Point(element.getPosition().x - margins.left + offset.x, element.getPosition().y + element.getSize().y + margins.bottom + offset.y));
    pts.add(new Point(element.getPosition().x + element.getSize().x + margins.right + offset.x, element.getPosition().y - margins.top + offset.y));
    pts.add(new Point(element.getPosition().x + element.getSize().x + margins.right + offset.x, element.getPosition().y + element.getSize().y + margins.bottom + offset.y));
}
Also used : LMargin(org.eclipse.elk.alg.layered.graph.LMargin) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Point(org.eclipse.elk.alg.layered.compaction.recthull.Point)

Example 4 with LMargin

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

the class CommentPostprocessor method process.

/**
 * Process a node with its connected comment boxes.
 *
 * @param node a normal node
 * @param topBoxes a list of boxes to be placed on top, or {@code null}
 * @param bottomBoxes a list of boxes to be placed in the bottom, or {@code null}
 */
private void process(final LNode node, final List<LNode> topBoxes, final List<LNode> bottomBoxes) {
    KVector nodePos = node.getPosition();
    KVector nodeSize = node.getSize();
    LMargin margin = node.getMargin();
    double commentCommentSpacing = Spacings.getIndividualOrDefault(node, LayeredOptions.SPACING_COMMENT_COMMENT);
    if (topBoxes != null) {
        // determine the total width and maximal height of the top boxes
        double boxesWidth = commentCommentSpacing * (topBoxes.size() - 1);
        double maxHeight = 0;
        for (LNode box : topBoxes) {
            boxesWidth += box.getSize().x;
            maxHeight = Math.max(maxHeight, box.getSize().y);
        }
        // place the boxes on top of the node, horizontally centered around the node itself
        double x = nodePos.x - (boxesWidth - nodeSize.x) / 2;
        double baseLine = nodePos.y - margin.top + maxHeight;
        double anchorInc = nodeSize.x / (topBoxes.size() + 1);
        double anchorX = anchorInc;
        for (LNode box : topBoxes) {
            box.getPosition().x = x;
            box.getPosition().y = baseLine - box.getSize().y;
            x += box.getSize().x + commentCommentSpacing;
            // set source and target point for the connecting edge
            LPort boxPort = getBoxPort(box);
            boxPort.getPosition().x = box.getSize().x / 2 - boxPort.getAnchor().x;
            boxPort.getPosition().y = box.getSize().y;
            LPort nodePort = box.getProperty(InternalProperties.COMMENT_CONN_PORT);
            if (nodePort.getDegree() == 1) {
                nodePort.getPosition().x = anchorX - nodePort.getAnchor().x;
                nodePort.getPosition().y = 0;
                nodePort.setNode(node);
            }
            anchorX += anchorInc;
        }
    }
    if (bottomBoxes != null) {
        // determine the total width and maximal height of the bottom boxes
        double boxesWidth = commentCommentSpacing * (bottomBoxes.size() - 1);
        double maxHeight = 0;
        for (LNode box : bottomBoxes) {
            boxesWidth += box.getSize().x;
            maxHeight = Math.max(maxHeight, box.getSize().y);
        }
        // place the boxes in the bottom of the node, horizontally centered around the node itself
        double x = nodePos.x - (boxesWidth - nodeSize.x) / 2;
        double baseLine = nodePos.y + nodeSize.y + margin.bottom - maxHeight;
        double anchorInc = nodeSize.x / (bottomBoxes.size() + 1);
        double anchorX = anchorInc;
        for (LNode box : bottomBoxes) {
            box.getPosition().x = x;
            box.getPosition().y = baseLine;
            x += box.getSize().x + commentCommentSpacing;
            // set source and target point for the connecting edge
            LPort boxPort = getBoxPort(box);
            boxPort.getPosition().x = box.getSize().x / 2 - boxPort.getAnchor().x;
            boxPort.getPosition().y = 0;
            LPort nodePort = box.getProperty(InternalProperties.COMMENT_CONN_PORT);
            if (nodePort.getDegree() == 1) {
                nodePort.getPosition().x = anchorX - nodePort.getAnchor().x;
                nodePort.getPosition().y = nodeSize.y;
                nodePort.setNode(node);
            }
            anchorX += anchorInc;
        }
    }
}
Also used : LMargin(org.eclipse.elk.alg.layered.graph.LMargin) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) KVector(org.eclipse.elk.core.math.KVector)

Example 5 with LMargin

use of org.eclipse.elk.alg.layered.graph.LMargin 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

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