Search in sources :

Example 21 with ElkPadding

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

the class DisCoPolyominoCompactor method applyToDCGraph.

/**
 * Sets an offset to the {@link DCComponent DCComponents} of the given graph indicating a vector, which yields its
 * new absolute position after packing, if added to its original coordinates. Prerequisite:
 * {@link #packPolyominoes()} must have been called before this method.
 */
private void applyToDCGraph() {
    // Crop base grid to the bounding box of all filled/marked cells.
    Quadruple<Integer, Integer, Integer, Integer> gridCrop = grid.getFilledBounds();
    // Compute width and height of the minimum bounding box of the new layout and set the the dimensions of the
    // graph accordingly. The coordinates are thereby translated from the discrete integer coordinates of the low
    // resolution polyominoes back to the real coordinates of the DCGraph.
    ElkPadding padding = cmpGraph.getProperty(DisCoOptions.PADDING);
    double paddingHori = padding.getHorizontal();
    double paddingVert = padding.getVertical();
    double parentWidth = (gridCrop.getThird() * gridCellSizeX) + paddingHori;
    double parentHeight = (gridCrop.getFourth() * gridCellSizeY) + paddingVert;
    cmpGraph.setDimensions(new KVector(parentWidth, parentHeight));
    for (DCPolyomino poly : polys) {
        // Compute the position of the upper left corner of each polyomino relative to the upper left corner of the
        // bounding box of all filled/marked cells of the base grid.
        int absoluteIntPositionX = poly.getX() - gridCrop.getFirst();
        int absoluteIntPositionY = poly.getY() - gridCrop.getSecond();
        // Compute new position of DCComponent
        KVector absolutePositionOnCanvas = new KVector(absoluteIntPositionX, absoluteIntPositionY).scale(poly.getCellSizeX(), poly.getCellSizeY()).add(poly.getOffset());
        // Get original coordinates of DCCopmponent (These will not be updated, as so far all classes implementing
        // the IGraphTransformer only use the offsets of the components to layout their underlying graph structures.
        KVector originalCoordinates = poly.getRepresentee().getMinCorner();
        // Set offset of new position relative to the original position of the component
        poly.getRepresentee().setOffset(absolutePositionOnCanvas.sub(originalCoordinates));
    }
}
Also used : DCPolyomino(org.eclipse.elk.alg.disco.structures.DCPolyomino) KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 22 with ElkPadding

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

the class Draw2DLayoutProvider method buildDraw2dGraph.

/**
 * Builds the graph which is used internally by the Draw2D layout algorithm.
 *
 * @param layoutNode parent layout node
 * @return a graph that contains the children of the given parent
 */
@SuppressWarnings("unchecked")
private DirectedGraph buildDraw2dGraph(final ElkNode layoutNode) {
    DirectedGraph graph = new DirectedGraph();
    // set layout options for the graph
    double minSpacing = layoutNode.getProperty(Draw2DOptions.SPACING_NODE_NODE);
    if (minSpacing < 0) {
        minSpacing = DEF_MIN_SPACING;
    }
    graph.setDefaultPadding(new Insets((int) minSpacing));
    ElkPadding padding = layoutNode.getProperty(Draw2DOptions.PADDING);
    graph.setMargin(new Insets((int) padding.top, (int) padding.left, (int) padding.bottom, (int) padding.right));
    Direction layoutDirection = layoutNode.getProperty(Draw2DOptions.DIRECTION);
    switch(layoutDirection) {
        case UP:
        case DOWN:
            graph.setDirection(PositionConstants.SOUTH);
            break;
        default:
            graph.setDirection(PositionConstants.EAST);
            break;
    }
    // add nodes to the graph
    Map<ElkNode, Node> nodeMap = new HashMap<>();
    for (ElkNode elknode : layoutNode.getChildren()) {
        Node draw2dNode = new Node(elknode);
        ElkUtil.resizeNode(elknode);
        draw2dNode.width = (int) elknode.getWidth();
        draw2dNode.height = (int) elknode.getHeight();
        nodeMap.put(elknode, draw2dNode);
        graph.nodes.add(draw2dNode);
    }
    // add edges to the graph
    for (ElkNode source : layoutNode.getChildren()) {
        Node draw2dSource = nodeMap.get(source);
        for (ElkEdge kedge : ElkGraphUtil.allOutgoingEdges(source)) {
            // we don't support hyperedges
            if (kedge.isHyperedge()) {
                continue;
            }
            ElkNode target = ElkGraphUtil.connectableShapeToNode(kedge.getTargets().get(0));
            Node draw2dTarget = nodeMap.get(target);
            if (draw2dTarget != null && draw2dTarget != draw2dSource) {
                Edge draw2dEdge = new Edge(kedge, draw2dSource, draw2dTarget);
                graph.edges.add(draw2dEdge);
            }
        }
    }
    return graph;
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) DirectedGraph(org.eclipse.draw2d.graph.DirectedGraph) ElkNode(org.eclipse.elk.graph.ElkNode) HashMap(java.util.HashMap) ElkNode(org.eclipse.elk.graph.ElkNode) Node(org.eclipse.draw2d.graph.Node) ElkPadding(org.eclipse.elk.core.math.ElkPadding) Direction(org.eclipse.elk.core.options.Direction) Edge(org.eclipse.draw2d.graph.Edge) ElkEdge(org.eclipse.elk.graph.ElkEdge) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 23 with ElkPadding

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

