package {
import flare.animate.Transitioner;
import flare.scale.ScaleType;
import flare.util.palette.ColorPalette;
import flare.util.palette.ShapePalette;
import flare.vis.Visualization;
import flare.vis.controls.ClickControl;
import flare.vis.data.Data;
import flare.vis.data.EdgeSprite;
import flare.vis.data.NodeSprite;
import flare.vis.operator.encoder.ColorEncoder;
import flare.vis.operator.encoder.ShapeEncoder;
import flare.vis.operator.encoder.SizeEncoder;
import flare.vis.operator.layout.AxisLayout;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Rectangle;
[SWF(width="500",height="400",backgroundColor="#ffffff",frameRade="30")]
public class Flare_axisLayout extends Sprite
{
public function Flare_axisLayout()
{
var data:Array=[{x:25,y:23,sex:"male",age:29},{x:32,y:58,sex:"female",age:29}];
var visual:Visualization=new Visualization(Data.fromArray(data));
var axis:AxisLayout=new AxisLayout("data.x","data.y");
visual.bounds=new Rectangle(50,50,400,300);
visual.operators.add(axis);
//set the axis style;
visual.xyAxes.xAxis.lineColor=0xff0000;
//add nodes to axis;
var node1:NodeSprite=visual.data.addNode({x:35,y:43,sex:"female",age:10});
var node2:NodeSprite=visual.data.addNode({x:12,y:27,sex:"unknow",age:2});
var edge:EdgeSprite=new EdgeSprite(node1,node2,false);
visual.data.addEdge(edge);
//add event listener to visual;note:no nodes;
var click:ClickControl=new ClickControl(null,1,clickHandler);
visual.controls.add(click);
var colorpalette:ColorPalette=new ColorPalette([0xffff0000,0xff00ff00,0xff0000ff],[0xffAAAAAA,0xff000000]);
var shapepalette:ShapePalette=new ShapePalette();
//add color style to nodes;
//palette:you just selected color from palette;
var color:ColorEncoder=new ColorEncoder("data.sex",Data.NODES,"fillColor",ScaleType.CATEGORIES,colorpalette);
visual.operators.add(color);
//add shape style to nodes;
var shape:ShapeEncoder=new ShapeEncoder("data.sex");
visual.operators.add(shape);
//add properties to nodes and edges;
var t:Transitioner=new Transitioner(3);
visual.data.nodes.setProperty("lineColor",0xffff0000,t);
visual.data.nodes.setProperty("lineWidth",2,t);
visual.data.edges.setProperty("lineWidth",2,t);
visual.data.edges.setProperty("lineColor",0xffff0000,t);
t.play();
//according to age property set the size style;
var size:SizeEncoder=new SizeEncoder("data.age");
visual.operators.add(size);
//
this.addChild(visual);
visual.update();
}
private function clickHandler(evt:Event):void{
trace("click")
}
}
}