1 package flare.vis.operator.filter
3 import flare.vis.operator.Operator;
4 import flare.animate.Transitioner;
5 import flare.vis.data.Data;
6 import flare.vis.data.DataSprite;
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.
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>
25 public class VisibilityFilter extends Operator
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. */
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
38 public var filter:Function;
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.
48 public function VisibilityFilter(predicate:Function,
49 which:int=1/*Data.NODES*/, filter:Function=null)
51 this.predicate = predicate;
57 public override function operate(t:Transitioner=null):void
59 t = (t==null ? Transitioner.DEFAULT : t);
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;
68 } // end of class VisibilityFilter