Browse Source

another quick fix for subgraphs

Kolja Strohm 6 years ago
parent
commit
47816f0e3f
4 changed files with 62 additions and 18 deletions
  1. 1 1
      src/bk/BKNodePlacement.java
  2. 6 1
      src/bk/PlaceBlock.java
  3. 4 4
      src/graph/LayeredNode.java
  4. 51 12
      src/view/NodeView.java

+ 1 - 1
src/bk/BKNodePlacement.java

@@ -186,7 +186,7 @@ public class BKNodePlacement extends AnimatedAlgorithm {
                             "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.TOP_BOTTOM_LEFT ) + "", 6 ) + 
                             "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.TOP_BOTTOM_RIGHT ) + "", 6 ) + 
                             "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.BOTTOM_TOP_LEFT ) + "", 6 ) + 
-                            "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.BOTTOM_TOP_LEFT ) + "", 6 ) + 
+                            "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.BOTTOM_TOP_RIGHT ) + "", 6 ) + 
                             "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.COMBINED ) + "", 6 ) + "|\n";
                 }
                 return info;

+ 6 - 1
src/bk/PlaceBlock.java

@@ -15,7 +15,9 @@ import codelines.IfLoop;
 import codelines.SetVariable;
 import codelines.WhileLoop;
 import graph.LayeredGraphNode;
+import graph.LayeredNode;
 // PAPER = OUR
+import view.NodeView;
 
 // DOWN = RIGHT
 // UP = LEFT
@@ -174,7 +176,10 @@ public class PlaceBlock{
     {
         double max = 0;
         for( LayeredGraphNode n : graph.getContainedNodes() )
-            max = Math.max( max, n.getWidth( layout ) );
+        {
+            NodeView v = ((LayeredNode)n).getView( layout );
+            max = Math.max( max, v.getOriginalWidth() );
+        }
         return max + 20;
     }
 }

+ 4 - 4
src/graph/LayeredNode.java

@@ -633,8 +633,8 @@ public class LayeredNode implements LayeredGraphNode {
             double min = Double.POSITIVE_INFINITY;
             for( LayeredGraphNode n : nodes )
             {
-                if( max < n.getX(layout) + n.getWidth(layout) + 50 )
-                    max = n.getX(layout) + n.getWidth(layout) + 50;
+                if( max < n.getX(layout) + n.getWidth(layout) )
+                    max = n.getX(layout) + n.getWidth(layout);
                 min = Math.min( n.getX(layout), min);
             }
             if( layout == LayoutType.TOP_BOTTOM_LEFT )
@@ -668,8 +668,8 @@ public class LayeredNode implements LayeredGraphNode {
         	double max = 0;
         	for( LayeredGraphNode n : nodes )
         	{
-        		if( max < n.getY(layout) + n.getHeight(layout) + 50 )
-        			max = n.getY(layout) + n.getHeight(layout) + 50;
+        		if( max < n.getY(layout) + n.getHeight(layout) )
+        			max = n.getY(layout) + n.getHeight(layout);
         	}
             if( layout == LayoutType.TOP_BOTTOM_LEFT )
                 return Math.max( max, layouts[ 0 ].h );

+ 51 - 12
src/view/NodeView.java

@@ -55,14 +55,16 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
     
     public int getScaledX( int x )
     {
-        double scale = Math.min( (getWidth()-50) / (double)getVirtualWidth(), (getHeight()-50) / (double)getVirtualHeight());
+        double scale1 = Math.min( (getWidth()) / (double)getWidthOfNeededArea(), (getHeight()) / (double)getHeightOfNeededArea());
+        double scale = Math.min( (getWidth()-50*scale1) / (double)getWidthOfNeededArea(), (getHeight()-50*scale1) / (double)getHeightOfNeededArea());
         x *= scale;
         return x;
     }
     
     public int getScaledY( int y )
     {
-        double scale = Math.min( (getWidth()-50) / (double)getVirtualWidth(), (getHeight()-50) / (double)getVirtualHeight());
+        double scale1 = Math.min( (getWidth()) / (double)getWidthOfNeededArea(), (getHeight()) / (double)getHeightOfNeededArea());
+        double scale = Math.min( (getWidth()-50*scale1) / (double)getWidthOfNeededArea(), (getHeight()-50*scale1) / (double)getHeightOfNeededArea());
         y *= scale;
         return y;
     }
@@ -76,7 +78,12 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
                             "<br>Shift: " + model.getShift( layout ) + "</html>" );
         }
         else
