Author: Christian Lopes
Date: 2010-11-29 14:15:23 -0800 (Mon, 29 Nov 2010)
New Revision: 23043

Modified:
   cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js
   cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js
   
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/ExternalObjectConverter.as
   
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/InteractionVO.as
   cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/Layouts.as
   cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ExternalMediator.as
   
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as
Log:
Finished the NetworkModel API for drawing a network with pure JavaScript 
objects, rather than XML/SIF files.
Changed how the Tree Layout defines the default root node when the network is 
directed.
Fixed bug that could lead to incorrect edge curvature, when applying and 
removing edge filters.

Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js    
2010-11-29 22:07:58 UTC (rev 23042)
+++ cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js    
2010-11-29 22:15:23 UTC (rev 23043)
@@ -187,11 +187,15 @@
          *
          * @param {Object} options
          *               <ul class="options">
-         *                    <li><code>network</code>: The string that 
describes the network. Cytoscape supports one of the following formats:
-         *                                              <a 
href="http://graphml.graphdrawing.org/primer/graphml-primer.html"; 
target="_blank">GraphML</a>,
-         *                                              <a 
href="http://www.cs.rpi.edu/~puninj/XGMML/"; target="_blank">XGMML</a> or
-         *                                              <a 
href="http://cytoscape.wodaklab.org/wiki/Cytoscape_User_Manual/Network_Formats/";
 target="_blank">SIF</a>.
-         *                                              Only this option is 
mandatory.</li>
+         *                    <li><code>network</code>: The model that 
describes the network. Only this option is mandatory. It can be one of the 
following formats:
+         *                                              <ul><li>{...@link 
org.cytoscapeweb.NetworkModel}: A simple JavaScript object that defines the raw 
data from which to build a network.</li>
+         *                                                  <li><a 
href="http://graphml.graphdrawing.org/primer/graphml-primer.html"; 
target="_blank">GraphML</a>: An XML format for graphs.</li>
+         *                                                  <li><a 
href="http://www.cs.rpi.edu/~puninj/XGMML/"; target="_blank">XGMML</a>: This XML 
format allows you to define
+         *                                                      visual 
properties (e.g. colors and shapes) and nodes positioning, if you want to,
+         *                                                      although using 
the <code>visualStyle</code> and <code>layout</code> options is usually 
better.</li>
+         *                                                  <li><a 
href="http://cytoscape.wodaklab.org/wiki/Cytoscape_User_Manual/Network_Formats/";
 target="_blank">SIF</a>: A simpler text format
+         *                                                      that can be 
very useful if you do not need to set custom nodes/edges attributes.</li>
+         *                                              </ul></li>
          *                    <li><code>visualStyle</code>: an optional 
{...@link org.cytoscapeweb.VisualStyle} object to be applied on this 
network.</li>
          *                    <li><code>layout</code>: an optional {...@link 
org.cytoscapeweb.Layout} object, or just the layout name.
          *                                             The default is 
"ForceDirected", unless the network data is an 
@@ -1166,14 +1170,14 @@
         },
 
         /**
-         * <p>Return the network as an object.</p>
-         * @return {org.cytoscapeweb.Network} The network as a JavaScript 
object.
+         * <p>Return the network model as an object.</p>
+         * @return {org.cytoscapeweb.NetworkModel} The network model as a 
JavaScript object.
          * @see org.cytoscapeweb.Visualization#graphml
          * @see org.cytoscapeweb.Visualization#xgmml
          * @see org.cytoscapeweb.Visualization#sif
          */
