Search in sources :

Example 6 with LLabel

use of org.eclipse.elk.alg.layered.graph.LLabel 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 7 with LLabel

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

Example 8 with LLabel

use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.

the class EndLabelSorterTest method testNode.

private void testNode(final LNode node) {
    switch(node.getType()) {
        case NORMAL:
            // Build a list of label strings that we can check
            if (node.hasProperty(InternalProperties.END_LABELS)) {
                for (LabelCell labelCell : node.getProperty(InternalProperties.END_LABELS).values()) {
                    List<String> labelStrings = labelCell.getLabels().stream().map(label -> label.getText()).collect(Collectors.toList());
                    failIfUnsorted(labelStrings);
                }
            }
            break;
        case LABEL:
            List<LLabel> labels = node.getProperty(InternalProperties.REPRESENTED_LABELS);
            assertNotNull(labels);
            List<String> labelStrings = labels.stream().map(label -> label.getText()).collect(Collectors.toList());
            failIfUnsorted(labelStrings);
            break;
    }
}
Also used : LayoutTestRunner(org.eclipse.elk.alg.test.framework.LayoutTestRunner) ModelResourcePath(org.eclipse.elk.alg.test.framework.io.ModelResourcePath) Iterator(java.util.Iterator) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) Algorithm(org.eclipse.elk.alg.test.framework.annotations.Algorithm) Assert.assertNotNull(org.junit.Assert.assertNotNull) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) DefaultConfiguration(org.eclipse.elk.alg.test.framework.annotations.DefaultConfiguration) Collectors(java.util.stream.Collectors) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) LabelCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell) List(java.util.List) AbstractResourcePath(org.eclipse.elk.alg.test.framework.io.AbstractResourcePath) Lists(com.google.common.collect.Lists) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) LNode(org.eclipse.elk.alg.layered.graph.LNode) GraphResourceProvider(org.eclipse.elk.alg.test.framework.annotations.GraphResourceProvider) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LabelCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell)

Example 9 with LLabel

use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.

the class NetworkSimplexPlacer method applyPositions.

// ------------------------------------------------------------------------------------------------
// Apply Layout
// ------------------------------------------------------------------------------------------------
private void applyPositions() {
    for (Layer l : lGraph) {
        for (LNode lNode : l) {
            // find the node's corners
            NodeRep nodeRep = nodeReps[lNode.id];
            double minY = nodeRep.head.layer;
            double maxY = nodeRep.tail.layer;
            // set new position and size
            lNode.getPosition().y = minY;
            double sizeDelta = (maxY - minY) - lNode.getSize().y;
            boolean flexibleNode = isFlexibleNode(lNode);
            NodeFlexibility nf = getNodeFlexibility(lNode);
            // modify the size?
            if (flexibleNode && nf.isFlexibleSizeWhereSpacePermits()) {
                lNode.getSize().y += sizeDelta;
            }
            // reposition ports if allowed
            if (flexibleNode && nf.isFlexiblePorts()) {
                for (LPort p : lNode.getPorts()) {
                    if (PortSide.SIDES_EAST_WEST.contains(p.getSide())) {
                        NNode nNode = portMap.get(p);
                        p.getPosition().y = nNode.layer - minY;
                    }
                }
                // when the node got resized, the positions of labels and south ports have to be adjusted
                for (LLabel label : lNode.getLabels()) {
                    adjustLabelPosition(lNode, label, sizeDelta);
                }
                if (nf.isFlexibleSizeWhereSpacePermits()) {
                    lNode.getPortSideView(PortSide.SOUTH).forEach(p -> p.getPosition().y += sizeDelta);
                }
            }
        }
    }
}
Also used : NNode(org.eclipse.elk.alg.common.networksimplex.NNode) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LPort(org.eclipse.elk.alg.layered.graph.LPort) NodeFlexibility.getNodeFlexibility(org.eclipse.elk.alg.layered.options.NodeFlexibility.getNodeFlexibility) NodeFlexibility(org.eclipse.elk.alg.layered.options.NodeFlexibility) LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 10 with LLabel

use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.

the class ElkGraphImporter method transformExternalPort.

/**
 * Transforms the given external port into a dummy node.
 *
 * @param elkgraph
 *            the original KGraph
 * @param lgraph
 *            the corresponding layered graph
 * @param elkport
 *            the port to be transformed
 */