the class Issue682Test method testGraph.

public Triple<ElkNode, ElkNode, ElkLabel> testGraph() {
    ElkNode graph = ElkGraphUtil.createGraph();
    graph.setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
    graph.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
    graph.setProperty(LayeredOptions.DIRECTION, layoutDirection);
    graph.setProperty(LayeredOptions.NODE_LABELS_PADDING, new ElkPadding(21, 32, 43, 54));
    ElkNode parent = ElkGraphUtil.createNode(graph);
    parent.setProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.NODE_LABELS));
    parent.setProperty(LayeredOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.insideTopCenter());
    ElkLabel label = ElkGraphUtil.createLabel("foobar", parent);
    // Arbitrary
    label.setWidth(23);
    label.setHeight(22);
    return new Triple<>(graph, parent, label);
}
Also used : Triple(org.eclipse.elk.core.util.Triple) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 24 with ElkPadding

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

the class Issue701Test method testMixInsideAndOutsideLabels.

/**
 * Check behavior for port labels that is forced to be inside or outside the node according to
 * {@link PortLabelPlacement} property, with more complex cases that {@link #testInsideLabels(ElkNode)} and
 * {@link #testOutsideLabels(ElkNode)}.
 */
@Test
public void testMixInsideAndOutsideLabels(final ElkNode graph) {
    ElkNode containerForMixInsideOutsideLabels = GraphTestUtils.getChild(graph, "ContainerWithLabelsInsideAndOutside", "Container_SeveralBorderNodes_LabelInsideAndOutside");
    // Ensure there is no label overlaps
    if (GraphTestUtils.haveOverlaps(assembleLabels(containerForMixInsideOutsideLabels))) {
    // TODO: Check deactivated because it fails for "MyCont2": case with 2 border nodes without edges. Maybe to
    // review for https://github.com/eclipse/elk/issues/638.
    // fail("Overlaps between labels detected in \"Container_SeveralBorderNodes_LabelInsideAndOutside\"!");
    }
    // Ports on north and on south sides
    ElkNode node1 = GraphTestUtils.getChild(containerForMixInsideOutsideLabels, "MyNode1");
    ElkPort node1Port1 = GraphTestUtils.getPort(node1, "P1");
    ElkPort node1Port2 = GraphTestUtils.getPort(node1, "P2");
    assertNodeWidthAccordingToPortWidth(node1, node1Port1, node1Port2, false);
    assertNodeHeightAccordingToPortHeight(node1, node1Port1, node1Port2, false);
    // Ports on east and on west sides
    ElkNode node2 = GraphTestUtils.getChild(containerForMixInsideOutsideLabels, "MyNode2");
    ElkPort node2Port1 = GraphTestUtils.getPort(node2, "P1");
    ElkPort node2Port2 = GraphTestUtils.getPort(node2, "P2");
    assertNodeWidthAccordingToPortWidth(node2, node2Port1, node2Port2, true);
    assertNodeHeightAccordingToPortHeight(node2, node2Port1, node2Port2, true);
    // Ports on east and on west sides with a node inside the container without edge
    // TODO: Ignored. The behavior seems KO. Maybe to review for https://github.com/eclipse/elk/issues/638.
    // ElkNode cont2 = GraphTestUtils.getChild(containerForMixInsideOutsideLabels, "MyCont2");
    // Ports on east and on west sides with a node inside the container and linked to the ports, check width of the
    // container
    ElkNode cont3 = GraphTestUtils.getChild(containerForMixInsideOutsideLabels, "MyCont3");
    ElkNode cont3Node2 = GraphTestUtils.getChild(cont3, "MyNode2");
    ElkPort cont3Port1 = GraphTestUtils.getPort(cont3, "P1");
    ElkLabel cont3Port1Label = cont3Port1.getLabels().get(0);
    ElkPort cont3Port2 = GraphTestUtils.getPort(cont3, "P2");
    ElkLabel cont3Port2Label = cont3Port2.getLabels().get(0);
    double spacingLabelCont3Port1 = cont3Port1.getProperty(CoreOptions.SPACING_LABEL_PORT);
    double spacingLabelCont3Port2 = cont3Port2.getProperty(CoreOptions.SPACING_LABEL_PORT);
    double cont3Port1BorderOffset = cont3Port1.getProperty(CoreOptions.PORT_BORDER_OFFSET);
    double cont3Port2BorderOffset = cont3Port2.getProperty(CoreOptions.PORT_BORDER_OFFSET);
    ElkPadding cont3Padding = cont3.getProperty(CoreOptions.PADDING);
    // Compute expected width
    double expectedCont3Width = cont3Padding.getLeft();
    // TODO: It seems to be a bug here. There is only 4 pixels instead of 12
    expectedCont3Width -= 8;
    expectedCont3Width += cont3Node2.getWidth();
    expectedCont3Width += -cont3Port2BorderOffset;
    expectedCont3Width += spacingLabelCont3Port2;
    expectedCont3Width += cont3Port2Label.getWidth();
    expectedCont3Width += cont3Port1Label.getWidth();
    expectedCont3Width += spacingLabelCont3Port1;
    expectedCont3Width += -cont3Port1BorderOffset;
    expectedCont3Width += cont3Padding.getRight();
    assertEquals("Wrong node width according to ports label width.", expectedCont3Width, cont3.getWidth(), 0);
    // Port on east side on a node in container, port on west side of the container, and with edge between ports,
    // check width of the container
    ElkNode cont4 = GraphTestUtils.getChild(containerForMixInsideOutsideLabels, "MyCont4");
    ElkNode cont4Node1 = GraphTestUtils.getChild(cont4, "MyNode1");
    ElkPort cont4Node1Port1 = GraphTestUtils.getPort(cont4Node1, "P1");
    ElkLabel cont4Node1Port1Label = cont4Node1Port1.getLabels().get(0);
    ElkPort cont4Port1 = GraphTestUtils.getPort(cont4, "P1");
    ElkLabel cont4Port1Label = cont4Port1.getLabels().get(0);
    double spacingLabelCont4Node1Port1 = cont4Node1Port1.getProperty(CoreOptions.SPACING_LABEL_PORT);
    double spacingLabelCont4Port1 = cont4Port1.getProperty(CoreOptions.SPACING_LABEL_PORT);
    double cont4Node1Port1BorderOffset = cont4Node1Port1.getProperty(CoreOptions.PORT_BORDER_OFFSET);
    double cont4Port1BorderOffset = cont4Port1.getProperty(CoreOptions.PORT_BORDER_OFFSET);
    ElkPadding cont4Padding = cont4.getProperty(CoreOptions.PADDING);
    // Compute expected width
    double expectedCont4Width = cont4Padding.getLeft();
    expectedCont4Width += cont4Node1.getWidth();
    // TODO: ElkUtil.calcPortOffset(cont4Node1Port1, PortSide.EAST); is supposed to do the same computing as below
    // but it is not the case
    expectedCont4Width += cont4Node1Port1.getWidth() + cont4Node1Port1BorderOffset;
    expectedCont4Width += spacingLabelCont4Node1Port1;
    expectedCont4Width += cont4Node1Port1Label.getWidth();
    expectedCont4Width += cont4Port1Label.getWidth();
    expectedCont4Width += spacingLabelCont4Port1;
    expectedCont4Width += -cont4Port1BorderOffset;
    expectedCont4Width += cont4Padding.getRight();
    assertEquals("Wrong node width according to ports label width.", expectedCont4Width, cont4.getWidth(), 0);
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) ElkPadding(org.eclipse.elk.core.math.ElkPadding) Test(org.junit.Test)

