Author: Christian Lopes Date: 2010-09-01 08:31:59 -0700 (Wed, 01 Sep 2010) New Revision: 21652
Added: cytoscapeweb/trunk/cytoscapeweb/lib-dev/assets/ Modified: cytoscapeweb/trunk/cytoscapeweb/default.properties cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js cytoscapeweb/trunk/cytoscapeweb/html-template/sample.html cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/ApplicationFacade.as cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/Layouts.as cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ApplicationMediator.as cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ExternalMediator.as cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/GraphMediator.as cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/layout/ForceDirectedLayout.as Log: Added dataSchema() function to the API. Attempt to fix stuck pan mode issue (http://cbio.mskcc.org/cytoscape/bugs/view.php?id=2329), by listening to ACTIVATE/DEACTIVATE events--It does not work because of a Flash bug (http://bugs.adobe.com/jira/browse/FP-892). Modified: cytoscapeweb/trunk/cytoscapeweb/default.properties =================================================================== --- cytoscapeweb/trunk/cytoscapeweb/default.properties 2010-08-31 23:56:11 UTC (rev 21651) +++ cytoscapeweb/trunk/cytoscapeweb/default.properties 2010-09-01 15:31:59 UTC (rev 21652) @@ -1,3 +1,3 @@ -build.version=0.5 +build.version=0.6 FLEX_HOME=/Applications/Adobe Flex Builder 3 Plug-in/sdks/3.2.0/ \ No newline at end of file Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js =================================================================== --- cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js 2010-08-31 23:56:11 UTC (rev 21651) +++ cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js 2010-09-01 15:31:59 UTC (rev 21652) @@ -764,6 +764,22 @@ }, /** + * <p>Get the network data schema, which contains all the nodes and edges data fields.</p> + * @example + * var schema = vis.dataSchema(); + * var nodeFields = schema.nodes; + * var edgeFields = schema.edges; + * + * @return {org.cytoscapeweb.DataSchema} The data schema object. + * @see org.cytoscapeweb.Visualization#addDataField + * @see org.cytoscapeweb.Visualization#removeDataField + * @see org.cytoscapeweb.Visualization#updateData + */ + dataSchema: function () { + return this.swf().getDataSchema(); + }, + + /** * <p>Add a custom attribute definition to the current node or edge data schema.</p> * <p>If an attribute with the same name is already defined for the same group, * the attribute will not be added again or replace the previous definitions.</p> @@ -778,28 +794,22 @@ * * @param {org.cytoscapeweb.Group} [gr] The group of network elements. If no group is passed, * Cytoscape Web will try to add the new field to both nodes and edges data schema. - * @param {Object} dataField An object that contains the attribute definitions: - * <ul class="options"> - * <li><code>name</code>: The name of the new data attribute.</li> - * <li><code>type</code>: The data type of the attribute. One of: - * <code>"string"</code>, <code>"boolean"</code>, - * <code>"number"</code>, <code>"int"</code>, <code>"object"</code>.</li> - * <li><code>defValue</code>: An optional default value.</li> - * </ul> + * @param {org.cytoscapeweb.DataField} dataField An object that contains the attribute definitions. * @return {org.cytoscapeweb.Visualization} The Visualization instance. * @see org.cytoscapeweb.Visualization#removeDataField * @see org.cytoscapeweb.Visualization#updateData + * @see org.cytoscapeweb.Visualization#dataSchema */ addDataField: function (/*gr, dataField*/) { - var gr, dataField, i = 0; - if (arguments.length > 1) { gr = arguments[i++]; } - dataField = arguments[i]; - if (dataField == null) { throw("The 'dataField' object is mandatory."); } - if (dataField.name == null) { throw("The 'name' of the data field is mandatory."); } - if (dataField.type == null) { throw("The 'type' of the data field is mandatory."); } - gr = this._normalizeGroup(gr); - this.swf().addDataField(gr, dataField); - return this; + var gr, dataField, i = 0; + if (arguments.length > 1) { gr = arguments[i++]; } + dataField = arguments[i]; + if (dataField == null) { throw("The 'dataField' object is mandatory."); } + if (dataField.name == null) { throw("The 'name' of the data field is mandatory."); } + if (dataField.type == null) { throw("The 'type' of the data field is mandatory."); } + gr = this._normalizeGroup(gr); + this.swf().addDataField(gr, dataField); + return this; }, /** @@ -824,6 +834,7 @@ * @return {org.cytoscapeweb.Visualization} The Visualization instance. * @see org.cytoscapeweb.Visualization#addDataField * @see org.cytoscapeweb.Visualization#updateData + * @see org.cytoscapeweb.Visualization#dataSchema */ removeDataField: function (/*gr, name*/) { var gr, name, i = 0; @@ -897,6 +908,7 @@ * @return {org.cytoscapeweb.Visualization} The Visualization instance. * @see org.cytoscapeweb.Visualization#addDataField * @see org.cytoscapeweb.Visualization#removeDataField + * @see org.cytoscapeweb.Visualization#dataSchema */ updateData: function (/*gr, items, data*/) { var gr, items, data; @@ -1934,7 +1946,7 @@ */ this.mouseY = options.mouseY; }; - + // ===[ Node ]================================================================================== /** @@ -2235,6 +2247,12 @@ * of <code>iterations</code>, until each edge length seems constant or until the * <code>maxTime</code> is reached. Set <code>false</code> if you think the results * look worse than expected, or if the layout is taking too long to execute.</li> + * <li><code>weightAttr</code> {String}: The name of the edge attribute that contains the weights. + * The default value is <code>null</code>, which means that the layout is unweighted. + * If you want to generate an edge-weighted layout, you just need to specify the attribute name. + * <li><code>weightNorm</code> {String}: The normalization method that is applied to the weight values when using a weighted layout. + * Possible values are: <code>"linear"</code>, <code>"inverselinear"</code> and <code>"log"</code>. + * The default value is <code>"linear"</code>. * </ul> * <li><b>Circle:</b></li> * <ul class="options"> @@ -2700,7 +2718,59 @@ * @type String * @memberOf org.cytoscapeweb.Error# */ + + // ===[ Data Schema ]================================================================================== + /** + * <p>This is an untyped object that represents a Data Schema type.</p> + * <p>A data schema is automatically created when a network is loaded into Cytoscape Web, + * and cannot be created programatically through the API. + * However you can use the {...@link org.cytoscapeweb.Visualization#addDataField} and + * {...@link org.cytoscapeweb.Visualization#removeDataField} methods to change the current schema.</p> + * <p>A data schema has two attributes:</p> + * <ul class="options"> + * <li><code>nodes</code> {Array}</li> + * <li><code>edges</code> {Array}</li></ul> + * <p>Those are arrays of {...@link org.cytoscapeweb.DataField} objects:</p> + * + * @example + * var schema = { + * nodes: [ + * { name: "id", type: "string" }, + * { name: "label", type: "string" } + * ], + * edges: [ + * { name: "id", type: "string" }, + * { name: "weight", type: "number", defValue: 0.5 } + * ] + * }; + * @class + * @name DataSchema + * @type Object + * @memberOf org.cytoscapeweb + * @see org.cytoscapeweb.Visualization#dataSchema + * @see org.cytoscapeweb.DataField + */ + + /** + * <p>This untyped object represents a Data Field, which is a node or edge attribute definition.</p> + * <p>A data field object contains the following properties:</p> + * <ul class="options"> + * <li><code>name</code>: The name of the data attribute.</li> + * <li><code>type</code>: The data type of the attribute. One of: + * <code>"string"</code>, <code>"boolean"</code>, <code>"number"</code>, <code>"int"</code>, <code>"object"</code>.</li> + * <li><code>defValue</code>: An optional default value.</li> + * </ul> + * @class + * @name DataField + * @type Object + * @memberOf org.cytoscapeweb + * @see org.cytoscapeweb.Visualization#addDataField + * @see org.cytoscapeweb.Visualization#removeDataField + * @see org.cytoscapeweb.Visualization#dataSchema + * @see org.cytoscapeweb.DataSchema + */ + // ===[ Fake Enum Types ]======================================================================= /** Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js =================================================================== --- cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js 2010-08-31 23:56:11 UTC (rev 21651) +++ cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js 2010-09-01 15:31:59 UTC (rev 21652) @@ -1064,6 +1064,23 @@ }); }); + test("Get Data Schema", function() { + var schema = vis.dataSchema(); + ok(schema.nodes.length > 0, "Empty 'nodes' schema"); + ok(schema.edges.length > 0, "Empty 'edges' schema"); + + $.each(schema.nodes, function(i, df) { + ok(df.name != null, "name (nodes schema)"); + ok(df.type != null, "type (nodes schema)"); + ok(df.defValue !== undefined, "defValue (nodes schema)"); + }); + $.each(schema.edges, function(i, df) { + ok(df.name != null, "name (edges schema)"); + ok(df.type != null, "type (edges schema)"); + ok(df.defValue !== undefined, "defValue (edges schema)"); + }); + }); + test("Add Data Field", function() { var all, nodes, edges, field; Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/sample.html =================================================================== --- cytoscapeweb/trunk/cytoscapeweb/html-template/sample.html 2010-08-31 23:56:11 UTC (rev 21651) +++ cytoscapeweb/trunk/cytoscapeweb/html-template/sample.html 2010-09-01 15:31:59 UTC (rev 21652) @@ -69,7 +69,7 @@ layout = { name: "Preset", options: { fitToScreen: true } }; } else { // GraphML or SIF if ($("#layouts").val() !== "Preset") { - layout = { name: $("#layouts").val(), options: { weightAttr: "weight", restLength: 50, autoStabilize: false } }; + layout = { name: $("#layouts").val(), options: { weightAttr: "weight", weightNorm: "inverselinear", restLength: 50, autoStabilize: false } }; } } Copied: cytoscapeweb/trunk/cytoscapeweb/lib-dev/assets (from rev 20823, cytoscapeweb/trunk/cytoscapeweb/src/assets) Modified: cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/ApplicationFacade.as =================================================================== --- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/ApplicationFacade.as 2010-08-31 23:56:11 UTC (rev 21651) +++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/ApplicationFacade.as 2010-09-01 15:31:59 UTC (rev 21652) @@ -104,6 +104,8 @@ public static const DOUBLE_CLICK_EVENT:String = "double_click_event"; public static const ROLLOVER_EVENT:String = "rollover_event"; public static const ROLLOUT_EVENT:String = "rollout_event"; + public static const ACTIVATE_EVENT:String = "activate_event"; + public static const DEACTIVATE_EVENT:String = "deactivate_event"; public static const GRAPH_DRAWN:String = "graph_drawn"; public static const GRAPH_DATA_CHANGED:String = "graph_data_changed"; Modified: cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/Layouts.as =================================================================== --- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/Layouts.as 2010-08-31 23:56:11 UTC (rev 21651) +++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/Layouts.as 2010-09-01 15:31:59 UTC (rev 21652) @@ -70,7 +70,7 @@ tension: 0.1, restLength: "auto", weightAttr: null, - weightType: ForceDirectedLayout.NORMALIZED_WEIGHT, + weightNorm: ForceDirectedLayout.NORMALIZED_WEIGHT, iterations: 400, maxTime: 30000, // milliseconds autoStabilize: true Modified: cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ApplicationMediator.as =================================================================== --- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ApplicationMediator.as 2010-08-31 23:56:11 UTC (rev 21651) +++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ApplicationMediator.as 2010-09-01 15:31:59 UTC (rev 21652) @@ -29,6 +29,7 @@ */ package org.cytoscapeweb.view { import flash.display.BitmapData; + import flash.events.Event; import flash.events.KeyboardEvent; import flash.events.MouseEvent; import flash.geom.Matrix; @@ -249,6 +250,8 @@ private function onApplicationComplete(evt:FlexEvent):void { // KEY BINDINGS: + application.stage.addEventListener(Event.DEACTIVATE, onDeactivate); + application.stage.addEventListener(Event.ACTIVATE, onActivate); application.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown, false, 0, true); // Listeners to drag the PAN ZOOM control: @@ -258,7 +261,7 @@ panZoomBox.addEventListener(MouseEvent.ROLL_OUT, onRollOutPanZoom, false, 0, true); panZoomBox.addEventListener(DragEvent.DRAG_COMPLETE, onDragCompletePanZoom, false, 0, true); - application.stage.focus = panZoomBox; + application.stage.focus = graphView; // Tell the client application that Cytoscape Web is ready: sendNotification(ApplicationFacade.CALL_EXTERNAL_INTERFACE, { functionName: ExternalFunctions.COMPLETE }); @@ -279,6 +282,14 @@ } } + private function onActivate(evt:Event):void { + sendNotification(ApplicationFacade.ACTIVATE_EVENT); + } + + private function onDeactivate(evt:Event):void { + sendNotification(ApplicationFacade.DEACTIVATE_EVENT); + } + private function onKeyDown(evt:KeyboardEvent):void { var panX:Number = 0; var panY:Number = 0; var amount:Number = 16; Modified: cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ExternalMediator.as =================================================================== --- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ExternalMediator.as 2010-08-31 23:56:11 UTC (rev 21651) +++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ExternalMediator.as 2010-09-01 15:31:59 UTC (rev 21652) @@ -30,6 +30,8 @@ package org.cytoscapeweb.view { import com.adobe.serialization.json.JSON; + import flare.data.DataField; + import flare.data.DataUtil; import flare.vis.data.EdgeSprite; import flare.vis.data.NodeSprite; @@ -398,6 +400,31 @@ { group: group, items: items, updateVisualMappers: updateVisualMappers }); } + private function getDataSchema():Object { + var obj:Object = { nodes: [], edges: [] }; + + var convert:Function = function(input:Array, output:Array):void { + for each (var df:DataField in input) { + var type:* = df.type; + switch (type) { + case DataUtil.BOOLEAN: type = "boolean"; break; + case DataUtil.INT: type = "int"; break; + case DataUtil.NUMBER: type = "number"; break; + case DataUtil.STRING: type = "string"; break; + case DataUtil.OBJECT: + default: type = "object"; + } + + output.push({ name: df.name, type: type, defValue: df.defaultValue }); + } + }; + + convert(graphProxy.nodesSchema.fields, obj.nodes); + convert(graphProxy.edgesSchema.fields, obj.edges); + + return obj; + } + private function addDataField(group:String, dataField:Object):void { sendNotification(ApplicationFacade.ADD_DATA_FIELD, { group: group, dataField: dataField }); } @@ -456,7 +483,7 @@ "setVisualStyle", "getVisualStyle", "getVisualStyleBypass", "setVisualStyleBypass", "addNode", "addEdge", "removeElements", - "addDataField", "removeDataField", "updateData", + "getDataSchema", "addDataField", "removeDataField", "updateData", "getNetworkAsText", "getNetworkAsImage", "exportNetwork" ]; Modified: cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/GraphMediator.as =================================================================== --- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/GraphMediator.as 2010-08-31 23:56:11 UTC (rev 21651) +++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/GraphMediator.as 2010-09-01 15:31:59 UTC (rev 21652) @@ -141,7 +141,9 @@ /** @inheritDoc */ override public function listNotificationInterests():Array { - return [ApplicationFacade.PAN_GRAPH, + return [ApplicationFacade.ACTIVATE_EVENT, + ApplicationFacade.DEACTIVATE_EVENT, + ApplicationFacade.PAN_GRAPH, ApplicationFacade.ENABLE_GRAB_TO_PAN, ApplicationFacade.CENTER_GRAPH]; } @@ -149,6 +151,10 @@ /** @inheritDoc */ override public function handleNotification(note:INotification):void { switch (note.getName()) { + case ApplicationFacade.DEACTIVATE_EVENT: + if (_ctrlDown) + graphView.stage.dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_UP, true, false, 0, Keyboard.CONTROL)); + break; case ApplicationFacade.ENABLE_GRAB_TO_PAN: updateCursor(); break; @@ -389,11 +395,12 @@ // VIEW listener functions: // ----------------------------------------------------------------------------------------- - private function onKeyDown(evt:KeyboardEvent):void { trace("* Key DOWN :: " + evt.keyCode); + private function onKeyDown(evt:KeyboardEvent):void { trace("* Key DOWN :: " + evt.keyCode + "/" + evt.charCode); var dirty:Boolean = _isMouseOverView || _selecting || _draggingGraph; if (evt.keyCode === Keyboard.CONTROL) { _ctrlDown = true; + if (dirty) updateCursor(); if (graphProxy.rolledOverNode != null) @@ -404,7 +411,7 @@ } } - private function onKeyUp(evt:KeyboardEvent):void { trace("* Key UP :: " + evt.keyCode); + private function onKeyUp(evt:KeyboardEvent):void { trace("* Key UP :: " + evt.keyCode + "/" + evt.charCode); if (evt.keyCode === Keyboard.CONTROL) { _ctrlDown = false; if (_isMouseOverView) updateCursor(); Modified: cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as =================================================================== --- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as 2010-08-31 23:56:11 UTC (rev 21651) +++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as 2010-09-01 15:31:59 UTC (rev 21652) @@ -450,9 +450,10 @@ var maxTime:uint = options.maxTime; var autoStab:Boolean = options.autoStabilize; var weightAttr:String = options.weightAttr; + var weightNorm:String = options.weightNorm; var sim:Simulation = new Simulation(); - var fdl:ForceDirectedLayout = new ForceDirectedLayout(true, iter, maxTime, autoStab, sim, weightAttr); + var fdl:ForceDirectedLayout = new ForceDirectedLayout(true, iter, maxTime, autoStab, sim, weightAttr, weightNorm); //fdl.ticksPerIteration = 1, fdl.simulation.dragForce.drag = options.drag; fdl.simulation.nbodyForce.gravitation = options.gravitation; Modified: cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/layout/ForceDirectedLayout.as =================================================================== --- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/layout/ForceDirectedLayout.as 2010-08-31 23:56:11 UTC (rev 21651) +++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/layout/ForceDirectedLayout.as 2010-09-01 15:31:59 UTC (rev 21652) @@ -58,8 +58,8 @@ // ========[ CONSTANTS ]==================================================================== - public static const NORMALIZED_WEIGHT:String = "normalized"; - public static const INV_NORMALIZED_WEIGHT:String = "invnormalized"; + public static const NORMALIZED_WEIGHT:String = "linear"; + public static const INV_NORMALIZED_WEIGHT:String = "inverselinear"; public static const LOG_WEIGHT:String = "log"; protected static const MIN_SPRING_WEIGHT:Number = 0.1; @@ -72,7 +72,7 @@ private var _maxTime:uint; private var _weightAttr:String; - private var _weightType:String; + private var _weightNormalization:String; private var _weighted:Boolean; private var _eLengths:/*edge_id->length*/Object; @@ -86,7 +86,7 @@ /** The name of the edge attribute that contains the weights. */ public function get weightAttr():String { return _weightAttr; } - public function get weightType():String { return _weightType; } + public function get weightNormalization():String { return _weightNormalization; } public function get weighted():Boolean { return _weighted } public function get edges():DataList { return visualization.data.group(Groups.MERGED_EDGES); } @@ -108,19 +108,19 @@ autoStabilize:Boolean=true, sim:Simulation=null, edgeWeightAttr:String=null, - edgeWeightType:String=null) { + edgeWeightNormalization:String=null) { super(enforceBounds, iterations, sim); this.maxTime = maxTime; this.autoStabilize = autoStabilize; _weightAttr = StringUtil.trim(edgeWeightAttr); - _weightType = StringUtil.trim(edgeWeightType).toLocaleLowerCase(); + _weightNormalization = StringUtil.trim(edgeWeightNormalization).toLocaleLowerCase(); _weighted = _weightAttr != ""; _eLengths = null; this.restLength = function(e:EdgeSprite):Number { var rl:Number = defaultSpringLength; if (weighted && !isNaN(e.props.springWeight)) { - switch (weightType) { + switch (edgeWeightNormalization) { case INV_NORMALIZED_WEIGHT: rl /= (MIN_SPRING_WEIGHT + MAX_SPRING_WEIGHT - e.props.springWeight); break; case LOG_WEIGHT: -- 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.
