use of org.eclipse.elk.alg.common.nodespacing.cellsystem.GridContainerCell in project elk by eclipse.
the class NodeLabelCellCreator method createNodeLabelCellContainers.
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Cell Creation and Retrieval
/**
* Creates all node label containers.
*/
private static void createNodeLabelCellContainers(final NodeContext nodeContext, final boolean onlyInside) {
boolean symmetry = !nodeContext.sizeOptions.contains(SizeOptions.ASYMMETRICAL);
boolean tabularNodeLabels = nodeContext.sizeOptions.contains(SizeOptions.FORCE_TABULAR_NODE_LABELS);
// Inside container
nodeContext.insideNodeLabelContainer = new GridContainerCell(tabularNodeLabels, symmetry, nodeContext.labelCellSpacing);
if (nodeContext.nodeLabelsPadding != null) {
nodeContext.insideNodeLabelContainer.getPadding().copy(nodeContext.nodeLabelsPadding);
}
nodeContext.nodeContainerMiddleRow.setCell(ContainerArea.CENTER, nodeContext.insideNodeLabelContainer);
// Outside containers, if requested
if (!onlyInside) {
StripContainerCell northContainer = new StripContainerCell(Strip.HORIZONTAL, symmetry, nodeContext.labelCellSpacing);
northContainer.getPadding().bottom = nodeContext.nodeLabelSpacing;
nodeContext.outsideNodeLabelContainers.put(PortSide.NORTH, northContainer);
StripContainerCell southContainer = new StripContainerCell(Strip.HORIZONTAL, symmetry, nodeContext.labelCellSpacing);
southContainer.getPadding().top = nodeContext.nodeLabelSpacing;
nodeContext.outsideNodeLabelContainers.put(PortSide.SOUTH, southContainer);
StripContainerCell westContainer = new StripContainerCell(Strip.VERTICAL, symmetry, nodeContext.labelCellSpacing);
westContainer.getPadding().right = nodeContext.nodeLabelSpacing;
nodeContext.outsideNodeLabelContainers.put(PortSide.WEST, westContainer);
StripContainerCell eastContainer = new StripContainerCell(Strip.VERTICAL, symmetry, nodeContext.labelCellSpacing);
eastContainer.getPadding().left = nodeContext.nodeLabelSpacing;
nodeContext.outsideNodeLabelContainers.put(PortSide.EAST, eastContainer);
}
}
use of org.eclipse.elk.alg.common.nodespacing.cellsystem.GridContainerCell in project elk by eclipse.
the class NodeLabelAndSizeCalculator method computeInsideNodeLabelPadding.
/**
* Computes the padding required to place inside non-center node labels. This can be used to reserve space around
* a hierarchical node while laying out its content. The layout direction is interesting here: usually, one would
* probably either use the graph's layout direction, or the layout direction used to lay out the node's children.
* However, the way the node's labels are placed may not have anything to do with either direction.
*
* @param graph
* the node's parent graph which may specify spacings inherited by the node.
* @param node
* the node to process.
* @param layoutDirection
* the layout direction to assume when computing the paddings.
* @return the padding required for inside node labels.
*/
public static ElkPadding computeInsideNodeLabelPadding(final GraphAdapter<?> graph, final NodeAdapter<?> node, final Direction layoutDirection) {
// Create a node context and fill it with all the inside node labels
NodeContext nodeContext = new NodeContext(null, node);
NodeLabelCellCreator.createNodeLabelCells(nodeContext, true, !layoutDirection.isVertical());
GridContainerCell labelCellContainer = nodeContext.insideNodeLabelContainer;
ElkPadding padding = new ElkPadding();
// Top
for (ContainerArea col : ContainerArea.values()) {
Cell labelCell = labelCellContainer.getCell(ContainerArea.BEGIN, col);
if (labelCell != null) {
padding.top = Math.max(padding.top, labelCell.getMinimumHeight());
}
}
// Bottom
for (ContainerArea col : ContainerArea.values()) {
Cell labelCell = labelCellContainer.getCell(ContainerArea.END, col);
if (labelCell != null) {
padding.bottom = Math.max(padding.bottom, labelCell.getMinimumHeight());
}
}
// Left
for (ContainerArea row : ContainerArea.values()) {
Cell labelCell = labelCellContainer.getCell(row, ContainerArea.BEGIN);
if (labelCell != null) {
padding.left = Math.max(padding.left, labelCell.getMinimumWidth());
}
}
// Right
for (ContainerArea row : ContainerArea.values()) {
Cell labelCell = labelCellContainer.getCell(row, ContainerArea.END);
if (labelCell != null) {
padding.right = Math.max(padding.right, labelCell.getMinimumWidth());
}
}
// Apply insets and gap where necessary
if (padding.top > 0) {
padding.top += labelCellContainer.getPadding().top;
padding.top += labelCellContainer.getGap();
}
if (padding.bottom > 0) {
padding.bottom += labelCellContainer.getPadding().bottom;
padding.bottom += labelCellContainer.getGap();
}
if (padding.left > 0) {
padding.left += labelCellContainer.getPadding().left;
padding.left += labelCellContainer.getGap();
}
if (padding.right > 0) {
padding.right += labelCellContainer.getPadding().right;
padding.right += labelCellContainer.getGap();
}
return padding;
}
Aggregations