12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package Algorithms;
- import java.util.ArrayList;
- import Model.LayeredGraphNode;
- /**
- * Ein simpler Algorithmus zum Setzen der Knotenkoordinaten
- * Die Knoten werden in einem Raster ausgerichtet, so dass alle Knoten den gleichen Abstand zwischen sich haben (wenn sie gleich groß sind)
- * @author kolja
- *
- */
- public class InitializeNodePositions {
- /**
- * the actual algorithm
- * @param graph the graph where the node positions are to be set.
- */
- public static void placeNodes( LayeredGraphNode graph ) {
-
- RandomColorGenerator cGen = new RandomColorGenerator();
- for( LayeredGraphNode n : graph.getContainedNodes() )
- {
- n.setWidth( 40 );
- n.setHeight( 40 );
- n.setColor( cGen.generateColor() );
- placeNodes( n );
- }
- int curY = 0;
- double maxWidth = 0, maxHeight = 0;
-
- for (LayeredGraphNode node : graph.getContainedNodes()) { // Suche die maximale Knotengröße
- maxWidth = Math.max(node.getWidth(), maxWidth);
- maxHeight = Math.max(node.getHeight(), maxHeight);
- }
-
- ArrayList< ArrayList< LayeredGraphNode > > layers = graph.getContainedLayers();
- for (ArrayList<LayeredGraphNode> layer : layers) { // Gehe alle Layer durch
- maxHeight = 0;
- for (LayeredGraphNode node : layer) { // Gehe alle Knoten durch
- maxHeight = Math.max(node.getHeight(), maxHeight);
- }
- int curX = 0;
- for (LayeredGraphNode node : layer) { // Gehe alle Knoten durch
- node.setX(curX + maxWidth / 2 - node.getWidth() / 2, false);
- node.setY(curY + maxHeight / 2 - node.getHeight() / 2); // Position setzen
- curX += maxWidth + 25;
- }
- curY += maxHeight + 25;
- }
- }
- }
|