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);
}
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);
}
}
}
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();
}
}
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);
}
Aggregations