Search in sources :

Example 1 with SizeOptions

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

the class ElkLayered method resizeGraph.

// //////////////////////////////////////////////////////////////////////////////
// Graph Postprocessing (Size and External Ports)
/**
 * Sets the size of the given graph such that size constraints are adhered to.
 * Furthermore, the border spacing is added to the graph size and the graph offset.
 * Afterwards, the border spacing property is reset to 0.
 *
 * <p>Major parts of this method are adapted from
 * {@link ElkUtil#resizeNode(org.eclipse.elk.graph.ElkNode, double, double, boolean, boolean)}.</p>
 *
 * <p>Note: This method doesn't care about labels of compound nodes since those labels are not
 * attached to the graph.</p>
 *
 * @param lgraph the graph to resize.
 */
private void resizeGraph(final LGraph lgraph) {
    Set<SizeConstraint> sizeConstraint = lgraph.getProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS);
    Set<SizeOptions> sizeOptions = lgraph.getProperty(LayeredOptions.NODE_SIZE_OPTIONS);
    KVector calculatedSize = lgraph.getActualSize();
    KVector adjustedSize = new KVector(calculatedSize);
    // calculate the new size
    if (sizeConstraint.contains(SizeConstraint.MINIMUM_SIZE)) {
        KVector minSize = lgraph.getProperty(LayeredOptions.NODE_SIZE_MINIMUM);
        // if minimum width or height are not set, maybe default to default values
        if (sizeOptions.contains(SizeOptions.DEFAULT_MINIMUM_SIZE)) {
            if (minSize.x <= 0) {
                minSize.x = ElkUtil.DEFAULT_MIN_WIDTH;
            }
            if (minSize.y <= 0) {
                minSize.y = ElkUtil.DEFAULT_MIN_HEIGHT;
            }
        }
        // apply new size including border spacing
        adjustedSize.x = Math.max(calculatedSize.x, minSize.x);
        adjustedSize.y = Math.max(calculatedSize.y, minSize.y);
    }
    resizeGraphNoReallyIMeanIt(lgraph, calculatedSize, adjustedSize);
}
Also used : SizeOptions(org.eclipse.elk.core.options.SizeOptions) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) KVector(org.eclipse.elk.core.math.KVector)

Example 2 with SizeOptions

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

the class ElkGraphLayoutTransferrer method applyLayout.

/**
 * Applies the layout information contained in the given LGraph to the ElkGraph elements it was
 * created from. All source ElkGraph elements are expected to be accessible through their LGraph
 * counterparts through the {@link InternalProperties#ORIGIN} property.
 *
 * @param lgraph the LGraph whose layout information to apply.
 */
