Search in sources :

Example 1 with ContentAlignment

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

the class HierarchicalNodeResizingProcessor 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 padding = lgraph.getPadding();
    lgraph.getSize().x = newSize.x - padding.left - padding.right;
    lgraph.getSize().y = newSize.y - padding.top - padding.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)

Example 2 with ContentAlignment

use of org.eclipse.elk.core.options.ContentAlignment 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

LNode (org.eclipse.elk.alg.layered.graph.LNode)2 LPadding (org.eclipse.elk.alg.layered.graph.LPadding)2 ContentAlignment (org.eclipse.elk.core.options.ContentAlignment)2 PortSide (org.eclipse.elk.core.options.PortSide)2