1 | package charts.series.bars {
|
---|
2 |
|
---|
3 | import flash.display.Sprite;
|
---|
4 | import flash.events.Event;
|
---|
5 | import flash.events.MouseEvent;
|
---|
6 | import caurina.transitions.Tweener;
|
---|
7 | import caurina.transitions.Equations;
|
---|
8 | import flash.geom.Point;
|
---|
9 | import charts.series.Element;
|
---|
10 |
|
---|
11 | public class Horizontal extends Element
|
---|
12 | {
|
---|
13 | private var right:Number;
|
---|
14 | private var left:Number;
|
---|
15 | //protected var width:Number;
|
---|
16 |
|
---|
17 | public var colour:Number;
|
---|
18 | protected var group:Number;
|
---|
19 |
|
---|
20 | public function Horizontal( index:Number, style:Object, group:Number )
|
---|
21 | {
|
---|
22 | super();
|
---|
23 | //
|
---|
24 | // we use the index of this bar to find its Y position
|
---|
25 | //
|
---|
26 | this.index = index;
|
---|
27 | //
|
---|
28 | // horizontal bar: value = X Axis position
|
---|
29 | // we'll use the ScreenCoords object to go [value -> x location]
|
---|
30 | //
|
---|
31 |
|
---|
32 | this.left = style.left ? style.left : 0;
|
---|
33 | this.right = style.right ? style.right : 0;
|
---|
34 |
|
---|
35 | this.colour = style.colour;
|
---|
36 | this.group = group;
|
---|
37 | this.visible = true;
|
---|
38 |
|
---|
39 | this.alpha = 0.5;
|
---|
40 |
|
---|
41 | this.tooltip = this.replace_magic_values( style.tip );
|
---|
42 |
|
---|
43 | this.addEventListener(MouseEvent.MOUSE_OVER, this.mouseOver);
|
---|
44 | this.addEventListener(MouseEvent.MOUSE_OUT, this.mouseOut);
|
---|
45 |
|
---|
46 | }
|
---|
47 |
|
---|
48 | protected function replace_magic_values( t:String ): String {
|
---|
49 |
|
---|
50 | t = t.replace('#right#', NumberUtils.formatNumber( this.right ));
|
---|
51 | t = t.replace('#left#', NumberUtils.formatNumber( this.left ));
|
---|
52 | t = t.replace('#val#', NumberUtils.formatNumber( this.right - this.left ));
|
---|
53 |
|
---|
54 | return t;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public override function mouseOver(event:Event):void {
|
---|
58 | Tweener.addTween(this, { alpha:1, time:0.6, transition:Equations.easeOutCirc } );
|
---|
59 | }
|
---|
60 |
|
---|
61 | public override function mouseOut(event:Event):void {
|
---|
62 | Tweener.addTween(this, { alpha:0.5, time:0.8, transition:Equations.easeOutElastic } );
|
---|
63 | }
|
---|
64 |
|
---|
65 | public override function resize( sc:ScreenCoordsBase ):void {
|
---|
66 |
|
---|
67 | // is it OK to cast up like this?
|
---|
68 | var sc2:ScreenCoords = sc as ScreenCoords;
|
---|
69 |
|
---|
70 | var tmp:Object = sc2.get_horiz_bar_coords( this.index, this.group );
|
---|
71 |
|
---|
72 | var left:Number = sc.get_x_from_val( this.left );
|
---|
73 | var right:Number = sc.get_x_from_val( this.right );
|
---|
74 | var width:Number = right - left;
|
---|
75 |
|
---|
76 | this.graphics.clear();
|
---|
77 | this.graphics.beginFill( this.colour, 1.0 );
|
---|
78 | this.graphics.drawRect( 0, 0, width, tmp.width );
|
---|
79 | this.graphics.endFill();
|
---|
80 |
|
---|
81 | this.x = left;
|
---|
82 | this.y = tmp.y;
|
---|
83 | }
|
---|
84 |
|
---|
85 | //
|
---|
86 | // for tooltip closest - return the middle point
|
---|
87 | //
|
---|
88 | public override function get_mid_point():flash.geom.Point {
|
---|
89 |
|
---|
90 | //
|
---|
91 | // bars mid point
|
---|
92 | //
|
---|
93 | return new flash.geom.Point( this.x + (this.width/2), this.y );
|
---|
94 | }
|
---|
95 |
|
---|
96 | public override function get_tip_pos():Object {
|
---|
97 | //
|
---|
98 | // Hover the tip over the right of the bar
|
---|
99 | //
|
---|
100 | return {x:this.x+this.width-20, y:this.y};
|
---|
101 | }
|
---|
102 |
|
---|
103 | public function get_max_x():Number {
|
---|
104 | return this.right;
|
---|
105 | }
|
---|
106 | }
|
---|
107 | }
|
---|