use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.
the class NetworkSimplexPlacer method follow.
private Path follow(final LEdge edge, final LNode current, final Path path) {
LNode other = edge.getOther(current);
path.add(edge);
// stop criteria
if (nodeState[other.id] == VISITED || nodeState[other.id] == JUNCTION || crossing[edge.id]) {
return path;
}
// recurse
nodeState[other.id] = VISITED;
for (LEdge incident : other.getConnectedEdges()) {
if (!isHandledEdge(incident) || (incident == edge)) {
continue;
}
return follow(incident, other, path);
}
return path;
}
use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.
the class NeighborhoodInformation method determineAllLeftNeighbors.
/**
* Gives all left neighbors (originally known as upper neighbors) of a given node. An upper
* neighbor is a node in a previous layer that has an edge pointing to the given node.
*/
private static void determineAllLeftNeighbors(final NeighborhoodInformation ni, final LGraph graph) {
for (Layer l : graph) {
for (LNode n : l) {
List<Pair<LNode, LEdge>> result = Lists.newArrayList();
int maxPriority = 0;
for (LEdge edge : n.getIncomingEdges()) {
if (edge.isSelfLoop() || edge.isInLayerEdge()) {
continue;
}
int edgePrio = edge.getProperty(LayeredOptions.PRIORITY_STRAIGHTNESS);
if (edgePrio > maxPriority) {
maxPriority = edgePrio;
result.clear();
}
if (edgePrio == maxPriority) {
result.add(Pair.of(edge.getSource().getNode(), edge));
}
}
Collections.sort(result, ni.neighborComparator);
ni.leftNeighbors.add(n.id, result);
}
}
}
use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.
the class NeighborhoodInformation method determineAllRightNeighbors.
/**
* Give all right neighbors (originally known as lower neighbors) of a given node. A lower
* neighbor is a node in a following layer that has an edge coming from the given node.
*/
private static void determineAllRightNeighbors(final NeighborhoodInformation ni, final LGraph graph) {
for (Layer l : graph) {
for (LNode n : l) {
List<Pair<LNode, LEdge>> result = Lists.newArrayList();
int maxPriority = 0;
for (LEdge edge : n.getOutgoingEdges()) {
if (edge.isSelfLoop() || edge.isInLayerEdge()) {
continue;
}
int edgePrio = edge.getProperty(LayeredOptions.PRIORITY_STRAIGHTNESS);
if (edgePrio > maxPriority) {
maxPriority = edgePrio;
result.clear();
}
if (edgePrio == maxPriority) {
result.add(Pair.of(edge.getTarget().getNode(), edge));
}
}
Collections.sort(result, ni.neighborComparator);
ni.rightNeighbors.add(n.id, result);
}
}
}
use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.
the class PolylineEdgeRouter method process.
/* Implementation Note:
*
* The process method works by going through each layer and possibly adding bend points to incoming
* edges of nodes and to outgoing edges of nodes to avoid edge-node-overlaps. While other edge
* routing algorithms insert all bend points required to route edges between a pair of layers, this
* router actually routes any edge in two steps: first while iterating through the source layer, and
* second while iterating through the target layer. Understanding causes the code below to make a
* lot more sense.
*/
@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
monitor.begin("Polyline edge routing", 1);
final double slopedEdgeZoneWidth = layeredGraph.getProperty(LayeredOptions.EDGE_ROUTING_POLYLINE_SLOPED_EDGE_ZONE_WIDTH);
final double nodeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS);
final double edgeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS);
final double edgeSpaceFac = Math.min(1.0, edgeSpacing / nodeSpacing);
double xpos = 0.0;
double layerSpacing = 0.0;
// Determine the horizontal spacing required to route west-side in-layer edges of the first layer
if (!layeredGraph.getLayers().isEmpty()) {
double yDiff = calculateWestInLayerEdgeYDiff(layeredGraph.getLayers().get(0));
xpos = LAYER_SPACE_FAC * edgeSpaceFac * yDiff;
}
// Iterate over the layers
ListIterator<Layer> layerIter = layeredGraph.getLayers().listIterator();
while (layerIter.hasNext()) {
Layer layer = layerIter.next();
boolean externalLayer = Iterables.all(layer, PRED_EXTERNAL_WEST_OR_EAST_PORT);
// The rightmost layer is not given any node spacing if it's an external port layer
if (externalLayer && xpos > 0) {
xpos -= nodeSpacing;
}
// Set horizontal coordinates for all nodes of the layer
LGraphUtil.placeNodesHorizontally(layer, xpos);
// While routing edges, we remember the maximum vertical span of any edge between this and
// the next layer to insert enough space between the layers to keep the edge slopes from
// becoming too steep
double maxVertDiff = 0.0;
// Iterate over the layer's nodes
for (LNode node : layer) {
// Calculate the maximal vertical span of output edges. In-layer edges will also be
// routed at this point
double maxCurrOutputYDiff = 0.0;
for (LEdge outgoingEdge : node.getOutgoingEdges()) {
double sourcePos = outgoingEdge.getSource().getAbsoluteAnchor().y;
double targetPos = outgoingEdge.getTarget().getAbsoluteAnchor().y;
if (layer == outgoingEdge.getTarget().getNode().getLayer() && !outgoingEdge.isSelfLoop()) {
// In-layer edges require an extra bend point to make them look nice
processInLayerEdge(outgoingEdge, xpos, LAYER_SPACE_FAC * edgeSpaceFac * Math.abs(sourcePos - targetPos));
if (outgoingEdge.getSource().getSide() == PortSide.WEST) {
// The spacing required for routing in-layer edges on the west side doesn't
// contribute anything to the spacing required between this and the next
// layer and was already taken into account previously
sourcePos = 0;
targetPos = 0;
}
}
maxCurrOutputYDiff = Math.max(maxCurrOutputYDiff, Math.abs(targetPos - sourcePos));
}
// We currently only handle certain node types. This might change in the future
switch(node.getType()) {
case NORMAL:
case LABEL:
case LONG_EDGE:
case NORTH_SOUTH_PORT:
case BREAKING_POINT:
processNode(node, xpos, slopedEdgeZoneWidth);
break;
}
maxVertDiff = Math.max(maxVertDiff, maxCurrOutputYDiff);
}
// enough space for routing them during the next iteration
if (layerIter.hasNext()) {
double yDiff = calculateWestInLayerEdgeYDiff(layerIter.next());
maxVertDiff = Math.max(maxVertDiff, yDiff);
layerIter.previous();
}
// Determine where next layer should start based on the maximal vertical span of edges
// between the two layers
layerSpacing = LAYER_SPACE_FAC * edgeSpaceFac * maxVertDiff;
if (!externalLayer && layerIter.hasNext()) {
layerSpacing += nodeSpacing;
}
xpos += layer.getSize().x + layerSpacing;
}
createdJunctionPoints.clear();
// Set the graph's horizontal size
layeredGraph.getSize().x = xpos;
monitor.done();
}
use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.
the class IInitializable method init.
/**
* Traverse graph and on each level call the respective methods for a list of initializable objects.
*
* @param initializables
* The objects to be initialized
*/
static void init(final List<IInitializable> initializables, final LNode[][] order) {
for (int l = 0; l < order.length; l++) {
for (IInitializable i : initializables) {
i.initAtLayerLevel(l, order);
}
for (int n = 0; n < order[l].length; n++) {
for (IInitializable i : initializables) {
i.initAtNodeLevel(l, n, order);
}
List<LPort> ports = order[l][n].getPorts();
for (int p = 0; p < ports.size(); p++) {
for (IInitializable i : initializables) {
i.initAtPortLevel(l, n, p, order);
}
LPort port = ports.get(p);
int e = 0;
for (LEdge edge : port.getConnectedEdges()) {
for (IInitializable i : initializables) {
i.initAtEdgeLevel(l, n, p, e++, edge, order);
}
}
}
}
}
for (IInitializable i : initializables) {
i.initAfterTraversal();
}
}
Aggregations