Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layered: Partition: Let dummy partition edges account for edge labels. #959

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public List<NEdge> getConnectedEdges() {
return allEdges;
}

@Override
public String toString() {
return this.origin.toString();
}

/**
* Builder class for {@link NNode}s.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.elk.alg.layered.graph.LEdge;
import org.eclipse.elk.alg.layered.graph.LGraph;
import org.eclipse.elk.alg.layered.graph.LNode;
import org.eclipse.elk.alg.layered.graph.LNode.NodeType;
import org.eclipse.elk.alg.layered.graph.LPort;
import org.eclipse.elk.alg.layered.options.InternalProperties;
import org.eclipse.elk.alg.layered.options.LayeredOptions;
Expand Down Expand Up @@ -98,6 +99,13 @@ private void connectNodes(final Collection<LNode> firstPartition, final Collecti
sourcePort.setNode(node);
sourcePort.setSide(PortSide.EAST);
sourcePort.setProperty(InternalProperties.PARTITION_DUMMY, true);
boolean labelConnected = false;

for (LEdge edge : node.getOutgoingEdges()) {
if (edge.getTarget().getNode().getType() == NodeType.LABEL) {
labelConnected = true;
}
}

for (LNode otherNode : secondPartition) {
LPort targetPort = new LPort();
Expand All @@ -109,6 +117,27 @@ private void connectNodes(final Collection<LNode> firstPartition, final Collecti
edge.setProperty(InternalProperties.PARTITION_DUMMY, true);
edge.setSource(sourcePort);
edge.setTarget(targetPort);

if (labelConnected) {
// Dummy node to compensate for potential edge label and its influence on the layering.
LNode dummyNode = new LNode(node.getGraph());
node.getGraph().getLayerlessNodes().add(dummyNode);
dummyNode.setType(NodeType.LONG_EDGE);
dummyNode.setProperty(InternalProperties.PARTITION_DUMMY, true);
LPort dummyIn = new LPort();
dummyIn.setNode(dummyNode);
dummyIn.setSide(PortSide.WEST);
LPort dummyOut = new LPort();
dummyOut.setNode(dummyNode);
dummyOut.setSide(PortSide.EAST);

edge.setTarget(dummyIn);

LEdge edge2 = new LEdge();
edge2.setProperty(InternalProperties.PARTITION_DUMMY, true);
edge2.setSource(dummyOut);
edge2.setTarget(targetPort);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ public void process(final LGraph lGraph, final IElkProgressMonitor monitor) {
monitor.begin("Partition postprocessing", 1);
// Remove all added ports and edges.
for (Layer layer : lGraph) {
for (LNode node : layer) {
final Iterator<LNode> layerIterator = layer.iterator();
while (layerIterator.hasNext()) {
LNode node = layerIterator.next();
if (node.getProperty(InternalProperties.PARTITION_DUMMY)) {
// Remove the node explicitly from the iterator to prevent
// ConcurrentModificationExceptions. This removes the port from the underlying
// collection and thus from the layer.
layerIterator.remove();
}
final Iterator<LPort> ports = node.getPorts().iterator();
while (ports.hasNext()) {
LPort port = ports.next();
Expand Down