Author: ruschein
Date: 2010-01-15 16:03:09 -0800 (Fri, 15 Jan 2010)
New Revision: 18945

Modified:
   
csplugins/trunk/ucsd/ruschein/BipartiteVisualiser/src/org/cytoscape/BipartiteVisualiserPlugin/duallayout/LayoutEngine.java
Log:
Work in progress.

Modified: 
csplugins/trunk/ucsd/ruschein/BipartiteVisualiser/src/org/cytoscape/BipartiteVisualiserPlugin/duallayout/LayoutEngine.java
===================================================================
--- 
csplugins/trunk/ucsd/ruschein/BipartiteVisualiser/src/org/cytoscape/BipartiteVisualiserPlugin/duallayout/LayoutEngine.java
  2010-01-15 23:56:15 UTC (rev 18944)
+++ 
csplugins/trunk/ucsd/ruschein/BipartiteVisualiser/src/org/cytoscape/BipartiteVisualiserPlugin/duallayout/LayoutEngine.java
  2010-01-16 00:03:09 UTC (rev 18945)
@@ -2,6 +2,7 @@
 
 import giny.model.Edge;
 import giny.view.EdgeView;
+import giny.view.NodeView;
 
 import java.util.HashSet;
 import java.util.List;
@@ -24,6 +25,10 @@
        private final CyNetwork network1;
        private final CyNetwork network2;
 
+       private static final int LEFT   = 0;
+       private static final int RIGHT  = 1;
+       private static final int CENTRE = 2;
+
        public LayoutEngine(final EdgeView edgeView, final CyNetwork 
parentNetwork,
                        final CyNetwork network1, final CyNetwork network2) {
 
@@ -82,15 +87,81 @@
                }
        }
 
-       private void performLayout(CyNetwork result) {
-               final CyNetworkView view = Cytoscape.createNetworkView(result);
-               CyLayouts.getDefaultLayout().doLayout(view);
+       private void performLayout(final CyNetwork result) {
+               final Set<CyNode> leftSet   = new HashSet<CyNode>();
+               final Set<CyNode> rightSet  = new HashSet<CyNode>();
+               categoriseNodes(result, leftSet, rightSet);
                
-               
-               // Add bipartite layout here.
-               
-               
-               
+               final CyNetworkView networkView = 
Cytoscape.createNetworkView(result);
+               CyLayouts.getDefaultLayout().doLayout(networkView);
+
+               final double[] xMin = new double[3];
+               final double[] xMax = new double[3];
+               final double[] yMin = new double[3];
+               final double[] yMax = new double[3];
+               findExtents(networkView, leftSet, rightSet, xMin, xMax, yMin, 
yMax);
        }
 
+       /**
+        * Sorts the nodes in "result" into 2 different sets: leftSet and 
rightSet.  If the
+        * original node was in both "network1" and "network2" it will be added 
to neither set if it
+        * was only in "network1", it will be added to leftSet, and if it was 
only in "network2" it
+        * will be put into rightSet.
+        */
+       private void categoriseNodes(final CyNetwork result, final Set<CyNode> 
leftSet,
+                                    final Set<CyNode> rightSet)
+       {
+               @SuppressWarnings("unchecked")
+               final Set<CyNode> orig1 = new 
HashSet<CyNode>((List<CyNode>)network1);
+               @SuppressWarnings("unchecked")
+               final Set<CyNode> orig2 = new 
HashSet<CyNode>((List<CyNode>)network2);
+
+               @SuppressWarnings("unchecked")
+               final List<CyNode> resultNodes = 
(List<CyNode>)result.nodesList();
+               for (final CyNode node : resultNodes) {
+                       final boolean inNetwork1 = orig1.contains(node);
+                       final boolean inNetwork2 = orig2.contains(node);
+
+                       if (inNetwork1 && inNetwork2)
+                               /* Do Nothing. */;
+                       else if (inNetwork1 && !inNetwork2)
+                               leftSet.add(node);
+                       else if (!inNetwork1 && inNetwork2)
+                               rightSet.add(node);
+                       else // This should never happen!
+                               throw new IllegalStateException("Do not know 
how to categorise a node!");
+               }
+       }
+
+       private void findExtents(final CyNetworkView networkView, final 
Set<CyNode> leftSet,
+                                final Set<CyNode> rightSet, final double 
xMin[],
+                                final double xMax[], final double yMin[], 
final double yMax[])
+       {
+               xMin[LEFT] = xMin[RIGHT] = xMin[CENTRE] = Double.MAX_VALUE;
+               xMax[LEFT] = xMax[RIGHT] = xMax[CENTRE] = Double.MIN_VALUE;
+
+               final java.util.Iterator nodeViewsIterator = 
networkView.getNodeViewsIterator();
+               while (nodeViewsIterator.hasNext()) {
+                       final NodeView nodeView = 
(NodeView)(nodeViewsIterator.next());
+                       final CyNode node = (CyNode)nodeView.getNode();
+                       if (leftSet.contains(node)) {
+                               xMin[LEFT] = Math.min(xMin[LEFT], 
nodeView.getXPosition());
+                               xMax[LEFT] = Math.max(xMax[LEFT], 
nodeView.getXPosition());
+                               yMin[LEFT] = Math.min(yMin[LEFT], 
nodeView.getYPosition());
+                               yMax[LEFT] = Math.max(yMax[LEFT], 
nodeView.getYPosition());
+                       }
+                       else if (rightSet.contains(node)) {
+                               xMin[RIGHT] = Math.min(xMin[RIGHT], 
nodeView.getXPosition());
+                               xMax[RIGHT] = Math.max(xMax[RIGHT], 
nodeView.getXPosition());
+                               yMin[RIGHT] = Math.min(yMin[RIGHT], 
nodeView.getYPosition());
+                               yMax[RIGHT] = Math.max(yMax[RIGHT], 
nodeView.getYPosition());
+                       }
+                       else { // Assume the node is in the centre set.
+                               xMin[CENTRE] = Math.min(xMin[CENTRE], 
nodeView.getXPosition());
+                               xMax[CENTRE] = Math.max(xMax[CENTRE], 
nodeView.getXPosition());
+                               yMin[CENTRE] = Math.min(yMin[CENTRE], 
nodeView.getYPosition());
+                               yMax[CENTRE] = Math.max(yMax[CENTRE], 
nodeView.getYPosition());
+                       }
+               }
+       }
 }

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.


Reply via email to