-            setToolTipText( "Name: " + model.toString() );
+        {
+            setToolTipText( "<html>Name: " + model.toString() + 
+                            "<br>result X: " + model.getX( LayoutType.COMBINED ) + 
+                            "<br>other layouts: [" + model.getX( LayoutType.TOP_BOTTOM_LEFT ) + "," + model.getX( LayoutType.TOP_BOTTOM_RIGHT ) + ","
+                                + model.getX( LayoutType.BOTTOM_TOP_LEFT ) + "," + model.getX( LayoutType.BOTTOM_TOP_RIGHT ) + "]</html>" );
+        }
         for( Component c : getComponents() )
         {
             if( !(c instanceof NodeView) )
@@ -88,16 +95,18 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
     public int getXOffset()
     {
         int x = 0;
-        double scale = Math.min( (getWidth()-50) / (double)getVirtualWidth(), (getHeight()-50) / (double)getVirtualHeight());
-        x += (getWidth()-50) / 2 - (getVirtualWidth() * scale ) / 2 + 25;
+        double scale1 = Math.min( (getWidth()) / (double)getWidthOfNeededArea(), (getHeight()) / (double)getHeightOfNeededArea());
+        double scale = Math.min( (getWidth()-50*scale1) / (double)getWidthOfNeededArea(), (getHeight()-50*scale1) / (double)getHeightOfNeededArea());
+        x += (getWidth()-50) / 2 - (getWidthOfNeededArea() * scale ) / 2 + 25;
         return x;
     }
     
     public int getYOffset()
     {
         int y = 0;
-        double scale = Math.min( (getWidth()-50) / (double)getVirtualWidth(), (getHeight()-50) / (double)getVirtualHeight());
-        y += (getHeight()-50) / 2 - (getVirtualHeight() * scale ) / 2 + 25;
+        double scale1 = Math.min( (getWidth()) / (double)getWidthOfNeededArea(), (getHeight()) / (double)getHeightOfNeededArea());
+        double scale = Math.min( (getWidth()-50*scale1) / (double)getWidthOfNeededArea(), (getHeight()-50*scale1) / (double)getHeightOfNeededArea());
+        y += (getHeight()-50) / 2 - (getHeightOfNeededArea() * scale ) / 2 + 25;
         return y;
     }
     
@@ -109,6 +118,34 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
         return originalHeight;
     }
     
+    private int getWidthOfNeededArea() {
+        int max = 0;
+        double min = Double.POSITIVE_INFINITY;
+        for( Component c : getComponents() )
+        {
+            if( c instanceof NodeView )
+            {
+                max = Math.max( max, ((NodeView)c).getVirtualX() + ((NodeView)c).getOriginalWidth() );
+                min = Math.min( ((AnnimatedView)c).getVirtualX(), min);
+            }
+        }
+        return max - (int)min;
+    }
+    
+    private int getHeightOfNeededArea() {
+        int max = 0;
+        double min = Double.POSITIVE_INFINITY;
+        for( Component c : getComponents() )
+        {
+            if( c instanceof NodeView )
+            {
+                max = Math.max( max, ((NodeView)c).getVirtualY() + ((NodeView)c).getOriginalHeight() );
+                min = Math.min( ((AnnimatedView)c).getVirtualY(), min);
+            }
+        }
+        return max - (int)min;
+    }
+    
     @Override
     public void doLayout() {
         double minX = Double.POSITIVE_INFINITY;
@@ -120,9 +157,10 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
         }
         int x = 0;
         int y = 0;
-        double scale = Math.min( (getWidth()-50) / (double)getVirtualWidth(), (getHeight()-50) / (double)getVirtualHeight());
-        y += (getHeight()-50) / 2 - (getVirtualHeight() * scale ) / 2 + 25;
-        x += (getWidth()-50) / 2 - (getVirtualWidth() * scale ) / 2 + 25;
+        double scale1 = Math.min( (getWidth()) / (double)getWidthOfNeededArea(), (getHeight()) / (double)getHeightOfNeededArea());
+        double scale = Math.min( (getWidth()-50*scale1) / (double)getWidthOfNeededArea(), (getHeight()-50*scale1) / (double)getHeightOfNeededArea());
+        x += (getWidth()) / 2 - (getWidthOfNeededArea() * scale ) / 2;
+        y += (getHeight()) / 2 - (getHeightOfNeededArea() * scale ) / 2;
         for( Component c : getComponents() )
         {
             if( !(c instanceof AnnimatedView) )
@@ -152,8 +190,9 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
             minX = Math.min( ((AnnimatedView)c).getVirtualX(), minX);
         }
         int x = 0;
-        double scale = Math.min( (getWidth()-50) / (double)getVirtualWidth(), (getHeight()-50) / (double)getVirtualHeight());
-        x += (getWidth()-50) / 2 - (getVirtualWidth() * scale ) / 2 + 25;
+        double scale1 = Math.min( (getWidth()) / (double)getWidthOfNeededArea(), (getHeight()) / (double)getHeightOfNeededArea());
+        double scale = Math.min( (getWidth()-50*scale1) / (double)getWidthOfNeededArea(), (getHeight()-50*scale1) / (double)getHeightOfNeededArea());
+        x += (getWidth()-50) / 2 - (getWidthOfNeededArea() * scale ) / 2 + 25;
         for( Component c : getComponents() )
         {
             if( c instanceof NodeView )