Skip to content

Commit 26363d8

Browse files
committed
Refactor and increase padding.
1 parent 3e11333 commit 26363d8

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/main/java/com/brunomnsilva/smartgraph/graphview/SmartCircularSortedPlacementStrategy.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,36 @@
3838
*/
3939
public class SmartCircularSortedPlacementStrategy implements SmartPlacementStrategy {
4040

41+
private static final int RADIUS_PADDING = 4;
42+
4143
@Override
4244
public <V, E> void place(double width, double height, SmartGraphPanel<V, E> smartGraphPanel) {
43-
Point2D center = new Point2D(width / 2, height / 2);
44-
45+
// Sort vertices by their label
4546
List<SmartGraphVertex<V>> vertices = new ArrayList<>(smartGraphPanel.getSmartVertices());
46-
int N = vertices.size();
47-
double angleIncrement = -360f / N;
48-
49-
//place first vertex at north position, others in clockwise manner
50-
boolean first = true;
51-
Point2D p = null;
5247

5348
vertices.sort((v1, v2) -> {
5449
V e1 = v1.getUnderlyingVertex().element();
5550
V e2 = v2.getUnderlyingVertex().element();
5651
return smartGraphPanel.getVertexLabelFor(e1).compareTo(smartGraphPanel.getVertexLabelFor(e2));
5752
});
5853

54+
//place first vertex at north position, others in clockwise manner
55+
Point2D center = new Point2D(width / 2, height / 2);
56+
int N = vertices.size();
57+
double angleIncrement = -360f / N;
58+
boolean first = true;
59+
Point2D p = null;
60+
5961
for (SmartGraphVertex<V> vertex : vertices) {
6062

6163
if (first) {
6264
//verify the smallest width and height.
6365
if(width > height)
6466
p = new Point2D(center.getX(),
65-
center.getY() - height / 2 + vertex.getRadius() * 2);
67+
center.getY() - height / 2 + vertex.getRadius() * RADIUS_PADDING);
6668
else
6769
p = new Point2D(center.getX(),
68-
center.getY() - width / 2 + vertex.getRadius() * 2);
70+
center.getY() - width / 2 + vertex.getRadius() * RADIUS_PADDING);
6971

7072
first = false;
7173
} else {

0 commit comments

Comments
 (0)