Author: chinmoy
Date: 2009-08-06 12:04:56 -0700 (Thu, 06 Aug 2009)
New Revision: 17721

Added:
   csplugins/trunk/soc/chinmoy/phylotree/samples/phyloxml1.xml
   csplugins/trunk/soc/chinmoy/phylotree/samples/treeoflife1234.xml
Modified:
   csplugins/trunk/soc/chinmoy/phylotree/
   
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/actions/PhyloTreeImportAction.java
   
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/CommonFunctions.java
   
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/visualstyle/LevelColor.java
Log:
Completed depth-to-color visual style 


Property changes on: csplugins/trunk/soc/chinmoy/phylotree
___________________________________________________________________
Name: svn:ignore
   + .settings
.classpath
.project


Added: csplugins/trunk/soc/chinmoy/phylotree/samples/phyloxml1.xml
===================================================================
--- csplugins/trunk/soc/chinmoy/phylotree/samples/phyloxml1.xml                 
        (rev 0)
+++ csplugins/trunk/soc/chinmoy/phylotree/samples/phyloxml1.xml 2009-08-06 
19:04:56 UTC (rev 17721)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phyloxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+   xsi:schemaLocation="http://www.phyloxml.org 
http://www.phyloxml.org/1.00/phyloxml.xsd";
+   xmlns="http://www.phyloxml.org";>
+   <phylogeny rooted="true">
+      <name>example from Prof. Joe Felsenstein's book "Inferring 
Phylogenies"</name>
+      <description>phyloXML allows to use either a "branch_length" attribute 
or element to indicate branch lengths.</description>
+      <clade>
+         <clade>
+            <branch_length>0.06</branch_length>
+            <clade>
+               <name>A</name>
+               <branch_length>0.102</branch_length>
+            </clade>
+            <clade>
+               <name>B</name>
+               <branch_length>0.23</branch_length>
+            </clade>
+         </clade>
+         <clade>
+            <name>C</name>
+            <branch_length>0.4</branch_length>
+         </clade>
+      </clade>
+   </phylogeny>
+</phyloxml>

Added: csplugins/trunk/soc/chinmoy/phylotree/samples/treeoflife1234.xml
===================================================================
--- csplugins/trunk/soc/chinmoy/phylotree/samples/treeoflife1234.xml            
                (rev 0)
