Author: Christian Lopes
Date: 2010-09-03 14:54:37 -0700 (Fri, 03 Sep 2010)
New Revision: 21694

Modified:
   cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/weighted1.graphml
   cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js
   cytoscapeweb/trunk/cytoscapeweb/html-template/sample.html
   
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/ContinuousVizMapperVO.as
   cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/GraphMediator.as
   
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/controls/EnclosingSelectionControl.as
   
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/layout/ForceDirectedLayout.as
Log:
Implemented feature #2288: Continuous mapper should allow user-custom scales 
(it needs more tests).
Added LOG normalization option to the weighted force directed layout.
Fixed bug that would prevent and element from being drag-selected when it was 
previously shift-clicked.


Modified: 
cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/weighted1.graphml
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/weighted1.graphml    
2010-09-03 21:23:07 UTC (rev 21693)
+++ cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/weighted1.graphml    
2010-09-03 21:54:37 UTC (rev 21694)
@@ -57,8 +57,9 @@
       <data key="shape">HEXAGON</data>
       <data key="label">A08</data>
     </node>
-    <node id="n1">
+    <node id="a09">
       <data key="weight">0.6234616006258875</data>
+      <data key="label">A09</data>
     </node>
     
     <edge id="e3" source="a01" directed="true" target="a02">
@@ -123,7 +124,7 @@
     <edge id="e15" source="a07" target="a04">
       <data key="weight">5000</data>
     </edge>
-    <edge id="e16" source="a07" target="n1">
+    <edge id="e16" source="a07" target="a09">
       <data key="weight">7000</data>
     </edge>
   </graph>

Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js    
2010-09-03 21:23:07 UTC (rev 21693)
+++ cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js    
2010-09-03 21:54:37 UTC (rev 21694)
@@ -2260,7 +2260,7 @@
      *                                               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 provide the name of the data 
attribute that should be used as weight.</li>
      *         <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>.
+     *                                               Possible values are: 
<code>"linear"</code>, <code>"invlinear"</code> and <code>"log"</code>.
      *                                               The default value is 
<code>"linear"</code>.</li>
      *         <li><code>minWeight</code> {Number}: The minimum edge weight to 
consider, if the layout is set to be weighted.
      *                                              Do not specify any value 
if you want the layout to get the minimum weight from the rendered edges data 
(filtered-out edges are ignored).
@@ -2588,8 +2588,16 @@
      *     <li>The mapping algorithm uses a linear interpolation to calculate 
the values.</li>
      *     <li>Continuous mappers ignore filtered out elements.</li>
      * </ul>
+     * 
      * @example
+     * // A mapper that could be used to set the sizes of the nodes, for 
example:
      * var sizeMapper = { attrName: "weight",  minValue: 12, maxValue: 36 };
+     * 
+     * // This one could be used to create a color gradient:
+     * var colorMapper = { attrName: "score",  minValue: "#ffff00", maxValue: 
"#00ff00" };
+     * 
+     * // In this example we want to specify the minimum and maximum data 
values for the scale:
+     * var widthMapper = { attrName: "weight",  minValue: 1, maxValue: 4, 
minAttrValue: 0.1, maxAttrValue: 1.0 };
      * @class
      * @name ContinuousMapper
      * @type Object
