Search in sources :

Example 16 with PortConstraints

use of org.eclipse.elk.core.options.PortConstraints in project elk by eclipse.

the class ElkGraphImporter method transformNodes.

/**
 * Transforms the nodes and ports defined by the given layout node.
 *
 * @param parentNode the layout node whose edges to transform.
 * @param fgraph the force graph.
 * @param elemMap the element map that maps the original {@code KGraph} elements to the
 *                transformed {@code FGraph} elements.
 */
private void transformNodes(final ElkNode parentNode, final FGraph fgraph, final Map<ElkNode, FNode> elemMap) {
    int index = 0;
    for (ElkNode knode : parentNode.getChildren()) {
        String label = "";
        if (!knode.getLabels().isEmpty()) {
            label = knode.getLabels().get(0).getText();
        }
        FNode newNode = new FNode(label);
        newNode.copyProperties(knode);
        newNode.setProperty(InternalProperties.ORIGIN, knode);
        newNode.id = index++;
        newNode.getPosition().x = knode.getX() + knode.getWidth() / 2;
        newNode.getPosition().y = knode.getY() + knode.getHeight() / 2;
        newNode.getSize().x = Math.max(knode.getWidth(), 1);
        newNode.getSize().y = Math.max(knode.getHeight(), 1);
        fgraph.getNodes().add(newNode);
        elemMap.put(knode, newNode);
        // port constraints cannot be undefined
        PortConstraints portConstraints = knode.getProperty(ForceOptions.PORT_CONSTRAINTS);
        if (portConstraints == PortConstraints.UNDEFINED) {
            portConstraints = PortConstraints.FREE;
        }
    // TODO consider ports
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) FNode(org.eclipse.elk.alg.force.graph.FNode) PortConstraints(org.eclipse.elk.core.options.PortConstraints)

Example 17 with PortConstraints

use of org.eclipse.elk.core.options.PortConstraints in project elk by eclipse.

the class ElkUtil method resizeNode.

/**
 * Sets the size of a given node, depending on the minimal size, the number of ports
 * on each side and the label.
 *
 * @param node the node that shall be resized
 * @return a vector holding the width and height resizing ratio, or {@code null} if the size
 *     constraint is set to {@code FIXED}
 */
public static KVector resizeNode(final ElkNode node) {
    Set<SizeConstraint> sizeConstraint = node.getProperty(CoreOptions.NODE_SIZE_CONSTRAINTS);
    if (sizeConstraint.isEmpty()) {
        return null;
    }
    double newWidth = 0, newHeight = 0;
    if (sizeConstraint.contains(SizeConstraint.PORTS)) {
        PortConstraints portConstraints = node.getProperty(CoreOptions.PORT_CONSTRAINTS);
        double minNorth = 2, minEast = 2, minSouth = 2, minWest = 2;
        Direction direction = node.getParent() == null ? node.getProperty(CoreOptions.DIRECTION) : node.getParent().getProperty(CoreOptions.DIRECTION);
        for (ElkPort port : node.getPorts()) {
            PortSide portSide = port.getProperty(CoreOptions.PORT_SIDE);
            if (portSide == PortSide.UNDEFINED) {
                portSide = calcPortSide(port, direction);
                port.setProperty(CoreOptions.PORT_SIDE, portSide);
            }
            if (portConstraints == PortConstraints.FIXED_POS) {
                switch(portSide) {
                    case NORTH:
                        minNorth = Math.max(minNorth, port.getX() + port.getWidth());
                        break;
                    case EAST:
                        minEast = Math.max(minEast, port.getY() + port.getHeight());
                        break;
                    case SOUTH:
                        minSouth = Math.max(minSouth, port.getX() + port.getWidth());
                        break;
                    case WEST:
                        minWest = Math.max(minWest, port.getY() + port.getHeight());
                        break;
                }
            } else {
                switch(portSide) {
                    case NORTH:
                        minNorth += port.getWidth() + 2;
                        break;
                    case EAST:
                        minEast += port.getHeight() + 2;
                        break;
                    case SOUTH:
                        minSouth += port.getWidth() + 2;
                        break;
                    case WEST:
                        minWest += port.getHeight() + 2;
                        break;
                }
            }
        }
        newWidth = Math.max(minNorth, minSouth);
        newHeight = Math.max(minEast, minWest);
    }
    return resizeNode(node, newWidth, newHeight, true, true);
}
Also used : ElkPort(org.eclipse.elk.graph.ElkPort) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) PortSide(org.eclipse.elk.core.options.PortSide) PortConstraints(org.eclipse.elk.core.options.PortConstraints) Direction(org.eclipse.elk.core.options.Direction)

Example 18 with PortConstraints

use of org.eclipse.elk.core.options.PortConstraints in project elk by eclipse.

the class RandomGraphGenerator method createNode.

/**
 * Creates a node.
 *
 * @param parent
 *            the parent node
 * @return the node
 */
private ElkNode createNode(final ElkNode parent) {
    ElkNode node = ElkGraphUtil.createNode(null);
    float hypernodeChance = get(GeneratorOptions.HYPERNODE_CHANCE);
    if (hypernodeChance > 0.0f && random.nextFloat() < hypernodeChance) {
        node.setProperty(CoreOptions.HYPERNODE, true);
    }
    // create label and identifier
    String nodeid = String.valueOf(nodeLabelCounter++);
    if (get(GeneratorOptions.CREATE_NODE_LABELS)) {
        ElkGraphUtil.createLabel("N" + nodeid, node);
    }
    node.setIdentifier("n" + nodeid);
    // set size of the node
    if (get(GeneratorOptions.SET_NODE_SIZE)) {
        node.setWidth(get(GeneratorOptions.NODE_WIDTH).floatVal(random));
        node.setHeight(get(GeneratorOptions.NODE_HEIGHT).floatVal(random));
    }
    // set port constraints
    PortConstraints portConstraints = get(GeneratorOptions.PORT_CONSTRAINTS);
    if (portConstraints != PortConstraints.UNDEFINED) {
        node.setProperty(CoreOptions.PORT_CONSTRAINTS, portConstraints);
    }
    parent.getChildren().add(node);
    return node;
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) PortConstraints(org.eclipse.elk.core.options.PortConstraints)

Aggregations

PortConstraints (org.eclipse.elk.core.options.PortConstraints)18 LNode (org.eclipse.elk.alg.layered.graph.LNode)9 PortSide (org.eclipse.elk.core.options.PortSide)8 Direction (org.eclipse.elk.core.options.Direction)6 LPort (org.eclipse.elk.alg.layered.graph.LPort)5 KVector (org.eclipse.elk.core.math.KVector)5 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)5 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)4 ElkLabel (org.eclipse.elk.graph.ElkLabel)4 ElkNode (org.eclipse.elk.graph.ElkNode)4 ElkPort (org.eclipse.elk.graph.ElkPort)4 EnumSet (java.util.EnumSet)3 List (java.util.List)3 Map (java.util.Map)3 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)3 Layer (org.eclipse.elk.alg.layered.graph.Layer)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 LPadding (org.eclipse.elk.alg.layered.graph.LPadding)2