Search in sources :

Example 16 with LLabel

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

the class SelfHyperLoopLabels method applyPlacementVerticalForVerticalLayout.

private void applyPlacementVerticalForVerticalLayout(final KVector offset) {
    double x = position.x;
    double y = position.y;
    for (LLabel lLabel : lLabels) {
        KVector labelPos = lLabel.getPosition();
        labelPos.x = x;
        // We always top-align, except for the northern side
        if (side == PortSide.NORTH) {
            labelPos.y = y + size.y - lLabel.getSize().y;
        } else {
            labelPos.y = y;
        }
        labelPos.add(offset);
        x += lLabel.getSize().x + labelLabelSpacing;
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) KVector(org.eclipse.elk.core.math.KVector)

Example 17 with LLabel

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

the class SelfHyperLoopLabels method applyPlacementForHorizontalLayout.

private void applyPlacementForHorizontalLayout(final KVector offset) {
    double x = position.x;
    double y = position.y;
    for (LLabel lLabel : lLabels) {
        KVector labelPos = lLabel.getPosition();
        // X coordinate depends on alignment and / or side
        if (alignment == Alignment.LEFT || side == PortSide.EAST) {
            labelPos.x = x;
        } else if (alignment == Alignment.RIGHT || side == PortSide.WEST) {
            labelPos.x = x + size.x - lLabel.getSize().x;
        } else {
            // Alignment is center
            labelPos.x = x + (size.x - lLabel.getSize().x) / 2;
        }
        labelPos.y = y;
        labelPos.add(offset);
        y += lLabel.getSize().y + labelLabelSpacing;
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) KVector(org.eclipse.elk.core.math.KVector)

Example 18 with LLabel

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

the class ElkGraphLayoutTransferrer method applyNodeLayout.

/**
 * Applies layout information computed for the given node.
 *
 * @param lnode
 *            the node that has the layout information.
 * @param offset
 *            offset to add to coordinates.
 */
private void applyNodeLayout(final LNode lnode, final KVector offset) {
    final ElkNode elknode = (ElkNode) lnode.getProperty(InternalProperties.ORIGIN);
    // Apply the nodeID and layerId that were set on the LGraph on the ElkGraph
    final int nodeID = lnode.getProperty(LayeredOptions.CROSSING_MINIMIZATION_POSITION_ID);
    final int layerID = lnode.getProperty(LayeredOptions.LAYERING_LAYER_ID);
    elknode.setProperty(LayeredOptions.CROSSING_MINIMIZATION_POSITION_ID, nodeID);
    elknode.setProperty(LayeredOptions.LAYERING_LAYER_ID, layerID);
    // Set the node position
    elknode.setX(lnode.getPosition().x + offset.x);
    elknode.setY(lnode.getPosition().y + offset.y);
    // Set the node size, if necessary
    if (!elknode.getProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS).isEmpty() || lnode.getNestedGraph() != null || (lnode.getGraph().getProperty(LayeredOptions.NODE_PLACEMENT_STRATEGY) == NodePlacementStrategy.NETWORK_SIMPLEX && NodeFlexibility.getNodeFlexibility(lnode).isFlexibleSizeWhereSpacePermits())) {
        elknode.setWidth(lnode.getSize().x);
        elknode.setHeight(lnode.getSize().y);
    }
    // Set port positions
    for (LPort lport : lnode.getPorts()) {
        Object origin = lport.getProperty(InternalProperties.ORIGIN);
        if (origin instanceof ElkPort) {
            ElkPort elkport = (ElkPort) origin;
            elkport.setLocation(lport.getPosition().x, lport.getPosition().y);
            elkport.setProperty(LayeredOptions.PORT_SIDE, lport.getSide());
        }
    }
    // Set node label positions, if they were not fixed
    // (that is at least one of the node or the label has a node label placement set)
    final boolean nodeHasLabelPlacement = !lnode.getProperty(LayeredOptions.NODE_LABELS_PLACEMENT).isEmpty();
    for (LLabel llabel : lnode.getLabels()) {
        if (nodeHasLabelPlacement || !llabel.getProperty(LayeredOptions.NODE_LABELS_PLACEMENT).isEmpty()) {
            ElkLabel elklabel = (ElkLabel) llabel.getProperty(InternalProperties.ORIGIN);
            elklabel.setDimensions(llabel.getSize().x, llabel.getSize().y);
            elklabel.setLocation(llabel.getPosition().x, llabel.getPosition().y);
        }
    }
    // Set port label positions, if they were not fixed
    if (!PortLabelPlacement.isFixed(lnode.getProperty(LayeredOptions.PORT_LABELS_PLACEMENT))) {
        for (LPort lport : lnode.getPorts()) {
            for (LLabel llabel : lport.getLabels()) {
                ElkLabel elklabel = (ElkLabel) llabel.getProperty(InternalProperties.ORIGIN);
                elklabel.setWidth(llabel.getSize().x);
                elklabel.setHeight(llabel.getSize().y);
                elklabel.setLocation(llabel.getPosition().x, llabel.getPosition().y);
            }
        }
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) LPort(org.eclipse.elk.alg.layered.graph.LPort) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint)

Example 19 with LLabel

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

the class ElkGraphLayoutTransferrer method applyEdgeLayout.

/**
 * Applies layout information computed for the given edge.
 *
 * @param ledge
 *            the edge that has the layout information.
 * @param routing
 *            the kind of routing applied to edges.
 * @param offset
 *            offset to add to coordinates.
 * @param additionalPadding
 *            the additional insets that may have to be taken into account for hierarchical that go
 *            into the bowels of their source node. These are already included in the offset, but
 *            are required separately.
 */
private void applyEdgeLayout(final LEdge ledge, final EdgeRouting routing, final KVector offset, final LPadding additionalPadding) {
    ElkEdge elkedge = (ElkEdge) ledge.getProperty(InternalProperties.ORIGIN);
    // untouched if another routing algorithm is selected.
    if (elkedge == null) {
        return;
    }
    KVectorChain bendPoints = ledge.getBendPoints();
    // The standard offset may need to be modified if the edge needs to end up in a coordinate system of
    // a graph in a higher hierarchy level
    KVector edgeOffset = new KVector(offset);
    edgeOffset.add(calculateHierarchicalOffset(ledge));
    // Adapt the offset value and add the source port position to the vector chain
    KVector sourcePoint;
    if (LGraphUtil.isDescendant(ledge.getTarget().getNode(), ledge.getSource().getNode())) {
        // The external port's anchor position, relative to the node's top left corner
        LPort sourcePort = ledge.getSource();
        sourcePoint = KVector.sum(sourcePort.getPosition(), sourcePort.getAnchor());
        // The source point will later have the passed offset added to it, which it doesn't actually
        // need, so we subtract it now (notice that the external port's position was already relative
        // to its node's top left corner, while adding the offset now would mean that it was relative
        // to the top left corner + its insets area)
        sourcePoint.sub(offset);
    } else {
        sourcePoint = ledge.getSource().getAbsoluteAnchor();
    }
    bendPoints.addFirst(sourcePoint);
    // Add the target port position to the vector chain, including additional offset
    KVector targetPoint = ledge.getTarget().getAbsoluteAnchor();
    if (ledge.getProperty(InternalProperties.TARGET_OFFSET) != null) {
        targetPoint.add(ledge.getProperty(InternalProperties.TARGET_OFFSET));
    }
    bendPoints.addLast(targetPoint);
    // Translate the bend points by the offset and apply the bend points
    bendPoints.offset(edgeOffset);
    // Give the edge a proper edge section to store routing information
    ElkEdgeSection elkedgeSection = ElkGraphUtil.firstEdgeSection(elkedge, true, true);
    elkedgeSection.setIncomingShape(elkedge.getSources().get(0));
    elkedgeSection.setOutgoingShape(elkedge.getTargets().get(0));
    ElkUtil.applyVectorChain(bendPoints, elkedgeSection);
    // Apply layout to labels
    for (LLabel llabel : ledge.getLabels()) {
        ElkLabel elklabel = (ElkLabel) llabel.getProperty(InternalProperties.ORIGIN);
        elklabel.setWidth(llabel.getSize().x);
        elklabel.setHeight(llabel.getSize().y);
        elklabel.setLocation(llabel.getPosition().x + edgeOffset.x, llabel.getPosition().y + edgeOffset.y);
        elklabel.setProperty(LabelDummySwitcher.INCLUDE_LABEL, llabel.getProperty(LabelDummySwitcher.INCLUDE_LABEL));
    }
    // Copy junction points
    KVectorChain junctionPoints = ledge.getProperty(LayeredOptions.JUNCTION_POINTS);
    if (junctionPoints != null) {
        junctionPoints.offset(edgeOffset);
        elkedge.setProperty(LayeredOptions.JUNCTION_POINTS, junctionPoints);
    } else {
        elkedge.setProperty(LayeredOptions.JUNCTION_POINTS, null);
    }
    // Mark the edge with information about its routing
    if (routing == EdgeRouting.SPLINES) {
        // SPLINES means that bend points shall be interpreted as control points for splines
        elkedge.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.SPLINES);
    } else {
        // null means that bend points shall be interpreted as bend points
        elkedge.setProperty(LayeredOptions.EDGE_ROUTING, null);
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) ElkLabel(org.eclipse.elk.graph.ElkLabel) KVectorChain(org.eclipse.elk.core.math.KVectorChain) LPort(org.eclipse.elk.alg.layered.graph.LPort) KVector(org.eclipse.elk.core.math.KVector) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 20 with LLabel

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

the class CommentPreprocessor method processBox.

/**
 * Process a comment box by putting it into a property of the corresponding node.
 *
 * @param box a comment box
 * @param edge the edge that connects the box with the real node
 * @param oppositePort the port of the real node to which the edge is incident
 * @param realNode the normal node that is connected with the comment
 */
private void processBox(final LNode box, final LEdge edge, final LPort oppositePort, final LNode realNode) {
    boolean topFirst, onlyTop = false, onlyBottom = false;
    if (realNode.getProperty(LayeredOptions.PORT_CONSTRAINTS).isSideFixed()) {
        boolean hasNorth = false, hasSouth = false;
        portLoop: for (LPort port1 : realNode.getPorts()) {
            for (LPort port2 : port1.getConnectedPorts()) {
                if (!port2.getNode().getProperty(LayeredOptions.COMMENT_BOX)) {
                    if (port1.getSide() == PortSide.NORTH) {
                        hasNorth = true;
                        break portLoop;
                    }
                    if (port1.getSide() == PortSide.SOUTH) {
                        hasSouth = true;
                        break portLoop;
                    }
                }
            }
        }
        onlyTop = hasSouth && !hasNorth;
        onlyBottom = hasNorth && !hasSouth;
    }
    if (!onlyTop && !onlyBottom && !realNode.getLabels().isEmpty()) {
        double labelPos = 0;
        for (LLabel label : realNode.getLabels()) {
            labelPos += label.getPosition().y + label.getSize().y / 2;
        }
        labelPos /= realNode.getLabels().size();
        topFirst = labelPos >= realNode.getSize().y / 2;
    } else {
        topFirst = !onlyBottom;
    }
    List<LNode> boxList;
    if (topFirst) {
        // determine the position to use, favoring the top position
        List<LNode> topBoxes = realNode.getProperty(InternalProperties.TOP_COMMENTS);
        if (topBoxes == null) {
            boxList = Lists.newArrayList();
            realNode.setProperty(InternalProperties.TOP_COMMENTS, boxList);
        } else if (onlyTop) {
            boxList = topBoxes;
        } else {
            List<LNode> bottomBoxes = realNode.getProperty(InternalProperties.BOTTOM_COMMENTS);
            if (bottomBoxes == null) {
                boxList = Lists.newArrayList();
                realNode.setProperty(InternalProperties.BOTTOM_COMMENTS, boxList);
            } else {
                if (topBoxes.size() <= bottomBoxes.size()) {
                    boxList = topBoxes;
                } else {
                    boxList = bottomBoxes;
                }
            }
        }
    } else {
        // determine the position to use, favoring the bottom position
        List<LNode> bottomBoxes = realNode.getProperty(InternalProperties.BOTTOM_COMMENTS);
        if (bottomBoxes == null) {
            boxList = Lists.newArrayList();
            realNode.setProperty(InternalProperties.BOTTOM_COMMENTS, boxList);
        } else if (onlyBottom) {
            boxList = bottomBoxes;
        } else {
            List<LNode> topBoxes = realNode.getProperty(InternalProperties.TOP_COMMENTS);
            if (topBoxes == null) {
                boxList = Lists.newArrayList();
                realNode.setProperty(InternalProperties.TOP_COMMENTS, boxList);
            } else {
                if (bottomBoxes.size() <= topBoxes.size()) {
                    boxList = bottomBoxes;
                } else {
                    boxList = topBoxes;
                }
            }
        }
    }
    // add the comment box to one of the two possible lists
    boxList.add(box);
    // set the opposite port as property for the comment box
    box.setProperty(InternalProperties.COMMENT_CONN_PORT, oppositePort);
    // detach the edge and the opposite port
    if (edge.getTarget() == oppositePort) {
        edge.setTarget(null);
        if (oppositePort.getDegree() == 0) {
            oppositePort.setNode(null);
        }
        removeHierarchicalPortDummyNode(oppositePort);
    } else {
        edge.setSource(null);
        if (oppositePort.getDegree() == 0) {
            oppositePort.setNode(null);
        }
    }
    edge.getBendPoints().clear();
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) List(java.util.List)

Aggregations

LLabel (org.eclipse.elk.alg.layered.graph.LLabel)38 LPort (org.eclipse.elk.alg.layered.graph.LPort)20 LNode (org.eclipse.elk.alg.layered.graph.LNode)19 KVector (org.eclipse.elk.core.math.KVector)19 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)14 KVectorChain (org.eclipse.elk.core.math.KVectorChain)8 PortSide (org.eclipse.elk.core.options.PortSide)5 List (java.util.List)4 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)4 ElkLabel (org.eclipse.elk.graph.ElkLabel)4 LabelCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell)3 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)3 Layer (org.eclipse.elk.alg.layered.graph.Layer)3 EdgeLabelPlacement (org.eclipse.elk.core.options.EdgeLabelPlacement)3 Lists (com.google.common.collect.Lists)2 LMargin (org.eclipse.elk.alg.layered.graph.LMargin)2 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)2 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)2 Direction (org.eclipse.elk.core.options.Direction)2 PortConstraints (org.eclipse.elk.core.options.PortConstraints)2