@@ -2600,6 +2608,46 @@
      * @see org.cytoscapeweb.VisualStyle
      */
     /**
+     * The name of the data attribute that will be mapped to a visual style's 
property.
+     * @property
+     * @name attrName
+     * @type String
+     * @memberOf org.cytoscapeweb.ContinuousMapper#
+     */
+    /**
+     * The minimum value of the visual style's property. It is usually a 
number (e.g. edge width),
+     * but accepts strings if the visual property is a color.
+     * @property
+     * @name minValue
+     * @memberOf org.cytoscapeweb.ContinuousMapper#
+     */
+    /**
+     * The maximum value of the visual style's property. It is usually a 
number (e.g. edge width),
+     * but accepts strings if the visual property is a color.
+     * @property
+     * @name maxValue
+     * @memberOf org.cytoscapeweb.ContinuousMapper#
+     */
+    /**
+     * An optional minimum value for the linear scale. If you don't specify it,
+     * Cytoscape Web gets the lowest attribute value from the rendered nodes 
or edges (filtered-out elements are ignored).
+     * And if an element's data value is lower than the specified minimum, 
that element's visual property is simply scaled up to the minimum value.
+     * @property
+     * @name minAttrValue
+     * @type Number
+     * @memberOf org.cytoscapeweb.ContinuousMapper#
+     */
+    /**
+     * An optional maximum value for the linear scale. If you don't specify it,
+     * Cytoscape Web gets the highest attribute value from the rendered nodes 
or edges (filtered-out elements are ignored).
+     * And if an element's data value is higher than the specified maximum, 
that element's visual property is simply scaled down to the maximum value.
+     * @property
+     * @name maxAttrValue
+     * @type Number
+     * @memberOf org.cytoscapeweb.ContinuousMapper#
+     */
+    
+    /**
      * <p>This object represents a Discrete Mapper type, but is just an 
untyped object.</p>
      * <p>Discrete network attributes are mapped to discrete visual 
attributes.</p>
      * <p>For example, a discrete mapper can map node colors to gene 
annotations.</p>

Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/sample.html
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/html-template/sample.html   2010-09-03 
21:23:07 UTC (rev 21693)
+++ cytoscapeweb/trunk/cytoscapeweb/html-template/sample.html   2010-09-03 
21:54:37 UTC (rev 21694)
@@ -28,7 +28,7 @@
                     },
                     nodes: {
                         shape: "ELLIPSE",
-                        color: { defaultValue: "#cccccc", continuousMapper: { 
attrName: "weight",  minValue: "#ffffff", maxValue: "#0b94b1" } },
+                        color: { defaultValue: "#cccccc", continuousMapper: { 
attrName: "weight", minValue: "#ffffff", maxValue: "#0b94b1" } },
                         opacity: 0.9,
                         size: { defaultValue: 20, continuousMapper: { 
attrName: "weight",  minValue: 20, maxValue: 40 } },
                         borderWidth: 2,
@@ -41,7 +41,7 @@
                     },
                     edges: {
                        color: "#0b94b1",
-                        width: { defaultValue: 2, continuousMapper: { 
attrName: "weight",  minValue: 2, maxValue: 8 } },
+                        width: { defaultValue: 2, continuousMapper: { 
attrName: "weight",  minValue: 2, maxValue: 8, minAttrValue: 4000, 
maxAttrValue: 6000 } },
                         mergeWidth: { defaultValue: 2, continuousMapper: { 
attrName: "weight",  minValue: 2, maxValue: 8 } },
                         mergeColor: "#0b94b1",
                         opacity: 0.7,
@@ -70,7 +70,7 @@
                        layout = { name: "Preset", options: { fitToScreen: true 
} };
                     } else { // GraphML or SIF
                        if ($("#layouts").val() !== "Preset") {
-                            layout = { name: $("#layouts").val(), options: { 
weightAttr: "weight", weightNorm: "linear", restLength: 50, autoStabilize: 
false } };
+                            layout = { name: $("#layouts").val(), options: { 
weightAttr: "weight", weightNorm: "log", restLength: 50, autoStabilize: false } 
};
                         }
                                        }
 

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/ContinuousVizMapperVO.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/ContinuousVizMapperVO.as
    2010-09-03 21:23:07 UTC (rev 21693)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/ContinuousVizMapperVO.as
    2010-09-03 21:54:37 UTC (rev 21694)
@@ -46,6 +46,8 @@
         // Attribute values:
         private var _minAttrValue:Number;
         private var _maxAttrValue:Number;
+        private var _dynamicMin:Boolean = true;
+        private var _dynamicMax:Boolean = true;
         
         // ========[ PUBLIC PROPERTIES 
]============================================================
         
@@ -58,7 +60,7 @@
          */
         public function set dataList(list:Array):void {
             _dataList = list;
-            buildScale();
+            if (_dynamicMin || _dynamicMax) buildScale();
         }
         
         public function get minValue():Number {
@@ -69,15 +71,29 @@
             return _maxValue;
         }
         