+++ csplugins/trunk/soc/chinmoy/phylotree/samples/treeoflife1234.xml    
2009-08-06 19:04:56 UTC (rev 17721)
@@ -0,0 +1,266 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phyloxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://www.phyloxml.org 
http://www.phyloxml.org/1.00/phyloxml.xsd"; xmlns="http://www.phyloxml.org";>
+<phylogeny rooted="true">
+  <id type="Tree of Life">1234</id>
+  <clade>
+    <taxonomy>
+      <id type="tol">1234</id>
+      <common_name>Anisodactyloids</common_name>
+    </taxonomy>
+    <clade>
+      <taxonomy>
+        <id type="tol">1237</id>
+      </taxonomy>
+      <clade>
+        <taxonomy>
+          <id type="tol">1238</id>
+          <common_name>Progonochaetus</common_name>
+        </taxonomy>
+      </clade>
+      <clade>
+        <taxonomy>
+          <id type="tol">1239</id>
+          <common_name>Eudichirus</common_name>
+        </taxonomy>
+      </clade>
+    </clade>
+    <clade>
+      <taxonomy>
+        <id type="tol">1240</id>
+      </taxonomy>
+      <clade>
+        <taxonomy>
+          <id type="tol">1241</id>
+        </taxonomy>
+        <clade>
+          <taxonomy>
+            <id type="tol">1242</id>
+          </taxonomy>
+          <clade>
+            <taxonomy>
+              <id type="tol">1243</id>
+              <common_name>Phanagnathus</common_name>
+            </taxonomy>
+          </clade>
+          <clade>
+            <taxonomy>
+              <id type="tol">1244</id>
+            </taxonomy>
+            <clade>
+              <taxonomy>
+                <id type="tol">1245</id>
+                <common_name>Pseudognathaphanus</common_name>
+              </taxonomy>
+            </clade>
+            <clade>
+              <taxonomy>
+                <id type="tol">1246</id>
+              </taxonomy>
+              <clade>
+                <taxonomy>
+                  <id type="tol">1247</id>
+                  <common_name>Chydaeus</common_name>
+                </taxonomy>
+              </clade>
+              <clade>
+                <taxonomy>
+                  <id type="tol">1248</id>
+                </taxonomy>
+                <clade>
+                  <taxonomy>
+                    <id type="tol">1249</id>
+                    <common_name>Harpalomimetes</common_name>
+                  </taxonomy>
+                </clade>
+                <clade>
+                  <taxonomy>
+                    <id type="tol">1250</id>
+                    <common_name>Rhysopus</common_name>
+                  </taxonomy>
+                </clade>
+              </clade>
+            </clade>
+          </clade>
+        </clade>
+        <clade>
+          <taxonomy>
+            <id type="tol">1251</id>
+            <common_name>Xestonotus</common_name>
+          </taxonomy>
+        </clade>
+      </clade>
+      <clade>
+        <taxonomy>
+          <id type="tol">1252</id>
+        </taxonomy>
+        <clade>
+          <taxonomy>
+            <id type="tol">1253</id>
+          </taxonomy>
+          <clade>
+            <taxonomy>
+              <id type="tol">1254</id>
+            </taxonomy>
+            <clade>
+              <taxonomy>
+                <id type="tol">1255</id>
+              </taxonomy>
+              <clade>
+                <taxonomy>
+                  <id type="tol">1256</id>
+                </taxonomy>
+                <clade>
+                  <taxonomy>
+                    <id type="tol">1257</id>
+                    <common_name>Anisodactylus</common_name>
+                  </taxonomy>
+                </clade>
+                <clade>
+                  <taxonomy>
+                    <id type="tol">1258</id>
+                    <common_name>Pseudanisodactylus</common_name>
+                  </taxonomy>
+                </clade>
+              </clade>
+              <clade>
+                <taxonomy>
+                  <id type="tol">1259</id>
+                </taxonomy>
+                <clade>
+                  <taxonomy>
+                    <id type="tol">1260</id>
+                    <common_name>Pseudhexatrichus</common_name>
+                  </taxonomy>
+                </clade>
+                <clade>
+                  <taxonomy>
+                    <id type="tol">1261</id>
+                    <common_name>Hexatrichus</common_name>
+                  </taxonomy>
+                </clade>
+              </clade>
+            </clade>
+            <clade>
+              <taxonomy>
+                <id type="tol">1262</id>
+              </taxonomy>
+              <clade>
+                <taxonomy>
+                  <id type="tol">1263</id>
+                  <common_name>Pseudodichirus</common_name>
+                </taxonomy>
+              </clade>
+              <clade>
+                <taxonomy>
+                  <id type="tol">1264</id>
+                  <common_name>Gynandrotarsus</common_name>
+                </taxonomy>
+              </clade>
+            </clade>
+          </clade>
+          <clade>
+            <taxonomy>
+              <id type="tol">1265</id>
+            </taxonomy>
+            <clade>
+              <taxonomy>
+                <id type="tol">1266</id>
+                <common_name>Geopinus</common_name>
+              </taxonomy>
+            </clade>
+            <clade>
+              <taxonomy>
+                <id type="tol">1267</id>
+              </taxonomy>
+              <clade>
+                <taxonomy>
+                  <id type="tol">1268</id>
+                  <common_name>Anadaptus</common_name>
+                </taxonomy>
+              </clade>
+              <clade>
+                <taxonomy>
+                  <id type="tol">1269</id>
+                </taxonomy>
+                <clade>
+                  <taxonomy>
+                    <id type="tol">1270</id>
+                    <common_name>Spongopus</common_name>
+                  </taxonomy>
+                </clade>
+                <clade>
+                  <taxonomy>
+                    <id type="tol">1271</id>
+                  </taxonomy>
+                  <clade>
+                    <taxonomy>
+                      <id type="tol">1272</id>
+                      <common_name>Aplocentrus</common_name>
+                    </taxonomy>
+                  </clade>
+                  <clade>
+                    <taxonomy>
+                      <id type="tol">1273</id>
+                      <common_name>Pseudaplocentrus</common_name>
+                    </taxonomy>
+                  </clade>
+                </clade>
+              </clade>
+            </clade>
+          </clade>
+        </clade>
+        <clade>
+          <taxonomy>
+            <id type="tol">1274</id>
+          </taxonomy>
+          <clade>
+            <taxonomy>
+              <id type="tol">1275</id>
+            </taxonomy>
+            <clade>
+              <taxonomy>
+                <id type="tol">1276</id>
+                <common_name>Pseudamphasia</common_name>
+              </taxonomy>
+            </clade>
+            <clade>
+              <taxonomy>
+                <id type="tol">1277</id>
+                <common_name>Amphasia</common_name>
+              </taxonomy>
+            </clade>
+          </clade>
+          <clade>
+            <taxonomy>
+              <id type="tol">1278</id>
+            </taxonomy>
+            <clade>
+              <taxonomy>
+                <id type="tol">1279</id>
+              </taxonomy>
+              <clade>
+                <taxonomy>
+                  <id type="tol">1280</id>
+                  <common_name>Gynandromorphus</common_name>
+                </taxonomy>
+              </clade>
+              <clade>
+                <taxonomy>
+                  <id type="tol">1281</id>
+                  <common_name>Diachromus</common_name>
+                </taxonomy>
+              </clade>
+            </clade>
+            <clade>
+              <taxonomy>
+                <id type="tol">1282</id>
+                <common_name>Dicheirus</common_name>
+              </taxonomy>
+            </clade>
+          </clade>
+        </clade>
+      </clade>
+    </clade>
+  </clade>
+</phylogeny>
+</phyloxml>
\ No newline at end of file

