Search in sources :

Example 16 with KVector

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

the class LabelCell method addLabel.

// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Adding Labels
/**
 * Adds a label to this cell.
 *
 * @param label
 *            the label.
 */
public void addLabel(final LabelAdapter<?> label) {
    labels.add(label);
    // Update our minimum size (how this works depends on the layout mode)
    KVector labelSize = label.getSize();
    if (horizontalLayoutMode) {
        minimumContentAreaSize.x = Math.max(minimumContentAreaSize.x, labelSize.x);
        minimumContentAreaSize.y += labelSize.y;
        // If this is not our first label, insert a gap
        if (labels.size() > 1) {
            minimumContentAreaSize.y += gap;
        }
    } else {
        minimumContentAreaSize.x += labelSize.x;
        minimumContentAreaSize.y = Math.max(minimumContentAreaSize.y, labelSize.y);
        // If this is not our first label, insert a gap
        if (labels.size() > 1) {
            minimumContentAreaSize.x += gap;
        }
    }
}
Also used : KVector(org.eclipse.elk.core.math.KVector)

Example 17 with KVector

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

the class HierarchicalPortOrthogonalEdgeRouter method applyNorthSouthDummyRatio.

/**
 * Sets the dummy's x coordinate to respect the ratio defined for its original port.
 *
 * @param dummy the dummy.
 * @param width the graph width.
 */
private void applyNorthSouthDummyRatio(final LNode dummy, final double width) {
    KVector anchor = dummy.getProperty(LayeredOptions.PORT_ANCHOR);
    double offset = anchor == null ? 0 : anchor.x;
    dummy.getPosition().x = width * dummy.getProperty(InternalProperties.PORT_RATIO_OR_POSITION) - offset;
}
Also used : KVector(org.eclipse.elk.core.math.KVector)

Example 18 with KVector

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

the class HierarchicalPortOrthogonalEdgeRouter method applyNorthSouthDummyPosition.

/**
 * Sets the dummy's x coordinate to its original port's x coordinate.
 *
 * @param dummy the dummy.
 */
private void applyNorthSouthDummyPosition(final LNode dummy) {
    KVector anchor = dummy.getProperty(LayeredOptions.PORT_ANCHOR);
    double offset = anchor == null ? 0 : anchor.x;
    dummy.getPosition().x = dummy.getProperty(InternalProperties.PORT_RATIO_OR_POSITION) - offset;
}
Also used : KVector(org.eclipse.elk.core.math.KVector)

Example 19 with KVector

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

the class HierarchicalPortOrthogonalEdgeRouter method correctSlantedEdgeSegments.

/**
 * Goes over the eastern and western hierarchical dummy nodes in the given layer and checks
 * whether their incident edges have slanted segments. Note that only the first and last
 * segment needs to be checked.
 *
 * @param layer the layer.
 */
private void correctSlantedEdgeSegments(final Layer layer) {
    for (LNode node : layer) {
        if (node.getType() != NodeType.EXTERNAL_PORT) {
            // We're only looking for hierarchical port dummies
            continue;
        }
        PortSide extPortSide = node.getProperty(InternalProperties.EXT_PORT_SIDE);
        if (extPortSide == PortSide.EAST || extPortSide == PortSide.WEST) {
            for (LEdge edge : node.getConnectedEdges()) {
                KVectorChain bendPoints = edge.getBendPoints();
                if (bendPoints.isEmpty()) {
                    // TODO: The edge has no bend points yet, but may still be slanted. Handle that!
                    continue;
                }
                // Correct a slanted segment connected to the source port if it belongs to our node
                LPort sourcePort = edge.getSource();
                if (sourcePort.getNode() == node) {
                    KVector firstBendPoint = bendPoints.getFirst();
                    firstBendPoint.y = sourcePort.getAbsoluteAnchor().y;
                }
                // Correct a slanted segment connected to the target port if it belongs to our node
                LPort targetPort = edge.getTarget();
                if (targetPort.getNode() == node) {
                    KVector lastBendPoint = bendPoints.getLast();
                    lastBendPoint.y = targetPort.getAbsoluteAnchor().y;
                }
            }
        }
    }
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) KVectorChain(org.eclipse.elk.core.math.KVectorChain) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) PortSide(org.eclipse.elk.core.options.PortSide) KVector(org.eclipse.elk.core.math.KVector)

