Search in sources :

Example 16 with LEdge

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

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

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

the class TestGraphCreator method addEdgeBetweenPorts.

protected void addEdgeBetweenPorts(final LPort from, final LPort to) {
    LEdge edge = new LEdge();
    edge.setSource(from);
    edge.setTarget(to);
    edge.id = edgeId++;
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge)

Example 19 with LEdge

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

the class DotDebugUtil method writeLayer.

/**
 * Writes the given list of nodes and their edges.
 *
 * @param writer writer to write to.
 * @param layerNumber the layer number. {@code -1} for layerless nodes.
 * @param nodes the nodes in the layer.
 */
private static void writeLayer(final StringWriter writer, final int layerNumber, final List<LNode> nodes) {
    if (nodes.isEmpty()) {
        return;
    }
    // Go through the layer's nodes
    int nodeNumber = -1;
    for (LNode node : nodes) {
        nodeNumber++;
        // The node's name in the output is its hash code (unique!)
        writer.write("        " + node.hashCode());
        // Options time!
        StringBuffer options = new StringBuffer();
        // Label
        options.append("label=\"");
        if (node.getType() == NodeType.NORMAL) {
            // Normal nodes display their name, if any
            if (node.getDesignation() != null) {
                options.append(node.getDesignation().replace("\"", "\\\"") + " ");
            }
        } else {
            // Dummy nodes show their name (if set), or their node ID
            if (node.getDesignation() != null) {
                options.append(node.getDesignation().replace("\"", "\\\"") + " ");
            } else {
                options.append("n_" + node.id + " ");
            }
            if (node.getType() == NodeType.NORTH_SOUTH_PORT) {
                Object origin = node.getProperty(InternalProperties.ORIGIN);
                if (origin instanceof LNode) {
                    options.append("(" + ((LNode) origin).toString() + ")");
                }
            }
        }
        options.append("(" + layerNumber + "," + nodeNumber + ")\",");
        // Node type
        if (node.getType() == NodeType.NORMAL) {
            options.append("shape=box,");
        } else {
            options.append("style=\"rounded,filled\",");
            String color = node.getType().getColor();
            if (color != null) {
                options.append("color=\"" + color + "\",");
            }
        }
        // Print options, if any
        options.deleteCharAt(options.length() - 1);
        if (options.length() > 0) {
            writer.write("[" + options + "]");
        }
        // End the node line
        writer.write(";\n");
    }
    // Write the edges
    for (LNode node : nodes) {
        // Go through all edges and output those that have this node as their source
        for (LPort port : node.getPorts()) {
            for (LEdge edge : port.getOutgoingEdges()) {
                writer.write("    " + node.hashCode() + " -> " + edge.getTarget().getNode().hashCode());
                writer.write(";\n");
            }
        }
    }
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Example 20 with LEdge

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

the class JsonDebugUtil method calculateMinMaxPositions.

/**
 * Inspects the given node, its outgoing edges and its ports for minimal and maximal coordinates
 * and adjusts the given vectors {@code min} and {@code max} if necessary.
 *
 * @param min
 *            the minimal coordinates used by the graph.
 * @param max
 *            the maximal coordinates used by the graph.
 * @param node
 *            the current node to inspect.
 */
private static void calculateMinMaxPositions(final KVector min, final KVector max, final LNode node) {
    min.x = Math.min(min.x, node.getPosition().x - node.getMargin().left);
    max.x = Math.max(max.x, node.getPosition().x + node.getSize().x + node.getMargin().right);
    min.y = Math.min(min.y, node.getPosition().y - node.getMargin().top);
    max.y = Math.max(max.y, node.getPosition().y + node.getSize().y + node.getMargin().bottom);
    for (LPort port : node.getPorts()) {
        min.x = Math.min(min.x, node.getPosition().x + port.getPosition().x - port.getMargin().left);
        max.x = Math.max(max.x, node.getPosition().x + port.getPosition().x + port.getSize().x + port.getMargin().right);
        min.y = Math.min(min.y, node.getPosition().y + port.getPosition().y - port.getMargin().top);
        max.y = Math.max(max.y, node.getPosition().y + port.getPosition().y + port.getSize().y + port.getMargin().bottom);
    }
    for (LEdge edge : node.getOutgoingEdges()) {
        for (KVector bendpoint : edge.getBendPoints()) {
            min.x = Math.min(min.x, bendpoint.x);
            max.x = Math.max(max.x, bendpoint.x);
            min.y = Math.min(min.y, bendpoint.y);
            max.y = Math.max(max.y, bendpoint.y);
        }
    }
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort) KVector(org.eclipse.elk.core.math.KVector)

Aggregations

LEdge (org.eclipse.elk.alg.layered.graph.LEdge)148 LNode (org.eclipse.elk.alg.layered.graph.LNode)107 LPort (org.eclipse.elk.alg.layered.graph.LPort)80 Layer (org.eclipse.elk.alg.layered.graph.Layer)41 KVector (org.eclipse.elk.core.math.KVector)34 KVectorChain (org.eclipse.elk.core.math.KVectorChain)20 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)17 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)16 PortSide (org.eclipse.elk.core.options.PortSide)11 ArrayList (java.util.ArrayList)9 List (java.util.List)9 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)8 Set (java.util.Set)7 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)7 Map (java.util.Map)6 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)6 Lists (com.google.common.collect.Lists)5 Iterator (java.util.Iterator)5 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)5 Pair (org.eclipse.elk.core.util.Pair)5