Modified: 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/actions/PhyloTreeImportAction.java
===================================================================
--- 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/actions/PhyloTreeImportAction.java
        2009-08-06 12:40:56 UTC (rev 17720)
+++ 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/actions/PhyloTreeImportAction.java
        2009-08-06 19:04:56 UTC (rev 17721)
@@ -246,8 +246,14 @@
                NodeData nodeData = node.getNodeData();
        
                CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
-               nodeAttributes.setAttribute(nodeID, "Degree", 2);
                
+               if(nodeID.equals("A")||nodeID.equals("B")||nodeID.equals("C"))
+                       nodeAttributes.setAttribute(nodeID, "Degree", 1);
+               else if(nodeID.equals("Node0"))
+                       nodeAttributes.setAttribute(nodeID, "Degree", 2);
+               else
+                       nodeAttributes.setAttribute(nodeID, "Degree", 3);
+                               
                // Check and assign node attributes
                
                if(nodeData.isHasTaxonomy())

Modified: 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/CommonFunctions.java
===================================================================
--- 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/CommonFunctions.java
       2009-08-06 12:40:56 UTC (rev 17720)
+++ 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/CommonFunctions.java
       2009-08-06 19:04:56 UTC (rev 17721)
@@ -272,6 +272,28 @@
        }
 
        /**
+        * Find the depth of the node (Root is depth 0)
+        * @param node - the node whose depth is to be found
+        * @return the depth of the node
+        */
+       public int getDepth(CyNetwork network, Node node)
+       {
+               if(network.getInDegree(node, false) == 0)
+                       {
+                       return 0;
+                       }
+               else
+               {
+                       int [] incomingEdges = 
network.getAdjacentEdgeIndicesArray(node.getRootGraphIndex(), false, true, 
false);
+                       
+                       int depth= getDepth(network, 
network.getEdge(incomingEdges[0]).getSource());
+                               
+                       
+
+                       return depth+1;
+               }
+       }
+       /**
         * Calculate the number of leaves in the tree
         * @return - the number of leaves in the tree
         */

Modified: 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/visualstyle/LevelColor.java
===================================================================
--- 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/visualstyle/LevelColor.java
       2009-08-06 12:40:56 UTC (rev 17720)
+++ 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/visualstyle/LevelColor.java
       2009-08-06 19:04:56 UTC (rev 17721)
@@ -1,11 +1,17 @@
 package org.cytoscape.phylotree.visualstyle;
 
+import cytoscape.data.CyAttributes;
 import cytoscape.visual.VisualStyle;
 
 import cytoscape.CyNetwork;
+import cytoscape.Cytoscape;
+import cytoscape.visual.Appearance;
 import cytoscape.visual.ArrowShape;