-        network: function () {
-            return this.swf().getNetwork();
+        networkModel: function () {
+            return this.swf().getNetworkModel();
         },
         
         /**
@@ -1181,7 +1185,7 @@
          * @return {String} The XML text.
          * @see org.cytoscapeweb.Visualization#xgmml
          * @see org.cytoscapeweb.Visualization#sif
-         * @see org.cytoscapeweb.Visualization#network
+         * @see org.cytoscapeweb.Visualization#networkModel
          */
         graphml: function () {
                return this.swf().getNetworkAsText("graphml");
@@ -1192,7 +1196,7 @@
          * @return {String} The XML text.
          * @see org.cytoscapeweb.Visualization#graphml
          * @see org.cytoscapeweb.Visualization#sif
-         * @see org.cytoscapeweb.Visualization#network
+         * @see org.cytoscapeweb.Visualization#networkModel
          */
         xgmml: function () {
             return this.swf().getNetworkAsText("xgmml");
@@ -1237,7 +1241,7 @@
          * @return {String} The SIF text.
          * @see org.cytoscapeweb.Visualization#graphml
          * @see org.cytoscapeweb.Visualization#xgmml
-         * @see org.cytoscapeweb.Visualization#network
+         * @see org.cytoscapeweb.Visualization#networkModel
          */
         sif: function (interactionAttr) {
             return this.swf().getNetworkAsText("sif", { interactionAttr: 
interactionAttr });
@@ -1996,6 +2000,52 @@
         this.mouseY = options.mouseY;
     };
     
+    // ===[ NetworkModel 
]==========================================================================
+    
+    /**
+     * <p>This object represents a NetworkModel type, but is actually just an 
untyped object.</p>
+     * <p>It defines the raw data (nodes and edges data values) and the data 
schema for a network.
+     * It is important to notice that the network model does <b>not</b> 
contain {...@link org.cytoscapeweb.Node} and {...@link org.cytoscapeweb.Edge} 
objects, 
+     * as it is not supposed to describe visual attributes such as colors, 
shapes and x/y coordinates.
+     * Visual styles must be defined separately, through {...@link 
org.cytoscapeweb.VisualStyle} or {...@link org.cytoscapeweb.VisualStyleBypass}.
+     * Nodes positioning are done by {...@link org.cytoscapeweb.Layout} 
objects.</p>
+     * <p>A NetworkModel object has only two fields:</p>
+     * <ul class="options">
+      *     <li><code>dataSchema</code> {...@link 
org.cytoscapeweb.DataSchema}}: It defines the nodes/edges data fields.</li>
+      *     <li><code>data</code> {Object}: The actual nodes/edges data values 
used to create {...@link org.cytoscapeweb.Node} and {...@link 
org.cytoscapeweb.Edge} elements.
+      *         It contains two fields (<code>nodes</code> and 
<code>edges</code>), which are arrays of nodes/edges data objects.</li>
+      *</ul>
+     * @example
+     * var network = {
+     * 
+     *     dataSchema: {
+     *         nodes: [ { name: "label", type: "string" },
+     *                  { name: "score", type: "number" } ],
+     *                  
+     *         edges: [ { name: "label", type: "string" },
+     *                  { name: "weight", type: "number" },
+     *                  { name: "directed", type: "boolean", defValue: true} ]
+     *     },
+     *     
+     *     data: {
+     *         nodes: [ { id: "n1", label: "Node 1", score: 1.0 },
+     *                  { id: "n2", label: "Node 2", score: 2.2 },
+     *                  { id: "n3", label: "Node 3", score: 3.5 } ],
+     *                  
+     *         edges: [ { id: "e1", label: "Edge 1", weight: 1.1, source: 
"n1", target: "n3" },
+     *                  { id: "e2", label: "Edge 2", weight: 3.3, source:"n2", 
target:"n1"} ]
+     *     }
+     * };
+     * @class
+     * @name NetworkModel
+     * @type Object
+     * @memberOf org.cytoscapeweb
+     * @see org.cytoscapeweb.Visualization#draw
+     * @see org.cytoscapeweb.Visualization#networkModel
+     * @see org.cytoscapeweb.Visualization#dataSchema
+     * @see org.cytoscapeweb.DataSchema
+     */
+    
     // ===[ Node 
]==================================================================================
      
     /**

Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js   2010-11-29 
22:07:58 UTC (rev 23042)
+++ cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js   2010-11-29 
22:15:23 UTC (rev 23043)
@@ -1193,8 +1193,8 @@
        ok(fail === false, "Null 'name' throws exception");
     });
     
-    test("Network", function() {
-       var net = vis.network();
+    test("NetworkModel", function() {
+       var model = vis.networkModel();
        var nodes = vis.nodes();
        var edges = vis.edges();
        var schema = vis.dataSchema();
@@ -1204,9 +1204,9 @@
        $.each(nodes, function(i, n) { nodesData.push(n.data); });
        $.each(edges, function(i, e) { edgesData.push(e.data); });
 
-       same(net.schema, schema, "Schema");
-       same(net.data.nodes, nodesData, "Nodes Data");
-       same(net.data.edges, edgesData, "Edges Data");
+       same(model.dataSchema, schema, "Schema");
+       same(model.data.nodes, nodesData, "Nodes Data");
+       same(model.data.edges, edgesData, "Edges Data");
     });
     
     test("GraphML", function() {

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/ExternalObjectConverter.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/ExternalObjectConverter.as
    2010-11-29 22:07:58 UTC (rev 23042)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/ExternalObjectConverter.as
    2010-11-29 22:15:23 UTC (rev 23043)
@@ -56,7 +56,7 @@
         
         // ========[ CONSTANTS 
]====================================================================
         
-        public static const SCHEMA:String = "schema";
+        public static const SCHEMA:String = "dataSchema";
         public static const DATA:String = "data";
         public static const NAME:String = "name";
         public static const TYPE:String = "type";
@@ -92,7 +92,7 @@
         /** @inheritDoc */
         public function write(ds:DataSet, output:IDataOutput=null):IDataOutput 
{
             // Plain object to output
-            var obj:Object = toExtNetwork(ds);
+            var obj:Object = toExtNetworkModel(ds);
             
             if (output == null) output = new ByteArray();
             output.writeObject(obj);
@@ -184,7 +184,7 @@
             );
         }
         
