├── .gitignore ├── etc └── flexTasks.jar ├── flare.tests ├── lib │ └── unitest.swc ├── .settings │ └── com.adobe.flexbuilder.project.prefs ├── html-template │ ├── playerProductInstall.swf │ └── deeplinking │ │ ├── deeplinking.css │ │ └── historyFrame.html ├── .project ├── src │ ├── tests.as │ └── flare │ │ └── tests │ │ └── MatrixTests.as └── .actionScriptProperties ├── flare ├── build │ ├── deploy │ │ └── flare-1.0b1.swc │ ├── version.properties │ └── build-swc.sh ├── .settings │ └── org.eclipse.core.resources.prefs ├── src │ └── flare │ │ ├── query │ │ ├── methods │ │ │ ├── _.as │ │ │ ├── count.as │ │ │ ├── sum.as │ │ │ ├── max.as │ │ │ ├── min.as │ │ │ ├── average.as │ │ │ ├── distinct.as │ │ │ ├── select.as │ │ │ ├── where.as │ │ │ ├── orderby.as │ │ │ ├── update.as │ │ │ ├── or.as │ │ │ ├── and.as │ │ │ ├── variance.as │ │ │ ├── xor.as │ │ │ ├── stddev.as │ │ │ ├── not.as │ │ │ ├── isa.as │ │ │ ├── fn.as │ │ │ ├── mod.as │ │ │ ├── add.as │ │ │ ├── div.as │ │ │ ├── eq.as │ │ │ ├── lt.as │ │ │ ├── neq.as │ │ │ ├── sub.as │ │ │ ├── gt.as │ │ │ ├── mul.as │ │ │ ├── lte.as │ │ │ ├── gte.as │ │ │ ├── iff.as │ │ │ └── range.as │ │ ├── Count.as │ │ ├── Sum.as │ │ ├── Maximum.as │ │ ├── Minimum.as │ │ ├── Average.as │ │ ├── Distinct.as │ │ ├── Or.as │ │ ├── And.as │ │ ├── Xor.as │ │ ├── Variable.as │ │ ├── Literal.as │ │ ├── Range.as │ │ ├── Not.as │ │ ├── AggregateExpression.as │ │ ├── Variance.as │ │ ├── IsA.as │ │ └── If.as │ │ ├── physics │ │ ├── IForce.as │ │ ├── DragForce.as │ │ ├── GravityForce.as │ │ ├── SpringForce.as │ │ ├── Spring.as │ │ └── Particle.as │ │ ├── util │ │ ├── IEvaluable.as │ │ ├── IPredicate.as │ │ ├── IValueProxy.as │ │ ├── palette │ │ │ ├── Palette.as │ │ │ ├── ShapePalette.as │ │ │ └── SizePalette.as │ │ ├── heap │ │ │ └── HeapNode.as │ │ ├── Orientation.as │ │ ├── Padding.as │ │ ├── Filter.as │ │ ├── gradient │ │ │ └── GradientStop.as │ │ └── math │ │ │ └── IMatrix.as │ │ ├── vis │ │ ├── data │ │ │ └── render │ │ │ │ ├── IRenderer.as │ │ │ │ ├── ArrowType.as │ │ │ │ └── ShapeRenderer.as │ │ ├── axis │ │ │ ├── AxisLabel.as │ │ │ ├── AxisGridLine.as │ │ │ └── Axes.as │ │ ├── controls │ │ │ ├── IControl.as │ │ │ ├── Control.as │ │ │ ├── AnchorControl.as │ │ │ ├── DragControl.as │ │ │ └── ExpandControl.as │ │ ├── operator │ │ │ ├── layout │ │ │ │ ├── RandomLayout.as │ │ │ │ └── PieLayout.as │ │ │ ├── IOperator.as │ │ │ ├── encoder │ │ │ │ ├── ShapeEncoder.as │ │ │ │ └── SizeEncoder.as │ │ │ ├── SortOperator.as │ │ │ ├── Operator.as │ │ │ └── OperatorSwitch.as │ │ └── events │ │ │ ├── VisualizationEvent.as │ │ │ ├── TooltipEvent.as │ │ │ ├── SelectionEvent.as │ │ │ └── DataEvent.as │ │ ├── animate │ │ ├── Pause.as │ │ ├── ISchedulable.as │ │ ├── TransitionEvent.as │ │ └── interpolate │ │ │ ├── DateInterpolator.as │ │ │ ├── NumberInterpolator.as │ │ │ ├── ObjectInterpolator.as │ │ │ ├── PointInterpolator.as │ │ │ ├── ArrayInterpolator.as │ │ │ ├── ColorInterpolator.as │ │ │ ├── RectangleInterpolator.as │ │ │ ├── VectorInterpolator.as │ │ │ └── MatrixInterpolator.as │ │ ├── display │ │ ├── render │ │ │ ├── IBackgroundRenderer.as │ │ │ └── BackgroundRenderer.as │ │ └── LineSprite.as │ │ ├── data │ │ ├── DataSet.as │ │ ├── converters │ │ │ ├── Converters.as │ │ │ ├── IDataConverter.as │ │ │ └── JSONConverter.as │ │ ├── DataTable.as │ │ ├── DataField.as │ │ └── DataSchema.as │ │ ├── analytics │ │ └── cluster │ │ │ └── MergeEdge.as │ │ └── scale │ │ ├── LinearScale.as │ │ ├── RootScale.as │ │ ├── ScaleType.as │ │ ├── IScaleMap.as │ │ └── QuantileScale.as ├── src-flex-integration │ └── flex-manifest.xml ├── .project └── lib │ └── com │ └── adobe │ └── serialization │ └── json │ └── JSONTokenType.as ├── flare.apps ├── src │ └── flare │ │ ├── apps │ │ ├── verdana.TTF │ │ └── App.as │ │ └── widgets │ │ └── PreLoader.as ├── html-template │ ├── playerProductInstall.swf │ └── deeplinking │ │ ├── deeplinking.css │ │ └── historyFrame.html ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.ltk.core.refactoring.prefs ├── .project ├── etc │ └── CodeExtract.py └── .actionScriptProperties ├── flare.demos ├── .settings │ └── com.adobe.flexbuilder.project.prefs ├── html-template │ ├── playerProductInstall.swf │ └── deeplinking │ │ ├── deeplinking.css │ │ └── historyFrame.html ├── .project ├── src │ └── flare │ │ └── demos │ │ ├── util │ │ ├── Link.as │ │ └── LinkGroup.as │ │ ├── Demo.as │ │ ├── TreeMap.as │ │ └── Smoke.as └── .actionScriptProperties ├── README └── license-flare.txt /.gitignore: -------------------------------------------------------------------------------- 1 | flare/bin/flare.swc -------------------------------------------------------------------------------- /etc/flexTasks.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwdata/Flare/master/etc/flexTasks.jar -------------------------------------------------------------------------------- /flare.tests/lib/unitest.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwdata/Flare/master/flare.tests/lib/unitest.swc -------------------------------------------------------------------------------- /flare/build/deploy/flare-1.0b1.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwdata/Flare/master/flare/build/deploy/flare-1.0b1.swc -------------------------------------------------------------------------------- /flare.apps/src/flare/apps/verdana.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwdata/Flare/master/flare.apps/src/flare/apps/verdana.TTF -------------------------------------------------------------------------------- /flare.apps/html-template/playerProductInstall.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwdata/Flare/master/flare.apps/html-template/playerProductInstall.swf -------------------------------------------------------------------------------- /flare.demos/.settings/com.adobe.flexbuilder.project.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jul 19 23:06:24 PDT 2010 2 | eclipse.preferences.version=1 3 | upgradeSDK/fb4= 4 | -------------------------------------------------------------------------------- /flare.tests/.settings/com.adobe.flexbuilder.project.prefs: -------------------------------------------------------------------------------- 1 | #Wed Aug 04 13:14:22 PDT 2010 2 | eclipse.preferences.version=1 3 | upgradeSDK/fb4= 4 | -------------------------------------------------------------------------------- /flare/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Wed May 07 18:21:41 PDT 2008 2 | eclipse.preferences.version=1 3 | encoding/=utf-8 4 | -------------------------------------------------------------------------------- /flare.apps/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Sat Jun 14 10:53:05 PDT 2008 2 | eclipse.preferences.version=1 3 | encoding/=utf-8 4 | -------------------------------------------------------------------------------- /flare.demos/html-template/playerProductInstall.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwdata/Flare/master/flare.demos/html-template/playerProductInstall.swf -------------------------------------------------------------------------------- /flare.tests/html-template/playerProductInstall.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uwdata/Flare/master/flare.tests/html-template/playerProductInstall.swf -------------------------------------------------------------------------------- /flare/build/version.properties: -------------------------------------------------------------------------------- 1 | build.groupId=flare 2 | build.artifactId=flare 3 | build.version=1.0b1 4 | build.finalName=${build.artifactId}-${build.version} -------------------------------------------------------------------------------- /flare.apps/.settings/org.eclipse.ltk.core.refactoring.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jul 28 18:50:46 PDT 2008 2 | eclipse.preferences.version=1 3 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false 4 | -------------------------------------------------------------------------------- /flare/build/build-swc.sh: -------------------------------------------------------------------------------- 1 | # swc 2 | compc \ 3 | -source-path src \ 4 | -include-sources src \ 5 | -namespace http://ns.flare.com/2010/mxml src-flex-integration/flare-manifest.xml \ 6 | -output bin/flare-1.1.0.swc -------------------------------------------------------------------------------- /flare/src/flare/query/methods/_.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Literal; 4 | 5 | /** 6 | * Returns a new Literal operator. 7 | * @param the input object 8 | * @return the new Literal expression 9 | */ 10 | public function _(a:*):Literal 11 | { 12 | return new Literal(a); 13 | } 14 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/count.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Count; 4 | 5 | /** 6 | * Creates a new Count query operator. 7 | * @param expr the input expression 8 | * @return the new query operator 9 | */ 10 | public function count(expr:*):Count 11 | { 12 | return new Count(expr); 13 | } 14 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/sum.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Sum; 4 | 5 | /** 6 | * Creates a new 'sum' Arithmetic query operator. 7 | * @param expr the input expression 8 | * @return the new query operator 9 | */ 10 | public function sum(expr:*):Sum 11 | { 12 | return new Sum(expr); 13 | } 14 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/max.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Maximum; 4 | 5 | /** 6 | * Creates a new Maximum query operator. 7 | * @param expr the input expression 8 | * @return the new query operator 9 | */ 10 | public function max(expr:*):Maximum 11 | { 12 | return new Maximum(expr); 13 | } 14 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/min.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Minimum; 4 | 5 | /** 6 | * Creates a new Minimum query operator. 7 | * @param expr the input expression 8 | * @return the new query operator 9 | */ 10 | public function min(expr:*):Minimum 11 | { 12 | return new Minimum(expr); 13 | } 14 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/average.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Average; 4 | 5 | /** 6 | * Creates a new Average query operator. 7 | * @param expr the input expression 8 | * @return the new query operator 9 | */ 10 | public function average(expr:*):Average 11 | { 12 | return new Average(expr); 13 | } 14 | } -------------------------------------------------------------------------------- /flare/src-flex-integration/flex-manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /flare/src/flare/query/methods/distinct.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Distinct; 4 | 5 | /** 6 | * Creates a new Distinct query operator. 7 | * @param expr the input expression 8 | * @return the new query operator 9 | */ 10 | public function distinct(expr:*):Distinct 11 | { 12 | return new Distinct(expr); 13 | } 14 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/select.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Query; 4 | 5 | /** 6 | * Create a new Query with the given select clauses. 7 | * @param terms a list of select clauses 8 | * @return the created query. 9 | */ 10 | public function select(...terms):Query 11 | { 12 | return new Query(terms); 13 | } 14 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/where.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Query; 4 | 5 | /** 6 | * Create a new Query with the given filter expression. 7 | * @param expr the filter expression 8 | * @return the created query. 9 | */ 10 | public function where(expr:*):Query 11 | { 12 | return new Query().where(expr); 13 | } 14 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/orderby.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Query; 4 | 5 | /** 6 | * Create a new Query with the given sort criteria. 7 | * @param terms a list of sort criteria 8 | * @return the created query. 9 | */ 10 | public function orderby(...terms):Query 11 | { 12 | return new Query(null, null, terms); 13 | } 14 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/update.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Query; 4 | 5 | /** 6 | * Create a new Query with the given update clauses. 7 | * @param terms a list of update clauses 8 | * @return the created query. 9 | */ 10 | public function update(...terms):Query 11 | { 12 | return new Query().update(terms); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /flare/src/flare/physics/IForce.as: -------------------------------------------------------------------------------- 1 | package flare.physics 2 | { 3 | /** 4 | * Interface representing a force within a physics simulation. 5 | */ 6 | public interface IForce 7 | { 8 | /** 9 | * Applies this force to a simulation. 10 | * @param sim the Simulation to apply the force to 11 | */ 12 | function apply(sim:Simulation):void; 13 | 14 | } // end of interface IForce 15 | } -------------------------------------------------------------------------------- /flare.apps/html-template/deeplinking/deeplinking.css: -------------------------------------------------------------------------------- 1 | /* This CSS stylesheet defines styles used by required elements in a DeepLinking application page */ 2 | 3 | #ie_historyFrame { width: 0px; height: 0px; display:none } 4 | #firefox_anchorDiv { width: 0px; height: 0px; display:none } 5 | #safari_formDiv { width: 0px; height: 0px; display:none } 6 | #safari_rememberDiv { width: 0px; height: 0px; display:none } 7 | -------------------------------------------------------------------------------- /flare.demos/html-template/deeplinking/deeplinking.css: -------------------------------------------------------------------------------- 1 | /* This CSS stylesheet defines styles used by required elements in a DeepLinking application page */ 2 | 3 | #ie_historyFrame { width: 0px; height: 0px; display:none } 4 | #firefox_anchorDiv { width: 0px; height: 0px; display:none } 5 | #safari_formDiv { width: 0px; height: 0px; display:none } 6 | #safari_rememberDiv { width: 0px; height: 0px; display:none } 7 | -------------------------------------------------------------------------------- /flare.tests/html-template/deeplinking/deeplinking.css: -------------------------------------------------------------------------------- 1 | /* This CSS stylesheet defines styles used by required elements in a DeepLinking application page */ 2 | 3 | #ie_historyFrame { width: 0px; height: 0px; display:none } 4 | #firefox_anchorDiv { width: 0px; height: 0px; display:none } 5 | #safari_formDiv { width: 0px; height: 0px; display:none } 6 | #safari_rememberDiv { width: 0px; height: 0px; display:none } 7 | -------------------------------------------------------------------------------- /flare/src/flare/query/methods/or.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Or; 4 | 5 | /** 6 | * Creates a new Or query operator. 7 | * @param rest a list of expressions to include in the or 8 | * @return the new query operator 9 | */ 10 | public function or(...rest):Or 11 | { 12 | var o:Or = new Or(); 13 | o.setChildren(rest); 14 | return o; 15 | } 16 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/and.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.And; 4 | 5 | /** 6 | * Creates a new And query operator. 7 | * @param rest a list of expressions to include in the and 8 | * @return the new query operator 9 | */ 10 | public function and(...rest):And 11 | { 12 | var a:And = new And(); 13 | a.setChildren(rest); 14 | return a; 15 | } 16 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/variance.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Variance; 4 | 5 | /** 6 | * Creates a new Variance query operator that computes 7 | * the population variance. 8 | * @param expr the input expression 9 | * @return the new query operator 10 | */ 11 | public function variance(expr:*):Variance 12 | { 13 | return new Variance(expr); 14 | } 15 | } -------------------------------------------------------------------------------- /flare/src/flare/util/IEvaluable.as: -------------------------------------------------------------------------------- 1 | package flare.util 2 | { 3 | /** 4 | * Interface for methods that evaluate an object and return a result. 5 | */ 6 | public interface IEvaluable 7 | { 8 | /** 9 | * Evaluates the input object 10 | * @o the object to evaluate 11 | * @return the computed result value 12 | */ 13 | function eval(o:Object=null):*; 14 | 15 | } // end of interface IEvaluable 16 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/xor.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Xor; 4 | 5 | /** 6 | * Creates a new Xor (exclusive or) query operator. 7 | * @param rest a list of expressions to include in the exclusive or 8 | * @return the new query operator 9 | */ 10 | public function xor(...rest):Xor 11 | { 12 | var x:Xor = new Xor(); 13 | x.setChildren(rest); 14 | return x; 15 | } 16 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/stddev.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Variance; 4 | 5 | /** 6 | * Creates a new Variance query operator that computes 7 | * the population standard deviation. 8 | * @param expr the input expression 9 | * @return the new query operator 10 | */ 11 | public function stddev(expr:*):Variance 12 | { 13 | return new Variance(expr, Variance.DEVIATION); 14 | } 15 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/data/render/IRenderer.as: -------------------------------------------------------------------------------- 1 | package flare.vis.data.render 2 | { 3 | import flare.vis.data.DataSprite; 4 | 5 | /** 6 | * Interface for DataSprite rendering modules. 7 | */ 8 | public interface IRenderer 9 | { 10 | /** 11 | * Renders drawing content for the input DataSprite. 12 | * @param d the DataSprite to draw 13 | */ 14 | function render(d:DataSprite):void; 15 | 16 | } // end of interface IRenderer 17 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/not.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Not; 4 | 5 | /** 6 | * Creates a new Not query operator. 7 | * @param x the expression to negate 8 | * This value can be an expression or a literal value. 9 | * Literal values are parsed using the Expression.expr method. 10 | * @return the new query operator 11 | */ 12 | public function not(x:*):Not 13 | { 14 | return new Not(x); 15 | } 16 | } -------------------------------------------------------------------------------- /flare/src/flare/util/IPredicate.as: -------------------------------------------------------------------------------- 1 | package flare.util 2 | { 3 | /** 4 | * Interface for methods that evaluate an object and return true or false. 5 | */ 6 | public interface IPredicate 7 | { 8 | /** 9 | * Boolean test function that returns true or false for an 10 | * input object. 11 | * @param o the input object 12 | * @return true or false 13 | */ 14 | function predicate(o:Object):Boolean; 15 | 16 | } // end of interface IPredicate 17 | } -------------------------------------------------------------------------------- /flare.apps/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | flare.apps 4 | 5 | 6 | 7 | 8 | 9 | com.adobe.flexbuilder.project.flexbuilder 10 | 11 | 12 | 13 | 14 | 15 | com.adobe.flexbuilder.project.actionscriptnature 16 | 17 | 18 | -------------------------------------------------------------------------------- /flare/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | flare 4 | 5 | 6 | 7 | 8 | 9 | com.adobe.flexbuilder.project.flexbuilder 10 | 11 | 12 | 13 | 14 | 15 | com.adobe.flexbuilder.project.flexlibnature 16 | com.adobe.flexbuilder.project.actionscriptnature 17 | 18 | 19 | -------------------------------------------------------------------------------- /flare/src/flare/animate/Pause.as: -------------------------------------------------------------------------------- 1 | package flare.animate 2 | { 3 | /** 4 | * Transition representing a pause or dwell in which nothing happens. 5 | * Useful for adding pauses within an animation sequence. 6 | */ 7 | public class Pause extends Transition 8 | { 9 | /** 10 | * Creates a new Pause transition with specified duration. 11 | * @param duration the length of the pause, in seconds 12 | */ 13 | public function Pause(duration:Number) { 14 | super(duration); 15 | } 16 | 17 | } // end of class Pause 18 | } -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Flare is an ActionScript library for creating visualizations that run in the Adobe Flash Player. From basic charts and graphs to complex interactive graphics, the toolkit supports data management, visual encoding, animation, and interaction techniques. 2 | 3 | Flare is a creation of the UC Berkeley Visualization Lab http://vis.berkeley.edu/. For more information see license-flare.txt and http://flare.prefuse.org/. 4 | 5 | This repository was initially created from the release available at http://downloads.sourceforge.net/prefuse/prefuse.flare-alpha-20090124.zip -------------------------------------------------------------------------------- /flare/src/flare/query/methods/isa.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.IsA; 4 | 5 | /** 6 | * Creates a new IsType query operator. 7 | * @param type the class type to check for 8 | * @param x the expression to type check 9 | * This value can be an expression or a literal value. 10 | * Literal values are parsed using the Expression.expr method. 11 | * @return the new query operator 12 | */ 13 | public function isa(type:Class, x:*=null):IsA 14 | { 15 | return new IsA(type, x); 16 | } 17 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/fn.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Fn; 4 | 5 | /** 6 | * Creates a new Fn query operator for a function in a query. 7 | * @param name the name of the function. This should be a function 8 | * registered with the Fn class. 9 | * @param args a list of arguments to the function 10 | * @return the new Fn operator 11 | */ 12 | public function fn(name:String, ...args):Fn 13 | { 14 | var f:Fn = new Fn(name); 15 | f.setChildren(args); 16 | return f; 17 | } 18 | } -------------------------------------------------------------------------------- /flare/src/flare/display/render/IBackgroundRenderer.as: -------------------------------------------------------------------------------- 1 | package flare.display.render 2 | { 3 | import flare.display.DisplaySprite; 4 | 5 | import flash.geom.Rectangle; 6 | 7 | /** 8 | * Interface for DisplaySprite background rendering modules. 9 | */ 10 | public interface IBackgroundRenderer 11 | { 12 | /** 13 | * Renders background content for the input DisplaySprite. 14 | * @param displaySprite the DisplaySprite to draw 15 | * @param bounds the background Rectangle bounds 16 | */ 17 | function render( displaySprite:DisplaySprite, bounds:Rectangle ):void; 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /flare.demos/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | flare.demos 4 | 5 | 6 | flare.animate 7 | flare.physics 8 | flare.util 9 | flare.vis 10 | 11 | 12 | 13 | com.adobe.flexbuilder.project.flexbuilder 14 | 15 | 16 | 17 | 18 | 19 | com.adobe.flexbuilder.project.actionscriptnature 20 | 21 | 22 | -------------------------------------------------------------------------------- /flare/src/flare/query/methods/mod.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Arithmetic; 4 | 5 | /** 6 | * Creates a new modulo Arithmetic query operator. 7 | * @param a the left side argument. 8 | * This value can be an expression or a literal value. 9 | * Literal values are parsed using the Expression.expr method. 10 | * @param b the right side argument 11 | * This value can be an expression or a literal value. 12 | * Literal values are parsed using the Expression.expr method. 13 | * @return the new query operator 14 | */ 15 | public function mod(a:*, b:*):Arithmetic 16 | { 17 | return Arithmetic.Mod(a, b); 18 | } 19 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/add.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Arithmetic; 4 | 5 | /** 6 | * Creates a new addition Arithmetic query operator. 7 | * @param a the left side argument. 8 | * This value can be an expression or a literal value. 9 | * Literal values are parsed using the Expression.expr method. 10 | * @param b the right side argument 11 | * This value can be an expression or a literal value. 12 | * Literal values are parsed using the Expression.expr method. 13 | * @return the new query operator 14 | */ 15 | public function add(a:*, b:*):Arithmetic 16 | { 17 | return Arithmetic.Add(a, b); 18 | } 19 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/div.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Arithmetic; 4 | 5 | /** 6 | * Creates a new division Arithmetic query operator. 7 | * @param a the left side argument. 8 | * This value can be an expression or a literal value. 9 | * Literal values are parsed using the Expression.expr method. 10 | * @param b the right side argument 11 | * This value can be an expression or a literal value. 12 | * Literal values are parsed using the Expression.expr method. 13 | * @return the new query operator 14 | */ 15 | public function div(a:*, b:*):Arithmetic 16 | { 17 | return Arithmetic.Divide(a, b); 18 | } 19 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/eq.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Comparison; 4 | 5 | /** 6 | * Creates a new equality Comparison query operator. 7 | * @param a the left side argument. 8 | * This value can be an expression or a literal value. 9 | * Literal values are parsed using the Expression.expr method. 10 | * @param b the right side argument 11 | * This value can be an expression or a literal value. 12 | * Literal values are parsed using the Expression.expr method. 13 | * @return the new query operator 14 | */ 15 | public function eq(a:*, b:*):Comparison 16 | { 17 | return Comparison.Equal(a, b); 18 | } 19 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/lt.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Comparison; 4 | 5 | /** 6 | * Creates a new less-than Comparison query operator. 7 | * @param a the left side argument. 8 | * This value can be an expression or a literal value. 9 | * Literal values are parsed using the Expression.expr method. 10 | * @param b the right side argument 11 | * This value can be an expression or a literal value. 12 | * Literal values are parsed using the Expression.expr method. 13 | * @return the new query operator 14 | */ 15 | public function lt(a:*, b:*):Comparison 16 | { 17 | return Comparison.LessThan(a, b); 18 | } 19 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/neq.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Comparison; 4 | 5 | /** 6 | * Creates a new inequality Comparison query operator. 7 | * @param a the left side argument. 8 | * This value can be an expression or a literal value. 9 | * Literal values are parsed using the Expression.expr method. 10 | * @param b the right side argument 11 | * This value can be an expression or a literal value. 12 | * Literal values are parsed using the Expression.expr method. 13 | * @return the new query operator 14 | */ 15 | public function neq(a:*, b:*):Comparison 16 | { 17 | return Comparison.NotEqual(a, b); 18 | } 19 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/sub.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Arithmetic; 4 | 5 | /** 6 | * Creates a new subtraction Arithmetic query operator. 7 | * @param a the left side argument. 8 | * This value can be an expression or a literal value. 9 | * Literal values are parsed using the Expression.expr method. 10 | * @param b the right side argument 11 | * This value can be an expression or a literal value. 12 | * Literal values are parsed using the Expression.expr method. 13 | * @return the new query operator 14 | */ 15 | public function sub(a:*, b:*):Arithmetic 16 | { 17 | return Arithmetic.Subtract(a, b); 18 | } 19 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/gt.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Comparison; 4 | 5 | /** 6 | * Creates a new greater-than Comparison query operator. 7 | * @param a the left side argument. 8 | * This value can be an expression or a literal value. 9 | * Literal values are parsed using the Expression.expr method. 10 | * @param b the right side argument 11 | * This value can be an expression or a literal value. 12 | * Literal values are parsed using the Expression.expr method. 13 | * @return the new query operator 14 | */ 15 | public function gt(a:*, b:*):Comparison 16 | { 17 | return Comparison.GreaterThan(a, b); 18 | } 19 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/mul.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Arithmetic; 4 | 5 | /** 6 | * Creates a new multiplication Arithmetic query operator. 7 | * @param a the left side argument. 8 | * This value can be an expression or a literal value. 9 | * Literal values are parsed using the Expression.expr method. 10 | * @param b the right side argument 11 | * This value can be an expression or a literal value. 12 | * Literal values are parsed using the Expression.expr method. 13 | * @return the new query operator 14 | */ 15 | public function mul(a:*, b:*):Arithmetic 16 | { 17 | return Arithmetic.Multiply(a, b); 18 | } 19 | } -------------------------------------------------------------------------------- /flare/src/flare/data/DataSet.as: -------------------------------------------------------------------------------- 1 | package flare.data 2 | { 3 | /** 4 | * A data set is a collection of data tables. 5 | */ 6 | public class DataSet 7 | { 8 | /** 9 | * Creates a new DataSet. 10 | * @param nodes a data table of node data 11 | * @param edges a data table of edge data (optional, for graphs only) 12 | */ 13 | public function DataSet(nodes:DataTable, edges:DataTable=null) { 14 | this.nodes = nodes; 15 | this.edges = edges; 16 | } 17 | 18 | /** A DataTable of nodes (or table rows). */ 19 | public var nodes:DataTable = null; 20 | 21 | /** A DataTable of edges. */ 22 | public var edges:DataTable = null; 23 | 24 | } // end of class DataSet 25 | } -------------------------------------------------------------------------------- /flare.tests/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | flare.tests 4 | 5 | 6 | flare.animate 7 | flare.data 8 | flare.physics 9 | flare.query 10 | flare.util 11 | flare.vis 12 | 13 | 14 | 15 | com.adobe.flexbuilder.project.flexbuilder 16 | 17 | 18 | 19 | 20 | 21 | com.adobe.flexbuilder.project.actionscriptnature 22 | 23 | 24 | -------------------------------------------------------------------------------- /flare/src/flare/query/methods/lte.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Comparison; 4 | 5 | /** 6 | * Creates a new less-than-or-equal Comparison query 7 | * operator. 8 | * @param a the left side argument. 9 | * This value can be an expression or a literal value. 10 | * Literal values are parsed using the Expression.expr method. 11 | * @param b the right side argument 12 | * This value can be an expression or a literal value. 13 | * Literal values are parsed using the Expression.expr method. 14 | * @return the new query operator 15 | */ 16 | public function lte(a:*, b:*):Comparison 17 | { 18 | return Comparison.LessThanOrEqual(a, b); 19 | } 20 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/gte.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Comparison; 4 | 5 | /** 6 | * Creates a new greater-than-or-equal Comparison query 7 | * operator. 8 | * @param a the left side argument. 9 | * This value can be an expression or a literal value. 10 | * Literal values are parsed using the Expression.expr method. 11 | * @param b the right side argument 12 | * This value can be an expression or a literal value. 13 | * Literal values are parsed using the Expression.expr method. 14 | * @return the new query operator 15 | */ 16 | public function gte(a:*, b:*):Comparison 17 | { 18 | return Comparison.GreaterThanOrEqual(a, b); 19 | } 20 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/axis/AxisLabel.as: -------------------------------------------------------------------------------- 1 | package flare.vis.axis 2 | { 3 | import flare.display.TextSprite; 4 | 5 | /** 6 | * Axis label in an axis display. 7 | */ 8 | public class AxisLabel extends TextSprite 9 | { 10 | private var _ordinal:int; 11 | private var _value:Object; 12 | 13 | /** The ordinal index of this axis label in the list of labels. */ 14 | public function get ordinal():int { return _ordinal; } 15 | public function set ordinal(ord:int):void { _ordinal = ord; } 16 | 17 | /** The data value represented by this axis label. */ 18 | public function get value():Object { return _value; } 19 | public function set value(value:Object):void { _value = value; } 20 | 21 | } // end of class AxisLabel 22 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/axis/AxisGridLine.as: -------------------------------------------------------------------------------- 1 | package flare.vis.axis 2 | { 3 | import flare.display.LineSprite; 4 | 5 | /** 6 | * Axis grid line in an axis display. 7 | */ 8 | public class AxisGridLine extends LineSprite 9 | { 10 | private var _ordinal:int; 11 | private var _value:Object; 12 | 13 | /** The ordinal index of this grid line in the list of grid lines. */ 14 | public function get ordinal():int { return _ordinal; } 15 | public function set ordinal(ord:int):void { _ordinal = ord; } 16 | 17 | /** The data value represented by this axis grid line. */ 18 | public function get value():Object { return _value; } 19 | public function set value(value:Object):void { _value = value; } 20 | 21 | } // end of class AxisGridLine 22 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/data/render/ArrowType.as: -------------------------------------------------------------------------------- 1 | package flare.vis.data.render 2 | { 3 | /** 4 | * Utility class defining arrow types for directed edges. 5 | */ 6 | public class ArrowType 7 | { 8 | /** Indicates that no arrows should be drawn. */ 9 | public static const NONE:String = "none"; 10 | /** Indicates that a closed triangular arrow head should be drawn. */ 11 | public static const TRIANGLE:String = "triangle"; 12 | /** Indicates that two lines should be used to draw the arrow head. */ 13 | public static const LINES:String = "lines"; 14 | 15 | /** 16 | * This constructor will throw an error, as this is an abstract class. 17 | */ 18 | public function ArrowType() 19 | { 20 | throw new Error("This is an abstract class."); 21 | } 22 | 23 | } // end of class ArrowType 24 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/controls/IControl.as: -------------------------------------------------------------------------------- 1 | package flare.vis.controls 2 | { 3 | import flash.display.InteractiveObject; 4 | 5 | public interface IControl 6 | { 7 | /** The interactive object this control is attached to. */ 8 | function get object():InteractiveObject; 9 | 10 | /** 11 | * Attach this control to the given interactive object. This method 12 | * will automatically detach if already attached to another object. 13 | * @param obj the display object to attach to 14 | */ 15 | function attach(obj:InteractiveObject):void; 16 | 17 | /** 18 | * Detach this control. 19 | * @return the interactive object this control was attached to, 20 | * or null if this control was not attached. 21 | */ 22 | function detach():InteractiveObject; 23 | 24 | } // end of interface IControl 25 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/iff.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.If; 4 | 5 | /** 6 | * Creates a new If query operator. 7 | * @param test the if test expression. 8 | * This value can be an expression or a literal value. 9 | * Literal values are parsed using the Expression.expr method. 10 | * @param then the then case expression 11 | * This value can be an expression or a literal value. 12 | * Literal values are parsed using the Expression.expr method. 13 | * @param els the else case expression 14 | * This value can be an expression or a literal value. 15 | * Literal values are parsed using the Expression.expr method. 16 | * @return the new query operator 17 | */ 18 | public function iff(test:*, then:*, els:*):If 19 | { 20 | return new If(test, then, els); 21 | } 22 | } -------------------------------------------------------------------------------- /flare/src/flare/data/converters/Converters.as: -------------------------------------------------------------------------------- 1 | package flare.data.converters 2 | { 3 | /** 4 | * Factory class for looking up the appropriate IDataConverter for a 5 | * given data format. 6 | */ 7 | public class Converters 8 | { 9 | private static var _lookup:Object = { 10 | "json":new JSONConverter(), 11 | "tab":new DelimitedTextConverter("\t"), 12 | "graphml":new GraphMLConverter() 13 | }; 14 | 15 | /** 16 | * Returns a data converter for the input format type. 17 | * @param type a format string (e.g., "tab" or "json"). 18 | * @return a data converter for the provided format, or null if no 19 | * matching converter was found. 20 | */ 21 | public static function lookup(type:String):IDataConverter 22 | { 23 | return _lookup[type.toLowerCase()]; 24 | } 25 | 26 | } // end of class Converters 27 | } -------------------------------------------------------------------------------- /flare/src/flare/query/methods/range.as: -------------------------------------------------------------------------------- 1 | package flare.query.methods 2 | { 3 | import flare.query.Range; 4 | 5 | /** 6 | * Creates a new Range query operator. 7 | * @param min the minimum range value. 8 | * This value can be an expression or a literal value. 9 | * Literal values are parsed using the Expression.expr method. 10 | * @param max the maximum range value. 11 | * This value can be an expression or a literal value. 12 | * Literal values are parsed using the Expression.expr method. 13 | * @param val the value to test for range inclusion. 14 | * This value can be an expression or a literal value. 15 | * Literal values are parsed using the Expression.expr method. 16 | * @return the new query operator 17 | */ 18 | public function range(min:*, max:*, val:*):Range 19 | { 20 | return new Range(min, max, val); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /flare/src/flare/data/DataTable.as: -------------------------------------------------------------------------------- 1 | package flare.data 2 | { 3 | /** 4 | * A data table maintains a collection of data objects, each 5 | * representing a row of data, and an optional data schema describing 6 | * the data variables. 7 | */ 8 | public class DataTable 9 | { 10 | /** 11 | * Creates a new data table instance. 12 | * @param data an array of tuples, each tuple is a row of data 13 | * @param schema an optional DataSchema describing the data columns 14 | */ 15 | public function DataTable(data:Array, schema:DataSchema=null) { 16 | this.data = data; 17 | this.schema = schema; 18 | } 19 | 20 | /** A DataSchema describing the data columns of the table. */ 21 | public var schema:DataSchema; 22 | 23 | /** An array of data objects, each representing a row of data. */ 24 | public var data:Array; 25 | 26 | } // end of class DataTable 27 | } -------------------------------------------------------------------------------- /flare.tests/src/tests.as: -------------------------------------------------------------------------------- 1 | package { 2 | import flare.tests.AnimationTests; 3 | import flare.tests.DataIOTests; 4 | import flare.tests.DataTests; 5 | import flare.tests.ExpressionTests; 6 | import flare.tests.MatrixTests; 7 | import flare.tests.SortTests; 8 | import flare.tests.StringFormatTests; 9 | import flare.tests.TreeTests; 10 | 11 | import unitest.TestSuite; 12 | 13 | [SWF(width="800", height="600", backgroundColor="#ffffff", frameRate="30")] 14 | public class tests extends TestSuite 15 | { 16 | public function tests() 17 | { 18 | addTest(new AnimationTests()); 19 | addTest(new StringFormatTests()); 20 | addTest(new ExpressionTests()); 21 | addTest(new DataTests()); 22 | addTest(new TreeTests()); 23 | addTest(new SortTests()); 24 | addTest(new DataIOTests()); 25 | addTest(new MatrixTests()); 26 | run(); 27 | } 28 | 29 | } // end of class tests 30 | } 31 | -------------------------------------------------------------------------------- /flare/src/flare/analytics/cluster/MergeEdge.as: -------------------------------------------------------------------------------- 1 | package flare.analytics.cluster 2 | { 3 | /** 4 | * Auxiliary class that represents a merge in a clustering. 5 | */ 6 | internal class MergeEdge 7 | { 8 | public var i:int; 9 | public var j:int; 10 | public var next:MergeEdge = null; 11 | public var prev:MergeEdge = null; 12 | 13 | public function MergeEdge(i:int, j:int) { 14 | this.i = i; 15 | this.j = j; 16 | } 17 | 18 | public function update(i:int, j:int):void 19 | { 20 | this.i = i; 21 | this.j = j; 22 | } 23 | 24 | public function add(e:MergeEdge):MergeEdge { 25 | if (next) { 26 | e.next = next; 27 | next.prev = e; 28 | } 29 | next = e; 30 | e.prev = this; 31 | return e; 32 | } 33 | 34 | public function remove():void { 35 | if (prev) prev.next = next; 36 | if (next) next.prev = prev; 37 | } 38 | 39 | } // end of class MergeEdge 40 | } -------------------------------------------------------------------------------- /flare.apps/html-template/deeplinking/historyFrame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 27 | Yo, I'm your history. 28 | 29 | 30 | -------------------------------------------------------------------------------- /flare.demos/html-template/deeplinking/historyFrame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 27 | Yo, I'm your history. 28 | 29 | 30 | -------------------------------------------------------------------------------- /flare.tests/html-template/deeplinking/historyFrame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 27 | Yo, I'm your history. 28 | 29 | 30 | -------------------------------------------------------------------------------- /flare/src/flare/query/Count.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Aggregate operator for counting the number of items in a set of values. 5 | */ 6 | public class Count extends AggregateExpression 7 | { 8 | private var _count:int; 9 | 10 | /** 11 | * Creates a new Count operator 12 | * @param input the sub-expression of which to count the value 13 | */ 14 | public function Count(input:*) { 15 | super(input); 16 | } 17 | 18 | /** 19 | * @inheritDoc 20 | */ 21 | public override function reset():void 22 | { 23 | _count = 0; 24 | } 25 | 26 | /** 27 | * @inheritDoc 28 | */ 29 | public override function eval(o:Object=null):* 30 | { 31 | return _count; 32 | } 33 | 34 | /** 35 | * @inheritDoc 36 | */ 37 | public override function aggregate(value:Object):void 38 | { 39 | if (_expr.eval(value) != null) { 40 | _count++; 41 | } 42 | } 43 | 44 | } // end of class Count 45 | } -------------------------------------------------------------------------------- /flare/src/flare/query/Sum.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Aggregate operator for computing the sum of a set of values. 5 | */ 6 | public class Sum extends AggregateExpression 7 | { 8 | private var _sum:Number; 9 | 10 | /** 11 | * Creates a new Sum operator. 12 | * @param input the sub-expression of which to compute the sum 13 | */ 14 | public function Sum(input:*) { 15 | super(input); 16 | } 17 | 18 | /** 19 | * @inheritDoc 20 | */ 21 | public override function reset():void 22 | { 23 | _sum = 0; 24 | } 25 | 26 | /** 27 | * @inheritDoc 28 | */ 29 | public override function eval(o:Object=null):* 30 | { 31 | return _sum; 32 | } 33 | 34 | /** 35 | * @inheritDoc 36 | */ 37 | public override function aggregate(value:Object):void 38 | { 39 | var x:Number = Number(_expr.eval(value)); 40 | if (!isNaN(x)) { 41 | _sum += x; 42 | } 43 | } 44 | 45 | } // end of class Sum 46 | } -------------------------------------------------------------------------------- /flare/src/flare/util/IValueProxy.as: -------------------------------------------------------------------------------- 1 | package flare.util 2 | { 3 | /** 4 | * Interface for classes that get and set named property values of objects. 5 | */ 6 | public interface IValueProxy 7 | { 8 | /** 9 | * Gets a named property value for an object. 10 | * @param object the object 11 | * @param name the property name 12 | * @return the value 13 | */ 14 | function getValue(object:Object, name:String):*; 15 | 16 | /** 17 | * Sets a named property value for an object. 18 | * @param object the object 19 | * @param name the property name 20 | * @param value the value 21 | */ 22 | function setValue(object:Object, name:String, value:*):void; 23 | 24 | /** 25 | * Returns a value proxy object for getting and setting values. 26 | * @param object the object 27 | * @return a value proxy object upon which clients can get and set 28 | * properties directly 29 | */ 30 | function $(object:Object):Object; 31 | 32 | } // end of interface IValueProxy 33 | } -------------------------------------------------------------------------------- /flare/src/flare/query/Maximum.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Aggregate operator for computing the maximum of a set of values. 5 | */ 6 | public class Maximum extends AggregateExpression 7 | { 8 | private var _value:Object = null; 9 | 10 | /** 11 | * Creates a new Maximum operator 12 | * @param input the sub-expression of which to compute the maximum 13 | */ 14 | public function Maximum(input:*) { 15 | super(input); 16 | } 17 | 18 | /** 19 | * @inheritDoc 20 | */ 21 | public override function eval(o:Object=null):* 22 | { 23 | return _value; 24 | } 25 | 26 | /** 27 | * @inheritDoc 28 | */ 29 | public override function reset():void 30 | { 31 | _value = null; 32 | } 33 | 34 | /** 35 | * @inheritDoc 36 | */ 37 | public override function aggregate(value:Object):void 38 | { 39 | value = _expr.eval(value); 40 | if (_value == null || value > _value) { 41 | _value = value; 42 | } 43 | } 44 | 45 | } // end of class Maximum 46 | } -------------------------------------------------------------------------------- /flare/src/flare/query/Minimum.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Aggregate operator for computing the minimum of a set of values. 5 | */ 6 | public class Minimum extends AggregateExpression 7 | { 8 | private var _value:Object = null; 9 | 10 | /** 11 | * Creates a new Minimum operator 12 | * @param input the sub-expression of which to compute the minimum 13 | */ 14 | public function Minimum(input:*) { 15 | super(input); 16 | } 17 | 18 | /** 19 | * @inheritDoc 20 | */ 21 | public override function eval(o:Object=null):* 22 | { 23 | return _value; 24 | } 25 | 26 | /** 27 | * @inheritDoc 28 | */ 29 | public override function reset():void 30 | { 31 | _value = null; 32 | } 33 | 34 | /** 35 | * @inheritDoc 36 | */ 37 | public override function aggregate(value:Object):void 38 | { 39 | value = _expr.eval(value); 40 | if (_value == null || value < _value) { 41 | _value = value; 42 | } 43 | } 44 | 45 | } // end of class Minimum 46 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/operator/layout/RandomLayout.as: -------------------------------------------------------------------------------- 1 | package flare.vis.operator.layout 2 | { 3 | import flare.vis.data.Data; 4 | import flare.vis.data.DataSprite; 5 | 6 | import flash.geom.Rectangle; 7 | 8 | /** 9 | * Layout that places nodes randomly within the layout bounds. 10 | */ 11 | public class RandomLayout extends Layout 12 | { 13 | /** The data group to layout. */ 14 | public var group:String; 15 | 16 | /** 17 | * Creates a new RandomLayout instance. 18 | * @param group the data group to layout 19 | */ 20 | public function RandomLayout(group:String=Data.NODES) { 21 | this.group = group; 22 | } 23 | 24 | /** @inheritDoc */ 25 | protected override function layout():void 26 | { 27 | var r:Rectangle = layoutBounds; 28 | visualization.data.visit(function(d:DataSprite):void 29 | { 30 | var o:Object = _t.$(d); 31 | o.x = r.x + r.width * Math.random(); 32 | o.y = r.y + r.height * Math.random(); 33 | }, group); 34 | } 35 | 36 | } // end of class RandomLayout 37 | } -------------------------------------------------------------------------------- /flare/src/flare/query/Average.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Aggregate operator for computing the average of a set of values. 5 | */ 6 | public class Average extends AggregateExpression 7 | { 8 | protected var _sum:Number; 9 | protected var _count:Number; 10 | 11 | /** 12 | * Creates a new Average operator 13 | * @param input the sub-expression of which to compute the average 14 | */ 15 | public function Average(input:*) { 16 | super(input); 17 | } 18 | 19 | /** 20 | * @inheritDoc 21 | */ 22 | public override function reset():void 23 | { 24 | _sum = 0; 25 | _count = 0; 26 | } 27 | 28 | /** 29 | * @inheritDoc 30 | */ 31 | public override function eval(o:Object=null):* 32 | { 33 | return _sum / _count; 34 | } 35 | 36 | /** 37 | * @inheritDoc 38 | */ 39 | public override function aggregate(value:Object):void 40 | { 41 | var x:Number = Number(_expr.eval(value)); 42 | if (!isNaN(x)) { 43 | _sum += x; 44 | _count += 1; 45 | } 46 | } 47 | 48 | } // end of class Average 49 | } -------------------------------------------------------------------------------- /flare/src/flare/query/Distinct.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Aggregate (group-by) operator for counting the number of distinct 5 | * values in a set of values. 6 | */ 7 | public class Distinct extends AggregateExpression 8 | { 9 | private var _map:Object; 10 | private var _count:int; 11 | 12 | /** 13 | * Creates a new Distinct operator 14 | * @param input the sub-expression of which to compute the distinct 15 | * values 16 | */ 17 | public function Distinct(input:*) { 18 | super(input); 19 | } 20 | 21 | /** 22 | * @inheritDoc 23 | */ 24 | public override function reset():void 25 | { 26 | _map = {}; 27 | _count = 0; 28 | } 29 | 30 | /** 31 | * @inheritDoc 32 | */ 33 | public override function eval(o:Object=null):* 34 | { 35 | return _count; 36 | } 37 | 38 | /** 39 | * @inheritDoc 40 | */ 41 | public override function aggregate(value:Object):void 42 | { 43 | value = _expr.eval(value); 44 | if (_map[value] == undefined) { 45 | _count++; 46 | _map[value] = 1; 47 | } 48 | } 49 | 50 | } // end of class Distinct 51 | } -------------------------------------------------------------------------------- /flare.demos/src/flare/demos/util/Link.as: -------------------------------------------------------------------------------- 1 | package flare.demos.util 2 | { 3 | import flare.display.TextSprite; 4 | 5 | import flash.events.MouseEvent; 6 | import flash.text.TextFormat; 7 | 8 | public class Link extends TextSprite 9 | { 10 | public var textColor:uint = 0x555555; 11 | public var selColor:uint = 0xff0000; 12 | public var hoverColor:uint = 0xff7777; 13 | private var _selected:Boolean = false; 14 | 15 | public function get selected():Boolean { return _selected; } 16 | public function set selected(b:Boolean):void { 17 | _selected = b; 18 | color = b ? selColor : textColor; 19 | } 20 | 21 | public function Link(text:String=null, size:int=14) 22 | { 23 | super(text, new TextFormat("Verdana",size,textColor)); 24 | name = text; 25 | buttonMode = true; 26 | mouseChildren = false; 27 | 28 | addEventListener(MouseEvent.ROLL_OVER, function(event:MouseEvent):void { 29 | color = selected ? selColor : hoverColor; 30 | }); 31 | addEventListener(MouseEvent.ROLL_OUT, function(event:MouseEvent):void { 32 | color = _selected ? selColor : textColor; 33 | }); 34 | } 35 | 36 | } 37 | } -------------------------------------------------------------------------------- /flare/src/flare/animate/ISchedulable.as: -------------------------------------------------------------------------------- 1 | package flare.animate 2 | { 3 | /** 4 | * Interface for "schedulable" objects that can be run by 5 | * the Scheduler class. 6 | */ 7 | public interface ISchedulable 8 | { 9 | /** 10 | * Evaluate a scheduled call. 11 | * @param time the current time in milliseconds 12 | * @return true if this item should be removed from the scheduler, 13 | * false if it should continue to be run. 14 | */ 15 | function evaluate(time:Number) : Boolean; 16 | 17 | /** A unique name identifying this schedulable object. The default 18 | * is null. If non-null, any other scheduled items with 19 | * the same id will be canceled upon scheduling. 20 | * 21 | *