Example 25 with ElkPadding

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

the class PropertyTest method testPropertyDefaultIDataObject.

@Test
public void testPropertyDefaultIDataObject() {
    // all IDataObjects
    KVector v = new KVector(2, 3);
    testPropertyObject(v);
    KVectorChain vc = new KVectorChain(v, v);
    testPropertyObject(vc);
    ElkPadding ep = new ElkPadding(2, 3);
    testPropertyObject(ep);
    ElkMargin em = new ElkMargin(3, 2);
    testPropertyObject(em);
}
Also used : KVectorChain(org.eclipse.elk.core.math.KVectorChain) KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding) ElkMargin(org.eclipse.elk.core.math.ElkMargin) Test(org.junit.Test)

Aggregations

ElkPadding (org.eclipse.elk.core.math.ElkPadding)73 ElkNode (org.eclipse.elk.graph.ElkNode)34 KVector (org.eclipse.elk.core.math.KVector)25 Test (org.junit.Test)18 BasicProgressMonitor (org.eclipse.elk.core.util.BasicProgressMonitor)15 ElkLabel (org.eclipse.elk.graph.ElkLabel)10 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)9 ElkEdge (org.eclipse.elk.graph.ElkEdge)9 KLabel (de.cau.cs.kieler.klighd.kgraph.KLabel)5 KContainerRendering (de.cau.cs.kieler.klighd.krendering.KContainerRendering)5 KText (de.cau.cs.kieler.klighd.krendering.KText)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)5 LabelDecorationConfigurator (de.cau.cs.kieler.klighd.labels.decoration.LabelDecorationConfigurator)4 List (java.util.List)4 ElkPort (org.eclipse.elk.graph.ElkPort)4 KPolyline (de.cau.cs.kieler.klighd.krendering.KPolyline)3 HashSet (java.util.HashSet)3 NodeStatement (org.eclipse.elk.alg.graphviz.dot.dot.NodeStatement)3