]> git.mjollnir.org Git - moodle.git/blob
d5eb457b2f7335d475c7e33f79de3de2aa158a93
[moodle.git] /
1 package flare.vis.operator.filter
2 {
3         import flare.vis.operator.Operator;
4         import flare.animate.Transitioner;
5         import flare.vis.data.Data;
6         import flare.vis.data.DataSprite;
7
8         /**
9          * Filter operator that sets item visibility based on a filtering
10          * condition. Filtering conditions are specified using Boolean-valued
11          * predicate functions that return true if the item meets the filtering
12          * criteria and false if it does not. For items which meet the criteria,
13          * this class sets the <code>visibility</code> property to true and
14          * the <code>alpha</code> value to 1. For those items that do not meet
15          * the criteria, this class sets the <code>visibility</code> property to
16          * false and the <code>alpha</code> value to 0.
17          * 
18          * <p>Predicate functions can either be arbitrary functions that take
19          * a single argument and return a Boolean value, or can be systematically
20          * constructed using the <code>Expression</code> language provided by the
21          * <code>flare.query</code> package.</p>
22          * 
23          * @see flare.query
24          */
25         public class VisibilityFilter extends Operator
26         {
27                 /** Predicate function determining item visibility. */
28                 public var predicate:Function;
29                 /** Flag indicating which data group (NODES, EDGES, or ALL) should
30                  *  be processed by this filter. */
31                 public var which:int;
32                 /** Boolean function indicating which items to process. This function
33                  *  <strong>does not</strong> determine which items will be visible, it
34                  *  only determines which items are visited by this operator. Only
35                  *  items for which this function return true will be considered by the
36                  *  VisibilityFilter. If the function is null, all items will be
37                  *  considered. */
38                 public var filter:Function;
39                 
40                 /**
41                  * Creates a new VisibilityFilter.
42                  * @param predicate the predicate function for filtering items. This
43                  *  should be a Boolean-valued function that returns true for items
44                  *  that pass the filtering criteria and false for those that do not.
45                  * @param which flag indicating which data group (NODES, EDGES, or ALL)
46                  *  should be processed by this filter.
47                  */
48                 public function VisibilityFilter(predicate:Function,
49                                                 which:int=1/*Data.NODES*/, filter:Function=null)
50                 {
51                         this.predicate = predicate;
52                         this.which = which;
53                         this.filter = filter;
54                 }
55
56                 /** @inheritDoc */
57                 public override function operate(t:Transitioner=null):void
58                 {
59                         t = (t==null ? Transitioner.DEFAULT : t);
60                         
61                         visualization.data.visit(function(d:DataSprite):void {
62                                 var visible:Boolean = predicate(d);
63                                 t.$(d).alpha = visible ? 1 : 0;
64                                 t.$(d).visible = visible;
65                         }, which, filter);
66                 }
67                 
68         } // end of class VisibilityFilter
69 }