1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package Algorithms;
- import java.util.ArrayList;
- import Algorithms.Animated.BK.ExtremalLayoutCalc.LayoutType;
- 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, null );
- n.setHeight( 40, null );
- n.setColor( cGen.generateColor(), null );
- 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( LayoutType.TOP_BOTTOM_LEFT ), maxWidth);
- maxHeight = Math.max(node.getHeight( LayoutType.TOP_BOTTOM_LEFT ), 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( LayoutType.TOP_BOTTOM_LEFT ), maxHeight);
- }
- int curX = 0;
- for (LayeredGraphNode node : layer) { // Gehe alle Knoten durch
- node.setX( curX + maxWidth / 2 - node.getWidth( LayoutType.TOP_BOTTOM_LEFT ) / 2, false, null );
- node.setY( curY + maxHeight / 2 - node.getHeight( LayoutType.TOP_BOTTOM_LEFT ) / 2, null ); // Position setzen
- curX += maxWidth + 25;
- }
- curY += maxHeight + 25;
- }
- }
- }
|