1 package flare.vis.operator.distortion
3 import flash.geom.Rectangle;
6 * Computes a graphical fisheye distortion of a graph view. This distortion
7 * allocates more space to items near the layout anchor and less space to
8 * items further away, magnifying space near the anchor and demagnifying
9 * distant space in a continuous fashion.
12 * For more details on this form of transformation, see Manojit Sarkar and
13 * Marc H. Brown, "Graphical Fisheye Views of Graphs", in Proceedings of
14 * CHI'92, Human Factors in Computing Systems, p. 83-91, 1992. Available
15 * online at <a href="http://citeseer.ist.psu.edu/sarkar92graphical.html">
16 * http://citeseer.ist.psu.edu/sarkar92graphical.html</a>.
19 public class FisheyeDistortion extends Distortion
21 private var _dx:Number; // x distortion factor
22 private var _dy:Number; // y distortion factor
23 private var _ds:Number; // size distortion factor
25 // --------------------------------------------------------------------
28 * Create a new FisheyeDistortion with the given distortion factors
29 * along the x and y directions.
30 * @param dx the distortion factor along the x axis (0 for none)
31 * @param dy the distortion factor along the y axis (0 for none)
32 * @param ds the distortion factor to use for sizes (0 for none)
34 public function FisheyeDistortion(dx:Number=4, dy:Number=4, ds:Number=3) {
38 super(_dx>0, _dy>0, _ds>0);
42 protected override function xDistort(x:Number):Number
44 return fisheye(x, layoutAnchor.x, _dx, _b.left, _b.right);
48 protected override function yDistort(y:Number):Number
50 return fisheye(y, layoutAnchor.y, _dy, _b.top, _b.bottom);
54 protected override function sizeDistort(bb:Rectangle, x:Number, y:Number):Number
56 if (!_distortX && !_distortY) return 1;
57 var fx:Number=1, fy:Number=1;
58 var a:Number, min:Number, max:Number, v:Number;
64 v = Math.abs(min-a) > Math.abs(max-a) ? min : max;
65 if (v < _b.left || v > _b.right) v = (v==min ? max : min);
66 fx = fisheye(v, a, _dx, _b.left, _b.right);
67 fx = Math.abs(x-fx) / (max - min);
74 v = Math.abs(min-a) > Math.abs(max-a) ? min : max;
75 if (v < _b.top || v > _b.bottom) v = (v==min ? max : min);
76 fy = fisheye(v, a, _dy, _b.top, _b.bottom);
77 fy = Math.abs(y-fy) / (max - min);
80 var sf:Number = (!_distortY ? fx : (!_distortX ? fy : Math.min(fx,fy)));
81 return (!isFinite(sf) || isNaN(sf)) ? 1 : _ds * sf;
84 private function fisheye(x:Number, a:Number, d:Number,
85 min:Number, max:Number) : Number
89 var left:Boolean = x<a;
90 var v:Number, m:Number = (left ? a-min : max-a);
91 if ( m == 0 ) m = max-min;
92 v = Math.abs(x - a) / m;
94 return (left?-1:1)*m*v + a;
97 } // end of class FisheyeDistortion