Example 20 with KVector

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

the class HierarchicalPortOrthogonalEdgeRouter method setNorthSouthDummyCoordinates.

// /////////////////////////////////////////////////////////////////////////////
// STEP 2: SET NORTH / SOUTH DUMMY COORDINATES
/**
 * Set coordinates for northern and southern external port dummy nodes.
 *
 * @param layeredGraph the layered graph.
 * @param northSouthDummies dummy nodes whose position to set.
 */
private void setNorthSouthDummyCoordinates(final LGraph layeredGraph, final List<LNode> northSouthDummies) {
    PortConstraints constraints = layeredGraph.getProperty(LayeredOptions.PORT_CONSTRAINTS);
    KVector graphSize = layeredGraph.getSize();
    LPadding graphPadding = layeredGraph.getPadding();
    double graphWidth = graphSize.x + graphPadding.left + graphPadding.right;
    double northY = 0 - graphPadding.top - layeredGraph.getOffset().y;
    double southY = graphSize.y + graphPadding.top + graphPadding.bottom - layeredGraph.getOffset().y;
    // Lists of northern and southern external port dummies
    List<LNode> northernDummies = Lists.newArrayList();
    List<LNode> southernDummies = Lists.newArrayList();
    for (LNode dummy : northSouthDummies) {
        // Set x coordinate
        switch(constraints) {
            case FREE:
            case FIXED_SIDE:
            case FIXED_ORDER:
                calculateNorthSouthDummyPositions(dummy);
                break;
            case FIXED_RATIO:
                applyNorthSouthDummyRatio(dummy, graphWidth);
                dummy.borderToContentAreaCoordinates(true, false);
                break;
            case FIXED_POS:
                applyNorthSouthDummyPosition(dummy);
                dummy.borderToContentAreaCoordinates(true, false);
                // Ensure that the graph is wide enough to hold the port
                graphSize.x = Math.max(graphSize.x, dummy.getPosition().x + dummy.getSize().x / 2.0);
                break;
        }
        // Set y coordinates and add the dummy to its respective list
        switch(dummy.getProperty(InternalProperties.EXT_PORT_SIDE)) {
            case NORTH:
                dummy.getPosition().y = northY;
                northernDummies.add((dummy));
                break;
            case SOUTH:
                dummy.getPosition().y = southY;
                southernDummies.add(dummy);
                break;
        }
    }
    // have been put on top of one another
    switch(constraints) {
        case FREE:
        case FIXED_SIDE:
            ensureUniquePositions(northernDummies, layeredGraph);
            ensureUniquePositions(southernDummies, layeredGraph);
            break;
        case FIXED_ORDER:
            restoreProperOrder(northernDummies, layeredGraph);
            restoreProperOrder(southernDummies, layeredGraph);
            break;
    }
}
Also used : LPadding(org.eclipse.elk.alg.layered.graph.LPadding) LNode(org.eclipse.elk.alg.layered.graph.LNode) KVector(org.eclipse.elk.core.math.KVector) PortConstraints(org.eclipse.elk.core.options.PortConstraints)

Aggregations

KVector (org.eclipse.elk.core.math.KVector)292 KVectorChain (org.eclipse.elk.core.math.KVectorChain)52 ElkNode (org.eclipse.elk.graph.ElkNode)49 LNode (org.eclipse.elk.alg.layered.graph.LNode)39 LPort (org.eclipse.elk.alg.layered.graph.LPort)37 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)36 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)35 Test (org.junit.Test)30 ElkEdge (org.eclipse.elk.graph.ElkEdge)28 ElkLabel (org.eclipse.elk.graph.ElkLabel)27 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)26 ElkPadding (org.eclipse.elk.core.math.ElkPadding)25 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)20 PortSide (org.eclipse.elk.core.options.PortSide)19 ElkPort (org.eclipse.elk.graph.ElkPort)18 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)17 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)15 ArrayList (java.util.ArrayList)13 Layer (org.eclipse.elk.alg.layered.graph.Layer)12 LMargin (org.eclipse.elk.alg.layered.graph.LMargin)11