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

https://github.com/fgontier/LBS_earnings_potential_calculator · ActionScript · 314 lines · 241 code · 39 blank · 34 comment · 31 complexity · 084fb4d64c8ffb39625f8d59518566d9 MD5 · raw file

  1. package charts.series.dots {
  2. import flash.display.Sprite;
  3. import flash.display.Graphics;
  4. import flash.display.BlendMode;
  5. import charts.series.Element;
  6. import caurina.transitions.Tweener;
  7. import caurina.transitions.Equations;
  8. import string.Utils;
  9. public class scat extends PointDotBase {
  10. public function scat( style:Object ) {
  11. // scatter charts have x, y (not value):
  12. style.value = style.y;
  13. super( -99, new Properties({}) );// style );
  14. // override the basics in PointDotBase:
  15. this._x = style.x;
  16. this._y = style.y;
  17. this.visible = true;
  18. if (style.alpha == null)
  19. style.alpha = 1;
  20. this.tooltip = this.replace_magic_values( style.tip );
  21. this.attach_events();
  22. // if style.x is null then user wants a gap in the line
  23. if (style.x == null)
  24. {
  25. this.visible = false;
  26. }
  27. else
  28. {
  29. var haloSize:Number = isNaN(style['halo-size']) ? 0 : style['halo-size'];
  30. var isHollow:Boolean = style['hollow'];
  31. if (isHollow)
  32. {
  33. // Hollow - set the fill to the background color/alpha
  34. if (style['background-colour'] != null)
  35. {
  36. var bgColor:Number = string.Utils.get_colour( style['background-colour'] );
  37. }
  38. else
  39. {
  40. bgColor = style.colour;
  41. }
  42. var bgAlpha:Number = isNaN(style['background-alpha']) ? 0 : style['background-alpha'];
  43. this.graphics.beginFill(bgColor, bgAlpha);
  44. }
  45. else
  46. {
  47. // set the fill to be the same color and alpha as the line
  48. this.graphics.beginFill( style.colour, style.alpha );
  49. }
  50. switch (style['type'])
  51. {
  52. case 'dot':
  53. this.graphics.lineStyle( 0, 0, 0 );
  54. this.graphics.beginFill( style.colour, style.alpha );
  55. this.graphics.drawCircle( 0, 0, style['dot-size'] );
  56. this.graphics.endFill();
  57. var s:Sprite = new Sprite();
  58. s.graphics.lineStyle( 0, 0, 0 );
  59. s.graphics.beginFill( 0, 1 );
  60. s.graphics.drawCircle( 0, 0, style['dot-size'] + haloSize );
  61. s.blendMode = BlendMode.ERASE;
  62. this.line_mask = s;
  63. break;
  64. case 'anchor':
  65. this.graphics.lineStyle( style.width, style.colour, style.alpha );
  66. var rotation:Number = isNaN(style['rotation']) ? 0 : style['rotation'];
  67. var sides:Number = Math.max(3, isNaN(style['sides']) ? 3 : style['sides']);
  68. this.drawAnchor(this.graphics, this.radius, sides, rotation);
  69. // Check to see if part of the line needs to be erased
  70. //trace("haloSize = ", haloSize);
  71. if (haloSize > 0)
  72. {
  73. haloSize += this.radius;
  74. s = new Sprite();
  75. s.graphics.lineStyle( 0, 0, 0 );
  76. s.graphics.beginFill( 0, 1 );
  77. this.drawAnchor(s.graphics, haloSize, sides, rotation);
  78. s.blendMode = BlendMode.ERASE;
  79. s.graphics.endFill();
  80. this.line_mask = s;
  81. }
  82. break;
  83. case 'bow':
  84. this.graphics.lineStyle( style.width, style.colour, style.alpha );
  85. rotation = isNaN(style['rotation']) ? 0 : style['rotation'];
  86. this.drawBow(this.graphics, this.radius, rotation);
  87. // Check to see if part of the line needs to be erased
  88. if (haloSize > 0)
  89. {
  90. haloSize += this.radius;
  91. s = new Sprite();
  92. s.graphics.lineStyle( 0, 0, 0 );
  93. s.graphics.beginFill( 0, 1 );
  94. this.drawBow(s.graphics, haloSize, rotation);
  95. s.blendMode = BlendMode.ERASE;
  96. s.graphics.endFill();
  97. this.line_mask = s;
  98. }
  99. break;
  100. case 'star':
  101. this.graphics.lineStyle( style.width, style.colour, style.alpha );
  102. rotation = isNaN(style['rotation']) ? 0 : style['rotation'];
  103. this.drawStar_2(this.graphics, this.radius, rotation);
  104. // Check to see if part of the line needs to be erased
  105. if (haloSize > 0)
  106. {
  107. haloSize += this.radius;
  108. s = new Sprite();
  109. s.graphics.lineStyle( 0, 0, 0 );
  110. s.graphics.beginFill( 0, 1 );
  111. this.drawStar_2(s.graphics, haloSize, rotation);
  112. s.blendMode = BlendMode.ERASE;
  113. s.graphics.endFill();
  114. this.line_mask = s;
  115. }
  116. break;
  117. default:
  118. this.graphics.drawCircle( 0, 0, this.radius );
  119. this.graphics.drawCircle( 0, 0, this.radius - 1 );
  120. this.graphics.endFill();
  121. }
  122. }
  123. }
  124. /*
  125. protected function replace_magic_values( t:String ): String {
  126. t = t.replace('#x#', NumberUtils.formatNumber(this._x));
  127. t = t.replace('#y#', NumberUtils.formatNumber(this._y));
  128. t = t.replace('#size#', NumberUtils.formatNumber(this.radius));
  129. return t;
  130. }
  131. */
  132. public override function set_tip( b:Boolean ):void {
  133. if ( b )
  134. {
  135. if ( !this.is_tip )
  136. {
  137. Tweener.addTween(this, {scaleX:1.3, time:0.4, transition:"easeoutbounce"} );
  138. Tweener.addTween(this, {scaleY:1.3, time:0.4, transition:"easeoutbounce" } );
  139. if (this.line_mask != null)
  140. {
  141. Tweener.addTween(this.line_mask, {scaleX:1.3, time:0.4, transition:"easeoutbounce"} );
  142. Tweener.addTween(this.line_mask, {scaleY:1.3, time:0.4, transition:"easeoutbounce" } );
  143. }
  144. }
  145. this.is_tip = true;
  146. }
  147. else
  148. {
  149. Tweener.removeTweens(this);
  150. Tweener.removeTweens(this.line_mask);
  151. this.scaleX = 1;
  152. this.scaleY = 1;
  153. if (this.line_mask != null)
  154. {
  155. this.line_mask.scaleX = 1;
  156. this.line_mask.scaleY = 1;
  157. }
  158. this.is_tip = false;
  159. }
  160. }
  161. public override function resize( sc:ScreenCoordsBase ): void {
  162. //
  163. // Look: we have a real X value, so get its screen location:
  164. //
  165. this.x = sc.get_x_from_val( this._x );
  166. this.y = sc.get_y_from_val( this._y, this.right_axis );
  167. // Move the mask so it is in the proper place also
  168. // this all needs to be moved into the base class
  169. if (this.line_mask != null)
  170. {
  171. this.line_mask.x = this.x;
  172. this.line_mask.y = this.y;
  173. }
  174. }
  175. private function drawAnchor( aGraphics:Graphics, aRadius:Number,
  176. aSides:Number, aRotation:Number ):void
  177. {
  178. if (aSides < 3) aSides = 3;
  179. if (aSides > 360) aSides = 360;
  180. var angle:Number = 360 / aSides;
  181. for (var ix:int = 0; ix <= aSides; ix++)
  182. {
  183. // Move start point to vertical axis (-90 degrees)
  184. var degrees:Number = -90 + aRotation + (ix % aSides) * angle;
  185. var xVal:Number = calcXOnCircle(aRadius, degrees);
  186. var yVal:Number = calcYOnCircle(aRadius, degrees);
  187. if (ix == 0)
  188. {
  189. aGraphics.moveTo(xVal, yVal);
  190. }
  191. else
  192. {
  193. aGraphics.lineTo(xVal, yVal);
  194. }
  195. }
  196. }
  197. private function drawBow( aGraphics:Graphics, aRadius:Number,
  198. aRotation:Number ):void
  199. {
  200. var angle:Number = 60;
  201. // Start at center point
  202. aGraphics.moveTo(0, 0);
  203. // Upper right side point (unrotated)
  204. var degrees:Number = -90 + aRotation + angle;
  205. var xVal:Number = calcXOnCircle(aRadius, degrees);
  206. var yVal:Number = calcYOnCircle(aRadius, degrees);
  207. aGraphics.lineTo(xVal, yVal);
  208. // Lower right side point (unrotated)
  209. degrees += angle;
  210. xVal = calcXOnCircle(aRadius, degrees);
  211. yVal = calcYOnCircle(aRadius, degrees);
  212. aGraphics.lineTo(xVal, yVal);
  213. // Back to the center
  214. aGraphics.lineTo(xVal, yVal);
  215. // Upper left side point (unrotated)
  216. degrees = -90 + aRotation - angle;
  217. xVal = calcXOnCircle(aRadius, degrees);
  218. yVal = calcYOnCircle(aRadius, degrees);
  219. aGraphics.lineTo(xVal, yVal);
  220. // Lower Left side point (unrotated)
  221. degrees -= angle;
  222. xVal = calcXOnCircle(aRadius, degrees);
  223. yVal = calcYOnCircle(aRadius, degrees);
  224. aGraphics.lineTo(xVal, yVal);
  225. // Back to the center
  226. aGraphics.lineTo(xVal, yVal);
  227. }
  228. private function drawStar_2( aGraphics:Graphics, aRadius:Number,
  229. aRotation:Number ):void
  230. {
  231. var angle:Number = 360 / 10;
  232. // Start at top point (unrotated)
  233. var degrees:Number = -90 + aRotation;
  234. for (var ix:int = 0; ix < 11; ix++)
  235. {
  236. var rad:Number;
  237. rad = (ix % 2 == 0) ? aRadius : aRadius/2;
  238. var xVal:Number = calcXOnCircle(rad, degrees);
  239. var yVal:Number = calcYOnCircle(rad, degrees);
  240. if(ix == 0)
  241. {
  242. aGraphics.moveTo(xVal, yVal);
  243. }
  244. else
  245. {
  246. aGraphics.lineTo(xVal, yVal);
  247. }
  248. degrees += angle;
  249. }
  250. }
  251. private function drawStar( aGraphics:Graphics, aRadius:Number,
  252. aRotation:Number ):void
  253. {
  254. var angle:Number = 360 / 5;
  255. // Start at top point (unrotated)
  256. var degrees:Number = -90 + aRotation;
  257. for (var ix:int = 0; ix <= 5; ix++)
  258. {
  259. var xVal:Number = calcXOnCircle(aRadius, degrees);
  260. var yVal:Number = calcYOnCircle(aRadius, degrees);
  261. if (ix == 0)
  262. {
  263. aGraphics.moveTo(xVal, yVal);
  264. }
  265. else
  266. {
  267. aGraphics.lineTo(xVal, yVal);
  268. }
  269. // Move 2 points clockwise
  270. degrees += (2 * angle);
  271. }
  272. }
  273. }
  274. }