use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.
the class LabelPlacer method placeVerticalOuterNodeLabelContainer.
/**
* Places a vertical outer node label container on the given side.
*/
private static void placeVerticalOuterNodeLabelContainer(final NodeContext nodeContext, final boolean outerNodeLabelsOverhang, final PortSide portSide) {
KVector nodeSize = nodeContext.nodeSize;
StripContainerCell nodeLabelContainer = nodeContext.outsideNodeLabelContainers.get(portSide);
ElkRectangle nodeLabelContainerRect = nodeLabelContainer.getCellRectangle();
// Set the container's width and height to its minimum width and height
nodeLabelContainerRect.width = nodeLabelContainer.getMinimumWidth();
nodeLabelContainerRect.height = nodeLabelContainer.getMinimumHeight();
// The container must be at least as high as the node is
nodeLabelContainerRect.height = Math.max(nodeLabelContainerRect.height, nodeSize.y);
// If node labels are not allowed to overhang and if they would do so right now, make the container smaller
if (nodeLabelContainerRect.height > nodeSize.y && !outerNodeLabelsOverhang) {
nodeLabelContainerRect.height = nodeSize.y;
}
// Container's y coordinate
nodeLabelContainerRect.y = -(nodeLabelContainerRect.height - nodeSize.y) / 2;
// Container's x coordinate depends on whether we place the thing on the eastern or western side
switch(portSide) {
case WEST:
nodeLabelContainerRect.x = -nodeLabelContainerRect.width;
break;
case EAST:
nodeLabelContainerRect.x = nodeSize.x;
break;
}
// Layout the container's children
nodeLabelContainer.layoutChildrenHorizontally();
nodeLabelContainer.layoutChildrenVertically();
}
use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.
the class LabelPlacer method placeHorizontalOuterNodeLabelContainer.
/**
* Places a horizontal outer node label container on the given side.
*/
private static void placeHorizontalOuterNodeLabelContainer(final NodeContext nodeContext, final boolean outerNodeLabelsOverhang, final PortSide portSide) {
KVector nodeSize = nodeContext.nodeSize;
StripContainerCell nodeLabelContainer = nodeContext.outsideNodeLabelContainers.get(portSide);
ElkRectangle nodeLabelContainerRect = nodeLabelContainer.getCellRectangle();
// Set the container's width and height to its minimum width and height
nodeLabelContainerRect.width = nodeLabelContainer.getMinimumWidth();
nodeLabelContainerRect.height = nodeLabelContainer.getMinimumHeight();
// The container must be at least as wide as the node is
nodeLabelContainerRect.width = Math.max(nodeLabelContainerRect.width, nodeSize.x);
// If node labels are not allowed to overhang and if they would do so right now, make the container smaller
if (nodeLabelContainerRect.width > nodeSize.x && !outerNodeLabelsOverhang) {
nodeLabelContainerRect.width = nodeSize.x;
}
// Container's x coordinate
nodeLabelContainerRect.x = -(nodeLabelContainerRect.width - nodeSize.x) / 2;
// Container's y coordinate depends on whether we place the thing on the northern or southern side
switch(portSide) {
case NORTH:
nodeLabelContainerRect.y = -nodeLabelContainerRect.height;
break;
case SOUTH:
nodeLabelContainerRect.y = nodeSize.y;
break;
}
// Layout the container's children
nodeLabelContainer.layoutChildrenHorizontally();
nodeLabelContainer.layoutChildrenVertically();
}
use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.
the class NodeLabelAndSizeUtilities method setNodePadding.
/**
* Calculates and stores the node padding, if requested by layout options.
*/
public static void setNodePadding(final NodeContext nodeContext) {
if (!nodeContext.sizeOptions.contains(SizeOptions.COMPUTE_PADDING)) {
return;
}
ElkRectangle nodeRect = nodeContext.nodeContainer.getCellRectangle();
ElkRectangle clientArea = nodeContext.insideNodeLabelContainer.getCenterCellRectangle();
ElkPadding nodePadding = new ElkPadding();
// The following code assumes that the client area rectangle lies fully inside the node rectangle, which should
// always be the case because of how the client area rectangle is computed
nodePadding.left = clientArea.x - nodeRect.x;
nodePadding.top = clientArea.y - nodeRect.y;
nodePadding.right = (nodeRect.x + nodeRect.width) - (clientArea.x + clientArea.width);
nodePadding.bottom = (nodeRect.y + nodeRect.height) - (clientArea.y + clientArea.height);
nodeContext.node.setPadding(nodePadding);
}
use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.
the class NodeSizeCalculator method setNodeHeight.
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Node Height
/**
* Sets the node's height according to the active node size constraints. Also sets that height on the cell system
* and tells it to compute a horizontal layout.
*/
public static void setNodeHeight(final NodeContext nodeContext) {
KVector nodeSize = nodeContext.nodeSize;
double height;
if (NodeLabelAndSizeUtilities.areSizeConstraintsFixed(nodeContext)) {
// Simply use the node's current height
height = nodeSize.y;
} else {
// Ask the cell system how heigh it would like to be
height = nodeContext.nodeContainer.getMinimumHeight();
// If we include node labels and outside node labels are not to overhang, we need to include those as well
if (nodeContext.sizeConstraints.contains(SizeConstraint.NODE_LABELS) && !nodeContext.sizeOptions.contains(SizeOptions.OUTSIDE_NODE_LABELS_OVERHANG)) {
height = Math.max(height, nodeContext.outsideNodeLabelContainers.get(PortSide.EAST).getMinimumHeight());
height = Math.max(height, nodeContext.outsideNodeLabelContainers.get(PortSide.WEST).getMinimumHeight());
}
// The node might have a minimum size set...
KVector minNodeSize = NodeLabelAndSizeUtilities.getMinimumNodeSize(nodeContext);
if (minNodeSize != null) {
height = Math.max(height, minNodeSize.y);
}
// come out of the cell system
if (nodeContext.sizeConstraints.contains(SizeConstraint.PORTS)) {
if (nodeContext.portConstraints == PortConstraints.FIXED_RATIO || nodeContext.portConstraints == PortConstraints.FIXED_POS) {
height = Math.max(height, nodeContext.insidePortLabelCells.get(PortSide.EAST).getMinimumHeight());
height = Math.max(height, nodeContext.insidePortLabelCells.get(PortSide.WEST).getMinimumHeight());
}
}
}
// Set the node's height
nodeSize.y = height;
// Set the cell system's height and tell it to compute vertical coordinates and heights
ElkRectangle nodeCellRectangle = nodeContext.nodeContainer.getCellRectangle();
nodeCellRectangle.y = 0;
nodeCellRectangle.height = height;
nodeContext.nodeContainer.layoutChildrenVertically();
}
use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.
the class PortLabelPlacementCalculator method simpleOutsidePortLabelPlacement.
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Simple Outside Port Labels
/**
* Place the port label cells outside of the node.
*/
private static void simpleOutsidePortLabelPlacement(final NodeContext nodeContext, final PortSide portSide) {
Collection<PortContext> portContexts = nodeContext.portContexts.get(portSide);
// If there are only two ports on a side, we place the first port's label on its other side to make it
// especially clear which port it belongs to. The same applies if the user requested space-efficient mode
boolean placeFirstPortDifferently = NodeLabelAndSizeUtilities.isFirstOutsidePortLabelPlacedDifferently(nodeContext, portSide);
for (PortContext portContext : portContexts) {
// If the port doesn't have labels, skip
if (portContext.portLabelCell == null || !portContext.portLabelCell.hasLabels()) {
continue;
}
// Retrieve information about the port itself
KVector portSize = portContext.port.getSize();
// Retrieve the label cell and its rectangle and set the rectangle's size (we will use the rectangle to
// place the cell relative to the port below)
LabelCell portLabelCell = portContext.portLabelCell;
ElkRectangle portLabelCellRect = portLabelCell.getCellRectangle();
portLabelCellRect.width = portLabelCell.getMinimumWidth();
portLabelCellRect.height = portLabelCell.getMinimumHeight();
// Calculate the position of the port's label space
switch(portSide) {
case NORTH:
if (portContext.labelsNextToPort) {
portLabelCellRect.x = (portSize.x - portLabelCellRect.width) / 2;
portLabelCell.setHorizontalAlignment(HorizontalLabelAlignment.CENTER);
} else if (placeFirstPortDifferently) {
portLabelCellRect.x = -portLabelCellRect.width - nodeContext.portLabelSpacing;
portLabelCell.setHorizontalAlignment(HorizontalLabelAlignment.RIGHT);
} else {
portLabelCellRect.x = portSize.x + nodeContext.portLabelSpacing;
portLabelCell.setHorizontalAlignment(HorizontalLabelAlignment.LEFT);
}
portLabelCellRect.y = -portLabelCellRect.height - nodeContext.portLabelSpacing;
portLabelCell.setVerticalAlignment(VerticalLabelAlignment.BOTTOM);
break;
case SOUTH:
if (portContext.labelsNextToPort) {
portLabelCellRect.x = (portSize.x - portLabelCellRect.width) / 2;
portLabelCell.setHorizontalAlignment(HorizontalLabelAlignment.CENTER);
} else if (placeFirstPortDifferently) {
portLabelCellRect.x = -portLabelCellRect.width - nodeContext.portLabelSpacing;
portLabelCell.setHorizontalAlignment(HorizontalLabelAlignment.RIGHT);
} else {
portLabelCellRect.x = portSize.x + nodeContext.portLabelSpacing;
portLabelCell.setHorizontalAlignment(HorizontalLabelAlignment.LEFT);
}
portLabelCellRect.y = portSize.y + nodeContext.portLabelSpacing;
portLabelCell.setVerticalAlignment(VerticalLabelAlignment.TOP);
break;
case EAST:
if (portContext.labelsNextToPort) {
double labelHeight = nodeContext.portLabelsTreatAsGroup ? portLabelCellRect.height : portLabelCell.getLabels().get(0).getSize().y;
portLabelCellRect.y = (portSize.y - labelHeight) / 2;
portLabelCell.setVerticalAlignment(VerticalLabelAlignment.CENTER);
} else if (placeFirstPortDifferently) {
portLabelCellRect.y = -portLabelCellRect.height - nodeContext.portLabelSpacing;
portLabelCell.setVerticalAlignment(VerticalLabelAlignment.BOTTOM);
} else {
portLabelCellRect.y = portSize.y + nodeContext.portLabelSpacing;
portLabelCell.setVerticalAlignment(VerticalLabelAlignment.TOP);
}
portLabelCellRect.x = portSize.x + nodeContext.portLabelSpacing;
portLabelCell.setHorizontalAlignment(HorizontalLabelAlignment.LEFT);
break;
case WEST:
if (portContext.labelsNextToPort) {
double labelHeight = nodeContext.portLabelsTreatAsGroup ? portLabelCellRect.height : portLabelCell.getLabels().get(0).getSize().y;
portLabelCellRect.y = (portSize.y - labelHeight) / 2;
portLabelCell.setVerticalAlignment(VerticalLabelAlignment.CENTER);
} else if (placeFirstPortDifferently) {
portLabelCellRect.y = -portLabelCellRect.height - nodeContext.portLabelSpacing;
portLabelCell.setVerticalAlignment(VerticalLabelAlignment.BOTTOM);
} else {
portLabelCellRect.y = portSize.y + nodeContext.portLabelSpacing;
portLabelCell.setVerticalAlignment(VerticalLabelAlignment.TOP);
}
portLabelCellRect.x = -portLabelCellRect.width - nodeContext.portLabelSpacing;
portLabelCell.setHorizontalAlignment(HorizontalLabelAlignment.RIGHT);
break;
}
// The next port definitely doesn't have special needs anymore
placeFirstPortDifferently = false;
}
}
Aggregations