-        public static function toExtNetwork(ds:DataSet):Object {
+        public static function toExtNetworkModel(ds:DataSet):Object {
             var obj:Object = {};
             
             // Add schema

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/InteractionVO.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/InteractionVO.as
    2010-11-29 22:07:58 UTC (rev 23042)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/InteractionVO.as
    2010-11-29 22:15:23 UTC (rev 23043)
@@ -158,11 +158,13 @@
                 // Summed weight:
                 var w:Number = Number(e.data.weight);
                 if (!isNaN(w)) weight += w;
+                e.dirty();
             }
 
             // Other cached data:
             mergedEdge.data.weight = weight;
             mergedEdge.props.$filteredOut = edgesList.length === 0;
+            mergedEdge.dirty();
                }
                
                public static function createKey(node1:NodeSprite, 
node2:NodeSprite):String {

Modified: cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/Layouts.as
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/Layouts.as        
2010-11-29 22:07:58 UTC (rev 23042)
+++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/Layouts.as        
2010-11-29 22:15:23 UTC (rev 23043)
@@ -29,6 +29,9 @@
 */
 package org.cytoscapeweb.util {
     import flare.util.Orientation;
+    import flare.vis.data.Data;
+    import flare.vis.data.DataList;
+    import flare.vis.data.NodeSprite;
     
     import org.cytoscapeweb.view.layout.ForceDirectedLayout;
     
@@ -107,6 +110,18 @@
             return o;
         }
         
+        public static function rootNode(data:Data):NodeSprite {
+            var nodes:DataList = data.nodes;
+            
+            if (data.directedEdges) {
+                for each (var n:NodeSprite in nodes) {
+                    if (n.inDegree === 0 && n.outDegree > 0) return n;
+                }
+            }
+            
+            return data.nodes[0];
+        }
+        
         // ========[ PRIVATE METHODS 
]==============================================================
 
     }

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ExternalMediator.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ExternalMediator.as   
    2010-11-29 22:07:58 UTC (rev 23042)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ExternalMediator.as   
    2010-11-29 22:15:23 UTC (rev 23043)
@@ -423,7 +423,7 @@
                 sendNotification(ApplicationFacade.UPDATE_DATA, { group: 
group, items: items, data: data });
         }
         
-        private function getNetwork():Object {
+        private function getNetworkModel():Object {
                var data:Object = graphProxy.graphData;
                var nodesSchema:DataSchema = graphProxy.nodesSchema;
                var edgesSchema:DataSchema = graphProxy.edgesSchema;
@@ -432,7 +432,7 @@
             var edgesTable:GraphicsDataTable = new 
GraphicsDataTable(data.group(Groups.REGULAR_EDGES), edgesSchema);
             var ds:DataSet = new DataSet(nodesTable, edgesTable);
                
-            return ExternalObjectConverter.toExtNetwork(ds);
+            return ExternalObjectConverter.toExtNetworkModel(ds);
         }
         
         private function getNetworkAsText(format:String="xgmml", 
options:Object=null):String {
@@ -484,7 +484,7 @@
                                         "getVisualStyleBypass", 
"setVisualStyleBypass",
                                         "addNode", "addEdge", "removeElements",
                                         "getDataSchema", "addDataField", 
"removeDataField", "updateData",
-                                        "getNetwork", "getNetworkAsText", 
"getNetworkAsImage", 
+                                        "getNetworkModel", "getNetworkAsText", 
"getNetworkAsImage", 
                                         "exportNetwork" ];
 
                 for each (var f:String in functions) addFunction(f);

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as
    2010-11-29 22:07:58 UTC (rev 23042)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as
    2010-11-29 22:15:23 UTC (rev 23043)
@@ -274,7 +274,7 @@
                         var d:Data = _dataList[i];
                         if (d.nodes.length > 1) {
                             var rect:Rectangle = 
GraphUtils.calculateGraphDimension(d.nodes, _layoutName, _style); 
-                            var root:NodeSprite = d.nodes[0];
+                            var root:NodeSprite = Layouts.rootNode(data);
                             
                             layout = createLayout(layoutObj, d, rect, root);
                             _appliedLayouts.push(layout);

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