private void transformExternalPort(final ElkNode elkgraph, final LGraph lgraph, final ElkPort elkport) {
    // We need some information about the port
    KVector elkportPosition = new KVector(elkport.getX() + elkport.getWidth() / 2.0, elkport.getY() + elkport.getHeight() / 2.0);
    int netFlow = calculateNetFlow(elkport);
    PortConstraints portConstraints = elkgraph.getProperty(LayeredOptions.PORT_CONSTRAINTS);
    // If we don't have a proper port side, calculate one
    PortSide portSide = elkport.getProperty(LayeredOptions.PORT_SIDE);
    assert portSide != PortSide.UNDEFINED;
    // If we don't have a port offset, infer one
    if (!elkport.getAllProperties().containsKey(LayeredOptions.PORT_BORDER_OFFSET)) {
        double portOffset;
        // if port coordinates are (0,0), we default to port offset 0 to make the common case frustration-free
        if (elkport.getX() == 0.0 && elkport.getY() == 0.0) {
            portOffset = 0.0;
        } else {
            portOffset = ElkUtil.calcPortOffset(elkport, portSide);
        }
        elkport.setProperty(LayeredOptions.PORT_BORDER_OFFSET, portOffset);
    }
    // Create the external port dummy node
    KVector graphSize = new KVector(elkgraph.getWidth(), elkgraph.getHeight());
    LNode dummy = LGraphUtil.createExternalPortDummy(elkport, portConstraints, portSide, netFlow, graphSize, elkportPosition, new KVector(elkport.getWidth(), elkport.getHeight()), lgraph.getProperty(LayeredOptions.DIRECTION), lgraph);
    dummy.setProperty(InternalProperties.ORIGIN, elkport);
    // The dummy only has one port
    LPort dummyPort = dummy.getPorts().get(0);
    dummyPort.setConnectedToExternalNodes(isConnectedToExternalNodes(elkport));
    dummy.setProperty(LayeredOptions.PORT_LABELS_PLACEMENT, PortLabelPlacement.outside());
    // If the compound node wants to have its port labels placed on the inside, we need to leave
    // enough space for them by creating an LLabel for the KLabels. If the compound node wants to
    // have its port labels placed on the outside, we still need to leave enough space for them
    // so the port placement does not cause problems on the outside, but we also don't want to waste
    // space inside. Thus, for east and west ports, we reduce the label width to zero, otherwise
    // we reduce the label height to zero
    boolean insidePortLabels = elkgraph.getProperty(LayeredOptions.PORT_LABELS_PLACEMENT).contains(PortLabelPlacement.INSIDE);
    // Transform all of the port's labels
    for (ElkLabel elklabel : elkport.getLabels()) {
        if (!elklabel.getProperty(LayeredOptions.NO_LAYOUT) && !Strings.isNullOrEmpty(elklabel.getText())) {
            LLabel llabel = transformLabel(elklabel);
            dummyPort.getLabels().add(llabel);
            // If the port labels are fixed, we should consider the part that is inside the node and not 0.
            if (!insidePortLabels) {
                double insidePart = 0;
                if (PortLabelPlacement.isFixed(elkgraph.getProperty(LayeredOptions.PORT_LABELS_PLACEMENT))) {
                    // We use 0 as port border offset here, as we only want the label part that is
                    // inside the node "after" the port.
                    insidePart = ElkUtil.computeInsidePart(new KVector(elklabel.getX(), elklabel.getY()), new KVector(elklabel.getWidth(), elklabel.getHeight()), new KVector(elkport.getWidth(), elkport.getHeight()), 0, portSide);
                }
                switch(portSide) {
                    case EAST:
                    case WEST:
                        llabel.getSize().x = insidePart;
                        break;
                    case NORTH:
                    case SOUTH:
                        llabel.getSize().y = insidePart;
                        break;
                }
            }
        }
    }
    // Remember the relevant spacings that will apply to the labels here. It's not the spacings in the graph, but
    // in the parent
    dummy.setProperty(LayeredOptions.SPACING_LABEL_PORT, elkgraph.getParent().getProperty(LayeredOptions.SPACING_LABEL_PORT));
    dummy.setProperty(LayeredOptions.SPACING_LABEL_LABEL, elkgraph.getParent().getProperty(LayeredOptions.SPACING_LABEL_LABEL));
    // Put the external port dummy into our graph and associate it with the original KPort
    lgraph.getLayerlessNodes().add(dummy);
    nodeAndPortMap.put(elkport, dummy);
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) ElkLabel(org.eclipse.elk.graph.ElkLabel) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) KVector(org.eclipse.elk.core.math.KVector) PortSide(org.eclipse.elk.core.options.PortSide) PortConstraints(org.eclipse.elk.core.options.PortConstraints) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint)

Aggregations

LLabel (org.eclipse.elk.alg.layered.graph.LLabel)38 LPort (org.eclipse.elk.alg.layered.graph.LPort)20 LNode (org.eclipse.elk.alg.layered.graph.LNode)19 KVector (org.eclipse.elk.core.math.KVector)19 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)14 KVectorChain (org.eclipse.elk.core.math.KVectorChain)8 PortSide (org.eclipse.elk.core.options.PortSide)5 List (java.util.List)4 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)4 ElkLabel (org.eclipse.elk.graph.ElkLabel)4 LabelCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell)3 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)3 Layer (org.eclipse.elk.alg.layered.graph.Layer)3 EdgeLabelPlacement (org.eclipse.elk.core.options.EdgeLabelPlacement)3 Lists (com.google.common.collect.Lists)2 LMargin (org.eclipse.elk.alg.layered.graph.LMargin)2 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)2 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)2 Direction (org.eclipse.elk.core.options.Direction)2 PortConstraints (org.eclipse.elk.core.options.PortConstraints)2