Search in sources :

Example 26 with KVector

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

the class FinalSplineBendpointsCalculator method calculateControlPointsConservative.

/**
 * For a regular upward pointing edge and the conservative routing style, control points ({@code +}) are computed
 * as follows:
 * <pre>
 *               ___
 *              |   |
 *          +--+|   |
 *   ___    |   |___|
 *  |   |   |
 *  |   |+--+
 *  |___|
 *  </pre>
 * An downward pointing edge is handled analog.
 */
private void calculateControlPointsConservative(final LEdge edge, final SplineSegment containingSegment) {
    final double startXPos = containingSegment.boundingBox.x;
    final double endXPos = containingSegment.boundingBox.x + containingSegment.boundingBox.width;
    final EdgeInformation ei = containingSegment.edgeInformation.get(edge);
    final double ySourceAnchor = ei.startY;
    final double yTargetAnchor = ei.endY;
    // Calculate bend points to draw inner layer segments straight
    // to prevent intersections with big nodes
    final KVector sourceStraightCP = new KVector(startXPos, ySourceAnchor);
    final KVector targetStraightCP = new KVector(endXPos, yTargetAnchor);
    double centerXPos = startXPos;
    if (!containingSegment.isWestOfInitialLayer) {
        centerXPos += edgeNodeSpacing;
    }
    centerXPos += containingSegment.xDelta + (containingSegment.rank + 0) * edgeEdgeSpacing;
    final KVector sourceVerticalCP = new KVector(centerXPos, ySourceAnchor);
    final KVector targetVerticalCP = new KVector(centerXPos, yTargetAnchor);
    // Traditional four control points (plus an extra center control point for hyperedges)
    edge.getBendPoints().addAll(sourceStraightCP, sourceVerticalCP);
    boolean isHyperedge = containingSegment.edges.size() > 1;
    if (isHyperedge) {
        // add an additional center control point to assert that the hyperedge segments share a part of their route
        final KVector center = new KVector(centerXPos, containingSegment.centerControlPointY);
        edge.getBendPoints().add(center);
    }
    edge.getBendPoints().addAll(targetVerticalCP, targetStraightCP);
}
Also used : EdgeInformation(org.eclipse.elk.alg.layered.p5edges.splines.SplineSegment.EdgeInformation) KVector(org.eclipse.elk.core.math.KVector)

Example 27 with KVector

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

the class FinalSplineBendpointsCalculator method calculateControlPointsStraight.

/**
 * Adds a single control point to a straight segment, halfway between the source and target layer.
 */
private void calculateControlPointsStraight(final SplineSegment segment) {
    double xStartPos = segment.boundingBox.x;
    double xEndPos = segment.boundingBox.x + segment.boundingBox.width;
    KVector halfway = new KVector(xStartPos + (xEndPos - xStartPos) / 2, segment.centerControlPointY);
    segment.edges.iterator().next().getBendPoints().add(halfway);
}
Also used : KVector(org.eclipse.elk.core.math.KVector)

Example 28 with KVector

use of org.eclipse.elk.core.math.KVector 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 29 with KVector

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

the class GraphTransformer method mirrorX.

// /////////////////////////////////////////////////////////////////////////////
// Mirror Horizontally
/**
 * Mirror the x coordinates of the given graph.
 *
 * @param nodes the nodes of the graph to transpose
 * @param graph the graph the nodes are part of
 */
