use of org.eclipse.elk.alg.common.nodespacing.internal.NodeLabelLocation in project elk by eclipse.
the class NodeLabelCellCreator method handleNodeLabel.
/**
* Handles the given node label by adding it to the corresponding node label cell. If such a cell doesn't exist
* yet, it is created and added to the correct container cell.
*/
private static void handleNodeLabel(final NodeContext nodeContext, final LabelAdapter<?> label, final boolean onlyInside, final boolean horizontalLayoutMode) {
// Find the effective label location
Set<NodeLabelPlacement> labelPlacement = label.hasProperty(CoreOptions.NODE_LABELS_PLACEMENT) ? label.getProperty(CoreOptions.NODE_LABELS_PLACEMENT) : nodeContext.nodeLabelPlacement;
NodeLabelLocation labelLocation = NodeLabelLocation.fromNodeLabelPlacement(labelPlacement);
// If the label has its location fixed, we will ignore it
if (labelLocation == NodeLabelLocation.UNDEFINED) {
return;
}
// If the label's location is on the node's outside but we only want inside node labels, we will ignore it
if (onlyInside && !labelLocation.isInsideLocation()) {
return;
}
retrieveNodeLabelCell(nodeContext, labelLocation, horizontalLayoutMode).addLabel(label);
}
use of org.eclipse.elk.alg.common.nodespacing.internal.NodeLabelLocation in project elk by eclipse.
the class CellSystemConfigurator method configureCellSystemSizeContributions.
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Size Contribution Configuration
/**
* Configures the cell system's constraints such that they work properly when calculating the required node space.
*/
public static void configureCellSystemSizeContributions(final NodeContext nodeContext) {
// calculate the node's size
if (nodeContext.sizeConstraints.isEmpty()) {
return;
}
// Go through the different size constraint components
if (nodeContext.sizeConstraints.contains(SizeConstraint.PORTS)) {
// The northern and southern inside port label cells have the correct width for the node
nodeContext.insidePortLabelCells.get(PortSide.NORTH).setContributesToMinimumWidth(true);
nodeContext.insidePortLabelCells.get(PortSide.SOUTH).setContributesToMinimumWidth(true);
// For the eastern and western cells, they only give a correct height if port placement is free instead of
// constrained (the constrained case is handled separately in the node size calculator). This is due to the
// fact that in the cell layout, the north and south cells are above and below the east and west cells,
// which would cause the node to become too high
boolean freePortPlacement = nodeContext.portConstraints != PortConstraints.FIXED_RATIO && nodeContext.portConstraints != PortConstraints.FIXED_POS;
nodeContext.insidePortLabelCells.get(PortSide.EAST).setContributesToMinimumHeight(freePortPlacement);
nodeContext.insidePortLabelCells.get(PortSide.WEST).setContributesToMinimumHeight(freePortPlacement);
// The main row needs to contribute height for the east and west port label cells to be able to contribute
// their height
nodeContext.nodeContainerMiddleRow.setContributesToMinimumHeight(freePortPlacement);
// Port labels only contribute their size if ports are accounted for as well
if (nodeContext.sizeConstraints.contains(SizeConstraint.PORT_LABELS)) {
// The port label cells contribute the space they need for inside port label placement
nodeContext.insidePortLabelCells.get(PortSide.NORTH).setContributesToMinimumHeight(true);
nodeContext.insidePortLabelCells.get(PortSide.SOUTH).setContributesToMinimumHeight(true);
nodeContext.insidePortLabelCells.get(PortSide.EAST).setContributesToMinimumWidth(true);
nodeContext.insidePortLabelCells.get(PortSide.WEST).setContributesToMinimumWidth(true);
// The main row needs to contribute Width for the east and west port label cells to be able to
// contribute their width
nodeContext.nodeContainerMiddleRow.setContributesToMinimumWidth(true);
}
}
if (nodeContext.sizeConstraints.contains(SizeConstraint.NODE_LABELS)) {
// The inside node label cell needs to contribute both width and height, as needs the middle row
nodeContext.insideNodeLabelContainer.setContributesToMinimumHeight(true);
nodeContext.insideNodeLabelContainer.setContributesToMinimumWidth(true);
nodeContext.nodeContainerMiddleRow.setContributesToMinimumHeight(true);
nodeContext.nodeContainerMiddleRow.setContributesToMinimumWidth(true);
// All node label cells need to contribute height and width, but outside node labels only do so unless they
// are configured to overhang
boolean overhang = nodeContext.sizeOptions.contains(SizeOptions.OUTSIDE_NODE_LABELS_OVERHANG);
for (NodeLabelLocation location : NodeLabelLocation.values()) {
LabelCell labelCell = nodeContext.nodeLabelCells.get(location);
if (labelCell != null) {
if (location.isInsideLocation()) {
labelCell.setContributesToMinimumHeight(true);
labelCell.setContributesToMinimumWidth(true);
} else {
labelCell.setContributesToMinimumHeight(!overhang);
labelCell.setContributesToMinimumWidth(!overhang);
}
}
}
}
// If the middle cell contributes to the node size, we need to set that up as well
if (nodeContext.sizeConstraints.contains(SizeConstraint.MINIMUM_SIZE) && nodeContext.sizeOptions.contains(SizeOptions.MINIMUM_SIZE_ACCOUNTS_FOR_PADDING)) {
// The middle row now needs to contribute width and height, and the center cell of the inside node label
// container needs to contribute width and height as well
nodeContext.nodeContainerMiddleRow.setContributesToMinimumHeight(true);
nodeContext.nodeContainerMiddleRow.setContributesToMinimumHeight(true);
// label container's center cell
if (!nodeContext.insideNodeLabelContainer.isContributingToMinimumHeight()) {
nodeContext.insideNodeLabelContainer.setContributesToMinimumHeight(true);
nodeContext.insideNodeLabelContainer.setContributesToMinimumWidth(true);
nodeContext.insideNodeLabelContainer.setOnlyCenterCellContributesToMinimumSize(true);
}
}
}
Aggregations