Search in sources :

Example 16 with ElkRectangle

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

the class LabelAndNodeSizeProcessor method computePortLabelBox.

/**
 * Returns the amount of space required to place the labels later, or {@code null} if there are no labels.
 */
private ElkRectangle computePortLabelBox(final LPort dummyPort, final double labelLabelSpacing) {
    if (dummyPort.getLabels().isEmpty()) {
        return null;
    } else {
        ElkRectangle result = new ElkRectangle();
        for (LLabel label : dummyPort.getLabels()) {
            KVector labelSize = label.getSize();
            result.width = Math.max(result.width, labelSize.x);
            result.height += labelSize.y;
        }
        result.height += (dummyPort.getLabels().size() - 1) * labelLabelSpacing;
        return result;
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) KVector(org.eclipse.elk.core.math.KVector)

Example 17 with ElkRectangle

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

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

the class ElkGraphImporter method importGraph.

@Override
public Graph importGraph(final ElkNode inputGraph) {
    elkGraph = inputGraph;
    nodeMap = Maps.newHashMap();
    // calculate margins
    ElkGraphAdapter adapter = ElkGraphAdapters.adapt(elkGraph);
    NodeDimensionCalculation.calculateNodeMargins(adapter);
    // retrieve layout options
    String preferredRootID = elkGraph.getProperty(SporeCompactionOptions.PROCESSING_ORDER_PREFERRED_ROOT);
    SpanningTreeCostFunction costFunctionID = elkGraph.getProperty(SporeCompactionOptions.PROCESSING_ORDER_SPANNING_TREE_COST_FUNCTION);
    TreeConstructionStrategy treeConstructionStrategy = elkGraph.getProperty(SporeCompactionOptions.PROCESSING_ORDER_TREE_CONSTRUCTION);
    CompactionStrategy compactionStrategy = elkGraph.getProperty(SporeCompactionOptions.COMPACTION_COMPACTION_STRATEGY);
    RootSelection rootSelection = elkGraph.getProperty(SporeCompactionOptions.PROCESSING_ORDER_ROOT_SELECTION);
    spacingNodeNode = elkGraph.getProperty(SporeCompactionOptions.SPACING_NODE_NODE);
    ICostFunction costFunction = centerDistance;
    switch(costFunctionID) {
        case CENTER_DISTANCE:
            costFunction = centerDistance;
            break;
        case CIRCLE_UNDERLAP:
            costFunction = circleUnderlap;
            break;
        case RECTANGLE_UNDERLAP:
            costFunction = rectangleUnderlap;
            break;
        case INVERTED_OVERLAP:
            costFunction = invertedOverlap;
            break;
        case MINIMUM_ROOT_DISTANCE:
            costFunction = minimumRootDistance;
            break;
        default:
            throw new IllegalArgumentException("No implementation available for " + costFunctionID.toString());
    }
    // instantiate Graph
    graph = new Graph(costFunction, treeConstructionStrategy, compactionStrategy);
    graph.setProperty(InternalProperties.DEBUG_SVG, elkGraph.getProperty(SporeCompactionOptions.DEBUG_MODE));
    graph.orthogonalCompaction = elkGraph.getProperty(SporeCompactionOptions.COMPACTION_ORTHOGONAL);
    if (elkGraph.getChildren().isEmpty()) {
        // don't bother
        return graph;
    }
    // create Nodes representing the ElkNodes
    for (ElkNode elkNode : elkGraph.getChildren()) {
        double halfWidth = elkNode.getWidth() / 2;
        double halfHeight = elkNode.getHeight() / 2;
        KVector vertex = new KVector(elkNode.getX() + halfWidth, elkNode.getY() + halfHeight);
        // randomly shift identical points a tiny bit to make them unique
        while (nodeMap.containsKey(vertex)) {
            // SUPPRESS CHECKSTYLE NEXT 1 MagicNumber
            vertex.add((Math.random() - 0.5) * 0.001, (Math.random() - 0.5) * 0.001);
        // If two positions were identical, their corresponding edge in the spanning tree would be
        // of zero length, had no direction, and couldn't be scaled by anything.
        }
        ElkMargin margin = elkNode.getProperty(CoreOptions.MARGINS);
        Node node = new Node(vertex, new ElkRectangle(vertex.x - halfWidth - spacingNodeNode / 2 - margin.left, vertex.y - halfHeight - spacingNodeNode / 2 - margin.top, elkNode.getWidth() + spacingNodeNode + margin.getHorizontal(), elkNode.getHeight() + spacingNodeNode + margin.getVertical()));
        graph.vertices.add(node);
        nodeMap.put(vertex, Pair.of(node, elkNode));
    }
    // spanning tree root selection method
    switch(rootSelection) {
        case FIXED:
            if (preferredRootID == null) {
                // get first Node in list if no ID specified
                graph.preferredRoot = graph.vertices.get(0);
            } else {
                // find Node associated with the ElkNode containing the ID
                for (Node node : graph.vertices) {
                    String id = nodeMap.get(node.originalVertex).getSecond().getIdentifier();
                    if (id != null && id.equals(preferredRootID)) {
                        graph.preferredRoot = node;
                    }
                }
            }
            break;
        case CENTER_NODE:
            // find node that is most central in the drawing
            KVector center = new KVector(elkGraph.getWidth(), elkGraph.getHeight());
            // CHECKSTYLEOFF MagicNumber
            center.scale(0.5);
            center.add(elkGraph.getX(), elkGraph.getY());
            double closest = Double.POSITIVE_INFINITY;
            for (Node node : graph.vertices) {
                double distance = node.originalVertex.distance(center);
                if (distance < closest) {
                    closest = distance;
                    graph.preferredRoot = node;
                }
            }
            break;
        default:
            throw new IllegalArgumentException("No implementation available for " + rootSelection.toString());
    }
    return graph;
}
Also used : ICostFunction(org.eclipse.elk.alg.common.ICostFunction) SpanningTreeCostFunction(org.eclipse.elk.alg.spore.options.SpanningTreeCostFunction) CompactionStrategy(org.eclipse.elk.alg.spore.options.CompactionStrategy) ElkNode(org.eclipse.elk.graph.ElkNode) Node(org.eclipse.elk.alg.common.spore.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ElkMargin(org.eclipse.elk.core.math.ElkMargin) RootSelection(org.eclipse.elk.alg.spore.options.RootSelection) Graph(org.eclipse.elk.alg.spore.graph.Graph) TreeConstructionStrategy(org.eclipse.elk.alg.spore.options.TreeConstructionStrategy) KVector(org.eclipse.elk.core.math.KVector) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) ElkGraphAdapter(org.eclipse.elk.core.util.adapters.ElkGraphAdapters.ElkGraphAdapter)

Example 19 with ElkRectangle

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

the class Block method placeRectsIn.

/**
 * Places the rectangles of this block in a given width.
 * @param width The width
 */
public boolean placeRectsIn(final double width) {
    double oldWidth = this.width;
    double oldHeight = this.height;
    ElkRectangle bounds = placeRectsIn(width, true);
    return bounds.width != oldWidth || bounds.height != oldHeight;
}
Also used : ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

Example 20 with ElkRectangle

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

the class CompactionTest method testLeftCompactionSpacingAware.

@Test
public void testLeftCompactionSpacingAware() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    CTestNode left = new CTestNode(new ElkRectangle(0, 0, 20, 20));
    graph.cNodes.add(left);
    CTestNode right = new CTestNode(new ElkRectangle(30, 20 + SPACING - 1, 20, 20));
    graph.cNodes.add(right);
    compacter(graph).changeDirection(Direction.LEFT).compact().finish();
    assertEquals(0, left.hitbox.x, EPSILON);
    assertEquals(25, right.hitbox.x, EPSILON);
}
Also used : CGraph(org.eclipse.elk.alg.layered.compaction.oned.CGraph) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Direction(org.eclipse.elk.core.options.Direction) Test(org.junit.Test)

Aggregations

ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)82 KVector (org.eclipse.elk.core.math.KVector)33 Test (org.junit.Test)27 Direction (org.eclipse.elk.core.options.Direction)18 CGraph (org.eclipse.elk.alg.layered.compaction.oned.CGraph)17 ElkPadding (org.eclipse.elk.core.math.ElkPadding)9 PortContext (org.eclipse.elk.alg.common.nodespacing.internal.PortContext)8 LabelCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell)7 CGroup (org.eclipse.elk.alg.layered.compaction.oned.CGroup)6 Point (org.eclipse.elk.alg.common.Point)4 LMargin (org.eclipse.elk.alg.layered.graph.LMargin)4 LPort (org.eclipse.elk.alg.layered.graph.LPort)4 ElkNode (org.eclipse.elk.graph.ElkNode)4 RectilinearConvexHull (org.eclipse.elk.alg.common.RectilinearConvexHull)3 AtomicCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.AtomicCell)3 RectangleStripOverlapRemover (org.eclipse.elk.alg.common.overlaps.RectangleStripOverlapRemover)3 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)3 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)3 LNode (org.eclipse.elk.alg.layered.graph.LNode)3 Random (java.util.Random)2