Once an item has been scheduled, it's id should not be changed. 22 | * However, it is left to subclasses to respect this convention. 23 | * If it is not followed, erratic cancels may occur.

*/ 24 | function get id():String; 25 | function set id(n:String):void; 26 | 27 | /** Invoked if a scheduled item is cancelled by the scheduler. */ 28 | function cancelled():void; 29 | 30 | } // end of interface ISchedulable 31 | } -------------------------------------------------------------------------------- /flare.demos/src/flare/demos/util/LinkGroup.as: -------------------------------------------------------------------------------- 1 | package flare.demos.util 2 | { 3 | import flash.display.DisplayObject; 4 | import flash.display.Sprite; 5 | import flash.events.MouseEvent; 6 | import flash.utils.Dictionary; 7 | 8 | public class LinkGroup extends Sprite 9 | { 10 | private var _cur:Link = null; 11 | private var _map:Dictionary = new Dictionary(); 12 | 13 | public override function addChild(child:DisplayObject):DisplayObject 14 | { 15 | child.x = width + (width>0 ? 10 : 0); 16 | super.addChild(child); 17 | return child; 18 | } 19 | 20 | public function add(link:Link):void { 21 | if (_map[link]) return; 22 | 23 | _map[link] = link; 24 | link.addEventListener(MouseEvent.CLICK, 25 | function(evt:MouseEvent):void { select(link); }); 26 | 27 | addChild(link); 28 | } 29 | 30 | public function remove(link:Link):void { 31 | delete _map[link]; 32 | } 33 | 34 | public function select(link:Link):void { 35 | if (link != null && !_map[link]) return; 36 | if (_cur) _cur.selected = false; 37 | _cur = link; 38 | if (_cur) _cur.selected = true; 39 | } 40 | 41 | } // end of class LinkGroup 42 | } -------------------------------------------------------------------------------- /flare/src/flare/query/Or.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Expression operator that computes the logical "or" of sub-expression 5 | * clauses. 6 | */ 7 | public class Or extends CompositeExpression 8 | { 9 | /** 10 | * Creates a new Or operator. 11 | * @param clauses the sub-expression clauses 12 | */ 13 | public function Or(...clauses) { 14 | super(clauses); 15 | } 16 | 17 | /** 18 | * @inheritDoc 19 | */ 20 | public override function clone():Expression 21 | { 22 | return cloneHelper(new Or()); 23 | } 24 | 25 | /** 26 | * @inheritDoc 27 | */ 28 | public override function eval(o:Object=null):* 29 | { 30 | return predicate(o); 31 | } 32 | 33 | /** 34 | * @inheritDoc 35 | */ 36 | public override function predicate(o:Object):Boolean 37 | { 38 | for each (var e:Expression in _children) { 39 | if (e.eval(o)) return true; 40 | } 41 | return false; 42 | } 43 | 44 | /** 45 | * @inheritDoc 46 | */ 47 | public override function toString():String 48 | { 49 | return _children.length==0 ? "FALSE" : super.getString("OR"); 50 | } 51 | 52 | } // end of class Or 53 | } -------------------------------------------------------------------------------- /flare/src/flare/physics/DragForce.as: -------------------------------------------------------------------------------- 1 | package flare.physics 2 | { 3 | /** 4 | * Force simulating frictional drag forces (e.g., air resistance). For 5 | * each particle, this force applies a drag based on the particles 6 | * velocity (F = a * v, where a is a drag co-efficient and 7 | * v is the velocity of the particle). 8 | */ 9 | public class DragForce implements IForce 10 | { 11 | private var _dc:Number; 12 | 13 | /** The drag co-efficient. */ 14 | public function get drag():Number { return _dc; } 15 | public function set drag(dc:Number):void { _dc = dc; } 16 | 17 | /** 18 | * Creates a new DragForce with given drag co-efficient. 19 | * @param dc the drag co-efficient. 20 | */ 21 | public function DragForce(dc:Number=0.1) { 22 | _dc = dc; 23 | } 24 | 25 | /** 26 | * Applies this force to a simulation. 27 | * @param sim the Simulation to apply the force to 28 | */ 29 | public function apply(sim:Simulation):void 30 | { 31 | if (_dc == 0) return; 32 | for (var i:uint = 0; iTransition
7 | * starts, steps, ends, or is canceled. 8 | */ 9 | public class TransitionEvent extends Event 10 | { 11 | /** A transition start event. */ 12 | public static const START:String = "start"; 13 | /** A transition step event. */ 14 | public static const STEP:String = "step"; 15 | /** A transition end event. */ 16 | public static const END:String = "end"; 17 | /** A transition cancel event. */ 18 | public static const CANCEL:String = "cancel"; 19 | 20 | private var _t:Transition; 21 | 22 | /** The transition this event corresponds to. */ 23 | public function get transition():Transition { return _t; } 24 | 25 | /** 26 | * Creates a new TransitionEvent. 27 | * @param type the event type (START, STEP, or END) 28 | * @param t the transition this event corresponds to 29 | */ 30 | public function TransitionEvent(type:String, t:Transition) 31 | { 32 | super(type); 33 | _t = t; 34 | } 35 | 36 | /** @inheritDoc */ 37 | public override function clone():Event 38 | { 39 | return new TransitionEvent(type, _t); 40 | } 41 | 42 | } // end of class TransitionEvent 43 | } -------------------------------------------------------------------------------- /flare/src/flare/query/Xor.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Expression operator that computes the exclusive-or ("xor") of 5 | * sub-expression clauses. 6 | */ 7 | public class Xor extends CompositeExpression 8 | { 9 | /** 10 | * Creates a new Xor operator. 11 | * @param clauses the sub-expression clauses 12 | */ 13 | public function Xor(...clauses) { 14 | super(clauses); 15 | } 16 | 17 | /** 18 | * @inheritDoc 19 | */ 20 | public override function clone():Expression 21 | { 22 | return cloneHelper(new Xor()); 23 | } 24 | 25 | /** 26 | * @inheritDoc 27 | */ 28 | public override function eval(o:Object=null):* 29 | { 30 | return predicate(o); 31 | } 32 | 33 | /** 34 | * @inheritDoc 35 | */ 36 | public override function predicate(o:Object):Boolean 37 | { 38 | if (_children.length == 0) return false; 39 | 40 | var b:Boolean = _children[0].predicate(o); 41 | for (var i:int=1; i<_children.length; ++i) { 42 | b = (b != Expression(_children[i]).predicate(o)); 43 | } 44 | return b; 45 | } 46 | 47 | /** 48 | * @inheritDoc 49 | */ 50 | public override function toString():String 51 | { 52 | return _children.length==0 ? "FALSE" : super.getString("XOR"); 53 | } 54 | 55 | } // end of class Xor 56 | } -------------------------------------------------------------------------------- /flare/src/flare/util/palette/Palette.as: -------------------------------------------------------------------------------- 1 | package flare.util.palette 2 | { 3 | /** 4 | * Base class for palettes, such as color and size palettes, that map from 5 | * interpolated scale values into visual properties 6 | */ 7 | public class Palette 8 | { 9 | /** Array of palette values. */ 10 | protected var _values:Array; 11 | 12 | /** The number of values in the palette. */ 13 | public function get size():int { return _values==null ? 0 : _values.length; } 14 | /** Array of palette values. */ 15 | public function get values():Array { return _values; } 16 | public function set values(a:Array):void { _values = a; } 17 | 18 | /** 19 | * Retrieves the palette value corresponding to the input interpolation 20 | * fraction. 21 | * @param f an interpolation fraction 22 | * @return the palette value corresponding to the input fraction 23 | */ 24 | public function getValue(f:Number):Object 25 | { 26 | if (_values==null || _values.length==0) 27 | return 0; 28 | return _values[uint(Math.round(f*(_values.length-1)))]; 29 | } 30 | 31 | // -- MXML ------------------------------------------------------------ 32 | 33 | /** @private */ 34 | public function initialized(document:Object, id:String):void 35 | { 36 | // do nothing 37 | } 38 | 39 | } // end of class Palette 40 | } -------------------------------------------------------------------------------- /flare/src/flare/query/Variable.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | import flare.util.Property; 4 | 5 | /** 6 | * Expression operator that retrieves a value from an object property. 7 | * Uses a flare.util.Property instance to access the value. 8 | * @see flare.util.Property 9 | */ 10 | public class Variable extends Expression 11 | { 12 | /** @private */ 13 | protected var _prop:Property; 14 | 15 | /** The name of the variable property. */ 16 | public function get name():String { return _prop.name; } 17 | public function set name(f:String):void { 18 | _prop = Property.$(f); 19 | } 20 | 21 | /** 22 | * Creates a new Variable operator. 23 | * @param name the name of the variable property 24 | */ 25 | public function Variable(name:String) { 26 | this.name = name; 27 | } 28 | 29 | /** 30 | * @inheritDoc 31 | */ 32 | public override function clone():Expression 33 | { 34 | return new Variable(_prop.name); 35 | } 36 | 37 | /** 38 | * @inheritDoc 39 | */ 40 | public override function eval(o:Object=null):* 41 | { 42 | return _prop.getValue(o); 43 | } 44 | 45 | /** 46 | * @inheritDoc 47 | */ 48 | public override function toString():String 49 | { 50 | return "`"+_prop.name+"`"; 51 | } 52 | 53 | } // end of class Variable 54 | } -------------------------------------------------------------------------------- /flare.apps/src/flare/apps/App.as: -------------------------------------------------------------------------------- 1 | package flare.apps 2 | { 3 | import flash.display.Sprite; 4 | import flash.display.StageAlign; 5 | import flash.display.StageScaleMode; 6 | import flash.events.Event; 7 | import flash.geom.Rectangle; 8 | 9 | public class App extends Sprite 10 | { 11 | protected var _appBounds:Rectangle; 12 | 13 | public function App() 14 | { 15 | addEventListener(Event.ADDED_TO_STAGE, onStageAdd); 16 | } 17 | 18 | private function onStageAdd(evt:Event):void 19 | { 20 | removeEventListener(Event.ADDED_TO_STAGE, onStageAdd); 21 | initStage(); 22 | init(); 23 | onResize(); 24 | stage.addEventListener(Event.RESIZE, onResize); 25 | } 26 | 27 | private function onResize(evt:Event=null):void 28 | { 29 | _appBounds = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight); 30 | resize(_appBounds.clone()); 31 | } 32 | 33 | protected function initStage():void 34 | { 35 | if (!stage) { 36 | throw new Error( 37 | "Can't initialize Stage -- not yet added to stage"); 38 | } 39 | stage.align = StageAlign.TOP_LEFT; 40 | stage.scaleMode = StageScaleMode.NO_SCALE; 41 | } 42 | 43 | protected function init():void 44 | { 45 | 46 | } 47 | 48 | public function resize(bounds:Rectangle):void 49 | { 50 | 51 | } 52 | 53 | } // end of class App 54 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/controls/Control.as: -------------------------------------------------------------------------------- 1 | package flare.vis.controls 2 | { 3 | import flare.util.Filter; 4 | 5 | import flash.display.InteractiveObject; 6 | import flash.events.EventDispatcher; 7 | 8 | /** 9 | * Base class for interactive controls. 10 | */ 11 | public class Control extends EventDispatcher implements IControl 12 | { 13 | /** @private */ 14 | protected var _object:InteractiveObject; 15 | /** @private */ 16 | protected var _filter:Function; 17 | 18 | /** Boolean function indicating the items considered by the control. 19 | * @see flare.util.Filter */ 20 | public function get filter():Function { return _filter; } 21 | public function set filter(f:*):void { _filter = Filter.$(f); } 22 | 23 | /** 24 | * Creates a new Control 25 | */ 26 | public function Control() { 27 | // do nothing 28 | } 29 | 30 | /** @inheritDoc */ 31 | public function get object():InteractiveObject 32 | { 33 | return _object; 34 | } 35 | 36 | /** @inheritDoc */ 37 | public function attach(obj:InteractiveObject):void 38 | { 39 | if (_object) detach(); 40 | _object = obj; 41 | } 42 | 43 | /** @inheritDoc */ 44 | public function detach():InteractiveObject 45 | { 46 | var obj:InteractiveObject = _object; 47 | _object = null; 48 | return obj; 49 | } 50 | 51 | 52 | } // end of class Control 53 | } -------------------------------------------------------------------------------- /flare/src/flare/util/heap/HeapNode.as: -------------------------------------------------------------------------------- 1 | package flare.util.heap 2 | { 3 | /** 4 | * A node in a heap data structure. 5 | * For use with the FibonacciHeap class. 6 | * @see flare.analytics.util.FibonacciHeap 7 | */ 8 | public class HeapNode 9 | { 10 | /** Arbitrary client data property to store with the node. */ 11 | public var data:*; 12 | /** The parent node of this node. */ 13 | public var parent:HeapNode; 14 | /** A child node of this node. */ 15 | public var child:HeapNode; 16 | /** The right child node of this node. */ 17 | public var right:HeapNode; 18 | /** The left child node of this node. */ 19 | public var left:HeapNode; 20 | /** Boolean flag useful for marking this node. */ 21 | public var mark:Boolean; 22 | /** Flag indicating if this node is currently in a heap. */ 23 | public var inHeap:Boolean = true; 24 | /** Key value used for sorting the heap nodes. */ 25 | public var key:Number; 26 | /** The degree of this heap node (number of child nodes). */ 27 | public var degree:int; 28 | 29 | /** 30 | * Creates a new HeapNode 31 | * @param data arbitrary data to store with this node 32 | * @param key the key value to sort on 33 | */ 34 | function HeapNode(data:*, key:Number) 35 | { 36 | this.data = data; 37 | this.key = key; 38 | right = this; 39 | left = this; 40 | } 41 | } // end of class HeapNode 42 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/operator/IOperator.as: -------------------------------------------------------------------------------- 1 | package flare.vis.operator 2 | { 3 | import flare.animate.Transitioner; 4 | import flare.vis.Visualization; 5 | 6 | /** 7 | * Interface for operators that perform processing tasks on the contents 8 | * of a Visualization. These tasks include layout, and color, shape, and 9 | * size encoding. Custom operators can be defined by implementing this 10 | * interface; 11 | */ 12 | public interface IOperator 13 | { 14 | /** The visualization processed by this operator. */ 15 | function get visualization():Visualization; 16 | function set visualization(v:Visualization):void; 17 | 18 | /** Indicates if the operator is enabled or disabled. */ 19 | function get enabled():Boolean; 20 | function set enabled(b:Boolean):void; 21 | 22 | /** 23 | * Sets parameter values for this operator. 24 | * @params an object containing parameter names and values. 25 | */ 26 | function set parameters(params:Object):void; 27 | 28 | /** 29 | * Performs an operation over the contents of a visualization. 30 | * @param t a Transitioner instance for collecting value updates. 31 | */ 32 | function operate(t:Transitioner=null):void; 33 | 34 | /** 35 | * Setup method invoked whenever this operator's visualization 36 | * property is set. 37 | */ 38 | function setup():void; 39 | 40 | } // end of interface IOperator 41 | } -------------------------------------------------------------------------------- /flare/src/flare/data/converters/IDataConverter.as: -------------------------------------------------------------------------------- 1 | package flare.data.converters 2 | { 3 | import flare.data.DataSchema; 4 | import flare.data.DataSet; 5 | 6 | import flash.utils.IDataInput; 7 | import flash.utils.IDataOutput; 8 | 9 | /** 10 | * Interface for data converters that map between an external data file 11 | * format and ActionScript objects (e.g., Arrays and Objects). 12 | */ 13 | public interface IDataConverter 14 | { 15 | /** 16 | * Converts data from an external format into ActionScript objects. 17 | * @param input the loaded input data 18 | * @param schema a data schema describing the structure of the data. 19 | * Schemas are optional in many but not all cases. 20 | * @return a DataSet instance containing converted data objects. 21 | */ 22 | function read(input:IDataInput, schema:DataSchema=null):DataSet; 23 | 24 | /** 25 | * Converts data from ActionScript objects into an external format. 26 | * @param data the data set to write. 27 | * @param output an object to which to write the output. If this value 28 | * is null, a new ByteArray will be created. 29 | * @return the converted data. If the output parameter is 30 | * non-null, it is returned. Otherwise the return value will be a 31 | * newly created ByteArray 32 | */ 33 | function write(data:DataSet, output:IDataOutput=null):IDataOutput; 34 | 35 | } // end of interface IDataConverter 36 | } -------------------------------------------------------------------------------- /flare/src/flare/query/Literal.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Expression operator for a literal value. 5 | */ 6 | public class Literal extends Expression 7 | { 8 | /** The boolean true literal. */ 9 | public static const TRUE:Literal = new Literal(true); 10 | /** The boolean false literal. */ 11 | public static const FALSE:Literal = new Literal(false); 12 | 13 | private var _value:Object = null; 14 | 15 | /** The literal value of this expression. */ 16 | public function get value():Object { return _value; } 17 | public function set value(val:Object):void { _value = val; } 18 | 19 | /** 20 | * Creates a new Literal instance. 21 | * @param val the literal value 22 | */ 23 | public function Literal(val:Object=null) { 24 | _value = val; 25 | } 26 | 27 | /** 28 | * @inheritDoc 29 | */ 30 | public override function clone():Expression 31 | { 32 | return new Literal(_value); 33 | } 34 | 35 | /** 36 | * @inheritDoc 37 | */ 38 | public override function predicate(o:Object):Boolean 39 | { 40 | return Boolean(_value); 41 | } 42 | 43 | /** 44 | * @inheritDoc 45 | */ 46 | public override function eval(o:Object=null):* 47 | { 48 | return _value; 49 | } 50 | 51 | /** 52 | * @inheritDoc 53 | */ 54 | public override function toString():String 55 | { 56 | return String(_value); 57 | } 58 | 59 | } // end of class Literal 60 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/axis/Axes.as: -------------------------------------------------------------------------------- 1 | package flare.vis.axis 2 | { 3 | import flash.display.Sprite; 4 | import flare.animate.Transitioner; 5 | import flare.vis.Visualization; 6 | import flash.geom.Rectangle; 7 | 8 | /** 9 | * Base class for representing metric data axes. 10 | */ 11 | public class Axes extends Sprite 12 | { 13 | /** The visualization the axes correspond to. */ 14 | protected var _vis:Visualization; 15 | /** The layout bounds of the axes. */ 16 | protected var _bounds:Rectangle; 17 | 18 | /** The visualization the axes correspond to. */ 19 | public function get visualization():Visualization { return _vis; } 20 | public function set visualization(v:Visualization):void { _vis = v; } 21 | 22 | /** The layout bounds of the axes. If this value is not directly set, 23 | * the layout bounds of the visualization are provided. */ 24 | public function get layoutBounds():Rectangle { 25 | if (_bounds != null) return _bounds; 26 | if (_vis != null) return _vis.bounds; 27 | return null; 28 | } 29 | public function set layoutBounds(b:Rectangle):void { _bounds = b; } 30 | 31 | /** 32 | * Update these axes, performing filtering and layout as needed. 33 | * @param trans a Transitioner for collecting value updates 34 | * @return the input transitioner 35 | */ 36 | public function update(trans:Transitioner=null):Transitioner 37 | { 38 | return trans; 39 | } 40 | 41 | } // end of class Axes 42 | } -------------------------------------------------------------------------------- /flare/src/flare/scale/LinearScale.as: -------------------------------------------------------------------------------- 1 | package flare.scale 2 | { 3 | import flare.util.Maths; 4 | import flare.util.Strings; 5 | 6 | /** 7 | * Scale that spaces values linearly along the scale range. This is the 8 | * default scale for numeric types. 9 | */ 10 | public class LinearScale extends QuantitativeScale 11 | { 12 | /** 13 | * Creates a new LinearScale. 14 | * @param min the minimum data value 15 | * @param max the maximum data value 16 | * @param base the number base to use 17 | * @param flush the flush flag for scale padding 18 | * @param labelFormat the formatting pattern for value labels 19 | */ 20 | public function LinearScale(min:Number=0, max:Number=0, base:Number=10, 21 | flush:Boolean=false, labelFormat:String=Strings.DEFAULT_NUMBER) 22 | { 23 | super(min, max, base, flush, labelFormat); 24 | } 25 | 26 | /** @inheritDoc */ 27 | public override function get scaleType():String { 28 | return ScaleType.LINEAR; 29 | } 30 | 31 | /** @inheritDoc */ 32 | public override function clone():Scale { 33 | return new LinearScale(_dmin, _dmax, _base, _flush, _format); 34 | } 35 | 36 | /** @inheritDoc */ 37 | protected override function interp(val:Number):Number { 38 | return Maths.invLinearInterp(val, _smin, _smax); 39 | } 40 | 41 | /** @inheritDoc */ 42 | public override function lookup(f:Number):Object { 43 | return Maths.linearInterp(f, _smin, _smax); 44 | } 45 | 46 | } // end of class LinearScale 47 | } -------------------------------------------------------------------------------- /flare/src/flare/physics/GravityForce.as: -------------------------------------------------------------------------------- 1 | package flare.physics 2 | { 3 | /** 4 | * Force simulating a global gravitational pull on Particle instances. 5 | */ 6 | public class GravityForce implements IForce 7 | { 8 | private var _gx:Number; 9 | private var _gy:Number; 10 | 11 | /** The gravitational acceleration in the horizontal dimension. */ 12 | public function get gravityX():Number { return _gx; } 13 | public function set gravityX(gx:Number):void { _gx = gx; } 14 | 15 | /** The gravitational acceleration in the vertical dimension. */ 16 | public function get gravityY():Number { return _gy; } 17 | public function set gravityY(gy:Number):void { _gy = gy; } 18 | 19 | /** 20 | * Creates a new gravity force with given acceleration values. 21 | * @param gx the gravitational acceleration in the horizontal dimension 22 | * @param gy the gravitational acceleration in the vertical dimension 23 | */ 24 | public function GravityForce(gx:Number=0, gy:Number=0) { 25 | _gx = gx; 26 | _gy = gy; 27 | } 28 | 29 | /** 30 | * Applies this force to a simulation. 31 | * @param sim the Simulation to apply the force to 32 | */ 33 | public function apply(sim:Simulation):void 34 | { 35 | if (_gx == 0 && _gy == 0) return; 36 | 37 | var p:Particle; 38 | for (var i:uint=0; iDate
values. 5 | */ 6 | public class DateInterpolator extends Interpolator 7 | { 8 | private var _start:Number; 9 | private var _end:Number; 10 | private var _d:Date; 11 | 12 | /** 13 | * Creates a new DateInterpolator. 14 | * @param target the object whose property is being interpolated 15 | * @param property the property to interpolate 16 | * @param start the starting date value to interpolate from 17 | * @param end the target date value to interpolate to 18 | */ 19 | public function DateInterpolator(target:Object, property:String, 20 | start:Object, end:Object) 21 | { 22 | super(target, property, start, end); 23 | } 24 | 25 | /** 26 | * Initializes this interpolator. 27 | * @param start the starting value of the interpolation 28 | * @param end the target value of the interpolation 29 | */ 30 | protected override function init(start:Object, end:Object) : void 31 | { 32 | _d = new Date(); 33 | _start = (start as Date).time; 34 | _end = (end as Date).time - _start; 35 | } 36 | 37 | /** 38 | * Calculate and set an interpolated property value. 39 | * @param f the interpolation fraction (typically between 0 and 1) 40 | */ 41 | public override function interpolate(f:Number) : void 42 | { 43 | _d.time = _start + f * _end; 44 | _prop.setValue(_target, _d); 45 | } 46 | 47 | } // end of class DateInterpolator 48 | } -------------------------------------------------------------------------------- /flare/src/flare/animate/interpolate/NumberInterpolator.as: -------------------------------------------------------------------------------- 1 | package flare.animate.interpolate 2 | { 3 | /** 4 | * Interpolator for Number and int values. 5 | */ 6 | public class NumberInterpolator extends Interpolator 7 | { 8 | private var _start:Number; 9 | private var _end:Number; 10 | 11 | /** 12 | * Creates a new NumberInterpolator. 13 | * @param target the object whose property is being interpolated 14 | * @param property the property to interpolate 15 | * @param start the starting number to interpolate from 16 | * @param end the target number to interpolate to 17 | */ 18 | public function NumberInterpolator(target:Object, property:String, 19 | start:Object, end:Object) 20 | { 21 | super(target, property, start, end); 22 | } 23 | 24 | /** 25 | * Initializes this interpolator. 26 | * @param start the starting value of the interpolation 27 | * @param end the target value of the interpolation 28 | */ 29 | protected override function init(start:Object, end:Object) : void 30 | { 31 | _start = Number(start); 32 | _end = Number(end); 33 | if (isNaN(_start)) _start = _end; 34 | _end = _end - _start; 35 | } 36 | 37 | /** 38 | * Calculate and set an interpolated property value. 39 | * @param f the interpolation fraction (typically between 0 and 1) 40 | */ 41 | public override function interpolate(f:Number) : void 42 | { 43 | _prop.setValue(_target, _start + f*_end); 44 | } 45 | 46 | } // end of class NumberInterpolator 47 | } -------------------------------------------------------------------------------- /flare/src/flare/util/Orientation.as: -------------------------------------------------------------------------------- 1 | package flare.util 2 | { 3 | /** 4 | * Constants defining layout orientations. 5 | */ 6 | public class Orientation 7 | { 8 | /** Constant indicating a left-to-right layout orientation. */ 9 | public static const LEFT_TO_RIGHT:String = "leftToRight"; 10 | /** Constant indicating a right-to-left layout orientation. */ 11 | public static const RIGHT_TO_LEFT:String = "rightToLeft"; 12 | /** Constant indicating a top-to-bottom layout orientation. */ 13 | public static const TOP_TO_BOTTOM:String = "topToBottom"; 14 | /** Constant indicating a bottom-to-top layout orientation. */ 15 | public static const BOTTOM_TO_TOP:String = "bottomToTop"; 16 | 17 | /** 18 | * This is an abstract class and can not be instantiated. 19 | */ 20 | public function Orientation() { 21 | throw new Error("This is an abstract class."); 22 | } 23 | 24 | /** 25 | * Returns true if the input string indicates a vertical orientation. 26 | * @param an orientation string 27 | * @return true if the input string indicates a vertical orientation 28 | */ 29 | public static function isVertical(orient:String):Boolean 30 | { 31 | return (orient==TOP_TO_BOTTOM || orient==BOTTOM_TO_TOP); 32 | } 33 | 34 | /** 35 | * Returns true if the input string indicates a horizontal orientation. 36 | * @param an orientation string 37 | * @return true if the input string indicates a horizontal orientation 38 | */ 39 | public static function isHorizontal(orient:String):Boolean 40 | { 41 | return (orient==LEFT_TO_RIGHT || orient==RIGHT_TO_LEFT); 42 | } 43 | 44 | } // end of class Orientation 45 | } -------------------------------------------------------------------------------- /license-flare.txt: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2007-2009 Regents of the University of California. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the University nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /flare.demos/src/flare/demos/Demo.as: -------------------------------------------------------------------------------- 1 | package flare.demos 2 | { 3 | import flare.demos.util.LinkGroup; 4 | 5 | import flash.display.Sprite; 6 | import flash.geom.Rectangle; 7 | 8 | public class Demo extends Sprite 9 | { 10 | public static var LINK_X:Number; 11 | public static var LINK_Y:Number; 12 | 13 | private var _init:Boolean = false; 14 | private var _bounds:Rectangle; 15 | private var _links:LinkGroup; 16 | 17 | public function get bounds():Rectangle { return _bounds; } 18 | public function set bounds(b:Rectangle):void { 19 | _bounds = b; 20 | if (_links) { 21 | _links.x = LINK_X; 22 | _links.y = LINK_Y; 23 | setChildIndex(_links, numChildren-1); 24 | } 25 | resize(); 26 | } 27 | 28 | protected function get links():LinkGroup { return _links; } 29 | protected function set links(links:LinkGroup):void 30 | { 31 | if (_links) removeChild(_links); 32 | _links = links; 33 | if (links != null) addChildAt(_links, numChildren); 34 | } 35 | 36 | // -------------------------------------------------------------------- 37 | 38 | public function Demo() { 39 | this.links = new LinkGroup(); 40 | } 41 | 42 | public function start():void 43 | { 44 | if (!_init) { init(); _init = true; } 45 | play(); 46 | if (_links) { 47 | _links.x = LINK_X; 48 | _links.y = LINK_Y; 49 | setChildIndex(_links, numChildren-1); 50 | } 51 | } 52 | 53 | public function init() : void 54 | { 55 | } 56 | 57 | public function play() : void 58 | { 59 | } 60 | 61 | public function stop() : void 62 | { 63 | } 64 | 65 | public function resize():void 66 | { 67 | } 68 | 69 | } // end of class Demo 70 | } -------------------------------------------------------------------------------- /flare.apps/etc/CodeExtract.py: -------------------------------------------------------------------------------- 1 | import os 2 | import stat 3 | import fnmatch 4 | import re 5 | 6 | asFile = fnmatch.translate('*.as') 7 | 8 | def checkdir(d, prefix): 9 | map = dict() 10 | for f in os.listdir(d): 11 | if re.match(asFile, f): 12 | map[f[0:len(f)-3]] = 1 13 | 14 | for f in os.listdir(d): 15 | path = d + os.sep + f 16 | fileStats = os.stat(path) 17 | if stat.S_ISDIR(fileStats[stat.ST_MODE]): 18 | if len(prefix)==0: 19 | pre = f 20 | else: 21 | pre = prefix + '.' + f 22 | checkdir(path, pre) 23 | elif re.match(asFile, f): 24 | name = prefix+'.'+f[0:len(f)-3] 25 | size = fileStats[stat.ST_SIZE] 26 | s = '{"name":"'+name+'",'+'"size":'+str(size)+',' 27 | s += '"imports":[' 28 | s += parse(prefix, name, path, map) + ']},' 29 | print s 30 | 31 | def parse(prefix, name, file, map): # parse an actionscript file 32 | """Parse an ActionScript file and extract imports""" 33 | f = open(file, 'r') 34 | s = "" 35 | imports = set() 36 | for line in f: 37 | line = line.strip() 38 | if line.startswith('import flare'): 39 | fimp = line[7:len(line)-1] 40 | if name != fimp: 41 | imports.add(fimp) 42 | else: 43 | for sib in map.iterkeys(): 44 | fsib = prefix + '.' + sib 45 | if line.find(sib) >= 0 and name != fsib: 46 | imports.add(fsib) 47 | 48 | for imp in imports: 49 | s += '"'+imp+'",' 50 | return s[0:len(s)-1] 51 | 52 | srcdir = 'c:\\dev\\flare\\flare\\src' 53 | print '[' 54 | checkdir(srcdir, '') 55 | print ']' -------------------------------------------------------------------------------- /flare/src/flare/query/Range.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Expression operator that tests if a value is within a given range. 5 | * Implemented as an And of Comparison 6 | * expressions. 7 | */ 8 | public class Range extends And 9 | { 10 | /** Sub-expression for the minimum value of the range. */ 11 | public function get min():Expression { return _children[0].left; } 12 | public function set min(e:*):void { 13 | _children[0].left = Expression.expr(e); 14 | } 15 | 16 | /** Sub-expression for the maximum value of the range. */ 17 | public function get max():Expression { return _children[1].right; } 18 | public function set max(e:*):void { 19 | _children[1].right = Expression.expr(e); 20 | } 21 | 22 | /** Sub-expression for the value to test for range inclusion. */ 23 | public function get val():Expression { return _children[0].right; } 24 | public function set val(e:*):void { 25 | var expr:Expression = Expression.expr(e); 26 | _children[0].right = expr; 27 | _children[1].left = expr; 28 | } 29 | 30 | /** 31 | * Create a new Range operator. 32 | * @param min sub-expression for the minimum value of the range 33 | * @param max sub-expression for the maximum value of the range 34 | * @param val sub-expression for the value to test for range inclusion 35 | */ 36 | public function Range(min:*, max:*, val:*) 37 | { 38 | addChild(new Comparison(Comparison.LTEQ, min, val)); 39 | addChild(new Comparison(Comparison.LTEQ, val, max)); 40 | } 41 | 42 | /** 43 | * @inheritDoc 44 | */ 45 | public override function clone():Expression 46 | { 47 | return new Range(min.clone(), max.clone(), val.clone()); 48 | } 49 | 50 | } // end of class RangePredicate 51 | } -------------------------------------------------------------------------------- /flare/src/flare/animate/interpolate/ObjectInterpolator.as: -------------------------------------------------------------------------------- 1 | package flare.animate.interpolate 2 | { 3 | /** 4 | * Interpolator for arbitrary Object values. Simply swaps the 5 | * initial value for the end value for interpolation fractions greater 6 | * than or equal to 0.5. 7 | */ 8 | public class ObjectInterpolator extends Interpolator 9 | { 10 | private var _start:Object; 11 | private var _end:Object; 12 | 13 | /** 14 | * Creates a new ObjectInterpolator. 15 | * @param target the object whose property is being interpolated 16 | * @param property the property to interpolate 17 | * @param start the starting object value to interpolate from 18 | * @param end the target object value to interpolate to 19 | */ 20 | public function ObjectInterpolator(target:Object, property:String, 21 | start:Object, end:Object) 22 | { 23 | super(target, property, start, end); 24 | } 25 | 26 | /** 27 | * Initializes this interpolator. 28 | * @param start the starting value of the interpolation 29 | * @param end the target value of the interpolation 30 | */ 31 | protected override function init(start:Object, end:Object) : void 32 | { 33 | _start = start; 34 | _end = end; 35 | } 36 | 37 | /** 38 | * Calculate and set an interpolated property value. This method sets 39 | * the target object's property to the starting value if the 40 | * interpolation fraction is less than 0.5 and to the ending value if 41 | * the fraction is greather than or equal to 0.5. 42 | * @param f the interpolation fraction (typically between 0 and 1) 43 | */ 44 | public override function interpolate(f:Number) : void 45 | { 46 | _prop.setValue(_target, f < 0.5 ? _start : _end); 47 | } 48 | 49 | } // end of class ObjectInterpolator 50 | } -------------------------------------------------------------------------------- /flare/src/flare/query/Not.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Expression operator that returns the logical "not" of a sub-expression. 5 | */ 6 | public class Not extends Expression 7 | { 8 | private var _clause:Expression; 9 | 10 | /** The sub-expression clause to negate. */ 11 | public function get clause():Expression { return _clause; } 12 | public function set clause(e:*):void { _clause = Expression.expr(e); } 13 | 14 | /** 15 | * @inheritDoc 16 | */ 17 | public override function get numChildren():int { return 1; } 18 | 19 | /** 20 | * Creates a new Not operator. 21 | * @param clause the sub-expression clause to negate 22 | */ 23 | public function Not(clause:*) { 24 | _clause = Expression.expr(clause); 25 | } 26 | 27 | /** 28 | * @inheritDoc 29 | */ 30 | public override function clone():Expression 31 | { 32 | return new Not(_clause.clone()); 33 | } 34 | 35 | /** 36 | * @inheritDoc 37 | */ 38 | public override function eval(o:Object=null):* 39 | { 40 | return predicate(o); 41 | } 42 | 43 | /** 44 | * @inheritDoc 45 | */ 46 | public override function predicate(o:Object):Boolean 47 | { 48 | return !_clause.eval(o); 49 | } 50 | 51 | /** 52 | * @inheritDoc 53 | */ 54 | public override function getChildAt(idx:int):Expression 55 | { 56 | return (idx==0 ? _clause : null); 57 | } 58 | 59 | /** 60 | * @inheritDoc 61 | */ 62 | public override function setChildAt(idx:int, expr:Expression):Boolean 63 | { 64 | if (idx == 0) { 65 | _clause = expr; 66 | return true; 67 | } 68 | return false; 69 | } 70 | 71 | /** 72 | * @inheritDoc 73 | */ 74 | public override function toString():String 75 | { 76 | return "NOT " + _clause.toString(); 77 | } 78 | 79 | } // end of class Not 80 | } -------------------------------------------------------------------------------- /flare/src/flare/physics/SpringForce.as: -------------------------------------------------------------------------------- 1 | package flare.physics 2 | { 3 | /** 4 | * Force simulating a spring force between two particles. This force 5 | * iterates over each Spring instance in a simulation and 6 | * computes the spring force between the attached particles. Spring forces 7 | * are computed using Hooke's Law plus a damping term modeling frictional 8 | * forces in the spring. 9 | * 10 | *

