|
38 | 38 | */ |
39 | 39 | public class SmartCircularSortedPlacementStrategy implements SmartPlacementStrategy { |
40 | 40 |
|
| 41 | + private static final int RADIUS_PADDING = 4; |
| 42 | + |
41 | 43 | @Override |
42 | 44 | 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 |
45 | 46 | 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; |
52 | 47 |
|
53 | 48 | vertices.sort((v1, v2) -> { |
54 | 49 | V e1 = v1.getUnderlyingVertex().element(); |
55 | 50 | V e2 = v2.getUnderlyingVertex().element(); |
56 | 51 | return smartGraphPanel.getVertexLabelFor(e1).compareTo(smartGraphPanel.getVertexLabelFor(e2)); |
57 | 52 | }); |
58 | 53 |
|
| 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 | + |
59 | 61 | for (SmartGraphVertex<V> vertex : vertices) { |
60 | 62 |
|
61 | 63 | if (first) { |
62 | 64 | //verify the smallest width and height. |
63 | 65 | if(width > height) |
64 | 66 | p = new Point2D(center.getX(), |
65 | | - center.getY() - height / 2 + vertex.getRadius() * 2); |
| 67 | + center.getY() - height / 2 + vertex.getRadius() * RADIUS_PADDING); |
66 | 68 | else |
67 | 69 | p = new Point2D(center.getX(), |
68 | | - center.getY() - width / 2 + vertex.getRadius() * 2); |
| 70 | + center.getY() - width / 2 + vertex.getRadius() * RADIUS_PADDING); |
69 | 71 |
|
70 | 72 | first = false; |
71 | 73 | } else { |
|
0 commit comments