/src/com/globalworks/lbs/tools/charts/series/bars/Horizontal.as

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