123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package lib;
- import java.awt.Color;
- import java.util.ArrayList;
- import bk.LayoutType;
- import graph.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 SimpleNodePlacement {
- /**
- * the actual algorithm
- * @param graph the graph where the node positions are to be set.
- */
- public static void placeNodes( LayeredGraphNode graph ) {
- float hue = 0; // color hue
- float saturation = 1f; // color saturation
- float brightness = 0.75f; // color brightness
- for( LayeredGraphNode n : graph.getContainedNodes() )
- {
- n.setColor( Color.getHSBColor( hue, saturation, brightness ), null );
- hue += 0.15f;
- 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 + 20;
- }
- curY += maxHeight + 20;
- }
- }
- }
|