Author: ruschein
Date: 2010-01-19 11:03:28 -0800 (Tue, 19 Jan 2010)
New Revision: 18957

Modified:
   
csplugins/trunk/ucsd/ruschein/BipartiteVisualiser/src/org/cytoscape/BipartiteVisualiserPlugin/duallayout/LayoutEngine.java
Log:
Completed first approximation of layout.

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-19 18:49:40 UTC (rev 18956)
+++ 
csplugins/trunk/ucsd/ruschein/BipartiteVisualiser/src/org/cytoscape/BipartiteVisualiserPlugin/duallayout/LayoutEngine.java
  2010-01-19 19:03:28 UTC (rev 18957)
@@ -5,6 +5,7 @@
 import giny.view.NodeView;
 
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -16,8 +17,9 @@
 import cytoscape.layout.CyLayouts;
 import cytoscape.task.TaskMonitor;
 import cytoscape.view.CyNetworkView;
-import cytoscape.visual.VisualStyle;
+import cytoscape.view.CyNodeView;
 
+
 public class LayoutEngine {
 
        static String MM_EDGE_ATTR_PREFIX = "MM-";
@@ -34,16 +36,18 @@
        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) {
-
+                           final CyNetwork network1, final CyNetwork network2)
+       {
                this.edgeView = edgeView;
                this.parentNetwork = parentNetwork;
                this.network1 = network1;
                this.network2 = network2;
        }
 
-       public void doLayout(TaskMonitor taskMonitor) {
+
+       public void doLayout(final TaskMonitor taskMonitor) {
                if (taskMonitor != null)
                        taskMonitor.setPercentCompleted(0);
 
@@ -73,8 +77,8 @@
                final Set<CyEdge> edgesInResult = new HashSet<CyEdge>(
                                (List<CyEdge>) result.edgesList());
                final CyAttributes edgeAttr = Cytoscape.getEdgeAttributes();
-
-               for (CyNode node : nodesInResult) {
+               
+               for (final CyNode node: nodesInResult) {
                        // Get the list of edges connected to this node
                        int[] edgeIndices = 
parentNetwork.getAdjacentEdgeIndicesArray(node
                                        .getRootGraphIndex(), true, true, true);
@@ -109,11 +113,43 @@
                final double[] yMin = new double[3];
                final double[] yMax = new double[3];
                findExtents(networkView, leftSet, rightSet, xMin, xMax, yMin, 
yMax);
-               
-               final VisualStyle style = 
VisualStyleBuilder.getVisualStyle(visualStyleName, network1.getTitle(), 
network2.getTitle());
-               networkView.setVisualStyle(style.getName());
-               Cytoscape.getVisualMappingManager().setVisualStyle(style);
-               networkView.redrawGraph(false, true);
+
+               // Calculate left/right shifts...
+               double maxWidth = Math.max(xMax[LEFT] - xMin[LEFT], xMax[RIGHT] 
- xMin[RIGHT]);
+               final boolean centreIsEmpty = xMin[CENTRE] == 
Double.POSITIVE_INFINITY;
+               if (!centreIsEmpty)
+                       maxWidth = Math.max(maxWidth, xMax[CENTRE] - 
xMin[CENTRE]);
+               final double baseShift = (maxWidth == 0) ? 100 : maxWidth / 3.0;
+               double leftShift, rightShift;
+               if (centreIsEmpty) {
+                       double delta = xMin[RIGHT] - xMax[LEFT];
+                       double totalShift = -delta + baseShift;
+                       leftShift  = - (totalShift / 2.0);
+                       rightShift = + (totalShift / 2.0);
+               } else { // We have at least one "shared" node in the centre.
+                       double delta = xMin[CENTRE] - xMax[LEFT];
+                       double totalShift = -delta + baseShift;
+                       leftShift = -totalShift;
+
+                       delta = xMin[RIGHT] - xMax[CENTRE];
+                       totalShift = -delta + baseShift;
+                       rightShift = +totalShift;
+               }
+
+               // ...and now apply them.
+               for (final CyNode node : leftSet) {
+                       final CyNodeView view = 
(CyNodeView)networkView.getNodeView(node);
+                       view.setXPosition(view.getXPosition() + leftShift);
+               }
+               for (final CyNode node : rightSet) {
+                       final CyNodeView view = 
(CyNodeView)networkView.getNodeView(node);
+                       view.setXPosition(view.getXPosition() + rightShift);
+               }
+
+               // Make sure all the nodes have their position updated.
+               Iterator nodeViewsIterator = networkView.getNodeViewsIterator();
+               while (nodeViewsIterator.hasNext())
+                       
((NodeView)nodeViewsIterator.next()).setNodePosition(true);
        }
 
        /**

-- 
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