Skip to content

Instantly share code, notes, and snippets.

Created August 22, 2008 19:48
Show Gist options
  • Save anonymous/6846 to your computer and use it in GitHub Desktop.
Save anonymous/6846 to your computer and use it in GitHub Desktop.
package {
import flare.scale.ScaleType;
import flare.util.Shapes;
import flare.vis.Visualization;
import flare.vis.data.Data;
import flare.vis.data.DataSprite;
import flare.vis.operator.OperatorList;
import flare.vis.operator.encoder.ColorEncoder;
import flare.vis.operator.encoder.PropertyEncoder;
import flare.vis.operator.encoder.SizeEncoder;
import flare.vis.operator.layout.AxisLayout;
import flash.display.Sprite;
import flash.geom.Rectangle;
[SWF(width="1000", height="600", backgroundColor="#ffffff", frameRate="30")]
public class BookTimeline extends Sprite {
private var vis:Visualization;
private var bounds:Rectangle;
public function BookTimeline() {
bounds = new Rectangle(0,0,800,400);
// set up timeline operators
var timeline:OperatorList = new OperatorList(
new AxisLayout("data.dateAdded", "data.series"),
new ColorEncoder("data.series", Data.NODES,
"fillColor", ScaleType.CATEGORIES),
new PropertyEncoder({
lineAlpha: 0, alpha: 0.5, buttonMode: false,
shape: Shapes.HORIZONTAL_BAR
}),
new SizeEncoder("data.duration", Data.NODES)
);
timeline[0].xScale.preferredMin = new Date(2007,1,1);
timeline[0].xScale.preferredMax = new Date(2008,10,1);
// get the data
var data:Data = getData();
// create the vis
vis = new Visualization(data);
vis.operators.add(timeline);
vis.bounds = bounds.clone();
vis.update();
vis.x = 10;
vis.y = 10;
addChild(vis);
}
private function getData():Data {
var data:Data = Data.fromArray([
{series: 'a', dateAdded: new Date(2008,8,1),
dateRead: new Date(2008,8,25)},
{series: 'j', dateAdded: new Date(2008,7,1),
dateRead: new Date(2008,7,11)}
]);
data.nodes.visit(function(n:DataSprite):void {
n.data.duration = n.data.dateRead - n.data.dateAdded;
});
return data;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment