Search in sources :

Example 6 with LPadding

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

the class ElkLayered method resizeGraphNoReallyIMeanIt.

/**
 * Applies a new effective size to a graph that previously had an old size calculated by the
 * layout algorithm. This method takes care of adjusting content alignments as well as external
 * ports that would be misplaced if the new size is larger than the old one.
 *
 * @param lgraph
 *            the graph to apply the size to.
 * @param oldSize
 *            old size as calculated by the layout algorithm.
 * @param newSize
 *            new size that may be larger than the old one.
 */
private void resizeGraphNoReallyIMeanIt(final LGraph lgraph, final KVector oldSize, final KVector newSize) {
    // obey to specified alignment constraints
    Set<ContentAlignment> contentAlignment = lgraph.getProperty(LayeredOptions.CONTENT_ALIGNMENT);
    // horizontal alignment
    if (newSize.x > oldSize.x) {
        if (contentAlignment.contains(ContentAlignment.H_CENTER)) {
            lgraph.getOffset().x += (newSize.x - oldSize.x) / 2f;
        } else if (contentAlignment.contains(ContentAlignment.H_RIGHT)) {
            lgraph.getOffset().x += newSize.x - oldSize.x;
        }
    }
    // vertical alignment
    if (newSize.y > oldSize.y) {
        if (contentAlignment.contains(ContentAlignment.V_CENTER)) {
            lgraph.getOffset().y += (newSize.y - oldSize.y) / 2f;
        } else if (contentAlignment.contains(ContentAlignment.V_BOTTOM)) {
            lgraph.getOffset().y += newSize.y - oldSize.y;
        }
    }
    // correct the position of eastern and southern hierarchical ports, if necessary
    if (lgraph.getProperty(InternalProperties.GRAPH_PROPERTIES).contains(GraphProperties.EXTERNAL_PORTS) && (newSize.x > oldSize.x || newSize.y > oldSize.y)) {
        // (at this point, the graph's nodes are not divided into layers anymore)
        for (LNode node : lgraph.getLayerlessNodes()) {
            // we're only looking for external port dummies
            if (node.getType() == NodeType.EXTERNAL_PORT) {
                // check which side the external port is on
                PortSide extPortSide = node.getProperty(InternalProperties.EXT_PORT_SIDE);
                if (extPortSide == PortSide.EAST) {
                    node.getPosition().x += newSize.x - oldSize.x;
                } else if (extPortSide == PortSide.SOUTH) {
                    node.getPosition().y += newSize.y - oldSize.y;
                }
            }
        }
    }
    // Actually apply the new size
    LPadding lPadding = lgraph.getPadding();
    lgraph.getSize().x = newSize.x - lPadding.left - lPadding.right;
    lgraph.getSize().y = newSize.y - lPadding.top - lPadding.bottom;
}
Also used : ContentAlignment(org.eclipse.elk.core.options.ContentAlignment) LPadding(org.eclipse.elk.alg.layered.graph.LPadding) LNode(org.eclipse.elk.alg.layered.graph.LNode) PortSide(org.eclipse.elk.core.options.PortSide)

Aggregations

LPadding (org.eclipse.elk.alg.layered.graph.LPadding)6 LNode (org.eclipse.elk.alg.layered.graph.LNode)5 KVector (org.eclipse.elk.core.math.KVector)3 PortSide (org.eclipse.elk.core.options.PortSide)3 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)2 GraphProperties (org.eclipse.elk.alg.layered.options.GraphProperties)2 ElkPadding (org.eclipse.elk.core.math.ElkPadding)2 ContentAlignment (org.eclipse.elk.core.options.ContentAlignment)2 PortConstraints (org.eclipse.elk.core.options.PortConstraints)2 Lists (com.google.common.collect.Lists)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Set (java.util.Set)1 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)1 LGraphUtil (org.eclipse.elk.alg.layered.graph.LGraphUtil)1 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)1 LPort (org.eclipse.elk.alg.layered.graph.LPort)1 LabelDummySwitcher (org.eclipse.elk.alg.layered.intermediate.LabelDummySwitcher)1 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)1 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)1