Search in sources :

Example 6 with ElkEdge

use of org.eclipse.elk.graph.ElkEdge in project elk by eclipse.

the class StraightLineEdgeRouter method routeEdges.

/**
 * Route edges from node center to node center. Then clip it, to not cross the node.
 */
public void routeEdges(final ElkNode node) {
    for (ElkEdge edge : ElkGraphUtil.allOutgoingEdges(node)) {
        if (!(edge.getSources().get(0) instanceof ElkPort)) {
            ElkNode target = ElkGraphUtil.connectableShapeToNode(edge.getTargets().get(0));
            if (!edge.isHierarchical()) {
                double sourceX = node.getX() + node.getWidth() / 2;
                double sourceY = node.getY() + node.getHeight() / 2;
                double targetX = target.getX() + target.getWidth() / 2;
                double targetY = target.getY() + target.getHeight() / 2;
                // Clipping
                KVector vector = new KVector();
                vector.x = targetX - sourceX;
                vector.y = targetY - sourceY;
                KVector sourceClip = new KVector(vector.x, vector.y);
                ElkMath.clipVector(sourceClip, node.getWidth(), node.getHeight());
                vector.x -= sourceClip.x;
                vector.y -= sourceClip.y;
                sourceX = targetX - vector.x;
                sourceY = targetY - vector.y;
                KVector targetClip = new KVector(vector.x, vector.y);
                ElkMath.clipVector(targetClip, target.getWidth(), target.getHeight());
                vector.x -= targetClip.x;
                vector.y -= targetClip.y;
                targetX = sourceX + vector.x;
                targetY = sourceY + vector.y;
                ElkEdgeSection section = ElkGraphUtil.firstEdgeSection(edge, true, true);
                section.setStartLocation(sourceX, sourceY);
                section.setEndLocation(targetX, targetY);
                routeEdges(target);
            }
        }
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) KVector(org.eclipse.elk.core.math.KVector) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 7 with ElkEdge

use of org.eclipse.elk.graph.ElkEdge in project elk by eclipse.

the class EdgeLengthOptimization method evaluate.

/**
 * This evaluation method calculates the sum of the length of each outgoing edge from the root node.
 */
@Override
public double evaluate(final ElkNode root) {
    double edgeLength = 0;
    for (ElkEdge edge : ElkGraphUtil.allOutgoingEdges(root)) {
        ElkNode target = ElkGraphUtil.connectableShapeToNode(edge.getTargets().get(0));
        double targetX = target.getX() + target.getWidth() / 2;
        double targetY = target.getY() + target.getHeight() / 2;
        double rootX = root.getX() + root.getWidth() / 2;
        double rootY = root.getY() + root.getHeight() / 2;
        // Clipping
        KVector vector = new KVector();
        vector.x = targetX - rootX;
        vector.y = targetY - rootY;
        KVector sourceClip = new KVector(vector.x, vector.y);
        ElkMath.clipVector(sourceClip, root.getWidth(), root.getHeight());
        vector.x -= sourceClip.x;
        vector.y -= sourceClip.y;
        rootX = targetX - vector.x;
        rootY = targetY - vector.y;
        KVector targetClip = new KVector(vector.x, vector.y);
        ElkMath.clipVector(targetClip, target.getWidth(), target.getHeight());
        vector.x -= targetClip.x;
        vector.y -= targetClip.y;
        targetX = rootX + vector.x;
        targetY = rootY + vector.y;
        double vectorX = targetX - rootX;
        double vectorY = targetY - rootY;
        edgeLength += Math.sqrt(vectorX * vectorX + vectorY * vectorY);
    }
    return edgeLength;
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) KVector(org.eclipse.elk.core.math.KVector) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 8 with ElkEdge

use of org.eclipse.elk.graph.ElkEdge in project elk by eclipse.

the class RadialUtil method getSuccessors.

/**
 * The nodes which succedes the given node in the tree. These are defined by the targets of all outgoing edges of
 * the node.
 *
 * @param node
 *            A node.
 * @return List of neighbors with outgoing edges.
 */
public static List<ElkNode> getSuccessors(final ElkNode node) {
    List<ElkNode> successors = new ArrayList<>();
    HashSet<ElkNode> children = new HashSet<ElkNode>(node.getChildren());
    for (ElkEdge outgoingEdge : ElkGraphUtil.allOutgoingEdges(node)) {
        if (!(outgoingEdge.getSources().get(0) instanceof ElkPort)) {
            ElkNode target = ElkGraphUtil.connectableShapeToNode(outgoingEdge.getTargets().get(0));
            if (!children.contains(target)) {
                successors.add(target);
            }
        }
    }
    return successors;
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 9 with ElkEdge

use of org.eclipse.elk.graph.ElkEdge in project elk by eclipse.

the class GraphRenderer method renderNodeChildren.

/**
 * Paints all children of the given parent node that fall into the given dirty area.
 *
 * @param parent the node whose children to paint
 * @param graphics the graphics context used to paint
 * @param area dirty area that needs painting
 * @param offset offset to be added to relative coordinates
 * @param nodeAlpha alpha value for nodes
 */
private void renderNodeChildren(final ElkNode parent, final GC graphics, final Rectangle area, final KVector offset, final int nodeAlpha) {
    for (ElkNode childNode : parent.getChildren()) {
        PaintRectangle rect = boundsMap.get(childNode);
        if (rect == null) {
            rect = new PaintRectangle(childNode, offset, scale);
            boundsMap.put(childNode, rect);
        }
        KVector childOffset = new KVector(rect.x, rect.y);
        // render the child node and its content
        if (!rect.painted && rect.intersects(area)) {
            // paint this node
            graphics.setAlpha(nodeAlpha);
            if (configurator.getNodeFillColor() != null) {
                graphics.setBackground(configurator.getNodeFillColor());
                graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
            }
            if (configurator.getNodeBorderColor() != null) {
                graphics.setForeground(configurator.getNodeBorderColor());
                graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
            }
            rect.painted = true;
            renderNodeChildren(childNode, graphics, area, childOffset, nodeAlpha);
        }
        // render node labels
        if (configurator.getNodeLabelFont() != null) {
            graphics.setFont(configurator.getNodeLabelFont());
            for (ElkLabel label : childNode.getLabels()) {
                renderLabel(label, graphics, area, childOffset, nodeAlpha);
            }
        }
        // render ports
        for (ElkPort port : childNode.getPorts()) {
            renderPort(port, graphics, area, childOffset, nodeAlpha);
        }
    }
    // Paint the edges contained in this node
    for (ElkEdge childEdge : parent.getContainedEdges()) {
        renderEdge(childEdge, graphics, area, offset, nodeAlpha);
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) KVector(org.eclipse.elk.core.math.KVector) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 10 with ElkEdge

use of org.eclipse.elk.graph.ElkEdge in project elk by eclipse.

the class GraphRenderer method calculateBaseOffsetFromTopLevelGraph.

/**
 * Calculate the base offset so all graph elements can fit onto the canvas.
 *
 * @param parent the graph to be drawn
 */
public void calculateBaseOffsetFromTopLevelGraph(final ElkNode parent) {
    double minX = Double.POSITIVE_INFINITY;
    double minY = Double.POSITIVE_INFINITY;
    for (ElkNode childNode : parent.getChildren()) {
        minX = Math.min(minX, childNode.getX());
        minY = Math.min(minY, childNode.getY());
        for (ElkLabel childNodeLabel : childNode.getLabels()) {
            minX = Math.min(minX, childNode.getX() + childNodeLabel.getX());
            minY = Math.min(minY, childNode.getY() + childNodeLabel.getY());
        }
    }
    for (ElkEdge edge : parent.getContainedEdges()) {
        PaintRectangle edgeRect = new PaintRectangle(edge, new KVector(), scale);
        minX = Math.min(minX, edgeRect.x);
        minY = Math.min(minY, edgeRect.y);
        for (ElkLabel edgeLabel : edge.getLabels()) {
            minX = Math.min(minX, edgeLabel.getX());
            minY = Math.min(minY, edgeLabel.getY());
        }
    }
    baseOffset.x = -Math.min(0, minX);
    baseOffset.y = -Math.min(0, minY);
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) KVector(org.eclipse.elk.core.math.KVector) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Aggregations

ElkEdge (org.eclipse.elk.graph.ElkEdge)73 ElkNode (org.eclipse.elk.graph.ElkNode)59 ElkPort (org.eclipse.elk.graph.ElkPort)27 KVector (org.eclipse.elk.core.math.KVector)23 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)21 ElkLabel (org.eclipse.elk.graph.ElkLabel)20 ElkConnectableShape (org.eclipse.elk.graph.ElkConnectableShape)10 LinkedList (java.util.LinkedList)9 ElkBendPoint (org.eclipse.elk.graph.ElkBendPoint)9 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)9 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 List (java.util.List)6 ElkPadding (org.eclipse.elk.core.math.ElkPadding)6 KVectorChain (org.eclipse.elk.core.math.KVectorChain)5 HashSet (java.util.HashSet)4 Lists (com.google.common.collect.Lists)3 Collection (java.util.Collection)3 Set (java.util.Set)3