+import cytoscape.visual.EdgeAppearance;
 import cytoscape.visual.EdgeAppearanceCalculator;
 import cytoscape.visual.GlobalAppearanceCalculator;
+import cytoscape.visual.LabelPosition;
+import cytoscape.visual.NodeAppearance;
 import cytoscape.visual.NodeAppearanceCalculator;
 import cytoscape.visual.NodeShape;
 import cytoscape.visual.VisualPropertyType;
@@ -18,9 +24,16 @@
 import cytoscape.visual.mappings.LinearNumberToColorInterpolator;
 import cytoscape.visual.mappings.ObjectMapping;
 import cytoscape.visual.mappings.PassThroughMapping;
+import giny.model.Edge;
+import giny.model.Node;
+
 import java.awt.Color;
+import java.util.Iterator;
+import java.util.List;
 
+import org.cytoscape.phylotree.layout.CommonFunctions;
 
+
 public class LevelColor implements PhyloVisualStyle {
        
        public String getName()
@@ -31,80 +44,261 @@
        public VisualStyle createStyle(CyNetwork network)
        {
                
+               // Add attributes defining node level
+               addDepthAttributes(network);
+               
                NodeAppearanceCalculator nodeAppCalc = new 
NodeAppearanceCalculator();
                EdgeAppearanceCalculator edgeAppCalc = new 
EdgeAppearanceCalculator();
                GlobalAppearanceCalculator globalAppCalc = new 
GlobalAppearanceCalculator(); 
+               
+               // Set the background
+               globalAppCalc.setDefaultBackgroundColor(Color.BLACK);
+       //      globalAppCalc.setDefaultBackgroundColor(Color.WHITE);
+               
 
-
                // Passthrough Mapping - set node label 
-               // PassThroughMapping pm = new PassThroughMapping(new String(), 
"attr2");
                PassThroughMapping pm = new PassThroughMapping(new String(), 
"ID");
-               Calculator nlc = new BasicCalculator("Example Node Label 
Calculator",pm, VisualPropertyType.NODE_LABEL);
+               Calculator nlc = new BasicCalculator("Node Label 
Calculator",pm, VisualPropertyType.NODE_LABEL);
                
                nodeAppCalc.setCalculator(nlc);
 
+               // Set node label color
+//             DiscreteMapping disColorMapping = new 
DiscreteMapping(Color.WHITE, ObjectMapping.NODE_MAPPING);
+//             disColorMapping.setControllingAttributeName("Level", network, 
false);
+//             Calculator labelColorCalculator = new BasicCalculator("Node 
Label Color Calculator", disColorMapping, VisualPropertyType.NODE_LABEL_COLOR);
+//             nodeAppCalc.setCalculator(labelColorCalculator);
 
+               
+               NodeAppearance nodeApp = new NodeAppearance();
+               nodeApp.set(VisualPropertyType.NODE_SHAPE, NodeShape.ELLIPSE);
+               nodeApp.set(VisualPropertyType.NODE_LABEL_COLOR, Color.WHITE);
+               nodeApp.set(VisualPropertyType.NODE_LABEL_POSITION, new 
LabelPosition(5,3,2,0,0));
+               nodeApp.set(VisualPropertyType.NODE_FONT_SIZE,20);
+               
+               
+               nodeAppCalc.setDefaultAppearance(nodeApp);
+               
+               
+               EdgeAppearance edgeApp = new EdgeAppearance();
+               edgeApp.set(VisualPropertyType.EDGE_LABEL_COLOR, Color.WHITE);
+               edgeApp.set(VisualPropertyType.EDGE_FONT_SIZE,20);
+               edgeApp.set(VisualPropertyType.EDGE_LINE_WIDTH,10);
+               edgeAppCalc.setDefaultAppearance(edgeApp);
+               
+               
                // Discrete Mapping - set node shapes 
-               DiscreteMapping disMapping = new DiscreteMapping(NodeShape.RECT,
-                                                                
ObjectMapping.NODE_MAPPING);
-               disMapping.setControllingAttributeName("ID", network, false);
-               disMapping.putMapValue(new Integer(1), NodeShape.DIAMOND);
-               disMapping.putMapValue(new Integer(2), NodeShape.ELLIPSE);
-               disMapping.putMapValue(new Integer(3), NodeShape.TRIANGLE);
+//             DiscreteMapping disMapping = new 
DiscreteMapping(NodeShape.ELLIPSE, ObjectMapping.NODE_MAPPING);
+//             disMapping.setControllingAttributeName("Level", network, false);
+//             disMapping.putMapValue(new Integer(0), NodeShape.ELLIPSE);
+//             disMapping.putMapValue(new Integer(1), NodeShape.ELLIPSE);
+//             disMapping.putMapValue(new Integer(2), NodeShape.ELLIPSE);
 
-               Calculator shapeCalculator = new BasicCalculator("Example Node 
Shape Calculator",
-                                                                 
disMapping,VisualPropertyType.NODE_SHAPE);
-               nodeAppCalc.setCalculator(shapeCalculator);
+//             Calculator shapeCalculator = new BasicCalculator("Node Shape 
Calculator",
+       //                                                        
disMapping,VisualPropertyType.NODE_SHAPE);
+               //nodeAppCalc.setCalculator(shapeCalculator);
 
 
-               // Continuous Mapping - set node color 
-               ContinuousMapping continuousMapping = new 
ContinuousMapping(Color.WHITE, 
-                                                            
ObjectMapping.NODE_MAPPING);
-               continuousMapping.setControllingAttributeName("ID", network, 
false);
+//             // Continuous Mapping - set node color 
+//             ContinuousMapping continuousMapping = new 
ContinuousMapping(Color.WHITE, 
+//                                                            
ObjectMapping.NODE_MAPPING);
+//             continuousMapping.setControllingAttributeName("ID", network, 
false);
+//
+//        Interpolator numToColor = new LinearNumberToColorInterpolator();
+//        continuousMapping.setInterpolator(numToColor);
+//
+//             Color underColor = Color.GRAY;
+//             Color minColor = Color.RED;
+//             Color midColor = Color.WHITE;
+//             Color maxColor = Color.GREEN;
+//             Color overColor = Color.BLUE;
+//
+//             // Create boundary conditions                     less than,   
equals,  greater than
+//             BoundaryRangeValues bv0 = new BoundaryRangeValues(underColor, 
minColor, minColor);
+//             BoundaryRangeValues bv1 = new BoundaryRangeValues(midColor, 
midColor, midColor);
+//             BoundaryRangeValues bv2 = new BoundaryRangeValues(maxColor, 
maxColor, overColor);
+//
+//        // Set the attribute point values associated with the boundary 
values 
+//             continuousMapping.addPoint(0.0, bv0);
+//             continuousMapping.addPoint(1.0, bv1);
+//             continuousMapping.addPoint(2.0, bv2);
+//             
+//             Calculator nodeColorCalculator = new BasicCalculator("Example 
Node Color Calc", 
+//                                                             
continuousMapping, 
+//                                                                             
                         VisualPropertyType.NODE_FILL_COLOR);
+               nodeAppCalc.setCalculator(createNodeColorCalculator(network));
+               
 
-        Interpolator numToColor = new LinearNumberToColorInterpolator();
-        continuousMapping.setInterpolator(numToColor);
+               // Discrete Mapping - Set edge target arrow shape       
+//             DiscreteMapping arrowMapping = new 
DiscreteMapping(ArrowShape.NONE,
+//                                                                
ObjectMapping.EDGE_MAPPING);
+//             arrowMapping.setControllingAttributeName("interaction", 
network, false);
+//             arrowMapping.putMapValue("pp", ArrowShape.ARROW);
+//             arrowMapping.putMapValue("pd", ArrowShape.CIRCLE);
+//
+//             Calculator edgeArrowCalculator = new BasicCalculator("Example 
Edge Arrow Shape Calculator",
+//                                              arrowMapping, 
VisualPropertyType.EDGE_TGTARROW_SHAPE);
+//             edgeAppCalc.setCalculator(edgeArrowCalculator);
+               edgeAppCalc.setCalculator(createEdgeColorCalculator(network));
 
-               Color underColor = Color.GRAY;
-               Color minColor = Color.RED;
-               Color midColor = Color.WHITE;
-               Color maxColor = Color.GREEN;
-               Color overColor = Color.BLUE;
+               // Create the visual style 
+               VisualStyle visualStyle = new VisualStyle("LevelColor", 
nodeAppCalc, edgeAppCalc, globalAppCalc);
 
-               // Create boundary conditions                     less than,   
equals,  greater than
+               return visualStyle;
+       }
+
+       private void addDepthAttributes(CyNetwork network)
+       {
+               // Get all nodes
+               List<Node> nodeList = network.nodesList();
+               Iterator<Node> nodeListIterator = nodeList.iterator();
+               
+               
+               CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
+               CyAttributes edgeAttributes = Cytoscape.getEdgeAttributes();
+               CommonFunctions cf = new CommonFunctions();
+               
+               // For each node, find level and set the level
+               while(nodeListIterator.hasNext())
+               {
+                       Node node = nodeListIterator.next();
+                       
+                       int depth = cf.getDepth(network, node);
+                       
+                       nodeAttributes.setAttribute(node.getIdentifier(), 
"Depth", depth);
+                       
+                       int [] edgeIndicesArray 
=network.getAdjacentEdgeIndicesArray(node.getRootGraphIndex(), false, false, 
true); 
+                       for(int i = 0; i<edgeIndicesArray.length; i++)
+                       {
+                               Edge edge = 
network.getEdge(edgeIndicesArray[i]);
+                               
edgeAttributes.setAttribute(edge.getIdentifier(),"Depth", depth);
+                               
+                       }
+               }
+               
+       }
+       
+       private Calculator createNodeColorCalculator(CyNetwork network) {
+               // Determine the min and max for degree
+               CyAttributes cyNodeAttrs = Cytoscape.getNodeAttributes();
+
+               int min = 0;
+               int max =0;
+
+               Iterator<Node> it = network.nodesIterator();
+               while (it.hasNext()) {
+                       Node node = (Node) it.next();
+                       Integer value = 
cyNodeAttrs.getIntegerAttribute(node.getIdentifier(), "Depth");
+                       if (value.intValue() < min) {
+                               min = value.intValue();
+                       }
+                       else if (value.intValue() > max) {
+                               max = value.intValue();
+                       }
+               }
+               
+               // pick 3 points within (min~max)
+               double p1 = min + (max-min)/3.0;
+               double p2 = p1 + (max-min)/3.0;
+               double p3 = p2 + (max-min)/3.0;
+               
+               // Create a calculator for "Degree" attribute
+               VisualPropertyType type = VisualPropertyType.NODE_FILL_COLOR;
+               final Object defaultObj = 
type.getDefault(Cytoscape.getVisualMappingManager().getVisualStyle());
+               
+               ContinuousMapping cm = new ContinuousMapping(defaultObj, 
ObjectMapping.NODE_MAPPING);
+               // Set controlling Attribute
+               cm.setControllingAttributeName("Depth", 
Cytoscape.getCurrentNetwork(), false);
+
+               Interpolator numToColor = new LinearNumberToColorInterpolator();
+               cm.setInterpolator(numToColor);
+               
+               // Power of the Sun
+               Color underColor = new Color(87,12,12);
+               Color minColor = new Color(91,33,15);
+               Color midColor = new Color(121,67,44);
+               Color maxColor = new Color(134,91,39);
+               Color overColor = new Color(151,136,53);
+                               
+               // Dark Knight
+//             Color underColor = new Color(8,33,75);
+//             Color minColor = new Color(30,55,98);
+//             Color midColor = new Color(55,82,127);
+//             Color maxColor = new Color(105,126,160);
+//             Color overColor = new Color(131,149,177);
+               
+               
+               // Froggy electric
+//             Color underColor = new Color(43,166,189);
+//             Color minColor = new Color(43,166,156);
+//             Color midColor = new Color(0,236,141);
+//             Color maxColor = new Color(0,236,120);
+//             Color overColor = new Color(140,201,77);
+               
+               
                BoundaryRangeValues bv0 = new BoundaryRangeValues(underColor, 
minColor, minColor);
                BoundaryRangeValues bv1 = new BoundaryRangeValues(midColor, 
midColor, midColor);
                BoundaryRangeValues bv2 = new BoundaryRangeValues(maxColor, 
maxColor, overColor);
-
-        // Set the attribute point values associated with the boundary values 
-               continuousMapping.addPoint(0.0, bv0);
-               continuousMapping.addPoint(1.0, bv1);
-               continuousMapping.addPoint(2.0, bv2);
                
-               Calculator nodeColorCalculator = new BasicCalculator("Example 
Node Color Calc", 
-                                                               
continuousMapping, 
-                                                                               
                         VisualPropertyType.NODE_FILL_COLOR);
-               nodeAppCalc.setCalculator(nodeColorCalculator);
+               // Set the attribute point values associated with the boundary 
values
+               cm.addPoint(p1, bv0);
+               cm.addPoint(p2, bv1);
+               cm.addPoint(p3, bv2);
+               
+               // Create a calculator
+               return new BasicCalculator("Node Color calcualtor", cm, 
VisualPropertyType.NODE_FILL_COLOR);                    
+       }
 
