use of org.eclipse.elk.core.math.KVector in project elk by eclipse.
the class LabelCell method addLabel.
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Adding Labels
/**
* Adds a label to this cell.
*
* @param label
* the label.
*/
public void addLabel(final LabelAdapter<?> label) {
labels.add(label);
// Update our minimum size (how this works depends on the layout mode)
KVector labelSize = label.getSize();
if (horizontalLayoutMode) {
minimumContentAreaSize.x = Math.max(minimumContentAreaSize.x, labelSize.x);
minimumContentAreaSize.y += labelSize.y;
// If this is not our first label, insert a gap
if (labels.size() > 1) {
minimumContentAreaSize.y += gap;
}
} else {
minimumContentAreaSize.x += labelSize.x;
minimumContentAreaSize.y = Math.max(minimumContentAreaSize.y, labelSize.y);
// If this is not our first label, insert a gap
if (labels.size() > 1) {
minimumContentAreaSize.x += gap;
}
}
}
use of org.eclipse.elk.core.math.KVector in project elk by eclipse.
the class HierarchicalPortOrthogonalEdgeRouter method applyNorthSouthDummyRatio.
/**
* Sets the dummy's x coordinate to respect the ratio defined for its original port.
*
* @param dummy the dummy.
* @param width the graph width.
*/
private void applyNorthSouthDummyRatio(final LNode dummy, final double width) {
KVector anchor = dummy.getProperty(LayeredOptions.PORT_ANCHOR);
double offset = anchor == null ? 0 : anchor.x;
dummy.getPosition().x = width * dummy.getProperty(InternalProperties.PORT_RATIO_OR_POSITION) - offset;
}
use of org.eclipse.elk.core.math.KVector in project elk by eclipse.
the class HierarchicalPortOrthogonalEdgeRouter method applyNorthSouthDummyPosition.
/**
* Sets the dummy's x coordinate to its original port's x coordinate.
*
* @param dummy the dummy.
*/
private void applyNorthSouthDummyPosition(final LNode dummy) {
KVector anchor = dummy.getProperty(LayeredOptions.PORT_ANCHOR);
double offset = anchor == null ? 0 : anchor.x;
dummy.getPosition().x = dummy.getProperty(InternalProperties.PORT_RATIO_OR_POSITION) - offset;
}
use of org.eclipse.elk.core.math.KVector in project elk by eclipse.
the class HierarchicalPortOrthogonalEdgeRouter method correctSlantedEdgeSegments.
/**
* Goes over the eastern and western hierarchical dummy nodes in the given layer and checks
* whether their incident edges have slanted segments. Note that only the first and last
* segment needs to be checked.
*
* @param layer the layer.
*/
private void correctSlantedEdgeSegments(final Layer layer) {
for (LNode node : layer) {
if (node.getType() != NodeType.EXTERNAL_PORT) {
// We're only looking for hierarchical port dummies
continue;
}
PortSide extPortSide = node.getProperty(InternalProperties.EXT_PORT_SIDE);
if (extPortSide == PortSide.EAST || extPortSide == PortSide.WEST) {
for (LEdge edge : node.getConnectedEdges()) {
KVectorChain bendPoints = edge.getBendPoints();
if (bendPoints.isEmpty()) {
// TODO: The edge has no bend points yet, but may still be slanted. Handle that!
continue;
}
// Correct a slanted segment connected to the source port if it belongs to our node
LPort sourcePort = edge.getSource();
if (sourcePort.getNode() == node) {
KVector firstBendPoint = bendPoints.getFirst();
firstBendPoint.y = sourcePort.getAbsoluteAnchor().y;
}
// Correct a slanted segment connected to the target port if it belongs to our node
LPort targetPort = edge.getTarget();
if (targetPort.getNode() == node) {
KVector lastBendPoint = bendPoints.getLast();
lastBendPoint.y = targetPort.getAbsoluteAnchor().y;
}
}
}
}
}
use of org.eclipse.elk.core.math.KVector in project elk by eclipse.
the class HierarchicalPortOrthogonalEdgeRouter method setNorthSouthDummyCoordinates.
// /////////////////////////////////////////////////////////////////////////////
// STEP 2: SET NORTH / SOUTH DUMMY COORDINATES
/**
* Set coordinates for northern and southern external port dummy nodes.
*
* @param layeredGraph the layered graph.
* @param northSouthDummies dummy nodes whose position to set.
*/
private void setNorthSouthDummyCoordinates(final LGraph layeredGraph, final List<LNode> northSouthDummies) {
PortConstraints constraints = layeredGraph.getProperty(LayeredOptions.PORT_CONSTRAINTS);
KVector graphSize = layeredGraph.getSize();
LPadding graphPadding = layeredGraph.getPadding();
double graphWidth = graphSize.x + graphPadding.left + graphPadding.right;
double northY = 0 - graphPadding.top - layeredGraph.getOffset().y;
double southY = graphSize.y + graphPadding.top + graphPadding.bottom - layeredGraph.getOffset().y;
// Lists of northern and southern external port dummies
List<LNode> northernDummies = Lists.newArrayList();
List<LNode> southernDummies = Lists.newArrayList();
for (LNode dummy : northSouthDummies) {
// Set x coordinate
switch(constraints) {
case FREE:
case FIXED_SIDE:
case FIXED_ORDER:
calculateNorthSouthDummyPositions(dummy);
break;
case FIXED_RATIO:
applyNorthSouthDummyRatio(dummy, graphWidth);
dummy.borderToContentAreaCoordinates(true, false);
break;
case FIXED_POS:
applyNorthSouthDummyPosition(dummy);
dummy.borderToContentAreaCoordinates(true, false);
// Ensure that the graph is wide enough to hold the port
graphSize.x = Math.max(graphSize.x, dummy.getPosition().x + dummy.getSize().x / 2.0);
break;
}
// Set y coordinates and add the dummy to its respective list
switch(dummy.getProperty(InternalProperties.EXT_PORT_SIDE)) {
case NORTH:
dummy.getPosition().y = northY;
northernDummies.add((dummy));
break;
case SOUTH:
dummy.getPosition().y = southY;
southernDummies.add(dummy);
break;
}
}
// have been put on top of one another
switch(constraints) {
case FREE:
case FIXED_SIDE:
ensureUniquePositions(northernDummies, layeredGraph);
ensureUniquePositions(southernDummies, layeredGraph);
break;
case FIXED_ORDER:
restoreProperOrder(northernDummies, layeredGraph);
restoreProperOrder(southernDummies, layeredGraph);
break;
}
}
Aggregations