Skip to content

Commit

Permalink
Fix bogus calculation of graph node location
Browse files Browse the repository at this point in the history
The location of the graph node should match whatever has been calculated
in the layout algorithm and should not include the node size.
  • Loading branch information
ptziegler committed Sep 19, 2024
1 parent 7102481 commit 1cc317b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void applyLayout() {
} else {
node.setSize(-1, -1);
if (location != null) {
node.setLocation(location.x - getSize().width / 2, location.y - size.height / 2);
node.setLocation(location.x, location.y);
}
if (size != null) {
Dimension currentSize = node.getSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ public void testCustomLayout() {
assertEquals(node1.getLocation().y, node3.getLocation().y);

waitEventLoop(5);

for (GraphNode node : graph.getNodes()) {
Point p = node.getLocation();
Rectangle bounds = graph.getBounds();
assertTrue("Node outside of bounds", p.x >= 0 && p.x <= bounds.width);
assertTrue("Node outside of bounds", p.y >= 0 && p.y <= bounds.height);
}

assertNoOverlap(graph);
}

Expand Down

0 comments on commit 1cc317b

Please sign in to comment.