Author: ghuck
Date: 2010-06-15 08:02:33 -0700 (Tue, 15 Jun 2010)
New Revision: 20541
Modified:
coreplugins/branches/labelLayout/AutomaticLayout/build.xml
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutEdge.java
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutLabelNodeImpl.java
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutNode.java
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutNodeImpl.java
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutPartition.java
Log:
almost finished this implementation for using LayoutLabelPartition.
Modified: coreplugins/branches/labelLayout/AutomaticLayout/build.xml
===================================================================
--- coreplugins/branches/labelLayout/AutomaticLayout/build.xml 2010-06-15
01:49:56 UTC (rev 20540)
+++ coreplugins/branches/labelLayout/AutomaticLayout/build.xml 2010-06-15
15:02:33 UTC (rev 20541)
@@ -24,7 +24,7 @@
<property name="cytoscape.dir" value="/Users/gerardohuck/Cytoscape"/>
<property name="cytoscape.lib.dir" value="${cytoscape.dir}/lib"/>
<property name="cytoscape.plugin.dir" value="${cytoscape.dir}/plugins/"/>
- <property name="csplugins.dir" value="../"/>
+ <property name="csplugins.dir" value="./src/csplugins"/>
<!-- Define the directories -->
<property name="layout.root.dir" value="./"/>
Modified:
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutEdge.java
===================================================================
---
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutEdge.java
2010-06-15 01:49:56 UTC (rev 20540)
+++
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutEdge.java
2010-06-15 15:02:33 UTC (rev 20541)
@@ -186,11 +186,11 @@
String source = "undefined";
String target = "undefined";
- if (v1 != null)
- source = v1.getIdentifier();
+ if (v1 != null && (v1.getClass().getName() == "LayoutNodeImpl")
)
+ source = ((LayoutNodeImpl) v1).getIdentifier();
- if (v2 != null)
- target = v2.getIdentifier();
+ if (v2 != null && (v2.getClass().getName() == "LayoutNodeImpl")
)
+ target = ((LayoutNodeImpl) v2).getIdentifier();
return "Edge " + edge.getIdentifier() + " connecting " + source
+ " and " + target
+ " with weight " + weight;
Modified:
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutLabelNodeImpl.java
===================================================================
---
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutLabelNodeImpl.java
2010-06-15 01:49:56 UTC (rev 20540)
+++
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutLabelNodeImpl.java
2010-06-15 15:02:33 UTC (rev 20541)
@@ -1,11 +1,12 @@
package csplugins.layout;
import cytoscape.*;
-import cytoscape.visual.LabelPosition;
+//import cytoscape.visual.LabelPosition;
import cytoscape.data.CyAttributes;
-
import cytoscape.view.*;
+import giny.view.*;
+
import java.util.*;
@@ -42,26 +43,66 @@
public void moveToLocation() {
- CyAttributes nodeAtts = Cytoscape.getNodeAttributes();
- String labelPosition = (String)
nodeAtts.getAttribute(parent.getNode().getIdentifier(),
-
"node.labelPosition");
- LabelPosition lp = LabelPosition.parse(labelPosition);
+ // CyAttributes nodeAtts = Cytoscape.getNodeAttributes();
+// String labelPosition = (String)
nodeAtts.getAttribute(parent.getNode().getIdentifier(),
+//
"node.labelPosition");
+// LabelPosition lp = LabelPosition.parse(labelPosition);
+ ObjectPosition labelPosition = parent.getNodeView().getLabelPosition();
- if (this.isLocked()) { // If node is locked, adjust X and Y to its
current location
+// if (this.isLocked()) { // If node is locked, adjust X and Y to its
current location
- this.setX(lp.getOffsetX() + parent.getNodeView().getXPosition());
- this.setY(lp.getOffsetY() + parent.getNodeView().getYPosition());
+// this.setX(lp.getOffsetX() + parent.getNodeView().getXPosition());
+// this.setY(lp.getOffsetY() + parent.getNodeView().getYPosition());
- } else { // If node is unlocked set labels offsets properly
+// } else { // If node is unlocked set labels offsets properly
- parent.moveToLocation(); // make sure parent is where it should be
+// parent.moveToLocation(); // make sure parent is where it should be
- lp.setOffsetX(this.getX() - parent.getX());
- lp.setOffsetY(this.getY() - parent.getY());
- }
+// lp.setOffsetX(this.getX() - parent.getX());
+// lp.setOffsetY(this.getY() - parent.getY());
+// }
}
+
+ /**
+ * Accessor function to return the CyNode associated with
+ * this LayoutNode.
+ *
+ * @return CyNode that is associated with this LayoutNode
+ */
+ public CyNode getNode() {
+ return parent.node;
+ }
+
+ /**
+ * Accessor function to return the NodeView associated with
+ * this LayoutNode.
+ *
+ * @return NodeView that is associated with this LayoutNode
+ */
+ public NodeView getNodeView() {
+ return parent.nodeView;
+ }
+
+ /**
+ * Return the width of this node
+ *
+ * @return width of this node
+ */
+ public double getWidth() {
+ return parent.nodeView.getWidth();
+ }
+
+ /**
+ * Return the height of this node
+ *
+ * @return height of this node
+ */
+ public double getHeight() {
+ return parent.nodeView.getHeight();
+ }
+
protected double getParentX() {
return parent.getX();
}
@@ -70,5 +111,23 @@
return parent.getY();
}
+ /**
+ * Return a string representation of the node
+ *
+ * @return String containing the node's identifier and location
+ */
+ public String toString() {
+ return "Label of Node: " + getIdentifier() + " at " + printLocation();
+ }
+ /**
+ * Return the node's identifier.
+ *
+ * @return String containing the node's identifier
+ */
+ public String getIdentifier() {
+ return "Label of node:" + parent.getIdentifier();
+ }
+
+
}
\ No newline at end of file
Modified:
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutNode.java
===================================================================
---
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutNode.java
2010-06-15 01:49:56 UTC (rev 20540)
+++
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutNode.java
2010-06-15 15:02:33 UTC (rev 20541)
@@ -4,6 +4,8 @@
import cytoscape.view.*;
+import giny.view.*;
+
import java.util.*;
/**
@@ -26,14 +28,68 @@
protected double y;
protected double dispX;
protected double dispY;
+ protected ArrayList<LayoutNode> neighbors = null;
+ protected int index = -1;
+ // instance methods
+
+
+ // !!!! This methods MUST be overriden by subclasses !!!!
+
+
/**
- * This method MUST be overriden by subclasses
+ *
*/
public abstract void moveToLocation();
- // instance methods
/**
+ * Accessor function to return the CyNode associated with
+ * this LayoutNode.
+ *
+ * @return CyNode that is associated with this LayoutNode
+ */
+ public abstract CyNode getNode();
+
+ /**
+ * Accessor function to return the NodeView associated with
+ * this LayoutNode.
+ *
+ * @return NodeView that is associated with this LayoutNode
+ */
+ public abstract NodeView getNodeView();
+
+ /**
+ * Return the width of this node
+ *
+ * @return width of this node
+ */
+ public abstract double getWidth();
+
+ /**
+ * Return the height of this node
+ *
+ * @return height of this node
+ */
+ public abstract double getHeight();
+
+ /**
+ * Return the node's identifier.
+ *
+ * @return String containing the node's identifier
+ */
+ public abstract String getIdentifier();
+
+ /**
+ * Return a string representation of the node
+ *
+ * @return String containing the node's identifier and location
+ */
+ public abstract String toString();
+
+ // End of abstract methods
+
+
+ /**
* Set the location of this LayoutNode. Note that this only
* sets the location -- it does not actually move the node to
* that location. Users should call moveToLocation to actually
@@ -200,7 +256,7 @@
* @param otherNode the node to measure the distance to
* @return the euclidean distance from this node to otherNode
*/
- public double distance(LayoutAbstractNode otherNode) {
+ public double distance(LayoutNode otherNode) {
double deltaX = this.x - otherNode.getX();
double deltaY = this.y - otherNode.getY();
@@ -221,4 +277,68 @@
return Math.max(EPSILON, Math.sqrt((deltaX * deltaX) + (deltaY *
deltaY)));
}
+ /**
+ * Convenience function to keep track of neighbors of this node. This can
be
+ * used to improve the performance of algorithms that try to determine the
edge
+ * partners of nodes.
+ *
+ * @param v LayoutNode that is a neighbor of this LayoutNode
+ */
+ public void addNeighbor(LayoutNode v) {
+ this.neighbors.add(v);
+ }
+
+ /**
+ * Convenience function to return the list of neighbors (connected nodes)
of this node.
+ *
+ * @return List of all of the neighbors (nodes with shared edges)
of this node.
+ */
+ public List<LayoutNode> getNeighbors() {
+ return this.neighbors;
+ }
+
+ /**
+ * Return the node's degree (i.e. number of nodes it's connected to).
+ *
+ * @return Degree of this node
+ */
+ public double getDegree() {
+ return (double)neighbors.size();
+ }
+
+ /**
+ * Return a string representation of the node's displacement
+ *
+ * @return String containing the node's X,Y displacement
+ */
+ public String printDisp() {
+ String ret = new String("" + dispX + ", " + dispY);
+
+ return ret;
+ }
+
+ /**
+ * Return a string representation of the node's location
+ *
+ * @return String containing the node's X,Y location
+ */
+ public String printLocation() {
+ String ret = new String("" + x + ", " + y);
+
+ return ret;
+ }
+
+ /**
+ * Returns the index of this LayoutNode. This is <em>not</em> the same as
the
+ * rootGraphIndex of the node. Its primarily used by LayoutPartition to
keep
+ * track of the offset in the node array that holds this LayoutNode.
+ *
+ * @return The index of this node
+ * @see LayoutPartition
+ */
+ public int getIndex() {
+ return this.index;
+ }
+
+
}
\ No newline at end of file
Modified:
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutNodeImpl.java
===================================================================
---
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutNodeImpl.java
2010-06-15 01:49:56 UTC (rev 20540)
+++
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutNodeImpl.java
2010-06-15 15:02:33 UTC (rev 20541)
@@ -62,10 +62,8 @@
// private double dispY;
// private boolean isLocked = false;
- private CyNode node;
- private NodeView nodeView;
- private int index;
- private ArrayList<LayoutNode> neighbors = null;
+ protected CyNode node;
+ protected NodeView nodeView;
/**
* Empty constructor
@@ -109,38 +107,6 @@
}
/**
- * Convenience function to keep track of neighbors of this node. This can
be
- * used to improve the performance of algorithms that try to determine the
edge
- * partners of nodes.
- *
- * @param v LayoutNode that is a neighbor of this LayoutNode
- */
- public void addNeighbor(LayoutNode v) {
- this.neighbors.add(v);
- }
-
- /**
- * Convenience function to return the list of neighbors (connected nodes)
of this node.
- *
- * @return List of all of the neighbors (nodes with shared edges)
of this node.
- */
- public List<LayoutNode> getNeighbors() {
- return this.neighbors;
- }
-
- /**
- * Returns the index of this LayoutNode. This is <em>not</em> the same as
the
- * rootGraphIndex of the node. Its primarily used by LayoutPartition to
keep
- * track of the offset in the node array that holds this LayoutNode.
- *
- * @return The index of this node
- * @see LayoutPartition
- */
- public int getIndex() {
- return this.index;
- }
-
- /**
* Return the width of this node
*
* @return width of this node
@@ -172,24 +138,6 @@
}
/**
- * Return the node's identifier.
- *
- * @return String containing the node's identifier
- */
- public String getIdentifier() {
- return node.getIdentifier();
- }
-
- /**
- * Return the node's degree (i.e. number of nodes it's connected to).
- *
- * @return Degree of this node
- */
- public double getDegree() {
- return (double)neighbors.size();
- }
-
- /**
* Return a string representation of the node
*
* @return String containing the node's identifier and location
@@ -199,25 +147,14 @@
}
/**
- * Return a string representation of the node's displacement
+ * Return the node's identifier.
*
- * @return String containing the node's X,Y displacement
+ * @return String containing the node's identifier
*/
- public String printDisp() {
- String ret = new String("" + dispX + ", " + dispY);
-
- return ret;
+ public String getIdentifier() {
+ return node.getIdentifier();
}
- /**
- * Return a string representation of the node's location
- *
- * @return String containing the node's X,Y location
- */
- public String printLocation() {
- String ret = new String("" + x + ", " + y);
- return ret;
- }
}
Modified:
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutPartition.java
===================================================================
---
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutPartition.java
2010-06-15 01:49:56 UTC (rev 20540)
+++
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutPartition.java
2010-06-15 15:02:33 UTC (rev 20541)
@@ -73,692 +73,692 @@
* @version 0.9
*/
public class LayoutPartition {
- protected ArrayList<LayoutNode> nodeList;
- protected ArrayList<LayoutEdge> edgeList;
- protected static HashMap<CyNode, LayoutNode> nodeToLayoutNode = null;
- protected static IntIntHash nodesSeenMap = null;
- protected static IntIntHash edgesSeenMap = null;
- protected int nodeIndex = 0;
- protected int partitionNumber = 0;
- protected EdgeWeighter edgeWeighter = null;
+ protected ArrayList<LayoutNode> nodeList;
+ protected ArrayList<LayoutEdge> edgeList;
+ protected static HashMap<CyNode, LayoutNode> nodeToLayoutNode = null;
+ protected static IntIntHash nodesSeenMap = null;
+ protected static IntIntHash edgesSeenMap = null;
+ protected int nodeIndex = 0;
+ protected int partitionNumber = 0;
+ protected EdgeWeighter edgeWeighter = null;
- // Keep track of the node min and max values
- protected double maxX = -100000;
- protected double maxY = -100000;
- protected double minX = 100000;
- protected double minY = 100000;
- protected double width = 0;
- protected double height = 0;
+ // Keep track of the node min and max values
+ protected double maxX = -100000;
+ protected double maxY = -100000;
+ protected double minX = 100000;
+ protected double minY = 100000;
+ protected double width = 0;
+ protected double height = 0;
- // Keep track of average location
- protected double averageX = 0;
- protected double averageY = 0;
+ // Keep track of average location
+ protected double averageX = 0;
+ protected double averageY = 0;
- // Keep track of the number of locked nodes we have in
- // this partition
- protected int lockedNodes = 0;
+ // Keep track of the number of locked nodes we have in
+ // this partition
+ protected int lockedNodes = 0;
- protected CyLogger logger = null;
+ protected CyLogger logger = null;
- // protected constants
- protected static final int m_NODE_HAS_NOT_BEEN_SEEN = 0;
- protected static final int m_NODE_HAS_BEEN_SEEN = 1;
+ // protected constants
+ protected static final int m_NODE_HAS_NOT_BEEN_SEEN = 0;
+ protected static final int m_NODE_HAS_BEEN_SEEN = 1;
- /**
- * LayoutPartition: use this constructor to create an empty
LayoutPartition.
- *
- * @param nodeCount The number of nodes in the new partition.
- * @param edgeCount The number of edges in the new partition.
- */
- public LayoutPartition(int nodeCount, int edgeCount) {
- logger = CyLogger.getLogger(LayoutPartition.class);
- nodeList = new ArrayList<LayoutNode>(nodeCount);
- edgeList = new ArrayList<LayoutEdge>(edgeCount);
- partitionNumber = 1;
+ /**
+ * LayoutPartition: use this constructor to create an empty
LayoutPartition.
+ *
+ * @param nodeCount The number of nodes in the new partition.
+ * @param edgeCount The number of edges in the new partition.
+ */
+ public LayoutPartition(int nodeCount, int edgeCount) {
+ logger = CyLogger.getLogger(LayoutPartition.class);
+ nodeList = new ArrayList<LayoutNode>(nodeCount);
+ edgeList = new ArrayList<LayoutEdge>(edgeCount);
+ partitionNumber = 1;
- if (nodeToLayoutNode == null)
- nodeToLayoutNode = new
HashMap<CyNode,LayoutNode>(nodeCount);
- }
+ if (nodeToLayoutNode == null)
+ nodeToLayoutNode = new HashMap<CyNode,LayoutNode>(nodeCount);
+ }
- /**
- * LayoutPartition: use this constructor to create a LayoutPartition
that
- * includes the entire network.
- *
- * @param network the CyNetwork to include
- * @param networkView the CyNetworkView to use
- * @param nodeSet the nodes to be considered
- * @param edgeWeighter the weighter to use for edge weighting
- */
- public LayoutPartition(CyNetwork network, CyNetworkView networkView,
Collection<CyNode>nodeSet,
- EdgeWeighter edgeWeighter) {
- initialize(network,networkView,nodeSet,edgeWeighter);
- }
+ /**
+ * LayoutPartition: use this constructor to create a LayoutPartition that
+ * includes the entire network.
+ *
+ * @param network the CyNetwork to include
+ * @param networkView the CyNetworkView to use
+ * @param nodeSet the nodes to be considered
+ * @param edgeWeighter the weighter to use for edge weighting
+ */
+ public LayoutPartition(CyNetwork network, CyNetworkView networkView,
Collection<CyNode>nodeSet,
+ EdgeWeighter edgeWeighter) {
+ initialize(network,networkView,nodeSet,edgeWeighter);
+ }
- /**
- * LayoutPartition: use this constructor to create a LayoutPartition
that
- * includes the entire network.
- *
- * @param network the CyNetwork to include
- * @param networkView the CyNetworkView to use
- * @param selectedOnly if true, only include selected nodes in the
partition
- * @param edgeWeighter the weighter to use for edge weighting
- */
- public LayoutPartition(CyNetwork network, CyNetworkView networkView,
boolean selectedOnly,
- EdgeWeighter edgeWeighter) {
- if (selectedOnly) {
-
initialize(network,networkView,(Collection<CyNode>)network.getSelectedNodes(),edgeWeighter);
- } else {
-
initialize(network,networkView,network.nodesList(),edgeWeighter);
- }
+ /**
+ * LayoutPartition: use this constructor to create a LayoutPartition that
+ * includes the entire network.
+ *
+ * @param network the CyNetwork to include
+ * @param networkView the CyNetworkView to use
+ * @param selectedOnly if true, only include selected nodes in the
partition
+ * @param edgeWeighter the weighter to use for edge weighting
+ */
+ public LayoutPartition(CyNetwork network, CyNetworkView networkView,
boolean selectedOnly,
+ EdgeWeighter edgeWeighter) {
+ if (selectedOnly) {
+
initialize(network,networkView,(Collection<CyNode>)network.getSelectedNodes(),edgeWeighter);
+ } else {
+ initialize(network,networkView,network.nodesList(),edgeWeighter);
}
+ }
- protected void initialize(CyNetwork network, CyNetworkView networkView,
Collection<CyNode>nodeSet,
- EdgeWeighter edgeWeighter) {
+ protected void initialize(CyNetwork network, CyNetworkView networkView,
Collection<CyNode>nodeSet,
+ EdgeWeighter edgeWeighter) {
- logger = CyLogger.getLogger(LayoutPartition.class);
+ logger = CyLogger.getLogger(LayoutPartition.class);
- this.edgeWeighter = edgeWeighter;
+ this.edgeWeighter = edgeWeighter;
- // Initialize
- nodeList = new ArrayList<LayoutNode>(network.getNodeCount());
- edgeList = new ArrayList<LayoutEdge>(network.getEdgeCount());
+ // Initialize
+ nodeList = new ArrayList<LayoutNode>(network.getNodeCount());
+ edgeList = new ArrayList<LayoutEdge>(network.getEdgeCount());
- if (nodeToLayoutNode == null)
- nodeToLayoutNode = new
HashMap<CyNode,LayoutNode>(network.getNodeCount());
+ if (nodeToLayoutNode == null)
+ nodeToLayoutNode = new
HashMap<CyNode,LayoutNode>(network.getNodeCount());
- // Now, walk the iterators and fill in the values
- nodeListInitialize(network, networkView, nodeSet);
- edgeListInitialize(network, networkView);
- trimToSize();
- partitionNumber = 1;
- }
+ // Now, walk the iterators and fill in the values
+ nodeListInitialize(network, networkView, nodeSet);
+ edgeListInitialize(network, networkView);
+ trimToSize();
+ partitionNumber = 1;
+ }
- /**
- * Set the EdgeWeighter to use for this partition. The EdgeWeighter
should be
- * shared by all partitions in the same graph to avoid contrary scaling
problems.
- *
- * @param edgeWeighter the weighter to use for edge weighting
- */
- public void setEdgeWeighter(EdgeWeighter edgeWeighter) {
- this.edgeWeighter = edgeWeighter;
- }
+ /**
+ * Set the EdgeWeighter to use for this partition. The EdgeWeighter
should be
+ * shared by all partitions in the same graph to avoid contrary scaling
problems.
+ *
+ * @param edgeWeighter the weighter to use for edge weighting
+ */
+ public void setEdgeWeighter(EdgeWeighter edgeWeighter) {
+ this.edgeWeighter = edgeWeighter;
+ }
- /**
- * Add a node to this partition.
- *
- * @param nv the NodeView of the node to add
- * @param locked a boolean value to determine if this node is locked or
not
- */
- protected void addNode(NodeView nv, boolean locked) {
- CyNode node = (CyNode) nv.getNode();
- LayoutNode v = new LayoutNodeImpl(nv, nodeIndex++);
- nodeList.add(v);
- nodeToLayoutNode.put(node, v);
+ /**
+ * Add a node to this partition.
+ *
+ * @param nv the NodeView of the node to add
+ * @param locked a boolean value to determine if this node is locked or not
+ */
+ protected void addNode(NodeView nv, boolean locked) {
+ CyNode node = (CyNode) nv.getNode();
+ LayoutNode v = new LayoutNodeImpl(nv, nodeIndex++);
+ nodeList.add(v);
+ nodeToLayoutNode.put(node, v);
- if (locked) {
- v.lock();
- lockedNodes++;
- } else {
- updateMinMax(nv.getXPosition(), nv.getYPosition());
- // this.width += Math.sqrt(nv.getWidth());
- // this.height += Math.sqrt(nv.getHeight());
- this.width += nv.getWidth();
- this.height += nv.getHeight();
- }
+ if (locked) {
+ v.lock();
+ lockedNodes++;
+ } else {
+ updateMinMax(nv.getXPosition(), nv.getYPosition());
+ // this.width += Math.sqrt(nv.getWidth());
+ // this.height += Math.sqrt(nv.getHeight());
+ this.width += nv.getWidth();
+ this.height += nv.getHeight();
}
+ }
- /**
- * Add an edge to this partition assuming that the source and target
- * nodes are not yet known.
- *
- * @param edge the CyEdge to add to the partition
- */
- protected void addEdge(CyEdge edge) {
- LayoutEdge newEdge = new LayoutEdge(edge);
- updateWeights(newEdge);
- edgeList.add(newEdge);
- }
+ /**
+ * Add an edge to this partition assuming that the source and target
+ * nodes are not yet known.
+ *
+ * @param edge the CyEdge to add to the partition
+ */
+ protected void addEdge(CyEdge edge) {
+ LayoutEdge newEdge = new LayoutEdge(edge);
+ updateWeights(newEdge);
+ edgeList.add(newEdge);
+ }
- /**
- * Add an edge to this partition assuming that the source and target
- * nodes <em>are</em> known.
- *
- * @param edge the CyEdge to add to the partition
- * @param v1 the LayoutNode of the edge source
- * @param v2 the LayoutNode of the edge target
- */
- protected void addEdge(CyEdge edge, LayoutNode v1, LayoutNode v2) {
- LayoutEdge newEdge = new LayoutEdge(edge, v1, v2);
- updateWeights(newEdge);
- edgeList.add(newEdge);
- }
+ /**
+ * Add an edge to this partition assuming that the source and target
+ * nodes <em>are</em> known.
+ *
+ * @param edge the CyEdge to add to the partition
+ * @param v1 the LayoutNode of the edge source
+ * @param v2 the LayoutNode of the edge target
+ */
+ protected void addEdge(CyEdge edge, LayoutNode v1, LayoutNode v2) {
+ LayoutEdge newEdge = new LayoutEdge(edge, v1, v2);
+ updateWeights(newEdge);
+ edgeList.add(newEdge);
+ }
- /**
- * Randomize the graph locations.
- */
- public void randomizeLocations() {
- // Get a seeded pseudo random-number generator
- Date today = new Date();
- Random random = new Random(today.getTime());
- // Reset our min and max values
- resetNodes();
+ /**
+ * Randomize the graph locations.
+ */
+ public void randomizeLocations() {
+ // Get a seeded pseudo random-number generator
+ Date today = new Date();
+ Random random = new Random(today.getTime());
+ // Reset our min and max values
+ resetNodes();
- for (LayoutNode node: nodeList) {
+ for (LayoutNode node: nodeList) {
- if (!node.isLocked()) {
- double x = random.nextDouble() * width;
- double y = random.nextDouble() * height;
- node.setLocation(x, y);
- updateMinMax(x, y);
- } else {
- updateMinMax(node.getX(), node.getY());
- }
- }
+ if (!node.isLocked()) {
+ double x = random.nextDouble() * width;
+ double y = random.nextDouble() * height;
+ node.setLocation(x, y);
+ updateMinMax(x, y);
+ } else {
+ updateMinMax(node.getX(), node.getY());
+ }
}
+ }
- /**
- * Move the node to its current X and Y values. This is a wrapper
- * to LayoutNode's moveToLocation, but has the property of updating
- * the current min and max values for this partition.
- *
- * @param node the LayoutNode to move
- */
- public void moveNodeToLocation(LayoutNode node) {
- // We provide this routine so that we can keep our
- // min/max values updated
- if (node.isLocked())
- return;
+ /**
+ * Move the node to its current X and Y values. This is a wrapper
+ * to LayoutNode's moveToLocation, but has the property of updating
+ * the current min and max values for this partition.
+ *
+ * @param node the LayoutNode to move
+ */
+ public void moveNodeToLocation(LayoutNode node) {
+ // We provide this routine so that we can keep our
+ // min/max values updated
+ if (node.isLocked())
+ return;
- node.moveToLocation();
- updateMinMax(node.getX(), node.getY());
- }
+ node.moveToLocation();
+ updateMinMax(node.getX(), node.getY());
+ }
- /**
- * Convenience routine to update the source and target for all of the
- * edges in a partition. This is useful when the algorithm used makes
it
- * difficult to record source and target until it has completed.
- */
- public void fixEdges() {
- for (LayoutEdge lEdge: edgeList) {
- // Get the underlying edge
- CyEdge edge = lEdge.getEdge();
- CyNode target = (CyNode) edge.getTarget();
- CyNode source = (CyNode) edge.getSource();
+ /**
+ * Convenience routine to update the source and target for all of the
+ * edges in a partition. This is useful when the algorithm used makes it
+ * difficult to record source and target until it has completed.
+ */
+ public void fixEdges() {
+ for (LayoutEdge lEdge: edgeList) {
+ // Get the underlying edge
+ CyEdge edge = lEdge.getEdge();
+ CyNode target = (CyNode) edge.getTarget();
+ CyNode source = (CyNode) edge.getSource();
- if (nodeToLayoutNode.containsKey(source) &&
nodeToLayoutNode.containsKey(target)) {
- // Add the connecting nodes
- lEdge.addNodes((LayoutNode)
nodeToLayoutNode.get(source),
- (LayoutNode)
nodeToLayoutNode.get(target));
- }
- }
+ if (nodeToLayoutNode.containsKey(source) &&
nodeToLayoutNode.containsKey(target)) {
+ // Add the connecting nodes
+ lEdge.addNodes((LayoutNode) nodeToLayoutNode.get(source),
+ (LayoutNode) nodeToLayoutNode.get(target));
+ }
}
+ }
- /**
- * Calculate and set the edge weights. Note that this will delete
- * edges from the calculation (not the graph) when certain conditions
- * are met.
- */
- public void calculateEdgeWeights() {
+ /**
+ * Calculate and set the edge weights. Note that this will delete
+ * edges from the calculation (not the graph) when certain conditions
+ * are met.
+ */
+ public void calculateEdgeWeights() {
- // Use a ListIterator so that we can modify the list
- // as we go
- ListIterator<LayoutEdge>iter = edgeList.listIterator();
- while (iter.hasNext()) {
- LayoutEdge edge = iter.next();
+ // Use a ListIterator so that we can modify the list
+ // as we go
+ ListIterator<LayoutEdge>iter = edgeList.listIterator();
+ while (iter.hasNext()) {
+ LayoutEdge edge = iter.next();
- // If we're only dealing with selected nodes, drop any
edges
- // that don't have any selected nodes
- if (edge.getSource().isLocked() &&
edge.getTarget().isLocked()) {
- iter.remove();
- } else if (edgeWeighter != null &&
edgeWeighter.normalizeWeight(edge) == false)
- iter.remove();
+ // If we're only dealing with selected nodes, drop any edges
+ // that don't have any selected nodes
+ if (edge.getSource().isLocked() && edge.getTarget().isLocked()) {
+ iter.remove();
+ } else if (edgeWeighter != null &&
edgeWeighter.normalizeWeight(edge) == false)
+ iter.remove();
- // logger.debug("Edge
"+edge.getEdge().getIdentifier()+" now has weight "+edge.getWeight());
- }
+ // logger.debug("Edge "+edge.getEdge().getIdentifier()+" now has
weight "+edge.getWeight());
}
+ }
- /**
- * Return the size of this partition, which is defined as the number of
- * nodes that it contains.
- *
- * @return partition size
- */
- public int size() {
- return nodeList.size();
- }
+ /**
+ * Return the size of this partition, which is defined as the number of
+ * nodes that it contains.
+ *
+ * @return partition size
+ */
+ public int size() {
+ return nodeList.size();
+ }
- /**
- * Return the list of LayoutNodes within this partition.
- *
- * @return List of LayoutNodes
- * @see LayoutNode
- */
- public List<LayoutNode> getNodeList() {
- return nodeList;
- }
+ /**
+ * Return the list of LayoutNodes within this partition.
+ *
+ * @return List of LayoutNodes
+ * @see LayoutNode
+ */
+ public List<LayoutNode> getNodeList() {
+ return nodeList;
+ }
- /**
- * Return the list of LayoutEdges within this partition.
- *
- * @return List of LayoutEdges
- * @see LayoutEdge
- */
- public List<LayoutEdge> getEdgeList() {
- return edgeList;
- }
+ /**
+ * Return the list of LayoutEdges within this partition.
+ *
+ * @return List of LayoutEdges
+ * @see LayoutEdge
+ */
+ public List<LayoutEdge> getEdgeList() {
+ return edgeList;
+ }
- /**
- * Return an iterator over all of the LayoutNodes in this parition
- *
- * @return Iterator over the list of LayoutNodes
- * @see LayoutNode
- */
- public Iterator<LayoutNode> nodeIterator() {
- return nodeList.iterator();
- }
+ /**
+ * Return an iterator over all of the LayoutNodes in this parition
+ *
+ * @return Iterator over the list of LayoutNodes
+ * @see LayoutNode
+ */
+ public Iterator<LayoutNode> nodeIterator() {
+ return nodeList.iterator();
+ }
- /**
- * Return an iterator over all of the LayoutEdges in this parition
- *
- * @return Iterator over the list of LayoutEdges
- * @see LayoutEdge
- */
- public Iterator<LayoutEdge> edgeIterator() {
- return edgeList.iterator();
- }
+ /**
+ * Return an iterator over all of the LayoutEdges in this parition
+ *
+ * @return Iterator over the list of LayoutEdges
+ * @see LayoutEdge
+ */
+ public Iterator<LayoutEdge> edgeIterator() {
+ return edgeList.iterator();
+ }
- /**
- * Return the number of nodes in this partition
- *
- * @return number of nodes in the partition
- */
- public int nodeCount() {
- return nodeList.size();
- }
+ /**
+ * Return the number of nodes in this partition
+ *
+ * @return number of nodes in the partition
+ */
+ public int nodeCount() {
+ return nodeList.size();
+ }
- /**
- * Return the number of edges in this partition
- *
- * @return number of edges in the partition
- */
- public int edgeCount() {
- return edgeList.size();
- }
+ /**
+ * Return the number of edges in this partition
+ *
+ * @return number of edges in the partition
+ */
+ public int edgeCount() {
+ return edgeList.size();
+ }
- /**
- * Return the maximum X location of all of the LayoutNodes
- *
- * @return maximum X location
- */
- public double getMaxX() {
- return maxX;
- }
+ /**
+ * Return the maximum X location of all of the LayoutNodes
+ *
+ * @return maximum X location
+ */
+ public double getMaxX() {
+ return maxX;
+ }
- /**
- * Return the maximum Y location of all of the LayoutNodes
- *
- * @return maximum Y location
- */
- public double getMaxY() {
- return maxY;
- }
+ /**
+ * Return the maximum Y location of all of the LayoutNodes
+ *
+ * @return maximum Y location
+ */
+ public double getMaxY() {
+ return maxY;
+ }
- /**
- * Return the minimum X location of all of the LayoutNodes
- *
- * @return minimum X location
- */
- public double getMinX() {
- return minX;
- }
+ /**
+ * Return the minimum X location of all of the LayoutNodes
+ *
+ * @return minimum X location
+ */
+ public double getMinX() {
+ return minX;
+ }
- /**
- * Return the minimum Y location of all of the LayoutNodes
- *
- * @return minimum Y location
- */
- public double getMinY() {
- return minY;
- }
+ /**
+ * Return the minimum Y location of all of the LayoutNodes
+ *
+ * @return minimum Y location
+ */
+ public double getMinY() {
+ return minY;
+ }
- /**
- * Return the total width of all of the LayoutNodes
- *
- * @return total width of all of the LayoutNodes
- */
- public double getWidth() {
- return width;
- }
+ /**
+ * Return the total width of all of the LayoutNodes
+ *
+ * @return total width of all of the LayoutNodes
+ */
+ public double getWidth() {
+ return width;
+ }
- /**
- * Return the total height of all of the LayoutNodes
- *
- * @return total height of all of the LayoutNodes
- */
- public double getHeight() {
- return height;
- }
+ /**
+ * Return the total height of all of the LayoutNodes
+ *
+ * @return total height of all of the LayoutNodes
+ */
+ public double getHeight() {
+ return height;
+ }
- /**
- * Return the partition number of this partition
- *
- * @return partition number
- */
- public int getPartitionNumber() {
- return partitionNumber;
- }
+ /**
+ * Return the partition number of this partition
+ *
+ * @return partition number
+ */
+ public int getPartitionNumber() {
+ return partitionNumber;
+ }
- /**
- * Set the partition number of this partition
- *
- * @param part partition number
- */
- public void setPartitionNumber(int part) {
- partitionNumber = part;
- }
+ /**
+ * Set the partition number of this partition
+ *
+ * @param part partition number
+ */
+ public void setPartitionNumber(int part) {
+ partitionNumber = part;
+ }
- /**
- * Return the number of locked nodes within this parititon
- *
- * @return number of locked nodes in partition
- */
- public int lockedNodeCount() {
- return lockedNodes;
- }
+ /**
+ * Return the number of locked nodes within this parititon
+ *
+ * @return number of locked nodes in partition
+ */
+ public int lockedNodeCount() {
+ return lockedNodes;
+ }
- /**
- * Return the average location of the nodes in this partition
- *
- * @return average location of the nodes as a Dimension
- * @see Dimension
- */
- public Dimension getAverageLocation() {
- int nodes = nodeCount() - lockedNodes;
- Dimension result = new Dimension();
- result.setSize(averageX / nodes, averageY / nodes);
+ /**
+ * Return the average location of the nodes in this partition
+ *
+ * @return average location of the nodes as a Dimension
+ * @see Dimension
+ */
+ public Dimension getAverageLocation() {
+ int nodes = nodeCount() - lockedNodes;
+ Dimension result = new Dimension();
+ result.setSize(averageX / nodes, averageY / nodes);
- return result;
- }
+ return result;
+ }
- /**
- * Offset all of the nodes in the partition by a fixed
- * amount. This is used by algorithms of offset each
- * partition after laying it out.
- *
- * @param xoffset the amount to offset in the X direction
- * @param yoffset the amount to offset in the Y direction
- */
- public void offset(double xoffset, double yoffset) {
- double myMinX = this.minX;
- double myMinY = this.minY;
- resetNodes();
+ /**
+ * Offset all of the nodes in the partition by a fixed
+ * amount. This is used by algorithms of offset each
+ * partition after laying it out.
+ *
+ * @param xoffset the amount to offset in the X direction
+ * @param yoffset the amount to offset in the Y direction
+ */
+ public void offset(double xoffset, double yoffset) {
+ double myMinX = this.minX;
+ double myMinY = this.minY;
+ resetNodes();
- for (LayoutNode node: nodeList) {
- node.increment(xoffset - myMinX, yoffset - myMinY);
- moveNodeToLocation(node);
- }
+ for (LayoutNode node: nodeList) {
+ node.increment(xoffset - myMinX, yoffset - myMinY);
+ moveNodeToLocation(node);
}
+ }
- /**
- * Reset routines
- */
+ /**
+ * Reset routines
+ */
- /**
- * Reset all of the data maintained for the LayoutNodes
- * contained within this partition, including the min, max
- * and average x and y values.
- */
- public void resetNodes() {
- maxX = -100000;
- maxY = -100000;
- minX = 100000;
- minY = 100000;
- averageX = 0;
- averageY = 0;
+ /**
+ * Reset all of the data maintained for the LayoutNodes
+ * contained within this partition, including the min, max
+ * and average x and y values.
+ */
+ public void resetNodes() {
+ maxX = -100000;
+ maxY = -100000;
+ minX = 100000;
+ minY = 100000;
+ averageX = 0;
+ averageY = 0;
+ }
+
+ /**
+ * Protected routines
+ */
+ protected void nodeListInitialize(CyNetwork network, CyNetworkView
networkView,
+ Collection<CyNode> nodeSet) {
+ int nodeIndex = 0;
+ this.nodeList = new ArrayList<LayoutNode>(network.getNodeCount());
+
+ Iterator<NodeView>iter = networkView.getNodeViewsIterator();
+ while (iter.hasNext()) {
+ NodeView nv = (NodeView) iter.next();
+ CyNode node = (CyNode) nv.getNode();
+
+ if (!nodeSet.contains(node)) {
+ addNode(nv, true);
+ } else {
+ addNode(nv, false);
+ }
}
+ }
+
+ protected void edgeListInitialize(CyNetwork network, CyNetworkView
networkView) {
+ for (CyEdge edge: (List<CyEdge>)network.edgesList()) {
- /**
- * Protected routines
- */
- protected void nodeListInitialize(CyNetwork network, CyNetworkView
networkView,
- Collection<CyNode> nodeSet) {
- int nodeIndex = 0;
- this.nodeList = new
ArrayList<LayoutNode>(network.getNodeCount());
+ CyNode source = (CyNode) edge.getSource();
+ CyNode target = (CyNode) edge.getTarget();
- Iterator<NodeView>iter = networkView.getNodeViewsIterator();
- while (iter.hasNext()) {
- NodeView nv = (NodeView) iter.next();
- CyNode node = (CyNode) nv.getNode();
+ if (source == target)
+ continue;
- if (!nodeSet.contains(node)) {
- addNode(nv, true);
- } else {
- addNode(nv, false);
- }
- }
- }
+ LayoutNode v1 = (LayoutNode) nodeToLayoutNode.get(source);
+ LayoutNode v2 = (LayoutNode) nodeToLayoutNode.get(target);
- protected void edgeListInitialize(CyNetwork network, CyNetworkView
networkView) {
- for (CyEdge edge: (List<CyEdge>)network.edgesList()) {
+ // Do we care about this edge?
+ if (v1.isLocked() || v2.isLocked())
+ continue; // no, ignore it
- CyNode source = (CyNode) edge.getSource();
- CyNode target = (CyNode) edge.getTarget();
+ EdgeView ev = networkView.getEdgeView(edge);
+ ev.clearBends();
- if (source == target)
- continue;
+ addEdge(edge, v1, v2);
+ }
+ }
- LayoutNode v1 = (LayoutNode)
nodeToLayoutNode.get(source);
- LayoutNode v2 = (LayoutNode)
nodeToLayoutNode.get(target);
+ /**
+ * Space saving convenience function to trim the internal arrays to fit the
+ * contained data. Useful to call this after a partition has been created
+ * and filled. This is used by the static method LayoutPartition.partition
+ */
+ protected void trimToSize() {
+ nodeList.trimToSize();
+ edgeList.trimToSize();
+ }
- // Do we care about this edge?
- if (v1.isLocked() || v2.isLocked())
- continue; // no, ignore it
+ protected void updateMinMax(double x, double y) {
+ minX = Math.min(minX, x);
+ minY = Math.min(minY, y);
+ maxX = Math.max(maxX, x);
+ maxY = Math.max(maxY, y);
+ averageX += x;
+ averageY += y;
+ }
- EdgeView ev = networkView.getEdgeView(edge);
- ev.clearBends();
-
- addEdge(edge, v1, v2);
- }
+ protected void updateWeights(LayoutEdge newEdge) {
+ if (edgeWeighter != null) {
+ edgeWeighter.setWeight(newEdge);
}
- /**
- * Space saving convenience function to trim the internal arrays to fit
the
- * contained data. Useful to call this after a partition has been
created
- * and filled. This is used by the static method
LayoutPartition.partition
- */
- protected void trimToSize() {
- nodeList.trimToSize();
- edgeList.trimToSize();
- }
+ // logger.debug("Updating "+newEdge);
+ }
- protected void updateMinMax(double x, double y) {
- minX = Math.min(minX, x);
- minY = Math.min(minY, y);
- maxX = Math.max(maxX, x);
- maxY = Math.max(maxY, y);
- averageX += x;
- averageY += y;
- }
+ // Static routines
- protected void updateWeights(LayoutEdge newEdge) {
- if (edgeWeighter != null) {
- edgeWeighter.setWeight(newEdge);
- }
+ /**
+ * Partition the graph -- this builds the LayoutEdge and LayoutNode
+ * arrays as a byproduct. The algorithm for this was taken from
+ * algorithms/graphPartition/SGraphPartition.java.
+ *
+ * @param network the CyNetwork containing the graph
+ * @param networkView the CyNetworkView representing the graph
+ * @param selectedOnly only consider selected nodes
+ * @param edgeWeighter the weighter to use for edge weighting
+ * @return a List of LayoutPartitions
+ */
+ public static List<LayoutPartition> partition(CyNetwork network,
CyNetworkView networkView,
+ boolean selectedOnly,
EdgeWeighter edgeWeighter) {
- // logger.debug("Updating "+newEdge);
+ if (selectedOnly) {
+ return
partition(network,networkView,network.getSelectedNodes(),edgeWeighter);
}
- // Static routines
+ return partition(network,networkView,network.nodesList(),edgeWeighter);
- /**
- * Partition the graph -- this builds the LayoutEdge and LayoutNode
- * arrays as a byproduct. The algorithm for this was taken from
- * algorithms/graphPartition/SGraphPartition.java.
- *
- * @param network the CyNetwork containing the graph
- * @param networkView the CyNetworkView representing the graph
- * @param selectedOnly only consider selected nodes
- * @param edgeWeighter the weighter to use for edge weighting
- * @return a List of LayoutPartitions
- */
- public static List<LayoutPartition> partition(CyNetwork network,
CyNetworkView networkView,
- boolean selectedOnly, EdgeWeighter
edgeWeighter) {
+ }
- if (selectedOnly) {
- return
partition(network,networkView,network.getSelectedNodes(),edgeWeighter);
- }
+ /**
+ * Partition the graph -- this builds the LayoutEdge and LayoutNode
+ * arrays as a byproduct. The algorithm for this was taken from
+ * algorithms/graphPartition/SGraphPartition.java.
+ *
+ * @param network the CyNetwork containing the graph
+ * @param networkView the CyNetworkView representing the graph
+ * @param nodeSet the set of nodes to consider
+ * @param edgeWeighter the weighter to use for edge weighting
+ * @return a List of LayoutPartitions
+ */
+ public static List<LayoutPartition> partition(CyNetwork network,
CyNetworkView networkView,
+ Collection<CyNode> nodeSet,
EdgeWeighter edgeWeighter) {
+ ArrayList<LayoutPartition> partitions = new
ArrayList<LayoutPartition>();
- return
partition(network,networkView,network.nodesList(),edgeWeighter);
+ nodesSeenMap = new IntIntHash();
+ edgesSeenMap = new IntIntHash();
- }
+ IntObjHash nodesToViews = new IntObjHash();
+ nodeToLayoutNode = new
HashMap<CyNode,LayoutNode>(network.getNodeCount());
- /**
- * Partition the graph -- this builds the LayoutEdge and LayoutNode
- * arrays as a byproduct. The algorithm for this was taken from
- * algorithms/graphPartition/SGraphPartition.java.
- *
- * @param network the CyNetwork containing the graph
- * @param networkView the CyNetworkView representing the graph
- * @param nodeSet the set of nodes to consider
- * @param edgeWeighter the weighter to use for edge weighting
- * @return a List of LayoutPartitions
- */
- public static List<LayoutPartition> partition(CyNetwork network,
CyNetworkView networkView,
- Collection<CyNode> nodeSet, EdgeWeighter
edgeWeighter) {
- ArrayList<LayoutPartition> partitions = new
ArrayList<LayoutPartition>();
+ // Initialize the maps
+ Iterator nodeViewIter = networkView.getNodeViewsIterator();
- nodesSeenMap = new IntIntHash();
- edgesSeenMap = new IntIntHash();
+ while (nodeViewIter.hasNext()) {
+ NodeView nv = (NodeView) nodeViewIter.next();
+ int node = nv.getNode().getRootGraphIndex();
+ nodesSeenMap.put(-node, m_NODE_HAS_NOT_BEEN_SEEN);
+ nodesToViews.put(-node, nv);
+ }
- IntObjHash nodesToViews = new IntObjHash();
- nodeToLayoutNode = new
HashMap<CyNode,LayoutNode>(network.getNodeCount());
+ for (CyEdge edge: (List<CyEdge>)network.edgesList()) {
+ int edgeIndex = edge.getRootGraphIndex();
+ edgesSeenMap.put(-edgeIndex, m_NODE_HAS_NOT_BEEN_SEEN);
+ }
- // Initialize the maps
- Iterator nodeViewIter = networkView.getNodeViewsIterator();
+ // OK, now traverse the graph
+ for (CyNode node: nodeSet) {
+ int nodeIndex = node.getRootGraphIndex();
- while (nodeViewIter.hasNext()) {
- NodeView nv = (NodeView) nodeViewIter.next();
- int node = nv.getNode().getRootGraphIndex();
- nodesSeenMap.put(-node, m_NODE_HAS_NOT_BEEN_SEEN);
- nodesToViews.put(-node, nv);
- }
+ // Have we seen this already?
+ if (nodesSeenMap.get(-nodeIndex) == m_NODE_HAS_BEEN_SEEN)
+ continue;
- for (CyEdge edge: (List<CyEdge>)network.edgesList()) {
- int edgeIndex = edge.getRootGraphIndex();
- edgesSeenMap.put(-edgeIndex, m_NODE_HAS_NOT_BEEN_SEEN);
- }
+ // Nope, first time
+ LayoutPartition part = new LayoutPartition(network.getNodeCount(),
+ network.getEdgeCount());
+ // Set the edge weighter
+ part.setEdgeWeighter(edgeWeighter);
- // OK, now traverse the graph
- for (CyNode node: nodeSet) {
- int nodeIndex = node.getRootGraphIndex();
+ nodesSeenMap.put(-nodeIndex, m_NODE_HAS_BEEN_SEEN);
- // Have we seen this already?
- if (nodesSeenMap.get(-nodeIndex) ==
m_NODE_HAS_BEEN_SEEN)
- continue;
+ // Traverse through all connected nodes
+ traverse(network, networkView, nodesToViews, node, part);
- // Nope, first time
- LayoutPartition part = new
LayoutPartition(network.getNodeCount(),
-
network.getEdgeCount());
- // Set the edge weighter
- part.setEdgeWeighter(edgeWeighter);
+ // Done -- finalize the parition
+ part.trimToSize();
- nodesSeenMap.put(-nodeIndex, m_NODE_HAS_BEEN_SEEN);
+ // Finally, now that we're sure we've touched all of our
+ // nodes. Fix up our edgeLayout list to have all of our
+ // layoutNodes
+ part.fixEdges();
- // Traverse through all connected nodes
- traverse(network, networkView, nodesToViews, node,
part);
+ partitions.add(part);
+ }
- // Done -- finalize the parition
- part.trimToSize();
+ // Now sort the partitions based on the partition's node count
+ LayoutPartition[] a = new LayoutPartition[1];
+ LayoutPartition[] parts = partitions.toArray(a);
+ Arrays.sort(parts,
+ new Comparator<LayoutPartition>() {
+ public int compare(LayoutPartition p1, LayoutPartition
p2) {
+ return (p2.size() - p1.size());
+ }
- // Finally, now that we're sure we've touched all of our
- // nodes. Fix up our edgeLayout list to have all of our
- // layoutNodes
- part.fixEdges();
+ public boolean equals(LayoutPartition obj) {
+ return false;
+ }
+ });
- partitions.add(part);
- }
+ return Arrays.asList(parts);
+ }
- // Now sort the partitions based on the partition's node count
- LayoutPartition[] a = new LayoutPartition[1];
- LayoutPartition[] parts = partitions.toArray(a);
- Arrays.sort(parts,
- new Comparator<LayoutPartition>() {
- public int compare(LayoutPartition p1,
LayoutPartition p2) {
- return (p2.size() - p1.size());
- }
+ /**
+ * This method traverses nodes connected to the specified node.
+ * @param network The CyNetwork we are laying out
+ * @param networkView The CyNetworkView we are laying out
+ * @param nodesToViews A map that maps between nodes and views
+ * @param node The node to search for connected
nodes.
+ * @param partition the partition we're laying out
+ */
+ protected static void traverse(CyNetwork network, CyNetworkView
networkView,
+ IntObjHash nodesToViews, CyNode node,
+ LayoutPartition partition) {
+ int nodeIndex = node.getRootGraphIndex();
- public boolean equals(LayoutPartition obj) {
- return false;
- }
- });
+ // Get the nodeView
+ NodeView nv = (NodeView) nodesToViews.get(-nodeIndex);
- return Arrays.asList(parts);
- }
+ // Add this node to the partition
+ partition.addNode(nv, false);
- /**
- * This method traverses nodes connected to the specified node.
- * @param network The CyNetwork we are laying out
- * @param networkView The CyNetworkView we are laying out
- * @param nodesToViews A map that maps between nodes and views
- * @param node The node to search for connected
nodes.
- * @param partition the partition we're laying out
- */
- protected static void traverse(CyNetwork network, CyNetworkView
networkView,
- IntObjHash nodesToViews, CyNode node,
- LayoutPartition partition) {
- int nodeIndex = node.getRootGraphIndex();
+ // Get the list of edges connected to this node
+ int[] incidentEdges = network.getAdjacentEdgeIndicesArray(nodeIndex,
true, true, true);
- // Get the nodeView
- NodeView nv = (NodeView) nodesToViews.get(-nodeIndex);
+ // Iterate through each connected edge
+ for (int i = 0; i < incidentEdges.length; i++) {
+ // Get the actual edge
+ CyEdge incidentEdge = (CyEdge) network.getEdge(incidentEdges[i]);
- // Add this node to the partition
- partition.addNode(nv, false);
+ int edgeIndex = incidentEdge.getRootGraphIndex();
- // Get the list of edges connected to this node
- int[] incidentEdges =
network.getAdjacentEdgeIndicesArray(nodeIndex, true, true, true);
+ // Have we already seen this edge?
+ if (edgesSeenMap.get(-edgeIndex) == m_NODE_HAS_BEEN_SEEN) {
+ // Yes, continue since it means we *must* have seen both sides
+ continue;
+ }
- // Iterate through each connected edge
- for (int i = 0; i < incidentEdges.length; i++) {
- // Get the actual edge
- CyEdge incidentEdge = (CyEdge)
network.getEdge(incidentEdges[i]);
+ edgesSeenMap.put(-edgeIndex, m_NODE_HAS_BEEN_SEEN);
- int edgeIndex = incidentEdge.getRootGraphIndex();
+ // Make sure we clean up after any previous layouts
+ EdgeView ev = networkView.getEdgeView(incidentEdge);
+ ev.clearBends();
- // Have we already seen this edge?
- if (edgesSeenMap.get(-edgeIndex) ==
m_NODE_HAS_BEEN_SEEN) {
- // Yes, continue since it means we *must* have
seen both sides
- continue;
- }
+ // Add the edge to the partition
+ partition.addEdge(incidentEdge);
- edgesSeenMap.put(-edgeIndex, m_NODE_HAS_BEEN_SEEN);
+ // Determine the node's index that is on the other side of the edge
+ CyNode otherNode;
- // Make sure we clean up after any previous layouts
- EdgeView ev = networkView.getEdgeView(incidentEdge);
- ev.clearBends();
+ if (incidentEdge.getSource() == node) {
+ otherNode = (CyNode) incidentEdge.getTarget();
+ } else {
+ otherNode = (CyNode) incidentEdge.getSource();
+ }
- // Add the edge to the partition
- partition.addEdge(incidentEdge);
+ int incidentNodeIndex = otherNode.getRootGraphIndex();
- // Determine the node's index that is on the other side
of the edge
- CyNode otherNode;
+ // Have we seen the connecting node yet?
+ if (nodesSeenMap.get(-incidentNodeIndex) ==
m_NODE_HAS_NOT_BEEN_SEEN) {
+ // Mark it as having been seen
+ nodesSeenMap.put(-incidentNodeIndex, m_NODE_HAS_BEEN_SEEN);
- if (incidentEdge.getSource() == node) {
- otherNode = (CyNode) incidentEdge.getTarget();
- } else {
- otherNode = (CyNode) incidentEdge.getSource();
- }
-
- int incidentNodeIndex = otherNode.getRootGraphIndex();
-
- // Have we seen the connecting node yet?
- if (nodesSeenMap.get(-incidentNodeIndex) ==
m_NODE_HAS_NOT_BEEN_SEEN) {
- // Mark it as having been seen
- nodesSeenMap.put(-incidentNodeIndex,
m_NODE_HAS_BEEN_SEEN);
-
- // Traverse through this one
- traverse(network, networkView, nodesToViews,
otherNode, partition);
- }
- }
+ // Traverse through this one
+ traverse(network, networkView, nodesToViews, otherNode,
partition);
+ }
}
+ }
}
--
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.