/src/com/globalworks/lbs/tools/charts/series/dots/PointDotBase.as

https://github.com/fgontier/LBS_earnings_potential_calculator · ActionScript · 269 lines · 171 code · 51 blank · 47 comment · 22 complexity · 992a97415cc6116cb5268c9b49c03034 MD5 · raw file

  1. package charts.series.dots {
  2. import flash.display.Sprite;
  3. import charts.series.Element;
  4. import flash.display.BlendMode;
  5. import flash.events.Event;
  6. import flash.events.MouseEvent;
  7. import flash.geom.Point;
  8. import caurina.transitions.Tweener;
  9. import caurina.transitions.Equations;
  10. public class PointDotBase extends Element {
  11. protected var radius:Number;
  12. protected var colour:Number;
  13. private var on_show_animate:Boolean;
  14. protected var on_show:Properties;
  15. public function PointDotBase( index:Number, props:Properties ) {
  16. super();
  17. this.is_tip = false;
  18. this.visible = true;
  19. this.on_show_animate = true;
  20. this.on_show = props.get('on-show');
  21. /*
  22. this.on_show = new Properties( {
  23. type: "",
  24. cascade: 3,
  25. delay: 0
  26. });
  27. */
  28. // line charts have a value and no X, scatter charts have
  29. // x, y (not value): radar charts have value, Y does not
  30. // make sense.
  31. if( !props.has('y') )
  32. props.set('y', props.get('value'));
  33. this._y = props.get('y');
  34. // no X passed in so calculate it from the index
  35. if( !props.has('x') )
  36. {
  37. this.index = this._x = index;
  38. }
  39. else
  40. {
  41. // tr.aces( 'x', props.get('x') );
  42. this._x = props.get('x');
  43. this.index = Number.MIN_VALUE;
  44. }
  45. this.radius = props.get('dot-size');
  46. this.tooltip = this.replace_magic_values( props.get('tip') );
  47. if ( props.has('on-click') )
  48. this.set_on_click( props.get('on-click') );
  49. //
  50. // TODO: fix this hack
  51. //
  52. if ( props.has('axis') )
  53. if ( props.get('axis') == 'right' )
  54. this.right_axis = true;
  55. }
  56. public override function resize( sc:ScreenCoordsBase ): void {
  57. var x:Number;
  58. var y:Number;
  59. if ( this.index != Number.MIN_VALUE ) {
  60. var p:flash.geom.Point = sc.get_get_x_from_pos_and_y_from_val( this.index, this._y, this.right_axis );
  61. x = p.x;
  62. y = p.y;
  63. }
  64. else
  65. {
  66. //
  67. // Look: we have a real X value, so get its screen location:
  68. //
  69. x = sc.get_x_from_val( this._x );
  70. y = sc.get_y_from_val( this._y, this.right_axis );
  71. }
  72. // Move the mask so it is in the proper place also
  73. // this all needs to be moved into the base class
  74. if (this.line_mask != null)
  75. {
  76. this.line_mask.x = x;
  77. this.line_mask.y = y;
  78. }
  79. if ( this.on_show_animate )
  80. this.first_show(x, y, sc);
  81. else {
  82. //
  83. // move the Sprite to the correct screen location:
  84. //
  85. this.y = y;
  86. this.x = x;
  87. }
  88. }
  89. public function is_tweening(): Boolean {
  90. return Tweener.isTweening(this);
  91. }
  92. protected function first_show(x:Number, y:Number, sc:ScreenCoordsBase): void {
  93. this.on_show_animate = false;
  94. Tweener.removeTweens(this);
  95. // tr.aces('base.as', this.on_show.get('type') );
  96. var d:Number = x / this.stage.stageWidth;
  97. d *= this.on_show.get('cascade');
  98. d += this.on_show.get('delay');
  99. switch( this.on_show.get('type') ) {
  100. case 'pop-up':
  101. this.x = x;
  102. this.y = sc.get_y_bottom(this.right_axis);
  103. Tweener.addTween(this, { y:y, time:1.4, delay:d, transition:Equations.easeOutQuad } );
  104. if ( this.line_mask != null )
  105. {
  106. this.line_mask.x = x;
  107. this.line_mask.y = sc.get_y_bottom(this.right_axis);
  108. Tweener.addTween(this.line_mask, { y:y, time:1.4, delay:d, transition:Equations.easeOutQuad });
  109. }
  110. break;
  111. case 'explode':
  112. this.x = this.stage.stageWidth/2;
  113. this.y = this.stage.stageHeight/2;
  114. Tweener.addTween(this, { y:y, x:x, time:1.4, delay:d, transition:Equations.easeOutQuad } );
  115. if ( this.line_mask != null )
  116. {
  117. this.line_mask.x = this.stage.stageWidth/2;
  118. this.line_mask.y = this.stage.stageHeight/2;
  119. Tweener.addTween(this.line_mask, { y:y, x:x, time:1.4, delay:d, transition:Equations.easeOutQuad });
  120. }
  121. break;
  122. case 'mid-slide':
  123. this.x = x;
  124. this.y = this.stage.stageHeight / 2;
  125. this.alpha = 0.2;
  126. Tweener.addTween(this, { alpha:1, y:y, time:1.4, delay:d, transition:Equations.easeOutQuad });
  127. if ( this.line_mask != null )
  128. {
  129. this.line_mask.x = x;
  130. this.line_mask.y = this.stage.stageHeight / 2;
  131. Tweener.addTween(this.line_mask, { y:y, time:1.4, delay:d, transition:Equations.easeOutQuad });
  132. }
  133. break;
  134. /*
  135. * the tooltips go a bit funny with this one
  136. * TODO: investigate if this will work with area charts - need to move the bottom anchors
  137. case 'slide-in-up':
  138. this.x = 20; // <-- left
  139. this.y = this.stage.stageHeight / 2;
  140. Tweener.addTween(
  141. this,
  142. { x:x, time:1.4, delay:d, transition:Equations.easeOutQuad,
  143. onComplete:function():void {
  144. Tweener.addTween(this,
  145. { y:y, time:1.4, transition:Equations.easeOutQuad } ) }
  146. } );
  147. break;
  148. */
  149. case 'drop':
  150. this.x = x;
  151. this.y = -height - 10;
  152. Tweener.addTween(this, { y:y, time:1.4, delay:d, transition:Equations.easeOutBounce } );
  153. if ( this.line_mask != null )
  154. {
  155. this.line_mask.x = x;
  156. this.line_mask.y = -height - 10;
  157. Tweener.addTween(this.line_mask, { y:y, time:1.4, delay:d, transition:Equations.easeOutQuad });
  158. }
  159. break;
  160. case 'fade-in':
  161. this.x = x;
  162. this.y = y;
  163. this.alpha = 0;
  164. Tweener.addTween(this, { alpha:1, time:1.2, delay:d, transition:Equations.easeOutQuad } );
  165. break;
  166. case 'shrink-in':
  167. this.x = x;
  168. this.y = y;
  169. this.scaleX = this.scaleY = 5;
  170. this.alpha = 0;
  171. Tweener.addTween(
  172. this,
  173. {
  174. scaleX:1, scaleY:1, alpha:1, time:1.2,
  175. delay:d, transition:Equations.easeOutQuad,
  176. onComplete:function():void { tr.ace('Fin'); }
  177. } );
  178. break;
  179. default:
  180. this.y = y;
  181. this.x = x;
  182. }
  183. }
  184. public override function set_tip( b:Boolean ):void {
  185. //this.visible = b;
  186. if( b ) {
  187. this.scaleY = this.scaleX = 1.3;
  188. this.line_mask.scaleY = this.line_mask.scaleX = 1.3;
  189. }
  190. else {
  191. this.scaleY = this.scaleX = 1;
  192. this.line_mask.scaleY = this.line_mask.scaleX = 1;
  193. }
  194. }
  195. //
  196. // Dirty hack. Takes tooltip text, and replaces the #val# with the
  197. // tool_tip text, so noew you can do: "My Val = $#val#%", which turns into:
  198. // "My Val = $12.00%"
  199. //
  200. protected function replace_magic_values( t:String ): String {
  201. t = t.replace('#val#', NumberUtils.formatNumber( this._y ));
  202. // for scatter charts
  203. t = t.replace('#x#', NumberUtils.formatNumber(this._x));
  204. t = t.replace('#y#', NumberUtils.formatNumber(this._y));
  205. // debug the dots sizes
  206. t = t.replace('#size#', NumberUtils.formatNumber(this.radius));
  207. return t;
  208. }
  209. protected function calcXOnCircle(aRadius:Number, aDegrees:Number):Number
  210. {
  211. return aRadius * Math.cos(aDegrees / 180 * Math.PI);
  212. }
  213. protected function calcYOnCircle(aRadius:Number, aDegrees:Number):Number
  214. {
  215. return aRadius * Math.sin(aDegrees / 180 * Math.PI);
  216. }
  217. }
  218. }