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

https://github.com/fgontier/LBS_earnings_potential_calculator
ActionScript | 102 lines | 63 code | 23 blank | 16 comment | 1 complexity | 354add4541a9b6dfee4140f15c4291d4 MD5 | raw file
  1. package charts.series.bars {
  2. import flash.display.Sprite;
  3. import flash.geom.Point;
  4. import charts.series.bars.Base;
  5. public class ECandle extends Base {
  6. protected var high:Number;
  7. protected var low:Number;
  8. public function ECandle( index:Number, props:Properties, group:Number ) {
  9. super(index, props, group);
  10. //super(index, {'top':props.get('top')}, props.get_colour('colour'), props.get('tip'), props.get('alpha'), group);
  11. //super(index, style, style.colour, style.tip, style.alpha, group);
  12. }
  13. //
  14. // a candle chart has many values used to display each point
  15. //
  16. protected override function parse_value( props:Properties ):void {
  17. // set top (open) and bottom (close)
  18. super.parse_value( props );
  19. this.high = props.get('high');
  20. this.low = props.get('low');
  21. }
  22. protected override function replace_magic_values( t:String ): String {
  23. t = super.replace_magic_values( t );
  24. t = t.replace('#high#', NumberUtils.formatNumber( this.high ));
  25. t = t.replace('#open#', NumberUtils.formatNumber( this.top ));
  26. t = t.replace('#close#', NumberUtils.formatNumber( this.bottom ));
  27. t = t.replace('#low#', NumberUtils.formatNumber( this.low ));
  28. return t;
  29. }
  30. public override function resize( sc:ScreenCoordsBase ):void {
  31. var s:ScreenCoords = sc as ScreenCoords;
  32. var tmp:Object = s.get_bar_coords( this.index, this.group );
  33. //
  34. var bar_high:Number = sc.get_y_from_val(this.high, this.right_axis);
  35. var bar_top:Number = sc.get_y_from_val(this.top, this.right_axis);
  36. var bar_bottom:Number = sc.get_y_from_val(this.bottom, this.right_axis);
  37. var bar_low:Number = sc.get_y_from_val(this.low, this.right_axis);
  38. var top:Number;
  39. var height:Number;
  40. var upside_down:Boolean = false;
  41. if( bar_bottom < bar_top ) {
  42. upside_down = true;
  43. }
  44. height = Math.abs( bar_bottom - bar_top );
  45. //
  46. // move the Sprite to the correct screen location:
  47. //
  48. this.y = bar_high;
  49. this.x = tmp.x;
  50. //
  51. // tell the tooltip where to show its self
  52. //
  53. this.tip_pos = new flash.geom.Point( this.x + (tmp.width / 2), this.y );
  54. var mid:Number = tmp.width / 2;
  55. this.graphics.clear();
  56. // top line
  57. this.graphics.beginFill( this.colour, 1.0 );
  58. this.graphics.moveTo( mid-1, 0 );
  59. this.graphics.lineTo( mid+1, 0 );
  60. this.graphics.lineTo( mid+1, bar_top-bar_high );
  61. this.graphics.lineTo( mid-1, bar_top-bar_high );
  62. this.graphics.endFill();
  63. // box
  64. this.graphics.beginFill( this.colour, 1.0 );
  65. this.graphics.moveTo( 0, bar_top-bar_high );
  66. this.graphics.lineTo( tmp.width, bar_top-bar_high );
  67. this.graphics.lineTo( tmp.width, bar_bottom-bar_high );
  68. this.graphics.lineTo( 0, bar_bottom-bar_high );
  69. this.graphics.endFill();
  70. // top line
  71. this.graphics.beginFill( this.colour, 1.0 );
  72. this.graphics.moveTo( mid-1, bar_bottom-bar_high );
  73. this.graphics.lineTo( mid+1, bar_bottom-bar_high );
  74. this.graphics.lineTo( mid+1, bar_low-bar_high );
  75. this.graphics.lineTo( mid-1, bar_low-bar_high );
  76. this.graphics.endFill();
  77. }
  78. }
  79. }