]> git.mjollnir.org Git - moodle.git/blob
d16b8bd488405f783ddc1ee36fad9ae86b5777be
[moodle.git] /
1 package flare.vis.operator.encoder
2 {
3         import flare.animate.Transitioner;
4         import flare.vis.data.DataSprite;
5         import flare.vis.operator.Operator;
6
7         /**
8          * A property encoder simply sets a group of properties to static
9          * values for all data sprites. An input object determines which
10          * properties to set and what their values are.
11          * 
12          * For example, a PropertyEncoder created with this call:
13          * <code>new PropertyEncoder({size:1, lineColor:0xff0000ff{);</code>
14          * will set the size to 1 and the line color to blue for all
15          * data sprites processed by the encoder.
16          */
17         public class PropertyEncoder extends Operator
18         {
19                 /** Flag indicating which data group (NODES, EDGES, or ALL) should
20                  *  be processed by this encoder. */
21                 protected var _which:int;
22                 /** Boolean function indicating which items to process. */
23                 protected var _filter:Function;
24                 /** Flag indicating if property values should be set immediately. */
25                 protected var _ignoreTrans:Boolean;
26                 /** The properties to set on each invocation. */
27                 protected var _values:Object;
28                 /** A transitioner for collecting value updates. */
29                 protected var _t:Transitioner;
30                 
31                 /** Flag indicating which data group (NODES, EDGES, or ALL) should
32                  *  be processed by this encoder. */
33                 public function get which():int { return _which; }
34                 public function set which(w:int):void { _which = w; }
35                 
36                 /** Boolean function indicating which items to process. Only items
37                  *  for which this function return true will be considered by the
38                  *  Encoder. If the function is null, all items will be considered. */
39                 public function get filter():Function { return _filter; }
40                 public function set filter(f:Function):void { _filter = f; }
41                 
42                 public function get ignoreTransitioner():Boolean { return _ignoreTrans; }
43                 public function set ignoreTransitioner(b:Boolean):void { _ignoreTrans = b; }
44                 
45                 /** The properties to set on each invocation. */
46                 public function get values():Object { return _values; }
47                 public function set values(o:Object):void { _values = o; }
48                 
49                 // --------------------------------------------------------------------
50                 
51                 /**
52                  * Creates a new PropertyEncoder
53                  * @param values The properties to set on each invocation. The input
54                  *  should be an object with a set of name/value pairs.
55                  * @param which Flag indicating which data group (NODES, EDGES, or ALL)
56                  *  should be processed by this encoder.
57                  * @param filter a Boolean-valued function that takes a DataSprite as
58                  *  input and returns true if the sprite should be processed
59                  * @param ignoreTransitioner Flag indicating if values should be set
60                  *  immediately rather than being processed by any transitioners
61                  */             
62                 public function PropertyEncoder(values:Object=null, which:int=1,
63                         filter:Function=null, ignoreTransitioner:Boolean=false)
64                 {
65                         _values = values==null ? {} : values;
66                         _which = which;
67                         _filter = filter;
68                         _ignoreTrans = ignoreTransitioner;
69                 }
70                 
71                 /** @inheritDoc */
72                 public override function operate(t:Transitioner=null):void
73                 {
74                         t = (t==null || _ignoreTrans ? Transitioner.DEFAULT : t);
75                         if (_values == null) return;
76                         
77                         visualization.data.visit(function(d:DataSprite):void {
78                                 for (var p:String in _values)
79                                         t.setValue(d, p, _values[p]);
80                         }, _which, _filter);
81                 }
82                 
83         } // end of class PropertyEncoder
84 }