Author: clopes
Date: 2010-11-26 18:09:35 -0800 (Fri, 26 Nov 2010)
New Revision: 23019
Modified:
cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/controller/DrawGraphCommand.as
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/controller/SetVisualStyleBypassCommand.as
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/controller/SetVisualStyleCommand.as
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/ConfigProxy.as
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/ConfigVO.as
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/VisualStyleBypassVO.as
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/ImageCache.as
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/NodeRenderer.as
Log:
Added "preloadImages" option.
Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js
2010-11-25 01:12:01 UTC (rev 23018)
+++ cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js
2010-11-27 02:09:35 UTC (rev 23019)
@@ -220,6 +220,11 @@
* will be
visible. The default value is <code>true</code>.
* The
visibility of the control can be changed later with
*
{...@link org.cytoscapeweb.Visualization#panZoomControlVisible}.</li>
+ * <li><code>preloadImages</code>: Boolean that
defines whether or not to load all images before rendering the network.
+ * If
<code>true</code>, all images from a
+ * {...@link
org.cytoscapeweb.VisualStyle} or {...@link org.cytoscapeweb.VisualStyleBypass}
+ * will be loaded
before the network is drawn or before a visual style (or bypass) is applied.
+ * The default
value is <code>true</code>.</li>
* </ul>
* @return {org.cytoscapeweb.Visualization} The Visualization instance.
* @see org.cytoscapeweb.Visualization#ready
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/controller/DrawGraphCommand.as
===================================================================
---
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/controller/DrawGraphCommand.as
2010-11-25 01:12:01 UTC (rev 23018)
+++
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/controller/DrawGraphCommand.as
2010-11-27 02:09:35 UTC (rev 23019)
@@ -29,15 +29,20 @@
*/
package org.cytoscapeweb.controller {
+ import flash.utils.setTimeout;
+
import org.cytoscapeweb.model.data.VisualStyleVO;
import org.cytoscapeweb.model.methods.error;
import org.cytoscapeweb.view.GraphMediator;
import org.cytoscapeweb.view.components.GraphView;
+ import org.cytoscapeweb.view.render.ImageCache;
import org.puremvc.as3.interfaces.INotification;
public class DrawGraphCommand extends BaseSimpleCommand {
+ private var _imgCache:ImageCache = ImageCache.instance;
+
override public function execute(notification:INotification):void {
try {
var options:Object = notification.getBody();
@@ -60,16 +65,28 @@
configProxy.panZoomControlVisible =
options.panZoomControlVisible;
if (options.mouseDownToDragDelay != null)
configProxy.mouseDownToDragDelay =
options.mouseDownToDragDelay;
+ if (options.preloadImages != null)
+ configProxy.preloadImages = options.preloadImages;
+ // Preload images:
+ if (configProxy.preloadImages)
+ _imgCache.loadImages(configProxy.visualStyle, draw);
+
+ // Load the model:
graphProxy.loadGraph(options.network,
configProxy.currentLayout);
- appMediator.applyVisualStyle(configProxy.visualStyle);
-
- var graphView:GraphView =
CytoscapeWeb(appMediator.getViewComponent()).graphView;
- facade.registerMediator(new GraphMediator(graphView));
-
- graphMediator.drawGraph();
+ // No image to preload; just draw:
+ if (_imgCache.hasNoCache()) draw();
+ function draw():void {
+ appMediator.applyVisualStyle(configProxy.visualStyle);
+
+ var graphView:GraphView =
CytoscapeWeb(appMediator.getViewComponent()).graphView;
+ facade.registerMediator(new GraphMediator(graphView));
+
+ graphMediator.drawGraph();
+ }
+
} catch (err:Error) {
trace("[ERROR]: DrawGraphCommand.execute: " +
err.getStackTrace());
error(err.message, err.errorID, err.name, err.getStackTrace());
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/controller/SetVisualStyleBypassCommand.as
===================================================================
---
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/controller/SetVisualStyleBypassCommand.as
2010-11-25 01:12:01 UTC (rev 23018)
+++
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/controller/SetVisualStyleBypassCommand.as
2010-11-27 02:09:35 UTC (rev 23019)
@@ -29,15 +29,27 @@
*/
package org.cytoscapeweb.controller {
import org.cytoscapeweb.model.data.VisualStyleBypassVO;
+ import org.cytoscapeweb.view.render.ImageCache;
import org.puremvc.as3.interfaces.INotification;
public class SetVisualStyleBypassCommand extends BaseSimpleCommand {
+ private var _imgCache:ImageCache = ImageCache.instance;
+
override public function execute(notification:INotification):void {
var bypass:VisualStyleBypassVO = notification.getBody() as
VisualStyleBypassVO;
+ configProxy.visualStyleBypass = bypass;
+
+ // Preload images:
+ if (configProxy.preloadImages)
+ _imgCache.loadImages(configProxy.visualStyleBypass,
setVisualStyleBypass);
- configProxy.visualStyleBypass = bypass;
+ // No image to preload; just set the new bypass
+ if (_imgCache.hasNoCache()) setVisualStyleBypass();
+ }
+
+ private function setVisualStyleBypass():void {
graphMediator.applyVisualBypass(configProxy.visualStyle);
}
}
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/controller/SetVisualStyleCommand.as
===================================================================
---
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/controller/SetVisualStyleCommand.as
2010-11-25 01:12:01 UTC (rev 23018)
+++
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/controller/SetVisualStyleCommand.as
2010-11-27 02:09:35 UTC (rev 23019)
@@ -29,24 +29,37 @@
*/
package org.cytoscapeweb.controller {
import org.cytoscapeweb.model.data.VisualStyleVO;
+ import org.cytoscapeweb.view.render.ImageCache;
import org.puremvc.as3.interfaces.INotification;
public class SetVisualStyleCommand extends BaseSimpleCommand {
+ private var _imgCache:ImageCache = ImageCache.instance;
+
override public function execute(notification:INotification):void {
var style:VisualStyleVO = notification.getBody() as VisualStyleVO;
if (style != null) {
// Set the new style:
configProxy.visualStyle = style;
+
+ // Preload images:
+ if (configProxy.preloadImages)
+ _imgCache.loadImages(configProxy.visualStyle,
setVisualStyle);
+
// Then bind the data again, so the new vizMappers can work:
configProxy.bindGraphData(graphProxy.graphData);
- // Finally ask the mediators to apply the new style:
- appMediator.applyVisualStyle(configProxy.visualStyle);
- graphMediator.applyVisualStyle(configProxy.visualStyle);
+ // No image to preload; just set the new style:
+ if (_imgCache.hasNoCache()) setVisualStyle();
}
}
+
+ private function setVisualStyle():void {
+ // Ask the mediators to apply the new style:
+ appMediator.applyVisualStyle(configProxy.visualStyle);
+ graphMediator.applyVisualStyle(configProxy.visualStyle);
+ }
}
}
\ No newline at end of file
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/ConfigProxy.as
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/ConfigProxy.as
2010-11-25 01:12:01 UTC (rev 23018)
+++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/ConfigProxy.as
2010-11-27 02:09:35 UTC (rev 23019)
@@ -208,6 +208,14 @@
public function set mouseDownToDragDelay(value:Number):void {
config.mouseDownToDragDelay = value;
}
+
+ public function get preloadImages():Boolean {
+ return config.preloadImages;
+ }
+
+ public function set preloadImages(value:Boolean):void {
+ config.preloadImages = value;
+ }
// ========[ CONSTRUCTOR
]==================================================================
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/ConfigVO.as
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/ConfigVO.as
2010-11-25 01:12:01 UTC (rev 23018)
+++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/ConfigVO.as
2010-11-27 02:09:35 UTC (rev 23019)
@@ -55,6 +55,7 @@
public var minZoom:Number = 0.002;
public var maxZoom:Number = 3;
public var mouseDownToDragDelay:Number = 400;
+ public var preloadImages:Boolean = true;
// ========[ CONSTRUCTOR
]==================================================================
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/VisualStyleBypassVO.as
===================================================================
---
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/VisualStyleBypassVO.as
2010-11-25 01:12:01 UTC (rev 23018)
+++
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/data/VisualStyleBypassVO.as
2010-11-27 02:09:35 UTC (rev 23019)
@@ -56,8 +56,8 @@
/**
* Return the visual property value associated with a node or edge.
+ * @param propName the visual property name.
* @param id a node or edge id
- * @param propName the visual property name.
* @return the mapped visual property value
*/
public function getValue(propName:String, id:*):* {
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as
===================================================================
---
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as
2010-11-25 01:12:01 UTC (rev 23018)
+++
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as
2010-11-27 02:09:35 UTC (rev 23019)
@@ -52,7 +52,6 @@
import flash.display.DisplayObject;
import flash.geom.Point;
import flash.geom.Rectangle;
- import flash.utils.setTimeout;
import org.cytoscapeweb.model.data.ConfigVO;
import org.cytoscapeweb.model.data.VisualStyleVO;
@@ -72,7 +71,6 @@
import org.cytoscapeweb.view.layout.PresetLayout;
import org.cytoscapeweb.view.layout.RadialTreeLayout;
import org.cytoscapeweb.view.layout.physics.Simulation;
- import org.cytoscapeweb.view.render.ImageCache;
import org.cytoscapeweb.view.render.Labeler;
@@ -188,10 +186,6 @@
public function applyVisualStyle(style:VisualStyleVO):void {
var firstTime:Boolean = this._style == null;
this._style = style;
-
- // Preload images:
- var imgCache:ImageCache = ImageCache.instance;
- imgCache.loadImages(style);
// Nodes & Edges properties:
// ---------------------------------------------------------
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/ImageCache.as
===================================================================
---
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/ImageCache.as
2010-11-25 01:12:01 UTC (rev 23018)
+++
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/ImageCache.as
2010-11-27 02:09:35 UTC (rev 23019)
@@ -39,6 +39,7 @@
import org.cytoscapeweb.model.data.DiscreteVizMapperVO;
import org.cytoscapeweb.model.data.VisualPropertyVO;
+ import org.cytoscapeweb.model.data.VisualStyleBypassVO;
import org.cytoscapeweb.model.data.VisualStyleVO;
import org.cytoscapeweb.model.methods.error;
import org.cytoscapeweb.util.ErrorCodes;
@@ -56,6 +57,8 @@
private var _images:Object = {};
private var _broken:Object = {};
+ private var _noCache:Boolean = true;
+ private var _onLoadingEnd:Function;
// ========[ PUBLIC METHODS
]===============================================================
@@ -76,49 +79,64 @@
return _broken[url];
}
+ public function hasNoCache():Boolean {
+ return _noCache;
+ }
+
public function contains(url:String):Boolean {
url = normalize(url);
return _images[url] !== undefined;
}
- public function loadImages(style:VisualStyleVO):void {
+ /**
+ * @param style a VisualStyleVO or VisualStyleBypassVO object
+ * @param onLoadingEnd an optional callback function
+ */
+ public function loadImages(style:*, onLoadingEnd:Function=null):void
{trace("ImageCache.loadImages...");
// First, clean the cache:
_images = {};
_broken = {};
+ _onLoadingEnd = onLoadingEnd;
+ _noCache = true;
// Then load all distinct URL values:
- $each(IMG_PROPS, function(i:uint, pname:String):Boolean {
- if (style.hasVisualProperty(pname)) {
- var vp:VisualPropertyVO = style.getVisualProperty(pname);
- // Default value:
- if (!contains(vp.defaultValue)) loadImage(vp.defaultValue);
-
- // Discrete Mapper values:
- var mapper:DiscreteVizMapperVO = vp.vizMapper as
DiscreteVizMapperVO;
- if (mapper != null) {
- var values:Array = mapper.distinctValues;
-
- $each(IMG_PROPS, function(j:uint, url:String):Boolean {
- if (!contains(url)) loadImage(url);
- return false;
- });
- }
- }
- return false;
- });
+ if (style is VisualStyleVO) {
+ $each(IMG_PROPS, function(i:uint, pname:String):Boolean {
+ if (style.hasVisualProperty(pname)) {
+ var vp:VisualPropertyVO =
style.getVisualProperty(pname);
+ // Default value:
+ if (!contains(vp.defaultValue))
loadImage(vp.defaultValue);
+
+ // Discrete Mapper values:
+ var mapper:DiscreteVizMapperVO = vp.vizMapper as
DiscreteVizMapperVO;
+ if (mapper != null) {
+ var values:Array = mapper.distinctValues;
+
+ $each(IMG_PROPS, function(j:uint,
url:String):Boolean {
+ if (!contains(url)) loadImage(url);
+ return false;
+ });
+ }
+ }
+ return false;
+ });
+ } else if (style is VisualStyleBypassVO) {
+ // TODO
+ }
}
- public function getImage(url:String):BitmapData {trace("getImage...");
+ public function getImage(url:String):BitmapData {trace("getImage: " +
url);
return _images[normalize(url)];
}
- public function loadImage(url:String):void {trace("loadImage...");
+ public function loadImage(url:String, onImgLoaded:Function=null):void
{trace("loadImage...");
url = normalize(url);
var bmp:BitmapData;
if (url.length > 0) {
_images[url] = null; // this flags the image state as "loading"
_broken[url] = false;
+ _noCache = false;
var urlRequest:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
@@ -127,11 +145,14 @@
bmp = e.target.content.bitmapData;
_images[url] = bmp;
_broken[url] = false;
+ if (onImgLoaded != null) onImgLoaded(url, bmp);
+ checkOnLoadingEnd();
});
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,
function(e:IOErrorEvent):void {trace("ImageCache - Error loading image: " + e);
_broken[url] = true;
error("Image cannot be loaded: " + url,
ErrorCodes.BROKEN_IMAGE, e.type, e.text);
+ checkOnLoadingEnd();
});
loader.load(urlRequest, new LoaderContext(true));
@@ -147,6 +168,12 @@
return url != null ? StringUtil.trim(url) : "";
}
+ private function checkOnLoadingEnd():void {
+ if (_onLoadingEnd != null) {
+ if (!isLoading()) _onLoadingEnd();
+ }
+ }
+
// ========[ SINGLETON STUFF
]==============================================================
private static var _instance:ImageCache;
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/NodeRenderer.as
===================================================================
---
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/NodeRenderer.as
2010-11-25 01:12:01 UTC (rev 23018)
+++
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/NodeRenderer.as
2010-11-27 02:09:35 UTC (rev 23019)
@@ -143,20 +143,20 @@
if (!_imgCache.contains(url)) {trace("Will load IMAGE...");
_imgCache.loadImage(url);
}
- if (_imgCache.isLoaded(url)) {trace("% LOADED :-)");
+ if (_imgCache.isLoaded(url)) {trace(" .LOADED :-)");
draw();
- } else {trace("% NOT loaded :-(");
+ } else {trace(" .NOT loaded :-(");
drawWhenLoaded();
}
function drawWhenLoaded():void {
- setTimeout(function():void {trace("TIMEOUT: Checking
again...");
+ setTimeout(function():void {trace(" .TIMEOUT: Checking
again...");
if (_imgCache.isLoaded(url)) draw();
else if (!_imgCache.isBroken(url)) drawWhenLoaded();
}, 50);
}
- function draw():void {trace("Will DRAW...: " + d.data.id);
+ function draw():void {trace("Will draw: " + d.data.id);
// Get the image from cache:
var bd:BitmapData = _imgCache.getImage(url);
--
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.