Search in sources :

Example 26 with ElkNode

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

the class BlockRow method updateRow.

/**
 * Updates the coordinates of all rectangles and the height and width of the row.
 */
public void updateRow() {
    double width = 0;
    double height = 0;
    for (ElkNode rect : rects) {
        rect.setX(x + width);
        rect.setY(this.y);
        width += rect.getWidth() + nodeNodeSpacing;
        height = Math.max(height, rect.getHeight() + nodeNodeSpacing);
    }
    this.width = width - nodeNodeSpacing;
    this.height = height - nodeNodeSpacing;
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode)

Example 27 with ElkNode

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

the class AnnulusWedgeCompaction method compact.

@Override
public void compact(final ElkNode graph) {
    // Get values of the graph
    root = graph.getProperty(InternalProperties.ROOT_NODE);
    setRoot(root);
    this.sorter = graph.getProperty(RadialOptions.SORTER).create();
    Integer stepSize = graph.getProperty(RadialOptions.COMPACTION_STEP_SIZE);
    if (stepSize != null) {
        setCompactionStep(stepSize);
    }
    Double spacing = graph.getProperty(CoreOptions.SPACING_NODE_NODE);
    setSpacing(spacing);
    // Calculate the first level nodes
    List<ElkNode> successors = RadialUtil.getSuccessors(root);
    if (sorter != null) {
        sorter.sort(successors);
    }
    constructContour(successors);
    // contract each wedge
    List<ElkNode> rootList = Arrays.asList(new ElkNode[] { root });
    // do it two times to assure each node is compacted as much as possible
    for (int k = 0; k < 2; k++) {
        for (int i = 0; i < successors.size(); i++) {
            List<ElkNode> nodeAsList = Arrays.asList(new ElkNode[] { successors.get(i) });
            ElkNode rightParent = i < successors.size() - 1 ? successors.get(i + 1) : successors.get(0);
            ElkNode leftParent = i == 0 ? successors.get(successors.size() - 1) : successors.get(i - 1);
            contractWedge(successors.get(i), rootList, leftParent, rightParent, nodeAsList);
        }
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode)

Example 28 with ElkNode

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

the class AnnulusWedgeCompaction method constructContour.

/**
 * Calculate the left and right contour of each node from the first layer.
 *
 * @param nodes
 *            The list of first layer nodes.
 */
private void constructContour(final List<ElkNode> nodes) {
    for (ElkNode node : nodes) {
        leftContour.put(node, node);
        rightContour.put(node, node);
        List<ElkNode> successors = RadialUtil.getSuccessors(node);
        if (!successors.isEmpty()) {
            if (sorter != null) {
                sorter.sort(successors);
            }
            leftContour.put(node, successors.get(0));
            rightContour.put(node, successors.get(successors.size() - 1));
            while (!RadialUtil.getNextLevelNodes(successors).isEmpty()) {
                successors = RadialUtil.getNextLevelNodes(successors);
                if (sorter != null) {
                    sorter.sort(successors);
                }
                leftContour.put(node, successors.get(0));
                rightContour.put(node, successors.get(successors.size() - 1));
            }
        }
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode)

Example 29 with ElkNode

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

the class RadialCompaction method calculateRadius.

/**
 * Calculate the radius by help of a node.
 *
 * @param node
 *            A node of the radius which will be determined.
 * @return the radius the given node is placed on.
 */
private double calculateRadius(final ElkNode node) {
    double xPos = node.getX();
    double yPos = node.getY();
    ElkNode root = getRoot();
    double rootX = root.getX();
    double rootY = root.getY();
    double vectorX = xPos - rootX;
    double vectorY = yPos - rootY;
    double radius = Math.sqrt(vectorX * vectorX + vectorY * vectorY);
    return radius;
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode)

Example 30 with ElkNode

use of org.eclipse.elk.graph.ElkNode 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)

Aggregations

ElkNode (org.eclipse.elk.graph.ElkNode)267 ElkEdge (org.eclipse.elk.graph.ElkEdge)64 ElkPort (org.eclipse.elk.graph.ElkPort)55 Test (org.junit.Test)52 KVector (org.eclipse.elk.core.math.KVector)51 ElkLabel (org.eclipse.elk.graph.ElkLabel)39 ElkPadding (org.eclipse.elk.core.math.ElkPadding)36 ArrayList (java.util.ArrayList)27 List (java.util.List)25 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)24 LinkedList (java.util.LinkedList)23 BasicProgressMonitor (org.eclipse.elk.core.util.BasicProgressMonitor)22 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)21 ElkConnectableShape (org.eclipse.elk.graph.ElkConnectableShape)17 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)15 Lists (com.google.common.collect.Lists)12 Collection (java.util.Collection)12 KVectorChain (org.eclipse.elk.core.math.KVectorChain)10 HashMap (java.util.HashMap)9 RecursiveGraphLayoutEngine (org.eclipse.elk.core.RecursiveGraphLayoutEngine)9