123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package lib;
- import java.awt.Color;
- import java.util.ArrayList;
- import bk.LayoutType;
- import graph.LayeredGraphNode;
- public class SimpleNodePlacement {
-
- public static void placeNodes( LayeredGraphNode graph ) {
- float hue = 0;
- float saturation = 1f;
- float brightness = 0.75f;
- 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()) {
- 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) {
- maxHeight = 0;
- for (LayeredGraphNode node : layer) {
- maxHeight = Math.max(node.getHeight( LayoutType.TOP_BOTTOM_LEFT ), maxHeight);
- }
- int curX = 0;
- for (LayeredGraphNode node : layer) {
- 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 );
- curX += maxWidth + 20;
- }
- curY += maxHeight + 20;
- }
- }
- }
|