+        public function get minAttrValue():Number {
+            return _minAttrValue;
+        }
+        
+        public function get maxAttrValue():Number {
+            return _maxAttrValue;
+        }
+        
         // ========[ CONSTRUCTOR 
]==================================================================
         
         public function ContinuousVizMapperVO(attrName:String,
                                               propName:String,
                                               minValue:Number,
-                                              maxValue:Number) {
+                                              maxValue:Number,
+                                              minAttrValue:Number=NaN,
+                                              maxAttrValue:Number=NaN) {
             super(attrName, propName, this);
-            this._minValue = minValue;
-            this._maxValue = maxValue;
+            _minValue = minValue;
+            _maxValue = maxValue;
+            _minAttrValue = minAttrValue;
+            _maxAttrValue = maxAttrValue;
+            _dynamicMin = isNaN(minAttrValue);
+            _dynamicMax = isNaN(maxAttrValue);
         }
         
         // ========[ PUBLIC METHODS 
]===============================================================
@@ -107,6 +123,8 @@
             obj.attrName = attrName;
             obj.minValue = VisualProperties.toExportValue(propName, minValue);
             obj.maxValue = VisualProperties.toExportValue(propName, maxValue);
+            if (!_dynamicMin) obj.minAttrValue = minAttrValue;
+            if (!_dynamicMax) obj.maxAttrValue = maxAttrValue;
             
             return obj;
         }
@@ -116,23 +134,29 @@
             var min:Number = VisualProperties.parseValue(propName, 
obj.minValue) as Number;
             var max:Number = VisualProperties.parseValue(propName, 
obj.maxValue) as Number;
             