private void mirrorX(final List<LNode> nodes, final LGraph graph) {
    /* Assuming that no nodes extend into negative x coordinates, mirroring a node means that the
         * space left to its left border equals the space right to its right border when mirrored. In
         * mathematical terms:
         *     oldPosition.x = graphWidth - newPosition.x - nodeWidth
         * We use the offset variable to store graphWidth, since that's the constant offset against which
         * we calculate the new node positions.
         * This, however, stops to work once nodes are allowed to extend into negative coordinates. Then,
         * we have to subtract from the graphWidth the amount of space the graph extends into negative
         * coordinates. This amount is saved in the graph's graphOffset. Thus, our offset here becomes:
         *     offset = graphWidth - graphOffset.x 
         */
    double offset = 0;
    // over its nodes
    if (graph.getSize().x == 0) {
        for (LNode node : nodes) {
            offset = Math.max(offset, node.getPosition().x + node.getSize().x + node.getMargin().right);
        }
    } else {
        offset = graph.getSize().x - graph.getOffset().x;
    }
    offset -= graph.getOffset().x;
    // mirror all nodes, ports, edges, and labels
    for (LNode node : nodes) {
        mirrorX(node.getPosition(), offset - node.getSize().x);
        mirrorX(node.getPadding());
        mirrorNodeLabelPlacementX(node);
        // mirror position
        if (node.getAllProperties().containsKey(LayeredOptions.POSITION)) {
            mirrorX(node.getProperty(LayeredOptions.POSITION), offset - node.getSize().x);
        }
        // mirror the alignment
        switch(node.getProperty(LayeredOptions.ALIGNMENT)) {
            case LEFT:
                node.setProperty(LayeredOptions.ALIGNMENT, Alignment.RIGHT);
                break;
            case RIGHT:
                node.setProperty(LayeredOptions.ALIGNMENT, Alignment.LEFT);
                break;
        }
        KVector nodeSize = node.getSize();
        for (LPort port : node.getPorts()) {
            mirrorX(port.getPosition(), nodeSize.x - port.getSize().x);
            mirrorX(port.getAnchor(), port.getSize().x);
            mirrorPortSideX(port);
            reverseIndex(port);
            for (LEdge edge : port.getOutgoingEdges()) {
                // Mirror bend points
                for (KVector bendPoint : edge.getBendPoints()) {
                    mirrorX(bendPoint, offset);
                }
                // Mirror junction points
                KVectorChain junctionPoints = edge.getProperty(LayeredOptions.JUNCTION_POINTS);
                if (junctionPoints != null) {
                    for (KVector jp : junctionPoints) {
                        mirrorX(jp, offset);
                    }
                }
                // Mirror edge label positions
                for (LLabel label : edge.getLabels()) {
                    mirrorX(label.getPosition(), offset - label.getSize().x);
                }
            }
            // Mirror port label positions
            for (LLabel label : port.getLabels()) {
                mirrorX(label.getPosition(), port.getSize().x - label.getSize().x);
            }
        }
        // External port dummy?
        if (node.getType() == NodeType.EXTERNAL_PORT) {
            mirrorExternalPortSideX(node);
            mirrorLayerConstraintX(node);
        }
        // Mirror node labels
        for (LLabel label : node.getLabels()) {
            mirrorNodeLabelPlacementX(label);
            mirrorX(label.getPosition(), nodeSize.x - label.getSize().x);
        }
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) 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) KVector(org.eclipse.elk.core.math.KVector)

Example 30 with KVector

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

the class GraphTransformer method mirrorY.

// /////////////////////////////////////////////////////////////////////////////
// Mirror Vertically
/**
 * Mirror the y coordinates of the given graph.
 *
 * @param nodes the nodes of the graph to transpose
 * @param graph the graph the nodes are part of
 */
private void mirrorY(final List<LNode> nodes, final LGraph graph) {
    // See mirrorX for an explanation of how the offset is calculated
    double offset = 0;
    if (graph.getSize().y == 0) {
        for (LNode node : nodes) {
            offset = Math.max(offset, node.getPosition().y + node.getSize().y + node.getMargin().bottom);
        }
    } else {
        offset = graph.getSize().y - graph.getOffset().y;
    }
    offset -= graph.getOffset().y;
    // mirror all nodes, ports, edges, and labels
    for (LNode node : nodes) {
        mirrorY(node.getPosition(), offset - node.getSize().y);
        mirrorY(node.getPadding());
        mirrorNodeLabelPlacementY(node);
        // mirror position
        if (node.getAllProperties().containsKey(LayeredOptions.POSITION)) {
            mirrorY(node.getProperty(LayeredOptions.POSITION), offset - node.getSize().y);
        }
        // mirror the alignment
        switch(node.getProperty(LayeredOptions.ALIGNMENT)) {
            case TOP:
                node.setProperty(LayeredOptions.ALIGNMENT, Alignment.BOTTOM);
                break;
            case BOTTOM:
                node.setProperty(LayeredOptions.ALIGNMENT, Alignment.TOP);
                break;
        }
        KVector nodeSize = node.getSize();
        for (LPort port : node.getPorts()) {
            mirrorY(port.getPosition(), nodeSize.y - port.getSize().y);
            mirrorY(port.getAnchor(), port.getSize().y);
            mirrorPortSideY(port);
            reverseIndex(port);
            for (LEdge edge : port.getOutgoingEdges()) {
                // Mirror bend points
                for (KVector bendPoint : edge.getBendPoints()) {
                    mirrorY(bendPoint, offset);
                }
                // Mirror junction points
                KVectorChain junctionPoints = edge.getProperty(LayeredOptions.JUNCTION_POINTS);
                if (junctionPoints != null) {
                    for (KVector jp : junctionPoints) {
                        mirrorY(jp, offset);
                    }
                }
                // Mirror edge label positions
                for (LLabel label : edge.getLabels()) {
                    mirrorY(label.getPosition(), offset - label.getSize().y);
                }
            }
            // Mirror port label positions
            for (LLabel label : port.getLabels()) {
                mirrorY(label.getPosition(), port.getSize().y - label.getSize().y);
            }
        }
        // External port dummy?
        if (node.getType() == NodeType.EXTERNAL_PORT) {
            mirrorExternalPortSideY(node);
            mirrorInLayerConstraintY(node);
        }
        // Mirror node labels
        for (LLabel label : node.getLabels()) {
            mirrorNodeLabelPlacementY(label);
            mirrorY(label.getPosition(), nodeSize.y - label.getSize().y);
        }
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) 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) KVector(org.eclipse.elk.core.math.KVector)

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