public void applyLayout(final LGraph lgraph) {
    Object graphOrigin = lgraph.getProperty(InternalProperties.ORIGIN);
    if (!(graphOrigin instanceof ElkNode)) {
        return;
    }
    // The ElkNode that represents this graph in the original ElkGraph
    ElkNode parentElkNode = (ElkNode) graphOrigin;
    // The LNode that represents this graph in the upper hierarchy level, if any
    LNode parentLNode = (LNode) lgraph.getParentNode();
    // Get the offset to be added to all coordinates
    KVector offset = new KVector(lgraph.getOffset());
    // Adjust offset (and with it the positions) by the requested padding
    LPadding lPadding = lgraph.getPadding();
    offset.x += lPadding.left;
    offset.y += lPadding.top;
    // Set node padding, if it was computed during layout
    final EnumSet<SizeOptions> sizeOptions = parentElkNode.getProperty(LayeredOptions.NODE_SIZE_OPTIONS);
    if (sizeOptions.contains(SizeOptions.COMPUTE_PADDING)) {
        ElkPadding padding = parentElkNode.getProperty(LayeredOptions.PADDING);
        padding.setBottom(lPadding.bottom);
        padding.setTop(lPadding.top);
        padding.setLeft(lPadding.left);
        padding.setRight(lPadding.right);
    }
    // Along the way, we collect the list of edges to be processed later
    List<LEdge> edgeList = Lists.newArrayList();
    // Process the nodes
    for (LNode lnode : lgraph.getLayerlessNodes()) {
        if (representsNode(lnode)) {
            applyNodeLayout(lnode, offset);
        } else if (representsExternalPort(lnode) && parentLNode == null) {
            // We have an external port here on the top-most hierarchy level of the current (possibly
            // hierarchical) layout run; set its position
            ElkPort elkport = (ElkPort) lnode.getProperty(InternalProperties.ORIGIN);
            KVector portPosition = LGraphUtil.getExternalPortPosition(lgraph, lnode, elkport.getWidth(), elkport.getHeight());
            elkport.setLocation(portPosition.x, portPosition.y);
        }
        // correctly)
        for (LPort port : lnode.getPorts()) {
            port.getOutgoingEdges().stream().filter(edge -> !LGraphUtil.isDescendant(edge.getTarget().getNode(), lnode)).forEach(edge -> edgeList.add(edge));
        }
    }
    // Collect edges that go from the current graph's representing LNode down into its descendants
    if (parentLNode != null) {
        for (LPort port : parentLNode.getPorts()) {
            port.getOutgoingEdges().stream().filter(edge -> LGraphUtil.isDescendant(edge.getTarget().getNode(), parentLNode)).forEach(edge -> edgeList.add(edge));
        }
    }
    // Iterate through all edges
    EdgeRouting routing = parentElkNode.getProperty(LayeredOptions.EDGE_ROUTING);
    for (LEdge ledge : edgeList) {
        applyEdgeLayout(ledge, routing, offset, lPadding);
    }
    // Setup the parent node
    applyParentNodeLayout(lgraph);
    // Process nested subgraphs
    for (LNode lnode : lgraph.getLayerlessNodes()) {
        LGraph nestedGraph = lnode.getNestedGraph();
        if (nestedGraph != null) {
            applyLayout(nestedGraph);
        }
    }
}
Also used : GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) PortLabelPlacement(org.eclipse.elk.core.options.PortLabelPlacement) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) KVectorChain(org.eclipse.elk.core.math.KVectorChain) ElkUtil(org.eclipse.elk.core.util.ElkUtil) Lists(com.google.common.collect.Lists) LabelDummySwitcher(org.eclipse.elk.alg.layered.intermediate.LabelDummySwitcher) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) ElkPadding(org.eclipse.elk.core.math.ElkPadding) EnumSet(java.util.EnumSet) NodePlacementStrategy(org.eclipse.elk.alg.layered.options.NodePlacementStrategy) NodeFlexibility(org.eclipse.elk.alg.layered.options.NodeFlexibility) PortConstraints(org.eclipse.elk.core.options.PortConstraints) ElkLabel(org.eclipse.elk.graph.ElkLabel) KVector(org.eclipse.elk.core.math.KVector) SizeOptions(org.eclipse.elk.core.options.SizeOptions) Set(java.util.Set) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) LGraphUtil(org.eclipse.elk.alg.layered.graph.LGraphUtil) LPadding(org.eclipse.elk.alg.layered.graph.LPadding) List(java.util.List) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) LPort(org.eclipse.elk.alg.layered.graph.LPort) EdgeRouting(org.eclipse.elk.core.options.EdgeRouting) LNode(org.eclipse.elk.alg.layered.graph.LNode) ElkEdge(org.eclipse.elk.graph.ElkEdge) ElkGraphUtil(org.eclipse.elk.graph.util.ElkGraphUtil) ElkNode(org.eclipse.elk.graph.ElkNode) SizeOptions(org.eclipse.elk.core.options.SizeOptions) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) ElkPort(org.eclipse.elk.graph.ElkPort) LPadding(org.eclipse.elk.alg.layered.graph.LPadding) EdgeRouting(org.eclipse.elk.core.options.EdgeRouting) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 3 with SizeOptions

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

the class ElkUtil method effectiveMinSizeConstraintFor.

/**
 * Returns the minimum size of the node according to the {@link CoreOptions#NODE_SIZE_MINIMUM} constraint. If that
 * constraint is not set, the size returned by this method will be {@code (0, 0)}.
 *
 * @param node the node whose minimum size to compute.
 * @return the minimum size.
 */
