use of org.eclipse.elk.alg.layered.graph.LNode.NodeType in project elk by eclipse.
the class InvertedPortProcessor method setLongEdgeSourceAndTarget.
/**
* Properly sets the
* {@link org.eclipse.elk.alg.layered.options.LayeredOptions#LONG_EDGE_SOURCE} and
* {@link org.eclipse.elk.alg.layered.options.LayeredOptions#LONG_EDGE_TARGET} properties for
* the given long edge dummy. This is required for the
* {@link org.eclipse.elk.alg.layered.intermediate.HyperedgeDummyMerger} to work correctly.
*
* @param longEdgeDummy
* the long edge dummy whose properties to set.
* @param dummyInputPort
* the dummy node's input port.
* @param dummyOutputPort
* the dummy node's output port.
* @param oddPort
* the odd port that prompted the dummy to be created.
*/
private void setLongEdgeSourceAndTarget(final LNode longEdgeDummy, final LPort dummyInputPort, final LPort dummyOutputPort, final LPort oddPort) {
// There's exactly one edge connected to the input and output port
LPort sourcePort = dummyInputPort.getIncomingEdges().get(0).getSource();
LNode sourceNode = sourcePort.getNode();
NodeType sourceNodeType = sourceNode.getType();
LPort targetPort = dummyOutputPort.getOutgoingEdges().get(0).getTarget();
LNode targetNode = targetPort.getNode();
NodeType targetNodeType = targetNode.getType();
// Set the LONG_EDGE_SOURCE property
if (sourceNodeType == NodeType.LONG_EDGE) {
// The source is a LONG_EDGE node; use its LONG_EDGE_SOURCE
longEdgeDummy.setProperty(InternalProperties.LONG_EDGE_SOURCE, sourceNode.getProperty(InternalProperties.LONG_EDGE_SOURCE));
} else {
// The target is the original node; use it
longEdgeDummy.setProperty(InternalProperties.LONG_EDGE_SOURCE, sourcePort);
}
// Set the LONG_EDGE_TARGET property
if (targetNodeType == NodeType.LONG_EDGE) {
// The target is a LONG_EDGE node; use its LONG_EDGE_TARGET
longEdgeDummy.setProperty(InternalProperties.LONG_EDGE_TARGET, targetNode.getProperty(InternalProperties.LONG_EDGE_TARGET));
} else {
// The target is the original node; use it
longEdgeDummy.setProperty(InternalProperties.LONG_EDGE_TARGET, targetPort);
}
}
use of org.eclipse.elk.alg.layered.graph.LNode.NodeType in project elk by eclipse.
the class InteractiveNodePlacer method placeNodes.
/**
* Places the nodes in the given layer.
*
* @param layer the layer whose nodes to place.
*/
private void placeNodes(final Layer layer) {
// The minimum value for the next valid y coordinate
double minValidY = Double.NEGATIVE_INFINITY;
// The node type of the last node
NodeType prevNodeType = NodeType.NORMAL;
for (LNode node : layer) {
// Check which kind of node it is
NodeType nodeType = node.getType();
if (nodeType != NodeType.NORMAL) {
// While normal nodes have their original position already in them, with dummy nodes
// it's more complicated. Check if the interactive crossing minimizer has calculated
// an original position for the dummy node. If not, we compute one.
Double originalYCoordinate = node.getProperty(InternalProperties.ORIGINAL_DUMMY_NODE_POSITION);
if (originalYCoordinate == null) {
// Make sure that the minimum valid Y position is usable
minValidY = Math.max(minValidY, 0.0);
node.getPosition().y = minValidY + spacings.getVerticalSpacing(nodeType, prevNodeType);
} else {
node.getPosition().y = originalYCoordinate;
}
}
// If the node extends into nodes we already placed above, we need to move it down
double spacing = spacings.getVerticalSpacing(nodeType, prevNodeType);
if (node.getPosition().y < minValidY + spacing + node.getMargin().top) {
node.getPosition().y = minValidY + spacing + node.getMargin().top;
}
// Update minimum valid y coordinate and remember node type
minValidY = node.getPosition().y + node.getSize().y + node.getMargin().bottom;
prevNodeType = nodeType;
}
}
use of org.eclipse.elk.alg.layered.graph.LNode.NodeType in project elk by eclipse.
the class LinearSegmentsNodePlacer method fillSegment.
/**
* Put a node into the given linear segment and check for following parts of a long edge.
*
* @param node
* the node to put into the linear segment
* @param segment
* a linear segment
* @return {@code true} if the given node was not already part of another segment and was thus
* added to the given segment.
*/
private boolean fillSegment(final LNode node, final LinearSegment segment) {
NodeType nodeType = node.getType();
if (node.id >= 0) {
// The node is already part of another linear segment
return false;
} else {
// Add the node to the given linear segment
node.id = segment.id;
segment.nodes.add(node);
}
segment.nodeType = nodeType;
if (nodeType == NodeType.LONG_EDGE || nodeType == NodeType.NORTH_SOUTH_PORT) {
// to be considered here
for (LPort sourcePort : node.getPorts()) {
for (LPort targetPort : sourcePort.getSuccessorPorts()) {
LNode targetNode = targetPort.getNode();
NodeType targetNodeType = targetNode.getType();
if (node.getLayer() != targetNode.getLayer()) {
// current no bignode and next node is LONG_EDGE and NORTH_SOUTH_PORT
if (targetNodeType == NodeType.LONG_EDGE || targetNodeType == NodeType.NORTH_SOUTH_PORT) {
if (fillSegment(targetNode, segment)) {
// That's quite enough.
return true;
}
}
}
}
}
}
return true;
}
use of org.eclipse.elk.alg.layered.graph.LNode.NodeType in project elk by eclipse.
the class Spacings method getLocalSpacing.
private double getLocalSpacing(final LNode n1, final LNode n2, final IProperty<Double>[][] nodeTypeSpacingMapping) {
NodeType t1 = n1.getType();
NodeType t2 = n2.getType();
IProperty<Double> layoutOption = nodeTypeSpacingMapping[t1.ordinal()][t2.ordinal()];
// get the spacing value for the first node
Double s1 = getIndividualOrDefault(n1, layoutOption);
Double s2 = getIndividualOrDefault(n2, layoutOption);
return Math.max(s1, s2);
}
use of org.eclipse.elk.alg.layered.graph.LNode.NodeType in project elk by eclipse.
the class LinearSegmentsNodePlacer method createUnbalancedPlacement.
// /////////////////////////////////////////////////////////////////////////////
// Unbalanced Placement
/**
* Creates an unbalanced placement for the sorted linear segments.
*
* @param layeredGraph
* the layered graph to create an unbalanced placement for.
*/
private void createUnbalancedPlacement(final LGraph layeredGraph) {
// How many nodes are currently placed in each layer
int[] nodeCount = new int[layeredGraph.getLayers().size()];
// The type of the node most recently placed in a given layer
NodeType[] recentNodeType = new NodeType[layeredGraph.getLayers().size()];
LNode[] recentNode = new LNode[layeredGraph.getLayers().size()];
// Iterate through the linear segments (in proper order!) and place them
for (LinearSegment segment : linearSegments) {
// Determine the uppermost placement for the linear segment
double uppermostPlace = 0.0f;
for (LNode node : segment.nodes) {
int layerIndex = node.getLayer().getIndex();
nodeCount[layerIndex]++;
// Calculate how much space to leave between the linear segment and the last
// node of the given layer
double spacing = layeredGraph.getProperty(LayeredOptions.SPACING_EDGE_EDGE);
if (nodeCount[layerIndex] > 0) {
if (recentNode[layerIndex] != null) {
// spacing = spacings.getVerticalSpacing(recentNodeType[layerIndex], nodeType);
spacing = spacings.getVerticalSpacing(recentNode[layerIndex], node);
}
}
uppermostPlace = Math.max(uppermostPlace, node.getLayer().getSize().y + spacing);
}
// Apply the uppermost placement to all elements
for (LNode node : segment.nodes) {
// Set the node position
node.getPosition().y = uppermostPlace + node.getMargin().top;
// Adjust layer size
Layer layer = node.getLayer();
layer.getSize().y = uppermostPlace + node.getMargin().top + node.getSize().y + node.getMargin().bottom;
recentNodeType[layer.getIndex()] = node.getType();
recentNode[layer.getIndex()] = node;
}
}
}