-            return new ContinuousVizMapperVO(attrName, propName, min, max);
+            var minAttr:Number, maxAttr:Number;
+            if (!isNaN(obj.minAttrValue)) minAttr = Number(obj.minAttrValue);
+            if (!isNaN(obj.maxAttrValue)) maxAttr = Number(obj.maxAttrValue);
+            
+            return new ContinuousVizMapperVO(attrName, propName, min, max, 
minAttr, maxAttr);
         }
         
         // ========[ PRIVATE METHODS 
]==============================================================
         
         private function buildScale():void {
-            _maxAttrValue = _minAttrValue = 0;
+//            _maxAttrValue = _minAttrValue = 0;
             
             if (dataList != null && dataList.length > 0) {
-                   _maxAttrValue = Number.NEGATIVE_INFINITY;
-                   _minAttrValue = Number.POSITIVE_INFINITY;
+                if (_dynamicMin) _minAttrValue = Number.POSITIVE_INFINITY;
+                   if (_dynamicMax) _maxAttrValue = Number.NEGATIVE_INFINITY;
                    
-                   for each (var dt:Object in dataList) {
-                       var value:Number = dt[attrName] as Number;
-                       _maxAttrValue = Math.max(_maxAttrValue, value);
-                       _minAttrValue = Math.min(_minAttrValue, value);
-                   }
+                   if (_dynamicMin || _dynamicMax) {
+                   for each (var dt:Object in dataList) {
+                       var value:Number = dt[attrName] as Number;
+                       if (_dynamicMin) _minAttrValue = 
Math.min(_minAttrValue, value);
+                       if (_dynamicMax) _maxAttrValue = 
Math.max(_maxAttrValue, value);
+                   }
+               }
             }
         }
     }

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/GraphMediator.as
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/GraphMediator.as  
2010-09-03 21:23:07 UTC (rev 21693)
+++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/GraphMediator.as  
2010-09-03 21:54:37 UTC (rev 21694)
@@ -548,7 +548,7 @@
             if (configProxy.mouseDownToDragDelay >= 0) {
                 _dragAllTimer = new Timer(configProxy.mouseDownToDragDelay, 1);
                 _dragAllTimer.addEventListener(TimerEvent.TIMER, 
function(te:TimerEvent):void {
-                   trace("* Hold Mouse DOWN - will drag part...");
+                    trace("* Hold Mouse DOWN - will drag part...");
                     _draggingComponent = true;
                     updateCursor();
                     vis.showDragRectangle(n);
@@ -573,6 +573,7 @@
             evt.currentTarget.removeEventListener(evt.type, arguments.callee);
             var n:NodeSprite = evt.target as NodeSprite;
             _draggingGraph = false;
+            _selectionControl.enabled = true;
             updateCursor();
             // Return the MOUSE DOWN to the View, so panning is possible again:
             graphView.stage.addEventListener(MouseEvent.MOUSE_DOWN, 
onMouseDownView, false, 0, true);
@@ -675,12 +676,12 @@
             if (_draggingComponent) vis.updateDragRectangle(amountX, amountY);
         }
         
-        private function onSelect(evt:SelectionEvent):void {
+        private function onSelect(evt:SelectionEvent):void {for each (var item 
in evt.items) { trace("   S---> " + item.data.label); }
             if (evt.items != null && evt.items.length > 0)
                 sendNotification(ApplicationFacade.SELECT, evt.items);
         }
         
-        private function onDeselect(evt:SelectionEvent):void {
+        private function onDeselect(evt:SelectionEvent):void {for each (var 
item in evt.items) { trace("   D---> " + item.data.label); }
             if (evt.items != null && evt.items.length > 0)
                 sendNotification(ApplicationFacade.DESELECT, evt.items);
         }

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/controls/EnclosingSelectionControl.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/controls/EnclosingSelectionControl.as
     2010-09-03 21:23:07 UTC (rev 21693)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/controls/EnclosingSelectionControl.as
     2010-09-03 21:54:37 UTC (rev 21694)
@@ -182,7 +182,7 @@
             }
         }
                 
-        private function mouseDown(evt:MouseEvent):void {
+        private function mouseDown(evt:MouseEvent):void {trace("--DOWN--");
             if (_stage == null) return;
             _stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
             _stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
@@ -195,11 +195,11 @@
             
             DisplayObjectContainer(_object).addChild(_shape);
             renderShape(_shape.graphics);
-            
+            trace(_enabled);
             if (_enabled) {
                 if (fireImmediately) {
                     selectionTest(evt);
-                } else if (!evt.shiftKey) {
+                } else {
                     // ALTERED: if SHIFT key is not pressed, it should reset 
everything first:
                     _rem = _add = null;
                     _rem0 = _add0 = null;
@@ -219,14 +219,14 @@
             }
         }
         
-        private function mouseUp(evt:MouseEvent):void {
+        private function mouseUp(evt:MouseEvent):void {trace("--UP--");
             if (!enabled) return;
             if (!fireImmediately)
                 selectionTest(evt);
             stopSelection();
         }
         
-        private function stopSelection():void {
+        private function stopSelection():void {trace("--stop sel");
             if (_drag) {
                 DisplayObjectContainer(_object).removeChild(_shape);
             }
@@ -247,7 +247,7 @@
             }
         }
         
-        private function selectionTest(evt:MouseEvent):void {           
+        private function selectionTest(evt:MouseEvent):void { trace("-->sel 
TEST");          
             var con:DisplayObjectContainer = DisplayObjectContainer(_object);
             for (var i:uint=0; i<con.numChildren; ++i) {
                 walkTree(con.getChildAt(i), test);

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/layout/ForceDirectedLayout.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/layout/ForceDirectedLayout.as
     2010-09-03 21:23:07 UTC (rev 21693)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/layout/ForceDirectedLayout.as
     2010-09-03 21:54:37 UTC (rev 21694)
@@ -59,7 +59,7 @@
         // ========[ CONSTANTS 
]====================================================================
         
         public static const NORMALIZED_WEIGHT:String = "linear";
-        public static const INV_NORMALIZED_WEIGHT:String = "inverselinear";
+        public static const INV_NORMALIZED_WEIGHT:String = "invlinear";
         public static const LOG_WEIGHT:String = "log";
         
         protected static const MIN_SPRING_WEIGHT:Number = 0.1;
@@ -135,9 +135,7 @@
                     switch (edgeWeightNormalization) {
                         case INV_NORMALIZED_WEIGHT:
                             rl /= (MIN_SPRING_WEIGHT + MAX_SPRING_WEIGHT - 
sw); break;
-                        case LOG_WEIGHT:
-                            // TODO...
-                        default: // normalized...
+                        default:
                             if (sw !== 0) rl /= sw;
                     }
                 }
@@ -322,6 +320,11 @@
                 }
             });
             
+            if (weightNormalization === LOG_WEIGHT) {
+                minWeight = Math.log(minWeight);
+                maxWeight = Math.log(maxWeight);
+            }
+            
             // set up simulation parameters
             // this needs to be kept separate from the above initialization
             // to ensure all simulation items are created first
@@ -340,6 +343,7 @@
                 
                 if (weighted) {
                     ew = e.data[weightAttr];
+                    if (weightNormalization === LOG_WEIGHT) ew = Math.log(ew);
 
                     // Normalize min and max weights for better visual results 
(always between 0 and 1):
                     if (minWeight === maxWeight) {
@@ -353,7 +357,7 @@
                         sw = Maths.linearInterp(f, MIN_SPRING_WEIGHT, 
MAX_SPRING_WEIGHT);
                     }
                 }
-                
+
                 e.props.springWeight = sw;
                 
                 if (restLength != null)

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