Skip to content
Closed
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 @@ -33,7 +33,7 @@
*
* @author Thomas Wuerthinger
*/
public class HierarchicalLayoutManager extends LayoutManager {
public class HierarchicalLayoutManager extends LayoutManager implements LayoutMover {

int maxLayerLength;
private LayoutGraph graph;
Expand Down Expand Up @@ -77,6 +77,62 @@ public void doLayout(LayoutGraph layoutGraph) {
graph = layoutGraph;
}

@Override
public void moveLink(Point linkPos, int shiftX) {
int layerNr = graph.findLayer(linkPos.y);
for (LayoutNode node : graph.getLayer(layerNr)) {
if (node.isDummy() && linkPos.x == node.getX()) {
LayoutLayer layer = graph.getLayer(layerNr);
if (layer.contains(node)) {
node.setX(linkPos.x + shiftX);
layer.sortNodesByX();
break;
}
}
}
writeBack();
}

@Override
public void moveVertices(Set<? extends Vertex> movedVertices) {
for (Vertex vertex : movedVertices) {
moveVertex(vertex);
}
writeBack();
}

private void writeBack() {
graph.optimizeBackEdgeCrossings();
graph.updateLayerMinXSpacing();
graph.straightenEdges();
WriteResult.apply(graph);
}

@Override
public void moveVertex(Vertex movedVertex) {
Point newLoc = movedVertex.getPosition();
LayoutNode movedNode = graph.getLayoutNode(movedVertex);
assert !movedNode.isDummy();

int layerNr = graph.findLayer(newLoc.y + movedNode.getOuterHeight() / 2);
if (movedNode.getLayer() == layerNr) { // we move the node in the same layer
LayoutLayer layer = graph.getLayer(layerNr);
if (layer.contains(movedNode)) {
movedNode.setX(newLoc.x);
layer.sortNodesByX();
}
} else { // only remove edges if we moved the node to a new layer
if (maxLayerLength > 0) return; // TODO: not implemented
graph.removeNodeAndEdges(movedNode);
layerNr = graph.insertNewLayerIfNeeded(movedNode, layerNr);
graph.addNodeToLayer(movedNode, layerNr);
movedNode.setX(newLoc.x);
graph.getLayer(layerNr).sortNodesByX();
graph.removeEmptyLayers();
graph.addEdges(movedNode, maxLayerLength);
}
}

/**
* Removes self-edges from nodes in the graph. If self-edges are to be included in the layout
* (`layoutSelfEdges` is true), it stores them in the node for later processing and marks the graph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ public void setTo(LayoutNode to) {
this.to = to;
}

/**
* Gets the absolute x-coordinate of the source node's connection point for this edge.
*
* @return The x-coordinate of the source node's connection point.
*/
public int getFromX() {
return from.getX() + getRelativeFromX();
}

/**
* Gets the absolute x-coordinate of the target node's connection point for this edge.
*
* @return The x-coordinate of the target node's connection point.
*/
public int getToX() {
return to.getX() + getRelativeToX();
}

/**
* Gets the relative horizontal position from the source node's left boundary to the edge's starting point.
*
Expand Down
Loading