Author: clopes
Date: 2011-10-12 16:28:29 -0700 (Wed, 12 Oct 2011)
New Revision: 27151
Modified:
cytoscapeweb/branches/compound/html-template/js/compound.js
cytoscapeweb/branches/compound/src/org/cytoscapeweb/model/converters/ExternalObjectConverter.as
Log:
JS NetworkModel API: Removed "network" data field from compound nodes--just use
data.parent instead.
Modified: cytoscapeweb/branches/compound/html-template/js/compound.js
===================================================================
--- cytoscapeweb/branches/compound/html-template/js/compound.js 2011-10-12
22:41:07 UTC (rev 27150)
+++ cytoscapeweb/branches/compound/html-template/js/compound.js 2011-10-12
23:28:29 UTC (rev 27151)
@@ -470,20 +470,15 @@
{ name: "weight", type: "number" } ]
},
data: {
- nodes: [ { id: "n1", label: "n1", network: {
- nodes: [ { id: "n11",
label: "n11"},
- { id: "n12",
label: "n12"},
- { id: "n13",
label: "n13", network: {
- nodes:
[{id: "n131", label: "n131"}]
- }
- }],
- edges: [ { id: "e12",
label: "e12", weight: 1.2, source: "n11", target: "n12" } ]
- }
- },
- { id: "n2", label: "n2"}/*,
- { id: "n3", label: "n3", network: { } }*/ ],
+ nodes: [ { id: "n1", label: "n1" },
+ { id: "n2", label: "n2" },
+ { id: "n11", label: "n11", parent: "n1" },
+ { id: "n12", label: "n12", parent: "n1" },
+ { id: "n13", label: "n13", parent: "n1" },
+ { id: "n131", label: "n131", parent: "n13" } ],
edges: [ { id: "e1", label: "e1", weight: 1.1, source:
"n1", target: "n2" },
- { id: "e2", label: "e2", weight: 1.6, source:
"n2", target: "n12" }]
+ { id: "e2", label: "e2", weight: 1.6, source:
"n2", target: "n12" },
+ { id: "e12", label: "e12", weight: 1.2,
source: "n11", target: "n12" }]
}
};
@@ -572,36 +567,8 @@
return array;
}
-/*
-function createObjectData()
-{
- var data = {
- dataSchema: {
- nodes: [ { name: "label", type: "string" } ],
- edges: [ { name: "label", type: "string" },
- { name: "weight", type: "number" } ]
- },
- data: {
- nodes: [ { id: "n0", label: "n0"},
- { id: "n1", label: "n1"},
- { id: "n2", label: "n2", network: { nodes: [ {
id: "n2:n0", label: "n2:n0"} ]} }],
- edges: [ { id: "e0", label: "e0", weight: 1.1, source:
"n1", target: "n0" },
- { id: "e1", label: "e1", weight: 1.1, source:
"n2:n0", target: "n0" },
- { id: "e2", label: "e2", weight: 1.1, source:
"n1", target: "n2" }]
- }
- };
-
- return data;
-}
-*/
-
-/*
- *
- */
-function clickNodeToAddEdge(evt)
-{
- if (_srcId != null)
- {
+function clickNodeToAddEdge(evt) {
+ if (_srcId != null) {
vis.removeListener("click", "nodes", clickNodeToAddEdge);
var e = vis.addEdge({ source: _srcId,
target: evt.target.data.id,
@@ -630,17 +597,13 @@
/*
* Add items to context menu
*/
-function initContextMenu()
-{
+function initContextMenu() {
+
vis.addContextMenuItem("Add new node", function(evt) {
var label = "node " + autoLabel;
autoLabel++;
- var n = vis.addNode(evt.mouseX,
- evt.mouseY,
- {label: label},
- true,
- evt.target);
+ var n = vis.addNode(evt.mouseX, evt.mouseY, {label: label},
true, evt.target);
});
vis.addContextMenuItem("Toggle node labels", function(evt) {
Modified:
cytoscapeweb/branches/compound/src/org/cytoscapeweb/model/converters/ExternalObjectConverter.as
===================================================================
---
cytoscapeweb/branches/compound/src/org/cytoscapeweb/model/converters/ExternalObjectConverter.as
2011-10-12 22:41:07 UTC (rev 27150)
+++
cytoscapeweb/branches/compound/src/org/cytoscapeweb/model/converters/ExternalObjectConverter.as
2011-10-12 23:28:29 UTC (rev 27151)
@@ -44,7 +44,6 @@
import flash.utils.IDataInput;
import flash.utils.IDataOutput;
- import org.cytoscapeweb.model.data.GraphicsDataTable;
import org.cytoscapeweb.model.error.CWError;
import org.cytoscapeweb.util.DataSchemaUtils;
import org.cytoscapeweb.util.ErrorCodes;
@@ -67,8 +66,6 @@
public static const TYPE:String = "type";
public static const DEF_VALUE:String = "defValue";
- public static const NETWORK:String = "network";
-
private static const NODE_ATTR:Object = {
id: 1
}
@@ -210,7 +207,6 @@
* @param nodeSchema DataSchema for data fields of nodes
* @param edgeSchema DataSchema for data fields of edges
* @param lookup lookup map (by id) for nodes
- * @param parentId optional parent id for
recursive calls
*/
private static function readData(extNodesData:Array,
extEdgesData:Array,
@@ -218,8 +214,7 @@
edges:Array,
nodeSchema:DataSchema,
edgeSchema:DataSchema,
- lookup:Object,
- parentId:String=null):void
{
+ lookup:Object):void {
var obj:Object;
var id:String, sid:String, tid:String;
var cns:CompoundNodeSprite;
@@ -227,32 +222,11 @@
// Nodes
for each (obj in extNodesData) {
cns = new CompoundNodeSprite();
-
- // check for a sub-network. If the sub network
exists,
- // recursively read sub-network data.
- if (obj[NETWORK] != null) {
- // initialize compound node in order to
add child nodes
- cns.initialize();
-
- readData(obj[NETWORK][Groups.NODES],
obj[NETWORK][Groups.EDGES],
- nodes, edges,
- nodeSchema, edgeSchema,
- lookup,
obj[DataSchemaUtils.ID]);
-
- // delete the sub-network field after
processing
- delete obj[NETWORK];
- }
-
normalizeData(obj, nodeSchema)
id = obj[DataSchemaUtils.ID];
cns.data = obj;
lookup[id] = cns;
- // update parent id of the current node
- if (parentId != null) {
- cns.data.parent = parentId;
- }
-
// add the node to the array of compound nodes
nodes.push(cns);
}
@@ -297,76 +271,17 @@
* @return object representing the given data set
*/
public static function toExtNetworkModel(ds:DataSet):Object {
- if (!(ds.nodes is GraphicsDataTable) || !(ds.edges is
GraphicsDataTable)) {
- return toExtSimpleNetworkModel(ds); // TODO:
why?
- }
-
- var objectModel:Object = new Object();
- var lookup:Object = new Object();
-
- // add schema
- objectModel[SCHEMA] = toExtSchema(ds.nodes.schema,
ds.edges.schema);
-
- // for each node, create an object and add it to the
array of nodes
- var nodesTable:GraphicsDataTable = ds.nodes as
GraphicsDataTable;
- var nodesArray:Array = new Array();
- var nodeObject:Object;
-
- for each (var ns:NodeSprite in nodesTable.dataSprites) {
- // process only parentless nodes, other nodes
are processed
- // during recursive calls
- if (ns.data.parent == null) {
- // create & store node object
- nodeObject = toExtNodeObject(ns,
lookup);
- nodesArray.push(nodeObject);
- }
- }
-
- // for each edge
- var edgesTable:GraphicsDataTable = ds.edges as
GraphicsDataTable;
- var edgesArray:Array = new Array();
-
- for each (var es:EdgeSprite in edgesTable.dataSprites) {
- var sParentId:String;
- var tParentId:String;
- var compound:Object = null;
-
- sParentId = es.source.data.parent;
- tParentId = es.target.data.parent;
-
- // if both source and target parents are in the
same
- // subgraph (i.e. in the same compound), then
the edge
- // information will be written to the
corresponding
- // compound node object.
- if (sParentId != null && tParentId != null &&
sParentId == tParentId) {
- // try to get the object corresponding
to the parent
- compound = lookup[sParentId];
- }
-
- // check if the target compound is valid
- if (compound != null) {
- // initialize array of edges if not
initialized before
- if (compound[NETWORK][Groups.EDGES] ==
null) {
- compound[NETWORK][Groups.EDGES]
= new Array();
- }
-
- // add edge to the array
- (compound[NETWORK][Groups.EDGES] as
Array).push(es.data);
- }
- // edge is either inter-graph edge, or a
top-level edge
- else
- {
- // add the edge data to the edges array
- edgesArray.push(es.data);
- }
- }
-
- // add graph data
- objectModel[DATA] = new Object();
- objectModel[DATA][Groups.NODES] = nodesArray;
- objectModel[DATA][Groups.EDGES] = edgesArray;
-
- return objectModel;
+ var obj:Object = {};
+
+ // Add schema
+ obj[SCHEMA] = toExtSchema(ds.nodes.schema, ds.edges.schema);
+
+ // Add graph data
+ obj[DATA] = {};
+ obj[DATA][Groups.NODES] = ds.nodes.data;
+ obj[DATA][Groups.EDGES] = ds.edges.data;
+
+ return obj;
}
@@ -536,58 +451,6 @@
// -- static helpers --------------------------------------------------
- /**
- * This function creates an object representing the given node
sprite.
- * If the given node is a compound node, then recursively
creates
- * its sub-network as an array of objects.
- *
- * @param ns node to be converted to an object
- * @param lookup lookup object to store compound nodes
- * @return an object representing the
given node sprite
- */
- private static function toExtNodeObject(ns:NodeSprite,
- lookup:Object) : Object
- {
- // create node object
-
- var nodeObject:Object = new Object();
- var nodes:Array;
-
- // copy node data
- for (var name:String in ns.data)
- {
- nodeObject[name] = ns.data[name];
- }
-
- if (ns is CompoundNodeSprite)
- {
- var cns:CompoundNodeSprite = ns as
CompoundNodeSprite;
-
- if (cns.isInitialized())
- {
- var childObj:Object;
-
- // recursively create sub network of
the compound
-
- nodeObject[NETWORK] = new Object();
- nodes = new Array();
-
- for each (var child:NodeSprite in
cns.getNodes())
- {
- childObj =
toExtNodeObject(child, lookup);
- nodes.push(childObj);
- }
-
- nodeObject[NETWORK][Groups.NODES] =
nodes;
-
- // store compound node object
- lookup[cns.data.id] = nodeObject;
- }
- }
-
- return nodeObject;
- }
-
private static function toCW_Type(type:String):int {
switch (type) {
case INT:
--
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.