public static KVector effectiveMinSizeConstraintFor(final ElkNode node) {
    Set<SizeConstraint> sizeConstraint = node.getProperty(CoreOptions.NODE_SIZE_CONSTRAINTS);
    if (sizeConstraint.contains(SizeConstraint.MINIMUM_SIZE)) {
        Set<SizeOptions> sizeOptions = node.getProperty(CoreOptions.NODE_SIZE_OPTIONS);
        KVector minSize = new KVector(node.getProperty(CoreOptions.NODE_SIZE_MINIMUM));
        // If minimum width or height are not set, maybe default to default values
        if (sizeOptions.contains(SizeOptions.DEFAULT_MINIMUM_SIZE)) {
            if (minSize.x <= 0) {
                minSize.x = DEFAULT_MIN_WIDTH;
            }
            if (minSize.y <= 0) {
                minSize.y = DEFAULT_MIN_HEIGHT;
            }
        }
        return minSize;
    } else {
        return new KVector();
    }
}
Also used : SizeOptions(org.eclipse.elk.core.options.SizeOptions) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) KVector(org.eclipse.elk.core.math.KVector)

Example 4 with SizeOptions

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

the class HierarchicalNodeResizingProcessor method resizeGraph.

// //////////////////////////////////////////////////////////////////////////////
// Graph Postprocessing (Size and External Ports)
/**
 * Sets the size of the given graph such that size constraints are adhered to. Furthermore, the padding is
 * added to the graph size and the graph offset. Afterwards, the border spacing property is reset to 0.
 *
 * <p>
 * Major parts of this method are adapted from
 * {@link ElkUtil#resizeNode(org.eclipse.elk.graph.ElkNode, double, double, boolean, boolean)}.
 * </p>
 *
 * <p>
 * Note: This method doesn't care about labels of compound nodes since those labels are not attached to the graph.
 * </p>
 *
 * @param lgraph
 *            the graph to resize.
 */
private void resizeGraph(final LGraph lgraph) {
    Set<SizeConstraint> sizeConstraint = lgraph.getProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS);
    Set<SizeOptions> sizeOptions = lgraph.getProperty(LayeredOptions.NODE_SIZE_OPTIONS);
    // getActualSize() used to take the border spacing (what is now included in the padding)
    // into account, which is why by this point it had to be cleared since it had already
    // been applied to the offset and the graph size. It currently does not take the padding
    // into account anymore, but if it does, it needs to be cleared again
    KVector calculatedSize = lgraph.getActualSize();
    KVector adjustedSize = new KVector(calculatedSize);
    // calculate the new size
    if (sizeConstraint.contains(SizeConstraint.MINIMUM_SIZE)) {
        KVector minSize = lgraph.getProperty(LayeredOptions.NODE_SIZE_MINIMUM);
        // if minimum width or height are not set, maybe default to default values
        if (sizeOptions.contains(SizeOptions.DEFAULT_MINIMUM_SIZE)) {
            if (minSize.x <= 0) {
                minSize.x = ElkUtil.DEFAULT_MIN_WIDTH;
            }
            if (minSize.y <= 0) {
                minSize.y = ElkUtil.DEFAULT_MIN_HEIGHT;
            }
        }
        // apply new size including border spacing
        adjustedSize.x = Math.max(calculatedSize.x, minSize.x);
        adjustedSize.y = Math.max(calculatedSize.y, minSize.y);
    }
    resizeGraphNoReallyIMeanIt(lgraph, calculatedSize, adjustedSize);
}
Also used : SizeOptions(org.eclipse.elk.core.options.SizeOptions) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) KVector(org.eclipse.elk.core.math.KVector)

Aggregations

KVector (org.eclipse.elk.core.math.KVector)4 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)4 SizeOptions (org.eclipse.elk.core.options.SizeOptions)4 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 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)1 LGraphUtil (org.eclipse.elk.alg.layered.graph.LGraphUtil)1 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)1 LNode (org.eclipse.elk.alg.layered.graph.LNode)1 LPadding (org.eclipse.elk.alg.layered.graph.LPadding)1 LPort (org.eclipse.elk.alg.layered.graph.LPort)1 LabelDummySwitcher (org.eclipse.elk.alg.layered.intermediate.LabelDummySwitcher)1 GraphProperties (org.eclipse.elk.alg.layered.options.GraphProperties)1 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)1 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)1 NodeFlexibility (org.eclipse.elk.alg.layered.options.NodeFlexibility)1 NodePlacementStrategy (org.eclipse.elk.alg.layered.options.NodePlacementStrategy)1