Skip to content

Commit 28b0f3e

Browse files
committedNov 29, 2024
8343705: IGV: Interactive Node Moving in Hierarchical Layout
Reviewed-by: chagedorn, thartmann, rcastanedalo
1 parent 4da7c35 commit 28b0f3e

File tree

9 files changed

+1298
-15
lines changed

9 files changed

+1298
-15
lines changed
 

‎src/utils/IdealGraphVisualizer/HierarchicalLayout/src/main/java/com/sun/hotspot/igv/hierarchicallayout/HierarchicalLayoutManager.java

+57-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*
3434
* @author Thomas Wuerthinger
3535
*/
36-
public class HierarchicalLayoutManager extends LayoutManager {
36+
public class HierarchicalLayoutManager extends LayoutManager implements LayoutMover {
3737

3838
int maxLayerLength;
3939
private LayoutGraph graph;
@@ -77,6 +77,62 @@ public void doLayout(LayoutGraph layoutGraph) {
7777
graph = layoutGraph;
7878
}
7979

80+
@Override
81+
public void moveLink(Point linkPos, int shiftX) {
82+
int layerNr = graph.findLayer(linkPos.y);
83+
for (LayoutNode node : graph.getLayer(layerNr)) {
84+
if (node.isDummy() && linkPos.x == node.getX()) {
85+
LayoutLayer layer = graph.getLayer(layerNr);
86+
if (layer.contains(node)) {
87+
node.setX(linkPos.x + shiftX);
88+
layer.sortNodesByX();
89+
break;
90+
}
91+
}
92+
}
93+
writeBack();
94+
}
95+
96+
@Override
97+
public void moveVertices(Set<? extends Vertex> movedVertices) {
98+
for (Vertex vertex : movedVertices) {
99+
moveVertex(vertex);
100+
}
101+
writeBack();
102+
}
103+
104+
private void writeBack() {
105+
graph.optimizeBackEdgeCrossings();
106+
graph.updateLayerMinXSpacing();
107+
graph.straightenEdges();
108+
WriteResult.apply(graph);
109+
}
110+
111+
@Override
112+
public void moveVertex(Vertex movedVertex) {
113+
Point newLoc = movedVertex.getPosition();
114+
LayoutNode movedNode = graph.getLayoutNode(movedVertex);
115+
assert !movedNode.isDummy();
116+
117+
int layerNr = graph.findLayer(newLoc.y + movedNode.getOuterHeight() / 2);
118+
if (movedNode.getLayer() == layerNr) { // we move the node in the same layer
119+
LayoutLayer layer = graph.getLayer(layerNr);
120+
if (layer.contains(movedNode)) {
121+
movedNode.setX(newLoc.x);
122+
layer.sortNodesByX();
123+
}
124+
} else { // only remove edges if we moved the node to a new layer
125+
if (maxLayerLength > 0) return; // TODO: not implemented
126+
graph.removeNodeAndEdges(movedNode);
127+
layerNr = graph.insertNewLayerIfNeeded(movedNode, layerNr);
128+
graph.addNodeToLayer(movedNode, layerNr);
129+
movedNode.setX(newLoc.x);
130+
graph.getLayer(layerNr).sortNodesByX();
131+
graph.removeEmptyLayers();
132+
graph.addEdges(movedNode, maxLayerLength);
133+
}
134+
}
135+
80136
/**
81137
* Removes self-edges from nodes in the graph. If self-edges are to be included in the layout
82138
* (`layoutSelfEdges` is true), it stores them in the node for later processing and marks the graph

‎src/utils/IdealGraphVisualizer/HierarchicalLayout/src/main/java/com/sun/hotspot/igv/hierarchicallayout/LayoutEdge.java

+18
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,24 @@ public void setTo(LayoutNode to) {
169169
this.to = to;
170170
}
171171

172+
/**
173+
* Gets the absolute x-coordinate of the source node's connection point for this edge.
174+
*
175+
* @return The x-coordinate of the source node's connection point.
176+
*/
177+
public int getFromX() {
178+
return from.getX() + getRelativeFromX();
179+
}
180+
181+
/**
182+
* Gets the absolute x-coordinate of the target node's connection point for this edge.
183+
*
184+
* @return The x-coordinate of the target node's connection point.
185+
*/
186+
public int getToX() {
187+
return to.getX() + getRelativeToX();
188+
}
189+
172190
/**
173191
* Gets the relative horizontal position from the source node's left boundary to the edge's starting point.
174192
*

0 commit comments

Comments
 (0)
Please sign in to comment.