+       private Calculator createEdgeColorCalculator(CyNetwork network) {
+               // Determine the min and max for degree
+               CyAttributes cyEdgeAttrs = Cytoscape.getEdgeAttributes();
 
-               // Discrete Mapping - Set edge target arrow shape       
-               DiscreteMapping arrowMapping = new 
DiscreteMapping(ArrowShape.NONE,
-                                                                  
ObjectMapping.EDGE_MAPPING);
-               arrowMapping.setControllingAttributeName("interaction", 
network, false);
-               arrowMapping.putMapValue("pp", ArrowShape.ARROW);
-               arrowMapping.putMapValue("pd", ArrowShape.CIRCLE);
+               int min = 0;
+               int max =0;
 
-               Calculator edgeArrowCalculator = new BasicCalculator("Example 
Edge Arrow Shape Calculator",
-                                              arrowMapping, 
VisualPropertyType.EDGE_TGTARROW_SHAPE);
-               edgeAppCalc.setCalculator(edgeArrowCalculator);
+               Iterator<Edge> it = network.edgesIterator();
+               while (it.hasNext()) {
+                       Edge edge = (Edge) it.next();
+                       Integer value = 
cyEdgeAttrs.getIntegerAttribute(edge.getIdentifier(), "Depth");
+                       if (value.intValue() < min) {
+                               min = value.intValue();
+                       }
+                       else if (value.intValue() > max) {
+                               max = value.intValue();
+                       }
+               }
+               
+               // pick 3 points within (min~max)
+               double p1 = min + (max-min)/3.0;
+               double p2 = p1 + (max-min)/3.0;
+               double p3 = p2 + (max-min)/3.0;
+               
+               // Create a calculator for "Degree" attribute
+               VisualPropertyType type = VisualPropertyType.EDGE_COLOR;
+               final Object defaultObj = 
type.getDefault(Cytoscape.getVisualMappingManager().getVisualStyle());
+               
+               ContinuousMapping cm = new ContinuousMapping(defaultObj, 
ObjectMapping.EDGE_MAPPING);
+               // Set controlling Attribute
+               cm.setControllingAttributeName("Depth", 
Cytoscape.getCurrentNetwork(), false);
 
+               Interpolator numToColor = new LinearNumberToColorInterpolator();
+               cm.setInterpolator(numToColor);
 
-               // Create the visual style 
-               VisualStyle visualStyle = new VisualStyle("LevelColor", 
nodeAppCalc, edgeAppCalc, globalAppCalc);
-
-               return visualStyle;
+               Color underColor = new Color(87,12,12);
+               Color minColor = new Color(91,33,15);
+               Color midColor = new Color(121,67,44);
+               Color maxColor = new Color(134,91,39);
+               Color overColor = new Color(151,136,53);
+               
+               BoundaryRangeValues bv0 = new BoundaryRangeValues(underColor, 
minColor, minColor);
+               BoundaryRangeValues bv1 = new BoundaryRangeValues(midColor, 
midColor, midColor);
+               BoundaryRangeValues bv2 = new BoundaryRangeValues(maxColor, 
maxColor, overColor);
+               
+               // Set the attribute point values associated with the boundary 
values
+               cm.addPoint(p1, bv0);
+               cm.addPoint(p2, bv1);
+               cm.addPoint(p3, bv2);
+               
+               // Create a calculator
+               return new BasicCalculator("Edge Color calcualtor", cm, 
VisualPropertyType.EDGE_COLOR);                 
        }
-
-       
-
 }


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