The actual equation is of the form: F = -k*(d - L) + a*d*(v1 - 11 | * v2), where k is the spring tension, d is the distance between 12 | * particles, L is the rest length of the string, a is the damping 13 | * co-efficient, and v1 and v2 are the velocities of the particles.

14 | */ 15 | public class SpringForce implements IForce 16 | { 17 | /** 18 | * Applies this force to a simulation. 19 | * @param sim the Simulation to apply the force to 20 | */ 21 | public function apply(sim:Simulation):void 22 | { 23 | var s:Spring, p1:Particle, p2:Particle; 24 | var dx:Number, dy:Number, dn:Number, dd:Number, k:Number, fx:Number, fy:Number; 25 | 26 | for (var i:uint=0; iflare.palette.ShapePalette and 13 | * flare.data.render.ShapeRenderer classes for more. 14 | */ 15 | public class ShapeEncoder extends Encoder 16 | { 17 | private var _palette:ShapePalette; 18 | 19 | /** @inheritDoc */ 20 | public override function get palette():Palette { return _palette; } 21 | public override function set palette(p:Palette):void { 22 | _palette = p as ShapePalette; 23 | } 24 | /** The palette as a ShapePalette instance. */ 25 | public function get shapes():ShapePalette { return _palette; } 26 | public function set shapes(p:ShapePalette):void { _palette = p; } 27 | 28 | // -------------------------------------------------------------------- 29 | 30 | /** 31 | * Creates a new ShapeEncoder. 32 | * @param source the source property 33 | * @param group the data group to process 34 | * @param palette the shape palette for assigning shapes 35 | */ 36 | public function ShapeEncoder(field:String=null, 37 | group:String=Data.NODES, palette:ShapePalette=null) 38 | { 39 | super(field, "shape", group); 40 | _binding.scaleType = ScaleType.CATEGORIES; 41 | _palette = palette ? palette : ShapePalette.defaultPalette(); 42 | } 43 | 44 | /** @inheritDoc */ 45 | protected override function encode(val:Object):* 46 | { 47 | return _palette.getShape(_binding.index(val)); 48 | } 49 | 50 | } // end of class ShapeEncoder 51 | } -------------------------------------------------------------------------------- /flare/src/flare/display/LineSprite.as: -------------------------------------------------------------------------------- 1 | package flare.display 2 | { 3 | /** 4 | * A Sprite representing a line. Supports position, color, and width 5 | * properties. 6 | */ 7 | public class LineSprite extends DirtySprite 8 | { 9 | private var _color:uint = 0xcccccc; 10 | private var _width:Number = 0; 11 | private var _x1:Number; 12 | private var _y1:Number; 13 | private var _x2:Number; 14 | private var _y2:Number; 15 | 16 | /** The x-coordinate for the first line endpoint. */ 17 | public function get x1():Number { return _x1; } 18 | public function set x1(x:Number):void { _x1 = x; dirty(); } 19 | 20 | /** The y-coordinate for the first line endpoint. */ 21 | public function get y1():Number { return _y1; } 22 | public function set y1(y:Number):void { _y1 = y; dirty(); } 23 | 24 | /** The x-coordinate for the second line endpoint. */ 25 | public function get x2():Number { return _x2; } 26 | public function set x2(x:Number):void { _x2 = x; dirty(); } 27 | 28 | /** The y-coordinate for the second line endpoint. */ 29 | public function get y2():Number { return _y2; } 30 | public function set y2(y:Number):void { _y2 = y; dirty(); } 31 | 32 | /** The color of the line. */ 33 | public function get lineColor():uint { return _color; } 34 | public function set lineColor(c:uint):void { _color = c; dirty(); } 35 | 36 | /** The width of the line. A value of zero indicates a hairwidth line, 37 | * as determined by Graphics.lineStyle */ 38 | public function get lineWidth():Number { return _width; } 39 | public function set lineWidth(w:Number):void { _width = w; dirty(); } 40 | 41 | public override function render():void 42 | { 43 | graphics.clear(); 44 | graphics.lineStyle(_width, _color, 1, true, "none"); 45 | graphics.moveTo(_x1, _y1); 46 | graphics.lineTo(_x2, _y2); 47 | } 48 | 49 | } // end of class LineSprite 50 | } -------------------------------------------------------------------------------- /flare/src/flare/query/AggregateExpression.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Base class representing an aggregate query operator. 5 | */ 6 | public class AggregateExpression extends Expression 7 | { 8 | /** The sub-expression to aggregate. */ 9 | protected var _expr:Expression; 10 | 11 | /** The sub-expression to aggregate. */ 12 | public function get input():Expression { return _expr; } 13 | public function set input(e:*):void { 14 | _expr = Expression.expr(e); 15 | } 16 | 17 | /** 18 | * @inheritDoc 19 | */ 20 | public override function get numChildren():int { 21 | return 1; 22 | } 23 | 24 | /** 25 | * Creates a new AggregateExpression. 26 | * @param input the sub-expression to aggregate. 27 | */ 28 | public function AggregateExpression(input:*) { 29 | this.input = input; 30 | } 31 | 32 | /** 33 | * @inheritDoc 34 | */ 35 | public override function getChildAt(idx:int):Expression 36 | { 37 | return idx==0 ? _expr : null; 38 | } 39 | 40 | /** 41 | * @inheritDoc 42 | */ 43 | public override function setChildAt(idx:int, expr:Expression):Boolean 44 | { 45 | if (idx == 0) { 46 | _expr = expr; 47 | return true; 48 | } 49 | return false; 50 | } 51 | 52 | // -------------------------------------------------------------------- 53 | 54 | /** 55 | * Resets the aggregation computation. 56 | */ 57 | public function reset():void 58 | { 59 | // subclasses override this 60 | } 61 | 62 | /** 63 | * Increments the aggregation computation to include the input value. 64 | * @param value a value to include within the aggregation. 65 | */ 66 | public function aggregate(value:Object):void 67 | { 68 | // subclasses override this 69 | } 70 | 71 | } // end of class AggregateExpression 72 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/events/TooltipEvent.as: -------------------------------------------------------------------------------- 1 | package flare.vis.events 2 | { 3 | import flare.vis.data.EdgeSprite; 4 | import flare.vis.data.NodeSprite; 5 | 6 | import flash.display.DisplayObject; 7 | import flash.events.Event; 8 | 9 | /** 10 | * Event fired in response to tooltip show, hide, or update events. 11 | * @see flare.vis.controls.TooltipControl 12 | */ 13 | public class TooltipEvent extends Event 14 | { 15 | /** A tooltip show event. */ 16 | public static const SHOW:String = "show"; 17 | /** A tooltip hide event. */ 18 | public static const HIDE:String = "hide"; 19 | /** A tooltip update event. */ 20 | public static const UPDATE:String = "update"; 21 | 22 | private var _object:DisplayObject; 23 | private var _tooltip:DisplayObject; 24 | 25 | /** The displayed tooltip object. */ 26 | public function get tooltip():DisplayObject { return _tooltip; } 27 | 28 | /** The moused-over interface object. */ 29 | public function get object():DisplayObject { return _object; } 30 | /** The moused-over interface object, cast to a NodeSprite. */ 31 | public function get node():NodeSprite { return _object as NodeSprite; } 32 | /** The moused-over interface object, cast to an EdgeSprite. */ 33 | public function get edge():EdgeSprite { return _object as EdgeSprite; } 34 | 35 | /** 36 | * Creates a new TooltipEvent. 37 | * @param type the event type (SHOW,HIDE, or UPDATE) 38 | * @param item the DisplayObject that was moused over 39 | * @param tip the tooltip DisplayObject 40 | */ 41 | public function TooltipEvent(type:String, item:DisplayObject, tip:DisplayObject) 42 | { 43 | super(type); 44 | _object = item; 45 | _tooltip = tip; 46 | } 47 | 48 | /** @inheritDoc */ 49 | public override function clone():Event 50 | { 51 | return new TooltipEvent(type, _object, _tooltip); 52 | } 53 | 54 | } // end of class TooltipEvent 55 | } -------------------------------------------------------------------------------- /flare/src/flare/animate/interpolate/PointInterpolator.as: -------------------------------------------------------------------------------- 1 | package flare.animate.interpolate 2 | { 3 | import flash.geom.Point; 4 | 5 | /** 6 | * Interpolator for flash.geom.Point values. 7 | */ 8 | public class PointInterpolator extends Interpolator 9 | { 10 | private var _startX:Number, _startY:Number; 11 | private var _rangeX:Number, _rangeY:Number; 12 | private var _cur:Point; 13 | 14 | /** 15 | * Creates a new PointInterpolator. 16 | * @param target the object whose property is being interpolated 17 | * @param property the property to interpolate 18 | * @param start the starting point value to interpolate from 19 | * @param end the target point value to interpolate to 20 | */ 21 | public function PointInterpolator(target:Object, property:String, 22 | start:Object, end:Object) 23 | { 24 | super(target, property, start, end); 25 | } 26 | 27 | /** 28 | * Initializes this interpolator. 29 | * @param start the starting value of the interpolation 30 | * @param end the target value of the interpolation 31 | */ 32 | protected override function init(start:Object, end:Object) : void 33 | { 34 | var e:Point = Point(end), s:Point = Point(start); 35 | _cur = _prop.getValue(_target) as Point; 36 | if (_cur == null || _cur == s || _cur == e) 37 | _cur = e.clone(); 38 | 39 | _startX = s.x; 40 | _startY = s.y; 41 | _rangeX = e.x - _startX; 42 | _rangeY = e.y - _startY; 43 | } 44 | 45 | /** 46 | * Calculate and set an interpolated property value. 47 | * @param f the interpolation fraction (typically between 0 and 1) 48 | */ 49 | public override function interpolate(f:Number) : void 50 | { 51 | _cur.x = _startX + f*_rangeX; 52 | _cur.y = _startY + f*_rangeY; 53 | _prop.setValue(_target, _cur.clone()); 54 | } 55 | 56 | } // end of class PointInterpolator 57 | } -------------------------------------------------------------------------------- /flare.apps/src/flare/widgets/PreLoader.as: -------------------------------------------------------------------------------- 1 | package flare.widgets 2 | { 3 | import flash.display.DisplayObject; 4 | import flash.display.MovieClip; 5 | import flash.display.StageAlign; 6 | import flash.display.StageScaleMode; 7 | import flash.events.Event; 8 | import flash.filters.DropShadowFilter; 9 | import flash.utils.describeType; 10 | import flash.utils.getDefinitionByName; 11 | 12 | public class PreLoader extends MovieClip 13 | { 14 | private var _bar:ProgressBar; 15 | 16 | public function PreLoader() 17 | { 18 | stage.scaleMode = StageScaleMode.NO_SCALE; 19 | stage.align = StageAlign.TOP_LEFT; 20 | 21 | // create progress bar 22 | addChild(_bar = new ProgressBar()); 23 | _bar.bar.filters = [new DropShadowFilter(1)]; 24 | _bar.x = (stage.stageWidth - _bar.width) / 2; 25 | _bar.y = (stage.stageHeight - _bar.height) / 2; 26 | addEventListener(Event.ENTER_FRAME, onEnterFrame); 27 | } 28 | 29 | private function onEnterFrame(event:Event):void 30 | { 31 | var percent:Number = root.loaderInfo.bytesLoaded / root.loaderInfo.bytesTotal; 32 | _bar.progress = percent; 33 | 34 | if (framesLoaded == totalFrames) { 35 | removeEventListener(Event.ENTER_FRAME, onEnterFrame); 36 | nextFrame(); 37 | init(); 38 | } 39 | } 40 | 41 | private function init():void 42 | { 43 | var name:String = root.loaderInfo.parameters.appClass; 44 | if (name != null) { 45 | var type:Class = Class(getDefinitionByName(name)); 46 | if (type) { 47 | var app:App = new type() as App; 48 | removeChild(_bar); 49 | addChild(app); 50 | return; 51 | } 52 | } 53 | _bar.message.text = "FAILED"; 54 | } 55 | 56 | } // end of class PreLoader 57 | } -------------------------------------------------------------------------------- /flare/src/flare/data/DataField.as: -------------------------------------------------------------------------------- 1 | package flare.data 2 | { 3 | /** 4 | * A data field stores metadata for an individual data variable. 5 | */ 6 | public class DataField 7 | { 8 | private var _id:String; 9 | private var _name:String; 10 | private var _format:String; 11 | private var _label:String; 12 | private var _type:int; 13 | private var _def:Object; 14 | 15 | /** A unique id for the data field, often the name. */ 16 | public function get id():String { return _id; } 17 | /** The name of the data field. */ 18 | public function get name():String { return _name; } 19 | /** A formatting string for printing values of this field. 20 | * @see flare.util.Stings#format 21 | */ 22 | public function get format():String { return _format; } 23 | /** A label describing this data field, useful for axis titles. */ 24 | public function get label():String { return _label; } 25 | /** The data type of this field. 26 | * @see flare.data.DataUtil. */ 27 | public function get type():int { return _type; } 28 | /** The default value for this data field. */ 29 | public function get defaultValue():Object { return _def; } 30 | 31 | /** 32 | * Creates a new DataField. 33 | * @param name the name of the data field 34 | * @param type the data type of this field 35 | * @param def the default value of this field 36 | * @param id a unique id for the field. If null, the name will be used 37 | * @param format a formatting string for printing values of this field 38 | * @param label a label describing this data field 39 | */ 40 | public function DataField(name:String, type:int, def:Object=null, 41 | id:String=null, format:String=null, label:String=null) 42 | { 43 | _name = name; 44 | _type = type; 45 | _def = def; 46 | _id = (id==null ? name : id); 47 | _format = format; 48 | _label = label==null ? name : _label; 49 | } 50 | 51 | } // end of class DataField 52 | } -------------------------------------------------------------------------------- /flare/src/flare/scale/RootScale.as: -------------------------------------------------------------------------------- 1 | package flare.scale 2 | { 3 | import flare.util.Maths; 4 | import flare.util.Strings; 5 | 6 | /** 7 | * Scale that performs a root transformation of the data. This could be a 8 | * square root or any arbitrary power. 9 | */ 10 | public class RootScale extends QuantitativeScale 11 | { 12 | private var _pow:Number = 2; 13 | 14 | /** The power of the root transform. A value of 2 indicates a square 15 | * root, 3 a cubic root, etc. */ 16 | public function get power():Number { return _pow; } 17 | public function set power(p:Number):void { _pow = p; } 18 | 19 | /** 20 | * Creates a new RootScale. 21 | * @param min the minimum data value 22 | * @param max the maximum data value 23 | * @param base the number base to use 24 | * @param flush the flush flag for scale padding 25 | * @param labelFormat the formatting pattern for value labels 26 | */ 27 | public function RootScale(min:Number=0, max:Number=0, base:Number=10, 28 | flush:Boolean=false, pow:Number=2, 29 | labelFormat:String=Strings.DEFAULT_NUMBER) 30 | { 31 | super(min, max, base, flush, labelFormat); 32 | _pow = pow; 33 | } 34 | 35 | /** @inheritDoc */ 36 | public override function get scaleType():String { 37 | return ScaleType.ROOT; 38 | } 39 | 40 | /** @inheritDoc */ 41 | public override function clone():Scale { 42 | return new RootScale(_dmin, _dmax, _base, _flush, _pow, _format); 43 | } 44 | 45 | /** @inheritDoc */ 46 | protected override function interp(val:Number):Number { 47 | if (_pow==2) return Maths.invSqrtInterp(val, _smin, _smax); 48 | return Maths.invRootInterp(val, _smin, _smax, _pow); 49 | } 50 | 51 | /** @inheritDoc */ 52 | public override function lookup(f:Number):Object { 53 | if (_pow==2) return Maths.sqrtInterp(f, _smin, _smax); 54 | return Maths.rootInterp(f, _smin, _smax, _pow); 55 | } 56 | 57 | } // end of class RootScale 58 | } -------------------------------------------------------------------------------- /flare/src/flare/scale/ScaleType.as: -------------------------------------------------------------------------------- 1 | package flare.scale 2 | { 3 | /** 4 | * Constants defining known scale types, such as linear, log, and 5 | * date/time scales. 6 | */ 7 | public class ScaleType 8 | { 9 | /** Constant indicating an unknown scale. */ 10 | public static const UNKNOWN:String = "unknown"; 11 | /** Constant indicating a categorical scale. */ 12 | public static const CATEGORIES:String = "categories"; 13 | /** Constant indicating an ordinal scale. */ 14 | public static const ORDINAL:String = "ordinal"; 15 | /** Constant indicating a linear numeric scale. */ 16 | public static const LINEAR:String = "linear"; 17 | /** Constant indicating a root-transformed numeric scale. */ 18 | public static const ROOT:String = "root"; 19 | /** Constant indicating a log-transformed numeric scale. */ 20 | public static const LOG:String = "log"; 21 | /** Constant indicating a quantile scale. */ 22 | public static const QUANTILE:String = "quantile"; 23 | /** Constant indicating a date/time scale. */ 24 | public static const TIME:String = "time"; 25 | 26 | /** 27 | * Constructor, throws an error if called, as this is an abstract class. 28 | */ 29 | public function ScaleType() { 30 | throw new Error("This is an abstract class."); 31 | } 32 | 33 | /** 34 | * Tests if a given scale type indicates an ordinal scale 35 | * @param type the scale type 36 | * @return true if the type indicates an ordinal scale, false otherwise 37 | */ 38 | public static function isOrdinal(type:String):Boolean 39 | { 40 | return type==ORDINAL || type==CATEGORIES; 41 | } 42 | 43 | /** 44 | * Tests if a given scale type indicates a quantitative scale 45 | * @param type the scale type 46 | * @return true if the type indicates a quantitative scale, 47 | * false otherwise 48 | */ 49 | public static function isQuantitative(type:String):Boolean 50 | { 51 | return type==LINEAR || type==ROOT || type==LOG; 52 | } 53 | 54 | } // end of class ScaleType 55 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/operator/encoder/SizeEncoder.as: -------------------------------------------------------------------------------- 1 | package flare.vis.operator.encoder 2 | { 3 | import flare.scale.ScaleType; 4 | import flare.util.palette.Palette; 5 | import flare.util.palette.SizePalette; 6 | import flare.vis.data.Data; 7 | 8 | /** 9 | * Encodes a data field into size values, using a scale transform and a 10 | * size palette to determines an item's scale. The target property of a 11 | * SizeEncoder is assumed to be the DataSprite.size property. 12 | */ 13 | public class SizeEncoder extends Encoder 14 | { 15 | private var _palette:SizePalette; 16 | 17 | /** @inheritDoc */ 18 | public override function get palette():Palette { return _palette; } 19 | public override function set palette(p:Palette):void { 20 | _palette = p as SizePalette; 21 | } 22 | /** The palette as a SizePalette instance. */ 23 | public function get sizes():SizePalette { return _palette; } 24 | 25 | // -------------------------------------------------------------------- 26 | 27 | /** 28 | * Creates a new SizeEncoder. By default, the scale type is set to 29 | * a quantile scale grouped into 5 bins. Adjust the values of the 30 | * scale property to change these defaults. 31 | * @param source the source property 32 | * @param group the data group to process 33 | * @param palette the size palette to use. If null, a default size 34 | * palette will be used. 35 | */ 36 | public function SizeEncoder(source:String=null, 37 | group:String=Data.NODES, palette:SizePalette=null) 38 | { 39 | super(source, "size", group); 40 | _binding.scaleType = ScaleType.QUANTILE; 41 | _binding.bins = 5; 42 | if (palette) { 43 | _palette = palette; 44 | } else { 45 | _palette = new SizePalette(); 46 | _palette.is2D = (group != Data.EDGES); 47 | } 48 | } 49 | 50 | /** @inheritDoc */ 51 | protected override function encode(val:Object):* 52 | { 53 | return _palette.getSize(_binding.interpolate(val)); 54 | } 55 | 56 | } // end of class SizeEncoder 57 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/events/SelectionEvent.as: -------------------------------------------------------------------------------- 1 | package flare.vis.events 2 | { 3 | import flash.display.DisplayObject; 4 | import flash.events.Event; 5 | import flash.events.MouseEvent; 6 | 7 | /** 8 | * Event fired in response to interactive selection events. 9 | */ 10 | public class SelectionEvent extends DataEvent 11 | { 12 | /** A selection event. */ 13 | public static const SELECT:String = "select"; 14 | /** A deselection event. */ 15 | public static const DESELECT:String = "deselect"; 16 | 17 | /** Indicates whether the Alt key is active (true) 18 | * or inactive (false). */ 19 | public var altKey:Boolean; 20 | /** Indicates whether the Control key is active (true) 21 | * or inactive (false). On Macintosh computers, you must 22 | * use this property to represent the Command key. */ 23 | public var ctrlKey:Boolean; 24 | /** Indicates whether the Shift key is active (true) 25 | * or inactive (false). */ 26 | public var shiftKey:Boolean; 27 | 28 | /** The event that triggered this event, if any. */ 29 | public function get cause():MouseEvent { return _cause; } 30 | private var _cause:MouseEvent; 31 | 32 | /** 33 | * Creates a new SelectionEvent. 34 | * @param type the event type (SELECT or DESELECT) 35 | * @param item the display object(s) that were selected or deselected 36 | * @param e (optional) the MouseEvent that triggered the selection 37 | */ 38 | public function SelectionEvent(type:String, items:*, e:MouseEvent=null) 39 | { 40 | super(type, items); 41 | if (e != null) { 42 | _cause = e; 43 | altKey = e.altKey; 44 | ctrlKey = e.ctrlKey; 45 | shiftKey = e.shiftKey; 46 | } 47 | } 48 | 49 | /** @inheritDoc */ 50 | public override function clone():Event 51 | { 52 | var se:SelectionEvent = new SelectionEvent(type, 53 | _items?_items:_item, _cause); 54 | se.altKey = altKey; 55 | se.ctrlKey = ctrlKey; 56 | se.shiftKey = shiftKey; 57 | return se; 58 | } 59 | 60 | } // end of class SelectionEvent 61 | } -------------------------------------------------------------------------------- /flare/src/flare/query/Variance.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Aggregate operator for computing variance or standard deviation. 5 | */ 6 | public class Variance extends AggregateExpression 7 | { 8 | /** Flag indicating the population variance or deviation. */ 9 | public static const POPULATION:int = 0; 10 | /** Flag indicating the sample variance or deviation. */ 11 | public static const SAMPLE:int = 2; 12 | /** Flag indicating the variance should be computed. */ 13 | public static const VARIANCE:int = 0; 14 | /** Flag indicating the standard deviation should be computed. */ 15 | public static const DEVIATION:int = 1; 16 | 17 | private var _type:int; 18 | private var _sum:Number; 19 | private var _accum:Number; 20 | private var _count:Number; 21 | 22 | /** 23 | * Creates a new Variance operator. By default, the population variance 24 | * is computed. Use the type flags to change this. For example, the type 25 | * argument Variance.SAMPLE | Variance.DEVIATION results in 26 | * the sample standard deviation being computed. 27 | * @param input the sub-expression of which to compute variance 28 | * @param type the type of variance or deviation to compute 29 | */ 30 | public function Variance(input:*, type:int=0) { 31 | super(input); 32 | _type = type; 33 | } 34 | 35 | /** 36 | * @inheritDoc 37 | */ 38 | public override function reset():void 39 | { 40 | _sum = 0; 41 | _accum = 0; 42 | _count = 0; 43 | } 44 | 45 | /** 46 | * @inheritDoc 47 | */ 48 | public override function eval(o:Object=null):* 49 | { 50 | var n:Number = _count - (_type & SAMPLE ? 1 : 0); 51 | var v:Number = _sum / n; 52 | v = v*v + _accum / n; 53 | return (_type & DEVIATION ? Math.sqrt(v) : v); 54 | } 55 | 56 | /** 57 | * @inheritDoc 58 | */ 59 | public override function aggregate(value:Object):void 60 | { 61 | var x:Number = Number(_expr.eval(value)); 62 | if (!isNaN(x)) { 63 | _sum += x; 64 | _accum += x*x; 65 | _count += 1; 66 | } 67 | } 68 | 69 | } // end of class Variance 70 | } -------------------------------------------------------------------------------- /flare.tests/.actionScriptProperties: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /flare/src/flare/animate/interpolate/ArrayInterpolator.as: -------------------------------------------------------------------------------- 1 | package flare.animate.interpolate 2 | { 3 | import flare.util.Arrays; 4 | 5 | /** 6 | * Interpolator for numeric Array values. Each value 7 | * contained in the array should be a numeric (Number or 8 | * int) value. 9 | */ 10 | public class ArrayInterpolator extends Interpolator 11 | { 12 | private var _start:Array; 13 | private var _end:Array; 14 | private var _cur:Array; 15 | 16 | /** 17 | * Creates a new ArrayInterpolator. 18 | * @param target the object whose property is being interpolated 19 | * @param property the property to interpolate 20 | * @param start the starting array of values to interpolate from 21 | * @param end the target array to interpolate to. This should be an 22 | * array of numerical values. 23 | */ 24 | public function ArrayInterpolator(target:Object, property:String, 25 | start:Object, end:Object) 26 | { 27 | super(target, property, start, end); 28 | } 29 | 30 | /** 31 | * Initializes this interpolator. 32 | * @param start the starting value of the interpolation 33 | * @param end the target value of the interpolation 34 | */ 35 | protected override function init(start:Object, end:Object) : void 36 | { 37 | _end = end as Array; 38 | if (!end) throw new Error("Target array is null!"); 39 | if (_start && _start.length != _end.length) _start = null; 40 | _start = Arrays.copy(start as Array, _start); 41 | 42 | if (_start.length != _end.length) 43 | throw new Error("Array dimensions don't match"); 44 | 45 | var cur:Array = _prop.getValue(_target) as Array; 46 | if (cur == end) cur = null; 47 | _cur = Arrays.copy(_start, cur); 48 | } 49 | 50 | /** 51 | * Calculate and set an interpolated property value. 52 | * @param f the interpolation fraction (typically between 0 and 1) 53 | */ 54 | public override function interpolate(f:Number) : void 55 | { 56 | for (var i:uint=0; i<_cur.length; ++i) { 57 | _cur[i] = _start[i] + f*(_end[i] - _start[i]); 58 | } 59 | _prop.setValue(_target, _cur); 60 | } 61 | 62 | } // end of class ArrayInterpolator 63 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/operator/SortOperator.as: -------------------------------------------------------------------------------- 1 | package flare.vis.operator 2 | { 3 | import flare.animate.Transitioner; 4 | import flare.util.Arrays; 5 | import flare.vis.data.Data; 6 | 7 | /** 8 | * A SortOperator sorts a data group. This can be used to sort 9 | * elements prior to running a subsequent operation such as layout. 10 | * @see flare.util.Sort 11 | */ 12 | public class SortOperator extends Operator 13 | { 14 | /** The data group to sort. */ 15 | public var group:String; 16 | 17 | /** The sorting criteria. Sort criteria are expressed as an 18 | * array of property names to sort on. These properties are accessed 19 | * by sorting functions using the Property class. 20 | * The default is to sort in ascending order. If the field name 21 | * includes a "-" (negative sign) prefix, that variable will instead 22 | * be sorted in descending order. */ 23 | public function get criteria():Array { return Arrays.copy(_crit); } 24 | public function set criteria(crit:*):void { 25 | if (crit is String) { 26 | _crit = [crit]; 27 | } else if (crit is Array) { 28 | _crit = Arrays.copy(crit as Array); 29 | } else { 30 | throw new ArgumentError("Invalid Sort specification type. " + 31 | "Input must be either a String or Array"); 32 | } 33 | } 34 | private var _crit:Array; 35 | 36 | /** 37 | * Creates a new SortOperator. 38 | * @param criteria the sorting criteria. Sort criteria are expressed as 39 | * an array of property names to sort on. These properties are 40 | * accessed by sorting functions using the Property 41 | * class. The default is to sort in ascending order. If the field name 42 | * includes a "-" (negative sign) prefix, that variable will instead 43 | * be sorted in descending order. 44 | * @param group the data group to sort 45 | */ 46 | public function SortOperator(criteria:Array, group:String="nodes") 47 | { 48 | this.group = group; 49 | this.criteria = criteria; 50 | } 51 | 52 | /** @inheritDoc */ 53 | public override function operate(t:Transitioner=null):void 54 | { 55 | visualization.data.group(group).sortBy(_crit); 56 | } 57 | 58 | } // end of class SortOperator 59 | } -------------------------------------------------------------------------------- /flare/src/flare/animate/interpolate/ColorInterpolator.as: -------------------------------------------------------------------------------- 1 | package flare.animate.interpolate 2 | { 3 | /** 4 | * Interpolator for color (uint) values. 5 | */ 6 | public class ColorInterpolator extends Interpolator 7 | { 8 | private var _start:uint; 9 | private var _end:uint; 10 | 11 | /** 12 | * Creates a new ColorInterpolator. 13 | * @param target the object whose property is being interpolated 14 | * @param property the property to interpolate 15 | * @param start the starting color value to interpolate from 16 | * @param end the target color value to interpolate to 17 | */ 18 | public function ColorInterpolator(target:Object, property:String, 19 | start:Object, end:Object) 20 | { 21 | super(target, property, start, end); 22 | } 23 | 24 | /** 25 | * Initializes this interpolator. 26 | * @param start the starting value of the interpolation 27 | * @param end the target value of the interpolation 28 | */ 29 | protected override function init(start:Object, end:Object) : void 30 | { 31 | _start = uint(start); 32 | _end = uint(end); 33 | } 34 | 35 | /** 36 | * Calculate and set an interpolated property value. 37 | * @param f the interpolation fraction (typically between 0 and 1) 38 | */ 39 | public override function interpolate(f:Number) : void 40 | { 41 | // we'll do all the work here to avoid the overhead of 42 | // extra method calls (rather than call Colors.interpolate) 43 | var a1:uint, a2:uint, r1:uint, r2:uint, 44 | g1:uint, g2:uint, b1:uint, b2:uint; 45 | 46 | // get color components 47 | a1 = (_start >> 24) & 0xFF; a2 = (_end >> 24) & 0xFF; 48 | r1 = (_start >> 16) & 0xFF; r2 = (_end >> 16) & 0xFF; 49 | g1 = (_start >> 8) & 0xFF; g2 = (_end >> 8) & 0xFF; 50 | b1 = _start & 0xff; b2 = _end & 0xFF; 51 | 52 | // interpolate the color components 53 | a1 += f*(a2-a1); r1 += f*(r2-r1); 54 | g1 += f*(g2-g1); b1 += f*(b2-b1); 55 | 56 | // recombine into final color 57 | a1 = ((a1 & 0xFF) << 24) | ((r1 & 0xFF) << 16) | 58 | ((g1 & 0xFF) << 8) | (b1 & 0xFF); 59 | 60 | // update the property value 61 | _prop.setValue(_target, a1); 62 | } 63 | 64 | } // end of class ColorInterpolator 65 | } -------------------------------------------------------------------------------- /flare/src/flare/animate/interpolate/RectangleInterpolator.as: -------------------------------------------------------------------------------- 1 | package flare.animate.interpolate 2 | { 3 | import flash.geom.Rectangle; 4 | 5 | /** 6 | * Interpolator for flash.geom.Rectangle values. 7 | */ 8 | public class RectangleInterpolator extends Interpolator 9 | { 10 | private var _startX:Number, _startY:Number; 11 | private var _startW:Number, _startH:Number; 12 | private var _rangeX:Number, _rangeY:Number; 13 | private var _rangeW:Number, _rangeH:Number; 14 | 15 | private var _cur:Rectangle; 16 | 17 | /** 18 | * Creates a new RectangleInterpolator. 19 | * @param target the object whose property is being interpolated 20 | * @param property the property to interpolate 21 | * @param start the starting rectangle value to interpolate from 22 | * @param end the target re3ctangle value to interpolate to 23 | */ 24 | public function RectangleInterpolator(target:Object, property:String, 25 | start:Object, end:Object) 26 | { 27 | super(target, property, start, end); 28 | } 29 | 30 | /** 31 | * Initializes this interpolator. 32 | * @param start the starting value of the interpolation 33 | * @param end the target value of the interpolation 34 | */ 35 | protected override function init(start:Object, end:Object) : void 36 | { 37 | var e:Rectangle = Rectangle(end), s:Rectangle = Rectangle(start); 38 | _cur = _prop.getValue(_target) as Rectangle; 39 | if (_cur == null || _cur == s || _cur == e) 40 | _cur = e.clone(); 41 | 42 | _startX = s.x; 43 | _startY = s.y; 44 | _startW = s.width; 45 | _startH = s.height; 46 | _rangeX = e.x - _startX; 47 | _rangeY = e.y - _startY; 48 | _rangeW = e.width - _startW; 49 | _rangeH = e.height - _startH; 50 | } 51 | 52 | /** 53 | * Calculate and set an interpolated property value. 54 | * @param f the interpolation fraction (typically between 0 and 1) 55 | */ 56 | public override function interpolate(f:Number) : void 57 | { 58 | _cur.x = _startX + f * _rangeX; 59 | _cur.y = _startY + f * _rangeY; 60 | _cur.width = _startW + f * _rangeW; 61 | _cur.height = _startH + f * _rangeH; 62 | _prop.setValue(_target, _cur); 63 | } 64 | 65 | } // end of class RectangleInterpolator 66 | } -------------------------------------------------------------------------------- /flare/src/flare/scale/IScaleMap.as: -------------------------------------------------------------------------------- 1 | package flare.scale 2 | { 3 | /** 4 | * Interface used by classes which support mapping between 5 | * spatial (x,y) coordinates and values in a data scale. For example, 6 | * both an axis or legend range should provide this functionality. 7 | */ 8 | public interface IScaleMap 9 | { 10 | /** 11 | * Returns the x-coordinate corresponding to the lower end of the scale. 12 | * @return the x-coordinate for the minimum value 13 | */ 14 | function get x1():Number; 15 | 16 | /** 17 | * Returns the y-coordinate corresponding to the lower end of the scale. 18 | * @return the y-coordinate for the minimum value 19 | */ 20 | function get y1():Number; 21 | 22 | /** 23 | * Returns the x-coordinate corresponding to the upper end of the scale. 24 | * @return the x-coordinate for the maximum value 25 | */ 26 | function get x2():Number; 27 | 28 | /** 29 | * Returns the y-coordinate corresponding to the upper end of the scale. 30 | * @return the y-coordinate for the maximum value 31 | */ 32 | function get y2():Number; 33 | 34 | /** 35 | * Returns the scale value corresponding to a given coordinate. 36 | * @param x the x-coordinate 37 | * @param y the y-coordinate 38 | * @param stayInBounds if true, x,y values outside the current layout 39 | * bounds will be snapped to the bounds. If false, the value lookup 40 | * will attempt to extrapolate beyond the scale bounds. This value 41 | * is true be default. 42 | * @return the scale value corresponding to the given coordinate. 43 | */ 44 | function value(x:Number, y:Number, stayInBounds:Boolean=true):Object; 45 | 46 | /** 47 | * Returns the x-coordinate corresponding to the given scale value 48 | * @param val the scale value to lookup 49 | * @return the x-coordinate at which that scale value is placed 50 | */ 51 | function X(val:Object):Number; 52 | 53 | /** 54 | * Returns the y-coordinate corresponding to the given scale value 55 | * @param val the scale value to lookup 56 | * @return the y-coordinate at which that scale value is placed 57 | */ 58 | function Y(val:Object):Number; 59 | 60 | } // end of interface IScaleMap 61 | } -------------------------------------------------------------------------------- /flare/src/flare/animate/interpolate/VectorInterpolator.as: -------------------------------------------------------------------------------- 1 | package flare.animate.interpolate 2 | { 3 | import flare.util.Vectors; 4 | 5 | /** 6 | * Interpolator for numeric Vector values. Each value 7 | * contained in the vector should be a numeric (Number or 8 | * int) value. 9 | */ 10 | public class VectorInterpolator extends Interpolator 11 | { 12 | private var _start:Vector.; 13 | private var _end:Vector.; 14 | private var _cur:Vector.; 15 | 16 | /** 17 | * Creates a new VectorInterpolator. 18 | * @param target the object whose property is being interpolated 19 | * @param property the property to interpolate 20 | * @param start the starting vector of values to interpolate from 21 | * @param end the target vector to interpolate to. This should be an 22 | * array of numerical values. 23 | */ 24 | public function VectorInterpolator(target:Object, property:String, 25 | start:Object, end:Object) 26 | { 27 | super(target, property, start, end); 28 | } 29 | 30 | /** 31 | * Initializes this interpolator. 32 | * @param start the starting value of the interpolation 33 | * @param end the target value of the interpolation 34 | */ 35 | protected override function init(start:Object, end:Object) : void 36 | { 37 | _end = end as Vector.; 38 | if (!end) throw new Error("Target vector is null!"); 39 | if (_start && _start.length != _end.length) _start = null; 40 | _start = Vectors.copy(start as Vector., _start); 41 | 42 | if (_start.length != _end.length) 43 | throw new Error("Vector dimensions don't match"); 44 | 45 | var cur:Vector. = _prop.getValue(_target) as Vector.; 46 | if (cur == end) cur = null; 47 | _cur = Vectors.copy(_start, cur); 48 | } 49 | 50 | /** 51 | * Calculate and set an interpolated property value. 52 | * @param f the interpolation fraction (typically between 0 and 1) 53 | */ 54 | public override function interpolate(f:Number) : void 55 | { 56 | for (var i:uint=0; i<_cur.length; ++i) { 57 | _cur[i] = (_start[i] as Number) + f*((_end[i] as Number) - (_start[i] as Number)); 58 | } 59 | _prop.setValue(_target, _cur); 60 | } 61 | 62 | } // end of class ArrayInterpolator 63 | } -------------------------------------------------------------------------------- /flare/src/flare/util/palette/ShapePalette.as: -------------------------------------------------------------------------------- 1 | package flare.util.palette 2 | { 3 | import flare.util.Shapes; 4 | 5 | /** 6 | * Palette for shape values that maps integer indices to shape drawing 7 | * functions. 8 | * @see flare.vis.util.graphics.Shapes 9 | */ 10 | public class ShapePalette extends Palette 11 | { 12 | /** 13 | * Creates a new, empty ShapePalette. 14 | */ 15 | public function ShapePalette() { 16 | _values = new Array(); 17 | } 18 | 19 | /** 20 | * Adds a shape to this ShapePalette. 21 | * @param shape the name of the shape. This name should be registered 22 | * with a drawing function using the 23 | * flare.vis.util.graphics.Shapes class. 24 | */ 25 | public function addShape(shape:String):void 26 | { 27 | _values.push(shape); 28 | } 29 | 30 | /** 31 | * Gets the shape at the given index into the palette. 32 | * @param idx the index of the shape 33 | * @return the name of the shape 34 | */ 35 | public function getShape(idx:uint):String 36 | { 37 | return _values[idx % _values.length]; 38 | } 39 | 40 | /** 41 | * Sets the shape at the given index into the palette. 42 | * @param idx the index of the shape 43 | * @param shape the name of the shape. This name should be registered 44 | * with a drawing function using the 45 | * flare.vis.util.graphics.Shapes class. 46 | */ 47 | public function setShape(idx:uint, shape:String):void 48 | { 49 | _values[idx] = shape; 50 | } 51 | 52 | /** 53 | * Returns a default shape palette instance. The default palette 54 | * consists of (in order): circle, square, cross, "x", diamond, 55 | * down-triangle, up-triangle, left-triangle, and right-triangle 56 | * shapes. 57 | * @return the default shape palette 58 | */ 59 | public static function defaultPalette():ShapePalette 60 | { 61 | var p:ShapePalette = new ShapePalette(); 62 | p.addShape(Shapes.CIRCLE); 63 | p.addShape(Shapes.SQUARE); 64 | p.addShape(Shapes.CROSS); 65 | p.addShape(Shapes.X); 66 | p.addShape(Shapes.DIAMOND); 67 | p.addShape(Shapes.TRIANGLE_DOWN); 68 | p.addShape(Shapes.TRIANGLE_UP); 69 | p.addShape(Shapes.TRIANGLE_LEFT); 70 | p.addShape(Shapes.TRIANGLE_RIGHT); 71 | return p; 72 | } 73 | 74 | } // end of class ShapePalette 75 | } -------------------------------------------------------------------------------- /flare/src/flare/query/IsA.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Expression operator that type checks a sub-expression. 5 | */ 6 | public class IsA extends Expression 7 | { 8 | private var _type:Class; 9 | private var _clause:Expression; 10 | 11 | /** The class type to check for. */ 12 | public function get type():Class { return _type; } 13 | 14 | /** The sub-expression clause to type check. */ 15 | public function get clause():Expression { return _clause; } 16 | public function set clause(e:*):void { 17 | _clause = e==null ? null : Expression.expr(e); 18 | } 19 | 20 | /** 21 | * @inheritDoc 22 | */ 23 | public override function get numChildren():int { return _clause ? 1 : 0; } 24 | 25 | /** 26 | * Creates a new IsA operator. 27 | * @param type the class type to check for 28 | * @param clause the sub-expression clause to type check. If null, 29 | * the input object (rather than a sub-property or expression result) 30 | * will be type checked. 31 | */ 32 | public function IsA(type:Class, clause:*=null) { 33 | _type = type; 34 | this.clause = clause; 35 | } 36 | 37 | /** 38 | * @inheritDoc 39 | */ 40 | public override function clone():Expression 41 | { 42 | return new IsA(_type, _clause.clone()); 43 | } 44 | 45 | /** 46 | * @inheritDoc 47 | */ 48 | public override function eval(o:Object=null):* 49 | { 50 | return predicate(o); 51 | } 52 | 53 | /** 54 | * @inheritDoc 55 | */ 56 | public override function predicate(o:Object):Boolean 57 | { 58 | if (_clause) { 59 | return _clause.eval(o) is _type; 60 | } else { 61 | return o is _type; 62 | } 63 | } 64 | 65 | /** 66 | * @inheritDoc 67 | */ 68 | public override function getChildAt(idx:int):Expression 69 | { 70 | return (idx==0 ? _clause : null); 71 | } 72 | 73 | /** 74 | * @inheritDoc 75 | */ 76 | public override function setChildAt(idx:int, expr:Expression):Boolean 77 | { 78 | if (idx == 0) { 79 | _clause = expr; 80 | return true; 81 | } 82 | return false; 83 | } 84 | 85 | /** 86 | * @inheritDoc 87 | */ 88 | public override function toString():String 89 | { 90 | var c:String = _clause ? _clause.toString() : ""; 91 | return "("+c + " IS " + _type.toString()+")"; 92 | } 93 | 94 | } // end of class IsA 95 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/controls/AnchorControl.as: -------------------------------------------------------------------------------- 1 | package flare.vis.controls 2 | { 3 | import flare.vis.Visualization; 4 | import flare.vis.operator.layout.Layout; 5 | 6 | import flash.display.InteractiveObject; 7 | import flash.events.Event; 8 | import flash.events.MouseEvent; 9 | import flash.geom.Point; 10 | 11 | /** 12 | * Interactive control for updating a layout's anchor point in response 13 | * to mouse movement. This control is often used to dynamically update a 14 | * focus+context distortion. 15 | */ 16 | public class AnchorControl extends Control 17 | { 18 | private var _layout:Layout; 19 | 20 | public function get layout():Layout { return _layout; } 21 | public function set layout(l:Layout):void { _layout = l; } 22 | 23 | /** Update function called when the layout anchor changes. */ 24 | public var update:Function = function():void { 25 | Visualization(_object).update(); 26 | } 27 | 28 | // -------------------------------------------------------------------- 29 | 30 | /** 31 | * Creates a new AnchorControl 32 | * @param layout the layout on which to update the anchor point 33 | */ 34 | public function AnchorControl(layout:Layout=null) 35 | { 36 | _layout = layout; 37 | } 38 | 39 | /** @inheritDoc */ 40 | public override function attach(obj:InteractiveObject):void 41 | { 42 | super.attach(obj); 43 | if (obj != null) { 44 | obj.addEventListener(Event.ENTER_FRAME, updateMouse); 45 | } 46 | } 47 | 48 | /** @inheritDoc */ 49 | public override function detach():InteractiveObject 50 | { 51 | if (_object != null) { 52 | _object.removeEventListener(Event.ENTER_FRAME, updateMouse); 53 | } 54 | return super.detach(); 55 | } 56 | 57 | /** 58 | * Causes the layout anchor to be updated according to the current 59 | * mouse position. 60 | * @param evt an optional mouse event 61 | */ 62 | public function updateMouse(evt:Event=null):void 63 | { 64 | // get current anchor, run update if changed 65 | var p1:Point = _layout.layoutAnchor; 66 | _layout.layoutAnchor = new Point(_object.mouseX, _object.mouseY); 67 | // distortion might snap the anchor to the layout bounds 68 | // so we need to re-retrieve the point to ensure accuracy 69 | var p2:Point = _layout.layoutAnchor; 70 | if (p1.x != p2.x || p1.y != p2.y) update(); 71 | } 72 | 73 | } // end of class AnchorControl 74 | } -------------------------------------------------------------------------------- /flare.tests/src/flare/tests/MatrixTests.as: -------------------------------------------------------------------------------- 1 | package flare.tests 2 | { 3 | import flare.util.math.DenseMatrix; 4 | import flare.util.math.IMatrix; 5 | import flare.util.math.SparseMatrix; 6 | 7 | import unitest.TestCase; 8 | 9 | public class MatrixTests extends TestCase 10 | { 11 | public function MatrixTests() 12 | { 13 | addTest("testDenseMatrix"); 14 | addTest("testSparseMatrix"); 15 | } 16 | 17 | private static function testMatrix(mat:IMatrix):void 18 | { 19 | var i:int, j:int, c:int = 7, v:Number; 20 | 21 | // populate matrix 22 | for (i=0; ileft property. 11 | */ 12 | protected var _left:Number = 0; 13 | 14 | /** 15 | * Backing variable for top property. 16 | */ 17 | protected var _top:Number = 0; 18 | 19 | /** 20 | * Backing variable for right property. 21 | */ 22 | protected var _right:Number = 0; 23 | 24 | /** 25 | * Backing variable for bottom property. 26 | */ 27 | protected var _bottom:Number = 0; 28 | 29 | // -- Public properties -------------------------------- 30 | 31 | /** 32 | * Left padding. 33 | */ 34 | public function get left():Number 35 | { 36 | return _left; 37 | } 38 | public function set left( value:Number ):void 39 | { 40 | _left = value; 41 | } 42 | 43 | /** 44 | * Top padding. 45 | */ 46 | public function get top():Number 47 | { 48 | return _top; 49 | } 50 | public function set top( value:Number ):void 51 | { 52 | _top = value; 53 | } 54 | 55 | /** 56 | * Right padding. 57 | */ 58 | public function get right():Number 59 | { 60 | return _right; 61 | } 62 | public function set right( value:Number ):void 63 | { 64 | _right = value; 65 | } 66 | 67 | /** 68 | * Bottom padding. 69 | */ 70 | public function get bottom():Number 71 | { 72 | return _bottom; 73 | } 74 | public function set bottom( value:Number ):void 75 | { 76 | _bottom = value; 77 | } 78 | 79 | // -- Constructor -------------------------------------- 80 | 81 | /** 82 | * Constructor. 83 | */ 84 | public function Padding( left:Number, top:Number, right:Number, bottom:Number ) 85 | { 86 | super(); 87 | 88 | this.left = left; 89 | this.top = top; 90 | this.right = right; 91 | this.bottom = bottom; 92 | } 93 | 94 | // -- Public methods ----------------------------------- 95 | 96 | public function apply( rectangle:Rectangle ):Rectangle 97 | { 98 | var result:Rectangle = rectangle.clone(); 99 | 100 | result.left -= left; 101 | result.top -= top; 102 | result.right += right; 103 | result.bottom += bottom; 104 | 105 | return result; 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /flare/src/flare/data/DataSchema.as: -------------------------------------------------------------------------------- 1 | package flare.data 2 | { 3 | import flare.util.Arrays; 4 | 5 | /** 6 | * A data schema represents a set of data variables and their associated 7 | * types. A schema maintains a collection of DataField 8 | * objects. 9 | * @see flare.data.DataField 10 | */ 11 | public class DataSchema 12 | { 13 | public var dataRoot:String = null; 14 | public var hasHeader:Boolean = false; 15 | 16 | private var _fields:/*DataField*/Array = []; 17 | private var _nameLookup:/*String->DataField*/Object = {}; 18 | private var _idLookup:/*String->DataField*/Object = {}; 19 | 20 | /** An array containing the data fields in this schema. */ 21 | public function get fields():Array { return Arrays.copy(_fields); } 22 | /** The number of data fields in this schema. */ 23 | public function get numFields():int { return _fields.length; } 24 | 25 | /** 26 | * Creates a new DataSchema. 27 | * @param fields an ordered list of data fields to include in the 28 | * schema 29 | */ 30 | public function DataSchema(...fields) 31 | { 32 | for each (var f:DataField in fields) { 33 | addField(f); 34 | } 35 | } 36 | 37 | /** 38 | * Adds a field to this schema. 39 | * @param field the data field to add 40 | */ 41 | public function addField(field:DataField):void 42 | { 43 | _fields.push(field); 44 | _nameLookup[field.name] = field; 45 | _idLookup[field.id] = field; 46 | } 47 | 48 | /** 49 | * Retrieves a data field by name. 50 | * @param name the data field name 51 | * @return the corresponding data field, or null if no data field is 52 | * found matching the name 53 | */ 54 | public function getFieldByName(name:String):DataField 55 | { 56 | return _nameLookup[name]; 57 | } 58 | 59 | /** 60 | * Retrieves a data field by id. 61 | * @param name the data field id 62 | * @return the corresponding data field, or null if no data field is 63 | * found matching the id 64 | */ 65 | public function getFieldById(id:String):DataField 66 | { 67 | return _idLookup[id]; 68 | } 69 | 70 | /** 71 | * Retrieves a data field by its index in this schema. 72 | * @param idx the index of the data field in this schema 73 | * @return the corresponding data field 74 | */ 75 | public function getFieldAt(idx:int):DataField 76 | { 77 | return _fields[idx]; 78 | } 79 | 80 | } // end of class DataSchema 81 | } -------------------------------------------------------------------------------- /flare/src/flare/animate/interpolate/MatrixInterpolator.as: -------------------------------------------------------------------------------- 1 | package flare.animate.interpolate 2 | { 3 | import flash.geom.Matrix; 4 | 5 | /** 6 | * Interpolator for flash.geom.Matrix values. 7 | */ 8 | public class MatrixInterpolator extends Interpolator 9 | { 10 | private var _startA:Number, _startB:Number, _startC:Number; 11 | private var _startD:Number, _startX:Number, _startY:Number; 12 | private var _rangeA:Number, _rangeB:Number, _rangeC:Number; 13 | private var _rangeD:Number, _rangeX:Number, _rangeY:Number; 14 | private var _cur:Matrix; 15 | 16 | /** 17 | * Creates a new MatrixInterpolator. 18 | * @param target the object whose property is being interpolated 19 | * @param property the property to interpolate 20 | * @param start the starting matrix value to interpolate from 21 | * @param end the target matrix value to interpolate to 22 | */ 23 | public function MatrixInterpolator(target:Object, property:String, 24 | start:Object, end:Object) 25 | { 26 | super(target, property, start, end); 27 | } 28 | 29 | /** 30 | * Initializes this interpolator. 31 | * @param start the starting value of the interpolation 32 | * @param end the target value of the interpolation 33 | */ 34 | protected override function init(start:Object, end:Object) : void 35 | { 36 | var e:Matrix = Matrix(end), s:Matrix = Matrix(start); 37 | _cur = _prop.getValue(_target) as Matrix; 38 | if (_cur == null || _cur == s || _cur == e) 39 | _cur = e.clone(); 40 | 41 | _startA = s.a; 42 | _startB = s.b; 43 | _startC = s.c; 44 | _startD = s.d; 45 | _startX = s.tx; 46 | _startY = s.ty; 47 | _rangeA = e.a - _startA; 48 | _rangeB = e.b - _startB; 49 | _rangeC = e.c - _startC; 50 | _rangeD = e.d - _startD; 51 | _rangeX = e.tx - _startX; 52 | _rangeY = e.ty - _startY; 53 | } 54 | 55 | /** 56 | * Calculate and set an interpolated property value. 57 | * @param f the interpolation fraction (typically between 0 and 1) 58 | */ 59 | public override function interpolate(f:Number) : void 60 | { 61 | _cur.a = _startA + f * _rangeA; 62 | _cur.b = _startB + f * _rangeB; 63 | _cur.c = _startC + f * _rangeC; 64 | _cur.d = _startD + f * _rangeD; 65 | _cur.tx = _startX + f * _rangeX; 66 | _cur.ty = _startY + f * _rangeY; 67 | _prop.setValue(_target, _cur); 68 | } 69 | 70 | } // end of class MatrixInterpolator 71 | } -------------------------------------------------------------------------------- /flare/src/flare/data/converters/JSONConverter.as: -------------------------------------------------------------------------------- 1 | package flare.data.converters 2 | { 3 | import com.adobe.serialization.json.JSON; 4 | 5 | import flare.data.DataField; 6 | import flare.data.DataSchema; 7 | import flare.data.DataSet; 8 | import flare.data.DataTable; 9 | import flare.data.DataUtil; 10 | import flare.util.Property; 11 | 12 | import flash.utils.ByteArray; 13 | import flash.utils.IDataInput; 14 | import flash.utils.IDataOutput; 15 | 16 | /** 17 | * Converts data between JSON (JavaScript Object Notation) strings and 18 | * flare DataSet instances. 19 | */ 20 | public class JSONConverter implements IDataConverter 21 | { 22 | /** 23 | * @inheritDoc 24 | */ 25 | public function read(input:IDataInput, schema:DataSchema=null):DataSet 26 | { 27 | var data:Array; 28 | return new DataSet(new DataTable( 29 | data = parse(input.readUTFBytes(input.bytesAvailable), schema), 30 | schema ? schema : DataUtil.inferSchema(data) 31 | )); 32 | } 33 | 34 | /** 35 | * Converts data from a JSON string into ActionScript objects. 36 | * @param input the loaded input data 37 | * @param schema a data schema describing the structure of the data. 38 | * Schemas are optional in many but not all cases. 39 | * @param data an array in which to write the converted data objects. 40 | * If this value is null, a new array will be created. 41 | * @return an array of converted data objects. If the data 42 | * argument is non-null, it is returned. 43 | */ 44 | public function parse(text:String, schema:DataSchema):Array 45 | { 46 | var json:Object = JSON.decode(text) as Object; 47 | var list:Array = json as Array; 48 | 49 | if (schema != null) { 50 | if (schema.dataRoot) { 51 | // if nested, extract data array 52 | list = Property.$(schema.dataRoot).getValue(json); 53 | } 54 | // convert value types according to schema 55 | for each (var t:Object in list) { 56 | for each (var f:DataField in schema.fields) { 57 | t[f.name] = DataUtil.parseValue(t[f.name], f.type); 58 | } 59 | } 60 | } 61 | return list; 62 | } 63 | 64 | /** 65 | * @inheritDoc 66 | */ 67 | public function write(data:DataSet, output:IDataOutput=null):IDataOutput 68 | { 69 | var tuples:Array = data.nodes.data; 70 | if (output==null) output = new ByteArray(); 71 | output.writeUTFBytes(JSON.encode(tuples)); 72 | return output; 73 | } 74 | 75 | } // end of class JSONConverter 76 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/events/DataEvent.as: -------------------------------------------------------------------------------- 1 | package flare.vis.events 2 | { 3 | import flare.vis.data.DataList; 4 | import flare.vis.data.DataSprite; 5 | import flare.vis.data.EdgeSprite; 6 | import flare.vis.data.NodeSprite; 7 | 8 | import flash.events.Event; 9 | 10 | /** 11 | * Event fired when a data collection is modified. 12 | */ 13 | public class DataEvent extends Event 14 | { 15 | /** A data added event. */ 16 | public static const ADD:String = "add"; 17 | /** A data removed event. */ 18 | public static const REMOVE:String = "remove"; 19 | /** A data updated event. */ 20 | public static const UPDATE:String = "update"; 21 | 22 | /** @private */ 23 | protected var _items:Array; 24 | /** @private */ 25 | protected var _item:Object; 26 | /** @private */ 27 | protected var _list:DataList; 28 | 29 | /** The number of items in this data event. */ 30 | public function get length():int { 31 | return _items ? _items.length : 1; 32 | } 33 | 34 | /** The list of effected data items. */ 35 | public function get items():Array { 36 | if (_items == null) _items = [_item]; 37 | return _items; 38 | } 39 | 40 | /** The data list (if any) the items belong to. */ 41 | public function get list():DataList { return _list; } 42 | 43 | /** The first element in the event list as an Object. */ 44 | public function get object():Object { return _item; } 45 | /** The first element in the event list as a DataSprite. */ 46 | public function get item():DataSprite { return _item as DataSprite; } 47 | /** The first element in the event list as a NodeSprite. */ 48 | public function get node():NodeSprite { return _item as NodeSprite; } 49 | /** The first element in the event list as an EdgeSprite. */ 50 | public function get edge():EdgeSprite { return _item as EdgeSprite; } 51 | 52 | /** 53 | * Creates a new DataEvent. 54 | * @param type the event type (ADD, REMOVE, or UPDATE) 55 | * @param items the DataSprite(s) that were added, removed, or updated 56 | * @param list (optional) the data list that was modified 57 | */ 58 | public function DataEvent(type:String, items:*, list:DataList=null) 59 | { 60 | super(type, false, true); 61 | if (items is Array) { 62 | _items = items; 63 | _item = _items[0]; 64 | } else { 65 | _items = null; 66 | _item = items; 67 | } 68 | _list = list; 69 | } 70 | 71 | /** @inheritDoc */ 72 | public override function clone():Event 73 | { 74 | return new DataEvent(type, _items?_items:_item, _list); 75 | } 76 | 77 | } // end of class DataEvent 78 | } -------------------------------------------------------------------------------- /flare/src/flare/util/palette/SizePalette.as: -------------------------------------------------------------------------------- 1 | package flare.util.palette 2 | { 3 | /** 4 | * Palette for size values represeneted as scale factors. The SizePalette 5 | * class distinguishes between 1D and 2D scale factors, with a square 6 | * root being applied to 2D scale factors to ensure that area scales 7 | * linearly with the size value. 8 | */ 9 | public class SizePalette extends Palette 10 | { 11 | private var _minSize:Number = 1; 12 | private var _range:Number = 6; 13 | private var _is2D:Boolean = true; 14 | 15 | /** The minimum scale factor in this size palette. */ 16 | public function get minimumSize():Number { return _minSize; } 17 | public function set minimumSize(s:Number):void { 18 | _range += s - _minSize; _minSize = s; 19 | } 20 | 21 | /** the maximum scale factor in this size palette. */ 22 | public function get maximumSize():Number { return _minSize + _range; } 23 | public function set maximumSize(s:Number):void { _range = s - _minSize; } 24 | 25 | /** Flag indicating if this size palette is for 2D shapes. */ 26 | public function get is2D():Boolean { return _is2D; } 27 | public function set is2D(b:Boolean):void { _is2D = b; } 28 | 29 | // -------------------------------------------------------------------- 30 | 31 | /** 32 | * Creates a new SizePalette. 33 | * @param minSize the minimum scale factor in the palette 34 | * @param maxSize the maximum scale factor in the palette 35 | * @param is2D flag indicating if the size values are for a 2D shape, 36 | * true by default 37 | */ 38 | public function SizePalette(minSize:Number=1, maxSize:Number=6, is2D:Boolean=true) 39 | { 40 | _minSize = minSize; 41 | _range = maxSize - minSize; 42 | _is2D = is2D; 43 | } 44 | 45 | /** @inheritDoc */ 46 | public override function getValue(f:Number):Object 47 | { 48 | return getSize(f); 49 | } 50 | 51 | /** 52 | * Retrieves the size value corresponding to the input interpolation 53 | * fraction. If the is2D flag is true, the square root 54 | * of the size value is returned. 55 | * @param f an interpolation fraction 56 | * @return the size value corresponding to the input fraction 57 | */ 58 | public function getSize(v:Number):Number 59 | { 60 | var s:Number; 61 | if (_values == null) { 62 | s = _minSize + v * _range; 63 | } else { 64 | s = _values[uint(Math.round(v*(_values.length-1)))]; 65 | } 66 | return _is2D ? Math.sqrt(s) : s; 67 | } 68 | 69 | } // end of class SizePalette 70 | } -------------------------------------------------------------------------------- /flare/src/flare/util/Filter.as: -------------------------------------------------------------------------------- 1 | package flare.util 2 | { 3 | /** 4 | * Utility methods for creating filter functions. The static 5 | * $() method takes an arbitrary object and generates a 6 | * corresponding filter function. 7 | * 8 | *

Filter functions are functions that take one argument and return a 9 | * Boolean value. The input argument to a filter function 10 | * passes the filter if the function returns true and fails the 11 | * filter if the function returns false.

12 | */ 13 | public class Filter 14 | { 15 | /** 16 | * Constructor, throws an error if called, as this is an abstract class. 17 | */ 18 | public function Filter() 19 | { 20 | throw new Error("This is an abstract class."); 21 | } 22 | 23 | /** 24 | * Convenience method that returns a filter function determined by the 25 | * input object. 26 | *
    27 | *
  • If the input is null or a Function, it is simply 28 | * returned.
  • 29 | *
  • If the input is an IPredicate, its 30 | * predicate function is returned.
  • 31 | *
  • If the input is a String, a Property 32 | * instance with the string as the property name is generated, and 33 | * the predicate function of the property is 34 | * returned.
  • 35 | *
  • If the input is a Class instance, a function that 36 | * performs type-checking for that class type is returned.
  • 37 | *
  • In any other case, an error is thrown.
  • 38 | *
39 | * @param f an input object specifying the filter criteria 40 | * @return the filter function 41 | */ 42 | public static function $(f:*):Function 43 | { 44 | if (f==null || f is Function) { 45 | return f; 46 | } else if (f is IPredicate) { 47 | return IPredicate(f).predicate; 48 | } else if (f is String) { 49 | return Property.$(f).predicate; 50 | } else if (f is Class) { 51 | return typeChecker(Class(f)); 52 | } else { 53 | throw new ArgumentError("Unrecognized filter type"); 54 | } 55 | } 56 | 57 | /** 58 | * Returns a filter function that performs type-checking. 59 | * @param type the Class type to check for 60 | * @return a Boolean-valued type checking filter function 61 | */ 62 | public static function typeChecker(type:Class):Function 63 | { 64 | return function(o:Object):Boolean { return o is type; } 65 | } 66 | 67 | } // end of class Filter 68 | } -------------------------------------------------------------------------------- /flare.demos/.actionScriptProperties: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /flare/src/flare/vis/data/render/ShapeRenderer.as: -------------------------------------------------------------------------------- 1 | package flare.vis.data.render 2 | { 3 | import flare.util.Shapes; 4 | import flare.vis.data.DataSprite; 5 | 6 | import flash.display.Graphics; 7 | 8 | /** 9 | * Renderer that draws shapes. The ShapeRender uses a ShapePalette instance 10 | * as needed to look up shape drawing routines based on the DataSprite 11 | * shape property. 12 | * @see flare.vis.palette.ShapePalette 13 | */ 14 | public class ShapeRenderer implements IRenderer 15 | { 16 | private static var _instance:ShapeRenderer = new ShapeRenderer(); 17 | /** Static ShapeRenderer instance. */ 18 | public static function get instance():ShapeRenderer { return _instance; } 19 | 20 | /** The default size value for drawn shapes. This value is multiplied 21 | * by a DataSprite's size property to determine the final size. */ 22 | public var defaultSize:Number; 23 | 24 | /** 25 | * Creates a new ShapeRenderer 26 | * @param defaultSize the default size (radius) for shapes 27 | */ 28 | public function ShapeRenderer(defaultSize:Number=6) { 29 | this.defaultSize = defaultSize; 30 | } 31 | 32 | /** @inheritDoc */ 33 | public function render(d:DataSprite):void 34 | { 35 | var lineAlpha:Number = d.lineAlpha; 36 | var fillAlpha:Number = d.fillAlpha; 37 | var size:Number = d.size * defaultSize; 38 | 39 | var g:Graphics = d.graphics; 40 | g.clear(); 41 | if (fillAlpha > 0) g.beginFill(d.fillColor, fillAlpha); 42 | if (lineAlpha > 0) g.lineStyle(d.lineWidth, d.lineColor, lineAlpha); 43 | 44 | switch (d.shape) { 45 | case null: break; 46 | 47 | case Shapes.BLOCK: g.drawRect(d.u-d.x, d.v-d.y, d.w, d.h); break; 48 | case Shapes.VERTICAL_BAR: g.drawRect(-size/2, -d.h, size, d.h); break; 49 | case Shapes.HORIZONTAL_BAR: g.drawRect(-d.w, -size/2, d.w, size); break; 50 | 51 | case Shapes.LINE: if (d.points!=null) Shapes.drawLine(g, d.points); break; 52 | case Shapes.CARDINAL: if (d.points!=null) Shapes.drawCardinal(g, d.points,d.points.length/2, 0.15, false); break; 53 | case Shapes.POLYGON: if (d.points!=null) Shapes.drawPolygon(g, d.points); break; 54 | case Shapes.POLYBLOB: if (d.points!=null) Shapes.drawCardinal(g, d.points,d.points.length/2, 0.15, true); break; 55 | 56 | case Shapes.WEDGE: Shapes.drawWedge(g, d.origin.x-d.x, d.origin.y-d.y, d.h, d.v, d.u, d.u+d.w); break; 57 | default: Shapes.getShape(d.shape)(g, size); 58 | } 59 | 60 | if (fillAlpha > 0) g.endFill(); 61 | } 62 | 63 | } // end of class ShapeRenderer 64 | } -------------------------------------------------------------------------------- /flare/src/flare/scale/QuantileScale.as: -------------------------------------------------------------------------------- 1 | package flare.scale 2 | { 3 | import flare.util.Maths; 4 | import flare.util.Strings; 5 | 6 | /** 7 | * Scale that organizes data into discrete bins by quantiles. 8 | * For example, the quantile scale can be used to create a discrete size 9 | * encoding by statistically dividing the data into bins. Quantiles are 10 | * computed using the flare.util.Maths.quantile method. 11 | * 12 | * @see flare.util.Maths#quantile 13 | */ 14 | public class QuantileScale extends Scale 15 | { 16 | private var _quantiles:Array; 17 | 18 | /** @inheritDoc */ 19 | public override function get flush():Boolean { return true; } 20 | public override function set flush(val:Boolean):void { /* nothing */ } 21 | 22 | /** @inheritDoc */ 23 | public override function get min():Object { return _quantiles[0]; } 24 | 25 | /** @inheritDoc */ 26 | public override function get max():Object { return _quantiles[_quantiles.length-1]; } 27 | 28 | // -------------------------------------------------------------------- 29 | 30 | /** 31 | * Creates a new QuantileScale. 32 | * @param n the number of quantiles desired 33 | * @param values the data values to organized into quantiles 34 | * @param sorted flag indicating if the input values array is 35 | * already pre-sorted 36 | * @param labelFormat the formatting pattern for value labels 37 | */ 38 | public function QuantileScale(n:int, values:Array, 39 | sorted:Boolean=false, labelFormat:String=Strings.DEFAULT_NUMBER) 40 | { 41 | _quantiles = (n<0 ? values : Maths.quantile(n, values, !sorted)); 42 | this.labelFormat = labelFormat; 43 | } 44 | 45 | /** @inheritDoc */ 46 | public override function get scaleType():String { 47 | return ScaleType.QUANTILE; 48 | } 49 | 50 | /** @inheritDoc */ 51 | public override function clone():Scale 52 | { 53 | return new QuantileScale(-1, _quantiles, false, _format); 54 | } 55 | 56 | /** @inheritDoc */ 57 | public override function interpolate(value:Object):Number 58 | { 59 | return Maths.invQuantileInterp(Number(value), _quantiles); 60 | } 61 | 62 | /** @inheritDoc */ 63 | public override function lookup(f:Number):Object 64 | { 65 | return Maths.quantileInterp(f, _quantiles); 66 | } 67 | 68 | /** @inheritDoc */ 69 | public override function values(num:int=-1):/*Number*/Array 70 | { 71 | var a:Array = new Array(); 72 | var stride:int = num<0 ? 1 : 73 | int(Math.max(1, Math.floor(_quantiles.length/num))); 74 | for (var i:uint=0; i<_quantiles.length; i += stride) { 75 | a.push(_quantiles[i]); 76 | } 77 | return a; 78 | } 79 | 80 | } // end of class QuantileScale 81 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/operator/Operator.as: -------------------------------------------------------------------------------- 1 | package flare.vis.operator 2 | { 3 | import flare.animate.Transitioner; 4 | import flare.util.IEvaluable; 5 | import flare.util.Property; 6 | import flare.vis.Visualization; 7 | 8 | /** 9 | * Operators performs processing tasks on the contents of a Visualization. 10 | * These tasks include layout, and color, shape, and size encoding. 11 | * Custom operators can be defined by subclassing this class. 12 | */ 13 | public class Operator implements IOperator 14 | { 15 | // -- Properties ------------------------------------------------------ 16 | 17 | protected var _vis:Visualization; 18 | protected var _enabled:Boolean = true; 19 | 20 | /** The visualization processed by this operator. */ 21 | public function get visualization():Visualization { return _vis; } 22 | public function set visualization(v:Visualization):void { 23 | _vis = v; setup(); 24 | } 25 | 26 | /** Indicates if the operator is enabled or disabled. */ 27 | public function get enabled():Boolean { return _enabled; } 28 | public function set enabled(b:Boolean):void { _enabled = b; } 29 | 30 | /** @inheritDoc */ 31 | public function set parameters(params:Object):void 32 | { 33 | applyParameters(this, params); 34 | } 35 | 36 | // -- Methods --------------------------------------------------------- 37 | 38 | /** 39 | * Performs an operation over the contents of a visualization. 40 | * @param t a Transitioner instance for collecting value updates. 41 | */ 42 | public function operate(t:Transitioner=null) : void { 43 | // for sub-classes to implement 44 | } 45 | 46 | /** 47 | * Setup method invoked whenever this operator's visualization 48 | * property is set. 49 | */ 50 | public function setup():void 51 | { 52 | // for subclasses 53 | } 54 | 55 | // -- MXML ------------------------------------------------------------ 56 | 57 | /** @private */ 58 | public function initialized(document:Object, id:String):void 59 | { 60 | // do nothing 61 | } 62 | 63 | // -- Parameterization ------------------------------------------------ 64 | 65 | /** 66 | * Static method that applies parameter settings to an operator. 67 | * @param op the operator 68 | * @param p the parameter object 69 | */ 70 | public static function applyParameters(op:IOperator,params:Object):void 71 | { 72 | if (op==null || params==null) return; 73 | var o:Object = op as Object; 74 | for (var name:String in params) { 75 | var p:Property = Property.$(name); 76 | var v:* = params[name]; 77 | var f:Function = v as Function; 78 | if (v is IEvaluable) f = IEvaluable(v).eval; 79 | p.setValue(op, f==null ? v : f(op)); 80 | } 81 | } 82 | 83 | } // end of class Operator 84 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/operator/OperatorSwitch.as: -------------------------------------------------------------------------------- 1 | package flare.vis.operator 2 | { 3 | import flare.animate.Transitioner; 4 | 5 | /** 6 | * An OperatorSwitch maintains a list of operators but only runs one 7 | * of these operators when invoked. A switch allows different operator 8 | * chains to be executed at different times. Operators can be added to 9 | * an OperatorSwitch using the add method. Once added, 10 | * operators can be retrieved and set using their index in the list, either 11 | * with array notation ([]) or with the 12 | * getOperatorAt and setOperatorAt methods. 13 | * 14 | *

The current sub-operator to run is determined by 15 | * the index property. This index can be set manually or can 16 | * be automatically determined upon each invocation by assigning a 17 | * custom function to the indexFunction property.

18 | */ 19 | public class OperatorSwitch extends OperatorList 20 | { 21 | private var _cur:int = -1; 22 | 23 | /** The currently active index of the switch. Only the operator at this 24 | * index is run when the operate method is called. */ 25 | public function get index():int { return _cur; } 26 | public function set index(i:int):void { _cur = i; } 27 | 28 | /** 29 | * A function that determines the current index value of this 30 | * OperatorSwitch. This can be used to have the operator automatically 31 | * adjust which sub-operators to run. If this property is non-null, 32 | * the function will be invoked each time this OperatorSwitch is run 33 | * and the index property will be set with the resulting value, 34 | * overriding any previous index setting. 35 | * The index function should accept zero arguments and return an 36 | * integer that is a legal index value for this switch. If the 37 | * returned value is not a legal index value (i.e., it is not an 38 | * integer or is out of bounds) then no sub-operators will be 39 | * run. 40 | */ 41 | public var indexFunction:Function = null; 42 | 43 | // -------------------------------------------------------------------- 44 | 45 | /** 46 | * Creates a new OperatorSwitch. 47 | * @param ops an ordered set of operators to include in the switch. 48 | */ 49 | public function OperatorSwitch(...ops) { 50 | for each (var op:IOperator in ops) { 51 | add(op); 52 | } 53 | } 54 | 55 | /** @inheritDoc */ 56 | public override function operate(t:Transitioner=null):void 57 | { 58 | t = (t!=null ? t : Transitioner.DEFAULT); 59 | if (indexFunction != null) { 60 | _cur = indexFunction(); 61 | } 62 | if (_cur >= 0 && _cur < _list.length && _list[_cur].enabled) 63 | _list[_cur].operate(t); 64 | } 65 | 66 | } // end of class OperatorSwitch 67 | } -------------------------------------------------------------------------------- /flare/lib/com/adobe/serialization/json/JSONTokenType.as: -------------------------------------------------------------------------------- 1 | /* 2 | Adobe Systems Incorporated(r) Source Code License Agreement 3 | Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. 4 | 5 | Please read this Source Code License Agreement carefully before using 6 | the source code. 7 | 8 | Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, 9 | no-charge, royalty-free, irrevocable copyright license, to reproduce, 10 | prepare derivative works of, publicly display, publicly perform, and 11 | distribute this source code and such derivative works in source or 12 | object code form without any attribution requirements. 13 | 14 | The name "Adobe Systems Incorporated" must not be used to endorse or promote products 15 | derived from the source code without prior written permission. 16 | 17 | You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and 18 | against any loss, damage, claims or lawsuits, including attorney's 19 | fees that arise or result from your use or distribution of the source 20 | code. 21 | 22 | THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT 23 | ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF 26 | NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA 27 | OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 30 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 32 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF 33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | package com.adobe.serialization.json { 37 | 38 | /** 39 | * Class containing constant values for the different types 40 | * of tokens in a JSON encoded string. 41 | * @private 42 | */ 43 | public class JSONTokenType { 44 | 45 | public static const UNKNOWN:int = -1; 46 | 47 | public static const COMMA:int = 0; 48 | 49 | public static const LEFT_BRACE:int = 1; 50 | 51 | public static const RIGHT_BRACE:int = 2; 52 | 53 | public static const LEFT_BRACKET:int = 3; 54 | 55 | public static const RIGHT_BRACKET:int = 4; 56 | 57 | public static const COLON:int = 6; 58 | 59 | public static const TRUE:int = 7; 60 | 61 | public static const FALSE:int = 8; 62 | 63 | public static const NULL:int = 9; 64 | 65 | public static const STRING:int = 10; 66 | 67 | public static const NUMBER:int = 11; 68 | 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /flare.apps/.actionScriptProperties: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /flare/src/flare/display/render/BackgroundRenderer.as: -------------------------------------------------------------------------------- 1 | package flare.display.render 2 | { 3 | import flare.display.DisplaySprite; 4 | 5 | import flash.display.Graphics; 6 | import flash.geom.Rectangle; 7 | 8 | public class BackgroundRenderer implements IBackgroundRenderer 9 | { 10 | /** 11 | * Backing variable for instance property. 12 | */ 13 | protected static var _instance:BackgroundRenderer = new BackgroundRenderer(); 14 | 15 | /** 16 | * Static BackgroundRenderer instance. 17 | */ 18 | public static function get instance():BackgroundRenderer 19 | { 20 | return _instance; 21 | } 22 | 23 | /** 24 | * Constructor. 25 | */ 26 | public function BackgroundRenderer() 27 | { 28 | super(); 29 | } 30 | 31 | /** 32 | * @inheritDoc 33 | */ 34 | public function render( displaySprite:DisplaySprite, bounds:Rectangle ):void 35 | { 36 | if ( !displaySprite.backgroundBorder && !displaySprite.backgroundFill ) 37 | return; 38 | 39 | var graphics:Graphics = displaySprite.graphics; 40 | 41 | graphics.clear(); 42 | 43 | // Set the border (if applicable). 44 | 45 | if ( displaySprite.backgroundBorder ) 46 | { 47 | graphics.lineStyle( 48 | displaySprite.backgroundBorderThickness, 49 | displaySprite.backgroundBorderColor & 0x00ffffff, 50 | displaySprite.backgroundBorderAlpha, 51 | displaySprite.backgroundBorderPixelHinting 52 | ); 53 | } 54 | 55 | // Begin the fill (if applicable). 56 | 57 | if ( displaySprite.backgroundFill ) 58 | { 59 | if ( displaySprite.backgroundFillGradient ) 60 | { 61 | displaySprite.backgroundFillGradient.begin( graphics, bounds ); 62 | } 63 | else 64 | { 65 | graphics.beginFill( 66 | displaySprite.backgroundFillColor & 0x00ffffff, 67 | displaySprite.backgroundFillAlpha 68 | ); 69 | } 70 | } 71 | 72 | // Draw the bounds (with rounded corners if specified). 73 | 74 | if ( displaySprite.backgroundCornerWidth > 0 || displaySprite.backgroundCornerHeight > 0 ) 75 | { 76 | graphics.drawRoundRect( 77 | bounds.x, bounds.y, 78 | bounds.width, bounds.height, 79 | displaySprite.backgroundCornerWidth, displaySprite.backgroundCornerHeight ); 80 | } 81 | else 82 | { 83 | graphics.drawRect( 84 | bounds.x, bounds.y, 85 | bounds.width, bounds.height ); 86 | } 87 | 88 | // End the fill (if applicable). 89 | 90 | if ( displaySprite.backgroundFill ) 91 | { 92 | if ( displaySprite.backgroundFillGradient ) 93 | { 94 | displaySprite.backgroundFillGradient.end( graphics ); 95 | } 96 | else 97 | { 98 | graphics.endFill(); 99 | } 100 | } 101 | 102 | displaySprite.cacheAsBitmap = true; 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /flare/src/flare/util/gradient/GradientStop.as: -------------------------------------------------------------------------------- 1 | package flare.util.gradient 2 | { 3 | import flare.util.Colors; 4 | 5 | public class GradientStop 6 | { 7 | // -- Protected Properties ----------------------------- 8 | 9 | /** 10 | * Backing variable for backgroundFillColor property. 11 | */ 12 | protected var _color:uint; 13 | 14 | /** 15 | * Backing variable for backgroundCornerHeight property. 16 | */ 17 | protected var _ratio:Number; 18 | 19 | // -- Public Properties -------------------------------- 20 | 21 | /** 22 | * Color. 23 | */ 24 | public function get color():uint 25 | { 26 | return _color; 27 | } 28 | public function set color( value:uint ):void 29 | { 30 | _color = value; 31 | } 32 | 33 | /** 34 | * Alpha (Number between 0 and 1). 35 | */ 36 | public function get alpha():Number 37 | { 38 | return Colors.a( _color ) / 255; 39 | } 40 | public function set alpha( value:Number ):void 41 | { 42 | _color = Colors.setAlpha( _color, uint( 255 * value ) % 256 ); 43 | } 44 | 45 | /** 46 | * Hue component of the color in HSV color space. 47 | */ 48 | public function get colorHue():Number 49 | { 50 | return Colors.hue( _color ); 51 | } 52 | public function set colorHue( hue:Number ):void 53 | { 54 | _color = 55 | Colors.hsv( 56 | hue, 57 | Colors.saturation( _color ), 58 | Colors.value( _color ), 59 | Colors.a( _color ) 60 | ); 61 | } 62 | 63 | /** 64 | * Saturation component of the color in HSV color space. 65 | */ 66 | public function get colorSaturation():Number 67 | { 68 | return Colors.saturation( _color ); 69 | } 70 | public function set colorSaturation( saturation:Number ):void 71 | { 72 | _color = 73 | Colors.hsv( 74 | Colors.hue( _color ), 75 | saturation, 76 | Colors.value( _color ), 77 | Colors.a( _color ) 78 | ); 79 | } 80 | 81 | /** 82 | * Value component of the color in HSV color space. 83 | */ 84 | public function get colorValue():Number 85 | { 86 | return Colors.value( _color ); 87 | } 88 | public function set colorValue( value:Number ):void 89 | { 90 | _color = 91 | Colors.hsv( 92 | Colors.hue( _color ), 93 | Colors.saturation( _color ), 94 | value, 95 | Colors.a( _color ) 96 | ); 97 | } 98 | 99 | /** 100 | * Ratio (Number between 0 and 1). 101 | */ 102 | public function get ratio():Number 103 | { 104 | return _ratio; 105 | } 106 | public function set ratio( value:Number ):void 107 | { 108 | _ratio = value; 109 | } 110 | 111 | // -- Constructor -------------------------------------- 112 | 113 | public function GradientStop( color:uint, ratio:Number ) 114 | { 115 | super(); 116 | 117 | this.color = color; 118 | this.ratio = ratio; 119 | } 120 | } 121 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/controls/DragControl.as: -------------------------------------------------------------------------------- 1 | package flare.vis.controls 2 | { 3 | import flare.vis.data.DataSprite; 4 | 5 | import flash.display.InteractiveObject; 6 | import flash.display.Sprite; 7 | import flash.events.Event; 8 | import flash.events.MouseEvent; 9 | 10 | /** 11 | * Interactive control for dragging items. A DragControl will enable 12 | * dragging of all Sprites in a container object by clicking and dragging 13 | * them. 14 | */ 15 | public class DragControl extends Control 16 | { 17 | private var _cur:Sprite; 18 | private var _mx:Number, _my:Number; 19 | 20 | /** Indicates if drag should be followed at frame rate only. 21 | * If false, drag events can be processed faster than the frame 22 | * rate, however, this may pre-empt other processing. */ 23 | public var trackAtFrameRate:Boolean = false; 24 | 25 | /** The active item currently being dragged. */ 26 | public function get activeItem():Sprite { return _cur; } 27 | 28 | /** 29 | * Creates a new DragControl. 30 | * @param filter a Boolean-valued filter function determining which 31 | * items should be draggable. 32 | */ 33 | public function DragControl(filter:*=null) { 34 | this.filter = filter; 35 | } 36 | 37 | /** @inheritDoc */ 38 | public override function attach(obj:InteractiveObject):void 39 | { 40 | super.attach(obj); 41 | obj.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); 42 | } 43 | 44 | /** @inheritDoc */ 45 | public override function detach() : InteractiveObject 46 | { 47 | if (_object != null) { 48 | _object.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); 49 | } 50 | return super.detach(); 51 | } 52 | 53 | private function onMouseDown(event:MouseEvent) : void { 54 | var s:Sprite = event.target as Sprite; 55 | if (s==null) return; // exit if not a sprite 56 | 57 | if (_filter==null || _filter(s)) { 58 | _cur = s; 59 | _mx = _object.mouseX; 60 | _my = _object.mouseY; 61 | if (_cur is DataSprite) (_cur as DataSprite).fix(); 62 | 63 | _cur.stage.addEventListener(MouseEvent.MOUSE_MOVE, onDrag); 64 | _cur.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); 65 | 66 | event.stopPropagation(); 67 | } 68 | } 69 | 70 | private function onDrag(event:Event) : void { 71 | var x:Number = _object.mouseX; 72 | if (x != _mx) { 73 | _cur.x += (x - _mx); 74 | _mx = x; 75 | } 76 | 77 | var y:Number = _object.mouseY; 78 | if (y != _my) { 79 | _cur.y += (y - _my); 80 | _my = y; 81 | } 82 | } 83 | 84 | private function onMouseUp(event:MouseEvent) : void { 85 | if (_cur != null) { 86 | _cur.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp); 87 | _cur.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onDrag); 88 | 89 | if (_cur is DataSprite) (_cur as DataSprite).unfix(); 90 | event.stopPropagation(); 91 | } 92 | _cur = null; 93 | } 94 | 95 | } // end of class DragControl 96 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/operator/layout/PieLayout.as: -------------------------------------------------------------------------------- 1 | package flare.vis.operator.layout 2 | { 3 | import flare.util.Property; 4 | import flare.util.Shapes; 5 | import flare.vis.data.Data; 6 | import flare.vis.data.DataList; 7 | import flare.vis.data.DataSprite; 8 | 9 | import flash.geom.Point; 10 | import flash.geom.Rectangle; 11 | 12 | /** 13 | * Layout that places wedges for pie and donut charts. In addition to 14 | * the layout, this operator updates each node to have a "wedge" shape. 15 | */ 16 | public class PieLayout extends Layout 17 | { 18 | private var _field:Property; 19 | 20 | /** The source property determining wedge size. */ 21 | public function get source():String { return _field.name; } 22 | public function set source(f:String):void { _field = Property.$(f); } 23 | 24 | /** The data group to layout. */ 25 | public var group:String = Data.NODES; 26 | 27 | /** The radius of the pie/donut chart. If this value is not a number 28 | * (NaN) the radius will be determined from the layout bounds. */ 29 | public var radius:Number = NaN; 30 | /** The width of wedges, negative for a full pie slice. */ 31 | public var width:Number = -1; 32 | /** The initial angle for the pie layout (in radians). */ 33 | public var startAngle:Number = Math.PI/2; 34 | /** The total angular size of the layout (in radians, default 2 pi). */ 35 | public var angleWidth:Number = 2*Math.PI; 36 | 37 | // -------------------------------------------------------------------- 38 | 39 | /** 40 | * Creates a new PieLayout 41 | * @param field the source data field for determining wedge size 42 | * @param width the radial width of wedges, negative for full slices 43 | */ 44 | public function PieLayout(field:String=null, width:Number=-1, 45 | group:String=Data.NODES) 46 | { 47 | layoutType = POLAR; 48 | this.group = group; 49 | this.width = width; 50 | _field = (field==null) ? null : new Property(field); 51 | } 52 | 53 | /** @inheritDoc */ 54 | protected override function layout():void 55 | { 56 | var b:Rectangle = layoutBounds; 57 | var r:Number = isNaN(radius) ? Math.min(b.width, b.height)/2 : radius; 58 | var a:Number = startAngle, aw:Number; 59 | var list:DataList = visualization.data.group(group); 60 | var sum:Number = list.stats(_field.name).sum; 61 | var anchor:Point = layoutAnchor; 62 | 63 | list.visit(function(d:DataSprite):void { 64 | var aw:Number = -angleWidth * (_field.getValue(d)/sum); 65 | var rh:Number = (width < 0 ? 0 : width) * r; 66 | var o:Object = _t.$(d); 67 | 68 | d.origin = anchor; 69 | 70 | //o.angle = a + aw/2; // angular mid-point 71 | //o.radius = (r+rh)/2; // radial mid-point 72 | o.x = 0; 73 | o.y = 0; 74 | 75 | o.u = a; // starting angle 76 | o.w = aw; // angle width 77 | o.h = r; // outer radius 78 | o.v = rh; // inner radius 79 | o.shape = Shapes.WEDGE; 80 | 81 | a += aw; 82 | }); 83 | } 84 | 85 | } // end of class PieLayout 86 | } -------------------------------------------------------------------------------- /flare.demos/src/flare/demos/Smoke.as: -------------------------------------------------------------------------------- 1 | package flare.demos 2 | { 3 | import flare.physics.Particle; 4 | import flare.physics.Simulation; 5 | 6 | import flash.display.Shape; 7 | import flash.events.Event; 8 | import flash.utils.Dictionary; 9 | 10 | /** 11 | * Demo showcasing use of the physics engine to simulate smoke. 12 | * Based on the smoke example from the traer physics library 13 | * for processing (http://www.cs.princeton.edu/~traer/physics/). 14 | */ 15 | public class Smoke extends Demo 16 | { 17 | private var _shapes:Array = new Array(); 18 | private var _spool:Array = new Array(); 19 | private var _sim:Simulation; 20 | private var _dict:Dictionary; 21 | private var _last:Particle; 22 | private var _life:Number = 62; 23 | 24 | public function Smoke() 25 | { 26 | name = "Smoke"; 27 | _shapes = new Array(); 28 | _dict = new Dictionary(); 29 | _last = null; 30 | 31 | // a simulation with slight upward gravity 32 | _sim = new Simulation(0, -0.1, 0.001, 0); 33 | } 34 | 35 | override public function play():void 36 | { 37 | addEventListener(Event.ENTER_FRAME, drawSmoke); 38 | } 39 | 40 | override public function stop():void 41 | { 42 | removeEventListener(Event.ENTER_FRAME, drawSmoke); 43 | } 44 | 45 | private function getShape():Shape 46 | { 47 | // get a new shape, check object pool before allocating a new one 48 | var s:Shape; 49 | if (_spool.length > 0) { 50 | s = _spool.pop(); 51 | s.alpha = 1; 52 | } else { 53 | s = new Shape(); 54 | s.graphics.beginFill(0x0); 55 | s.graphics.drawEllipse(-10,-10,20,20); 56 | s.graphics.endFill(); 57 | } 58 | return s; 59 | } 60 | 61 | private function reclaim(s:Shape):void 62 | { 63 | // reclaim shape in object pool for reuse 64 | _spool.push(s); 65 | } 66 | 67 | private function drawSmoke(evt:Event=null):void 68 | { 69 | // create five new smoke particles on each simulation tick 70 | for (var i:uint = 0; i<5; ++i) { 71 | var p:Particle = _sim.addParticle(1, root.mouseX, root.mouseY-10); 72 | 73 | var s:Shape = getShape(); 74 | _dict[s] = p; 75 | _shapes.push(s); 76 | addChild(s); 77 | 78 | p.vx = 2 * (Math.random()-0.5); 79 | p.vy = (3 * Math.random()) - 5; 80 | if (_last != null) { 81 | _sim.addSpring(p, _last, 10, 0.1, 0.1); 82 | } 83 | _last = p; 84 | } 85 | 86 | // run the simulation one timestep 87 | _sim.tick(); 88 | 89 | // update positions, handle removal of dead particles 90 | for (i = _shapes.length; --i >= 0; ) { 91 | s = _shapes[i] as Shape; 92 | p = _dict[s] as Particle; 93 | 94 | if (p.die) { 95 | _shapes.splice(i, 1); 96 | reclaim(s); 97 | removeChild(s); 98 | } else { 99 | if (p.age > _life) p.kill(); 100 | s.x = p.x; 101 | s.y = p.y; 102 | s.alpha = 1/(p.age+1); 103 | } 104 | } 105 | } 106 | 107 | } // end of class Smoke 108 | } -------------------------------------------------------------------------------- /flare/src/flare/util/math/IMatrix.as: -------------------------------------------------------------------------------- 1 | package flare.util.math 2 | { 3 | /** 4 | * Interface for a matrix of real-valued numbers. 5 | */ 6 | public interface IMatrix 7 | { 8 | /** The number of rows. */ 9 | function get rows():int; 10 | /** The number of columns. */ 11 | function get cols():int; 12 | /** The number of non-zero values. */ 13 | function get nnz():int; 14 | /** The sum of all the entries in this matrix. */ 15 | function get sum():Number; 16 | /** The sum of squares of all the entries in this matrix. */ 17 | function get sumsq():Number; 18 | 19 | /** Creates a copy of this matrix. */ 20 | function clone():IMatrix; 21 | 22 | /** 23 | * Creates a new matrix of the same type. 24 | * @param rows the number of rows in the new matrix 25 | * @param cols the number of columns in the new matrix 26 | * @return a new matrix 27 | */ 28 | function like(rows:int, cols:int):IMatrix; 29 | 30 | /** 31 | * Initializes the matrix to desired dimensions. This method also 32 | * resets all values in the matrix to zero. 33 | * @param rows the number of rows in this matrix 34 | * @param cols the number of columns in this matrix 35 | */ 36 | function init(rows:int, cols:int):void; 37 | 38 | /** 39 | * Returns the value at the given indices. 40 | * @param i the row index 41 | * @param j the column index 42 | * @return the value at position i,j 43 | */ 44 | function get(i:int, j:int):Number; 45 | 46 | /** 47 | * Sets the value at the given indices. 48 | * @param i the row index 49 | * @param j the column index 50 | * @param v the value to set 51 | * @return the input value v 52 | */ 53 | function set(i:int, j:int, v:Number):Number; 54 | 55 | /** 56 | * Multiplies all values in this matrix by the input scalar. 57 | * @param s the scalar to multiply by. 58 | */ 59 | function scale(s:Number):void; 60 | 61 | /** 62 | * Multiplies this matrix by another. The number of rows in this matrix 63 | * must match the number of columns in the input matrix. 64 | * @param b the matrix to multiply by. 65 | * @return a new matrix that is the product of this matrix with the 66 | * input matrix. The new matrix will be of the same type as this one. 67 | */ 68 | function multiply(b:IMatrix):IMatrix; 69 | 70 | /** 71 | * Visit all non-zero values in the matrix. 72 | * The input function is expected to take three arguments--the row 73 | * index, the column index, and the cell value--and return a number 74 | * which then becomes the new value for the cell. 75 | * @param f the function to invoke for each non-zero value 76 | */ 77 | function visitNonZero(f:Function):void; 78 | 79 | /** 80 | * Visit all values in the matrix. 81 | * The input function is expected to take three arguments--the row 82 | * index, the column index, and the cell value--and return a number 83 | * which then becomes the new value for the cell. 84 | * @param f the function to invoke for each value 85 | */ 86 | function visit(f:Function):void; 87 | 88 | } // end of interface IMatrix 89 | } -------------------------------------------------------------------------------- /flare/src/flare/physics/Particle.as: -------------------------------------------------------------------------------- 1 | package flare.physics 2 | { 3 | /** 4 | * Represents a Particle in a physics simulation. A particle is a 5 | * point-mass (or point-charge) subject to physical forces. 6 | */ 7 | public class Particle 8 | { 9 | /** The mass (or charge) of the particle. */ 10 | public var mass:Number; 11 | /** The number of springs (degree) attached to this particle. */ 12 | public var degree:Number; 13 | /** The x position of the particle. */ 14 | public var x:Number; 15 | /** The y position of the particle. */ 16 | public var y:Number; 17 | /** The x velocity of the particle. */ 18 | public var vx:Number; 19 | /** A temporary x velocity variable. */ 20 | public var _vx:Number; 21 | /** The y velocity of the particle. */ 22 | public var vy:Number; 23 | /** A temporary y velocity variable. */ 24 | public var _vy:Number; 25 | /** The x force exerted on the particle. */ 26 | public var fx:Number; 27 | /** The y force exerted on the particle. */ 28 | public var fy:Number; 29 | /** The age of the particle in simulation ticks. */ 30 | public var age:Number; 31 | /** Flag indicating if the particule should have a fixed position. */ 32 | public var fixed:Boolean; 33 | /** Flag indicating that the particle is scheduled for removal. */ 34 | public var die:Boolean; 35 | /** Tag property for storing an arbitrary value. */ 36 | public var tag:uint; 37 | 38 | /** 39 | * Creates a new Particle with given parameters. 40 | * @param mass the mass (or charge) of the particle 41 | * @param x the x position of the particle 42 | * @param y the y position of the particle 43 | * @param vx the x velocity of the particle 44 | * @param vy the y velocity of the particle 45 | * @param fixed flag indicating if the particle should have a 46 | * fixed position 47 | */ 48 | public function Particle(mass:Number=1, x:Number=0, y:Number=0, 49 | vx:Number=0, vy:Number=0, fixed:Boolean=false) 50 | { 51 | init(mass, x, y, vx, vy, fixed); 52 | } 53 | 54 | /** 55 | * Initializes an existing particle instance. 56 | * @param mass the mass (or charge) of the particle 57 | * @param x the x position of the particle 58 | * @param y the y position of the particle 59 | * @param vx the x velocity of the particle 60 | * @param vy the y velocity of the particle 61 | * @param fixed flag indicating if the particle should have a 62 | * fixed position 63 | */ 64 | public function init(mass:Number=1, x:Number=0, y:Number=0, 65 | vx:Number=0, vy:Number=0, fixed:Boolean=false):void 66 | { 67 | this.mass = mass; 68 | this.degree = 0; 69 | this.x = x; 70 | this.y = y; 71 | this.vx = this._vx = vx; 72 | this.vy = this._vy = vy; 73 | this.fx = 0; 74 | this.fy = 0; 75 | this.age = 0; 76 | this.fixed = fixed; 77 | this.die = false; 78 | this.tag = 0; 79 | } 80 | 81 | /** 82 | * "Kills" this particle, scheduling it for removal in the next 83 | * simulation cycle. 84 | */ 85 | public function kill():void { 86 | this.die = true; 87 | } 88 | 89 | } // end of class Particle 90 | } -------------------------------------------------------------------------------- /flare/src/flare/vis/controls/ExpandControl.as: -------------------------------------------------------------------------------- 1 | package flare.vis.controls 2 | { 3 | import flare.animate.Transitioner; 4 | import flare.vis.Visualization; 5 | import flare.vis.data.NodeSprite; 6 | 7 | import flash.display.InteractiveObject; 8 | import flash.events.MouseEvent; 9 | 10 | /** 11 | * Interactive control for expaning and collapsing graph or tree nodes 12 | * by clicking them. This control will only work when applied to a 13 | * Visualization instance. 14 | */ 15 | public class ExpandControl extends Control 16 | { 17 | private var _cur:NodeSprite; 18 | 19 | /** Update function invoked after expanding or collapsing an item. 20 | * By default, invokes the update method on the 21 | * visualization with a 1-second transitioner. */ 22 | public var update:Function = function():void { 23 | var vis:Visualization = _object as Visualization; 24 | if (vis) vis.update(1).play(); 25 | } 26 | 27 | // -------------------------------------------------------------------- 28 | 29 | /** 30 | * Creates a new ExpandControl. 31 | * @param filter a Boolean-valued filter function for determining which 32 | * item this control will expand or collapse 33 | * @param update function invokde after expanding or collapsing an 34 | * item. 35 | */ 36 | public function ExpandControl(filter:*=null, update:Function=null) 37 | { 38 | this.filter = filter; 39 | if (update != null) this.update = update; 40 | } 41 | 42 | /** @inheritDoc */ 43 | public override function attach(obj:InteractiveObject):void 44 | { 45 | if (obj==null) { detach(); return; } 46 | if (!(obj is Visualization)) { 47 | throw new Error("This control can only be attached to a Visualization"); 48 | } 49 | super.attach(obj); 50 | obj.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); 51 | } 52 | 53 | /** @inheritDoc */ 54 | public override function detach():InteractiveObject 55 | { 56 | if (_object != null) { 57 | _object.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); 58 | } 59 | return super.detach(); 60 | } 61 | 62 | private function onMouseDown(event:MouseEvent) : void { 63 | var s:NodeSprite = event.target as NodeSprite; 64 | if (s==null) return; // exit if not a NodeSprite 65 | 66 | if (_filter==null || _filter(s)) { 67 | _cur = s; 68 | _cur.stage.addEventListener(MouseEvent.MOUSE_MOVE, onDrag); 69 | _cur.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); 70 | } 71 | event.stopPropagation(); 72 | } 73 | 74 | private function onDrag(event:MouseEvent) : void { 75 | _cur.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp); 76 | _cur.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onDrag); 77 | _cur = null; 78 | } 79 | 80 | private function onMouseUp(event:MouseEvent) : void { 81 | _cur.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp); 82 | _cur.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onDrag); 83 | _cur.expanded = !_cur.expanded; 84 | _cur = null; 85 | event.stopPropagation(); 86 | 87 | update(); 88 | } 89 | 90 | } // end of class ExpandControl 91 | } -------------------------------------------------------------------------------- /flare/src/flare/query/If.as: -------------------------------------------------------------------------------- 1 | package flare.query 2 | { 3 | /** 4 | * Expression operator for an if statement that performs conditional 5 | * execution. 6 | */ 7 | public class If extends Expression 8 | { 9 | private var _test:Expression; 10 | private var _then:Expression; 11 | private var _else:Expression; 12 | 13 | /** The conditional clause of the if statement. */ 14 | public function get test():Expression { return _test; } 15 | public function set test(e:*):void { 16 | _test = Expression.expr(e); 17 | } 18 | 19 | /** Sub-expression evaluated if the test condition is true. */ 20 | public function get then():Expression { return _then; } 21 | public function set then(e:*):void { 22 | _then = Expression.expr(e); 23 | } 24 | 25 | /** Sub-expression evaluated if the test condition is false. */ 26 | public function get els():Expression { return _else; } 27 | public function set els(e:*):void { 28 | _else = Expression.expr(e); 29 | } 30 | 31 | /** 32 | * @inheritDoc 33 | */ 34 | public override function get numChildren():int { return 3; } 35 | 36 | // -------------------------------------------------------------------- 37 | 38 | /** 39 | * Create a new IfExpression. 40 | * @param test the test expression for the if statement 41 | * @param thenExpr the expression to evaluate if the test predicate 42 | * evaluates to true 43 | * @param elseExpr the expression to evaluate if the test predicate 44 | * evaluates to false 45 | */ 46 | public function If(test:*, thenExpr:*, elseExpr:*) 47 | { 48 | this.test = test; 49 | this.then = thenExpr; 50 | this.els = elseExpr; 51 | } 52 | 53 | /** 54 | * @inheritDoc 55 | */ 56 | public override function clone():Expression 57 | { 58 | return new If(_test.clone(), _then.clone(), _else.clone()); 59 | } 60 | 61 | /** 62 | * @inheritDoc 63 | */ 64 | public override function eval(o:Object=null):* 65 | { 66 | return (_test.predicate(o) ? _then : _else).eval(o); 67 | } 68 | 69 | /** 70 | * @inheritDoc 71 | */ 72 | public override function getChildAt(idx:int):Expression 73 | { 74 | switch (idx) { 75 | case 0: return _test; 76 | case 1: return _then; 77 | case 2: return _else; 78 | default: return null; 79 | } 80 | } 81 | 82 | /** 83 | * @inheritDoc 84 | */ 85 | public override function setChildAt(idx:int, expr:Expression):Boolean 86 | { 87 | switch (idx) { 88 | case 0: _test = expr; return true; 89 | case 1: _then = expr; return true; 90 | case 2: _else = expr; return true; 91 | default: return false; 92 | } 93 | } 94 | 95 | /** 96 | * @inheritDoc 97 | */ 98 | public override function toString():String 99 | { 100 | return "IF " + _test.toString() 101 | + " THEN " + _then.toString() 102 | + " ELSE " + _else.toString(); 103 | } 104 | 105 | } // end of class If 106 | } --------------------------------------------------------------------------------