Author: Christian Lopes
Date: 2010-10-28 14:55:18 -0700 (Thu, 28 Oct 2010)
New Revision: 22587
Modified:
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:
Node images: fixed defect that would repeat the first and last pixel columns
and rows when filling the node with the bitmap pixels, if the image were not
squared.
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as
===================================================================
---
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as
2010-10-28 21:09:41 UTC (rev 22586)
+++
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/components/GraphVis.as
2010-10-28 21:55:18 UTC (rev 22587)
@@ -189,66 +189,52 @@
var firstTime:Boolean = this._style == null;
this._style = style;
- // Preload images:
- doSetStyle();
-// TODO:
-// var imgCache:ImageCache = ImageCache.instance;
-// imgCache.loadImages(style);
-//
-// if (imgCache.isLoading()) waitForImages();
-// else doSetStyle();
-//
-// function waitForImages():void {trace("%% waiting for images...");
-// setTimeout(function():void {
-// if (imgCache.isLoading()) waitForImages();
-// else doSetStyle();
-// }, 50);
-// }
+ // Preload images:
+ var imgCache:ImageCache = ImageCache.instance;
+ imgCache.loadImages(style);
+
+ // Nodes & Edges properties:
+ // ---------------------------------------------------------
+ data.nodes.setProperties(Nodes.properties);
+ data.edges.setProperties(Edges.properties);
- function doSetStyle():void {
- // Nodes & Edges properties:
- // ---------------------------------------------------------
- data.nodes.setProperties(Nodes.properties);
- data.edges.setProperties(Edges.properties);
-
- // Node labels:
- // ---------------------------------------------------------
- nodeLabeler.cacheText = false;
- nodeLabeler.textMode = TextSprite.DEVICE;
-
- nodeLabeler.fontName = Labels.labelFontName;
- nodeLabeler.fontColor = Labels.labelFontColor;
- nodeLabeler.fontSize = Labels.labelFontSize;
- nodeLabeler.fontWeight = Labels.labelFontWeight;
- nodeLabeler.fontStyle = Labels.labelFontStyle;
- nodeLabeler.hAnchor = Labels.labelHAnchor;
- nodeLabeler.vAnchor = Labels.labelVAnchor;
- nodeLabeler.xOffsetFunc = Labels.labelXOffset;
- nodeLabeler.yOffsetFunc = Labels.labelYOffset;
- nodeLabeler.filters = Labels.filters;
- nodeLabeler.textFunction = Labels.text;
-
- // Edge labels:
- // ---------------------------------------------------------
- edgeLabeler.textMode = TextSprite.DEVICE;
-
- edgeLabeler.fontName = Labels.labelFontName;
- edgeLabeler.fontColor = Labels.labelFontColor;
- edgeLabeler.fontSize = Labels.labelFontSize;
- edgeLabeler.fontWeight = Labels.labelFontWeight;
- edgeLabeler.fontStyle = Labels.labelFontStyle;
- edgeLabeler.filters = Labels.filters;
- edgeLabeler.textFunction = Labels.text;
-
- if (!firstTime) {
- if (_config.nodeLabelsVisible) updateLabels(Data.NODES);
- if (_config.edgeLabelsVisible) updateLabels(Data.EDGES);
- }
-
- // Tooltips:
- // ---------------------------------------------------------
- tooltipControl.showDelay =
_style.getValue(VisualProperties.TOOLTIP_DELAY) as Number;
+ // Node labels:
+ // ---------------------------------------------------------
+ nodeLabeler.cacheText = false;
+ nodeLabeler.textMode = TextSprite.DEVICE;
+
+ nodeLabeler.fontName = Labels.labelFontName;
+ nodeLabeler.fontColor = Labels.labelFontColor;
+ nodeLabeler.fontSize = Labels.labelFontSize;
+ nodeLabeler.fontWeight = Labels.labelFontWeight;
+ nodeLabeler.fontStyle = Labels.labelFontStyle;
+ nodeLabeler.hAnchor = Labels.labelHAnchor;
+ nodeLabeler.vAnchor = Labels.labelVAnchor;
+ nodeLabeler.xOffsetFunc = Labels.labelXOffset;
+ nodeLabeler.yOffsetFunc = Labels.labelYOffset;
+ nodeLabeler.filters = Labels.filters;
+ nodeLabeler.textFunction = Labels.text;
+
+ // Edge labels:
+ // ---------------------------------------------------------
+ edgeLabeler.textMode = TextSprite.DEVICE;
+
+ edgeLabeler.fontName = Labels.labelFontName;
+ edgeLabeler.fontColor = Labels.labelFontColor;
+ edgeLabeler.fontSize = Labels.labelFontSize;
+ edgeLabeler.fontWeight = Labels.labelFontWeight;
+ edgeLabeler.fontStyle = Labels.labelFontStyle;
+ edgeLabeler.filters = Labels.filters;
+ edgeLabeler.textFunction = Labels.text;
+
+ if (!firstTime) {
+ if (_config.nodeLabelsVisible) updateLabels(Data.NODES);
+ if (_config.edgeLabelsVisible) updateLabels(Data.EDGES);
}
+
+ // Tooltips:
+ // ---------------------------------------------------------
+ tooltipControl.showDelay =
_style.getValue(VisualProperties.TOOLTIP_DELAY) as Number;
}
public function applyLayout(layoutObj:Object):Transition {
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/ImageCache.as
===================================================================
---
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/ImageCache.as
2010-10-28 21:09:41 UTC (rev 22586)
+++
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/ImageCache.as
2010-10-28 21:55:18 UTC (rev 22587)
@@ -99,11 +99,11 @@
});
}
- public function getImage(url:String):BitmapData {
+ public function getImage(url:String):BitmapData {trace("getImage...");
return _images[normalize(url)];
}
- public function loadImage(url:String):void {
+ public function loadImage(url:String):void {trace("loadImage...");
url = normalize(url);
var bmp:BitmapData;
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/NodeRenderer.as
===================================================================
---
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/NodeRenderer.as
2010-10-28 21:09:41 UTC (rev 22586)
+++
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/NodeRenderer.as
2010-10-28 21:55:18 UTC (rev 22587)
@@ -32,14 +32,20 @@
import flare.vis.data.DataSprite;
import flare.vis.data.render.ShapeRenderer;
+ import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
+ import flash.display.PixelSnapping;
+ import flash.display.Sprite;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.utils.setTimeout;
import mx.utils.StringUtil;
+ import org.cytoscapeweb.ApplicationFacade;
+ import org.cytoscapeweb.model.ConfigProxy;
+ import org.cytoscapeweb.model.GraphProxy;
import org.cytoscapeweb.util.NodeShapes;
@@ -58,10 +64,24 @@
private var _imgCache:ImageCache = ImageCache.instance;
+ private var _graphProxy:GraphProxy;
+ protected function get graphProxy():GraphProxy {
+ if (_graphProxy == null)
+ _graphProxy =
ApplicationFacade.getInstance().retrieveProxy(GraphProxy.NAME) as GraphProxy;
+ return _graphProxy;
+ }
+
+ private var _configProxy:ConfigProxy;
+ protected function get configProxy():ConfigProxy {
+ if (_configProxy == null)
+ _configProxy =
ApplicationFacade.getInstance().retrieveProxy(ConfigProxy.NAME) as ConfigProxy;
+ return _configProxy;
+ }
+
// ========[ PUBLIC METHODS
]===============================================================
/** @inheritDoc */
- public override function render(d:DataSprite):void {
+ public override function render(d:DataSprite):void {trace("RENDER
NODE: " + d.data.id);
var lineAlpha:Number = d.lineAlpha;
var fillAlpha:Number = d.fillAlpha;
var size:Number = d.size * defaultSize;
@@ -79,7 +99,7 @@
// Using a bit mask to avoid transparent mdes when
fillcolor=0xffffffff.
// See https://sourceforge.net/forum/message.php?msg_id=7393265
g.beginFill(0xffffff & d.fillColor, fillAlpha);
- drawShape(d, size);
+ drawShape(d, d.shape, size);
g.endFill();
// 2. Draw an image on top:
@@ -89,10 +109,10 @@
// ========[ PRIVATE METHODS
]==============================================================
- private function drawShape(d:DataSprite, size:Number):void {
- var g:Graphics = d.graphics;
+ private function drawShape(s:Sprite, shape:String, size:Number):void {
+ var g:Graphics = s.graphics;
- switch (d.shape) {
+ switch (shape) {
case null:
break;
case NodeShapes.RECTANGLE:
@@ -105,7 +125,7 @@
case NodeShapes.PARALLELOGRAM:
case NodeShapes.V:
var r:Rectangle = new Rectangle(-size/2, -size/2, size,
size);
- var points:Array = NodeShapes.getDrawPoints(r, d.shape);
+ var points:Array = NodeShapes.getDrawPoints(r, shape);
Shapes.drawPolygon(g, points);
break;
case NodeShapes.ROUND_RECTANGLE:
@@ -138,24 +158,81 @@
}, 50);
}
- function draw():void {trace("Will DRAW...");
+ function draw():void {trace("Will DRAW...: " + d.data.id);
// Get the image from cache:
- var bmp:BitmapData = _imgCache.getImage(url);
+ var bd:BitmapData = _imgCache.getImage(url);
- if (bmp != null) {
- var maxBmpSize:Number = Math.max(bmp.height,
bmp.width);
- var scale:Number = size/maxBmpSize;
-
+ if (bd != null) {
+ var bmpSize:Number = Math.max(bd.height, bd.width);
+ var maxZoom:Number = configProxy.maxZoom;
+
+ // Reduce the image, if it is too large, to avoid some
rendering issues:
+// const MAX_BMP_SCALE:uint = 30;
+// var zoom:Number = graphProxy.zoom;
+// var maxBmpSize:Number = size * zoom * MAX_BMP_SCALE;
+//
+// if (bmpSize > maxBmpSize) {
+// bd = resizeBitmap(bd, maxBmpSize/bmpSize);
+// bmpSize = Math.max(bd.height, bd.width);
+// }
+
+ bd = resizeBitmapToFit(bd, size*maxZoom, size*maxZoom);
+ bmpSize = Math.max(bd.height, bd.width);
+
+ var scale:Number = size/bmpSize;
+
var m:Matrix = new Matrix();
m.scale(scale, scale);
- m.translate(-size/2, -size/2);
-
- d.graphics.beginBitmapFill(bmp, m, false, true);
- drawShape(d, size);
+ m.translate(-(bd.width*scale)/2, -(bd.height*scale)/2);
+
+ var b:Bitmap = new Bitmap();
+
+ d.graphics.beginBitmapFill(bd, m, false, true);
+ drawShape(d, d.shape, size);
d.graphics.endFill();
}
}
}
}
+
+ private function resizeBitmapToFit(bd:BitmapData, nw:Number,
nh:Number):BitmapData {
+ if (bd.width > 0 && bd.height > 0) {
+ var w:Number = bd.width;
+ var h:Number = bd.height;
+ var originalRatio:Number = w/h;
+ var maxRatio:Number = nw/nh;
+ var scale:Number;
+
+ if (originalRatio > maxRatio) { // scale by width
+ scale = nw/w;
+ } else { // scale by height
+ scale = nh/h;
+ }
+
+ var m:Matrix = new Matrix();
+ m.scale(scale, scale);
+ m.translate(nw/2-(w*scale)/2, nh/2-(h*scale)/2);
+
+ var bd2:BitmapData = new BitmapData(nw, nh, true, 0x000000);
+ bd2.draw(bd, m, null, null, null, true);
+
+ var bmp:Bitmap = new Bitmap(bd2, PixelSnapping.NEVER, true);
+ return bmp.bitmapData;
+ }
+
+ return bd;
+ }
+
+// private function resizeBitmap(bd:BitmapData,
scale:Number):BitmapData {
+// var matrix:Matrix = new Matrix();
+// matrix.scale(scale, scale);
+//
+// var bd2:BitmapData = new BitmapData(bd.width * scale, bd.height
* scale, true, 0x000000);
+// bd2.draw(bd, matrix, null, null, null, true);
+//
+// var bmp:Bitmap = new Bitmap(bd2, PixelSnapping.NEVER, true);
+//
+// return bmp.bitmapData;
+// }
}
}
\ No newline at end of file
--
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.