PageRenderTime 58ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/src/com/globalworks/lbs/tools/charts/ScatterLine.as

https://github.com/fgontier/LBS_earnings_potential_calculator
ActionScript | 217 lines | 156 code | 31 blank | 30 comment | 28 complexity | a7fb5f58df0ef2076ca9c4a73d7e1700 MD5 | raw file
  1. package charts {
  2. import flash.events.Event;
  3. import flash.events.MouseEvent;
  4. import charts.series.Element;
  5. import charts.series.dots.scat;
  6. import string.Utils;
  7. import flash.geom.Point;
  8. import flash.display.Sprite;
  9. import flash.display.BlendMode;
  10. import charts.series.dots.DefaultDotProperties;
  11. public class ScatterLine extends ScatterBase
  12. {
  13. public var stepgraph:Number = 0;
  14. public static const STEP_HORIZONTAL:Number = 1;
  15. public static const STEP_VERTICAL:Number = 2;
  16. public function ScatterLine( json:Object )
  17. {
  18. super(json);
  19. //
  20. // so the mask child can punch a hole through the line
  21. //
  22. this.blendMode = BlendMode.LAYER;
  23. //
  24. this.style = {
  25. values: [],
  26. width: 2,
  27. colour: '#3030d0',
  28. text: '', // <-- default not display a key
  29. 'font-size': 12,
  30. stepgraph: 0,
  31. axis: 'left'
  32. };
  33. // hack: keep this incase the merge kills it, we'll
  34. // remove the merge later (and this hack)
  35. var tmp:Object = json['dot-style'];
  36. object_helper.merge_2( json, style );
  37. this.default_style = new DefaultDotProperties(
  38. json['dot-style'], this.style.colour, this.style.axis);
  39. this.style.colour = string.Utils.get_colour( style.colour );
  40. this.line_width = style.width;
  41. this.colour = this.style.colour;
  42. this.key = style.text;
  43. this.font_size = style['font-size'];
  44. //this.circle_size = style['dot-size'];
  45. switch (style['stepgraph']) {
  46. case 'horizontal':
  47. stepgraph = STEP_HORIZONTAL;
  48. break;
  49. case 'vertical':
  50. stepgraph = STEP_VERTICAL;
  51. break;
  52. }
  53. this.values = style.values;
  54. this.add_values();
  55. }
  56. // Draw points...
  57. public override function resize( sc:ScreenCoordsBase ): void {
  58. // move the dots:
  59. super.resize( sc );
  60. this.graphics.clear();
  61. this.graphics.lineStyle( this.style.width, this.style.colour );
  62. //if( this.style['line-style'].style != 'solid' )
  63. // this.dash_line(sc);
  64. //else
  65. this.solid_line(sc);
  66. }
  67. //
  68. // This is cut and paste from LineBase
  69. //
  70. public function solid_line( sc:ScreenCoordsBase ): void {
  71. var first:Boolean = true;
  72. var last_x:Number = 0;
  73. var last_y:Number = 0;
  74. var areaClosed:Boolean = true;
  75. var isArea:Boolean = false;
  76. var areaBaseX:Number = NaN;
  77. var areaBaseY:Number = NaN;
  78. var areaColour:Number = this.colour;
  79. var areaAlpha:Number = 0.4;
  80. var areaStyle:Object = this.style['area-style'];
  81. if (areaStyle != null)
  82. {
  83. isArea = true;
  84. if (areaStyle.x != null)
  85. {
  86. areaBaseX = areaStyle.x;
  87. }
  88. if (areaStyle.y != null)
  89. {
  90. areaBaseY = areaStyle.y;
  91. }
  92. if (areaStyle.colour != null)
  93. {
  94. areaColour = string.Utils.get_colour( areaStyle.colour );
  95. }
  96. if (areaStyle.alpha != null)
  97. {
  98. areaAlpha = areaStyle.alpha;
  99. }
  100. if (!isNaN(areaBaseX))
  101. {
  102. // Convert X Value to screen position
  103. areaBaseX = sc.get_x_from_val(areaBaseX);
  104. }
  105. if (!isNaN(areaBaseY))
  106. {
  107. // Convert Y Value to screen position
  108. areaBaseY = sc.get_y_from_val(areaBaseY); // TODO: Allow for right Y-Axis??
  109. }
  110. }
  111. for ( var i:Number = 0; i < this.numChildren; i++ ) {
  112. var tmp:Sprite = this.getChildAt(i) as Sprite;
  113. tr.ace("!!");
  114. //
  115. // filter out the line masks
  116. //
  117. if( tmp is Element )
  118. {
  119. var e:Element = tmp as Element;
  120. tr.ace(e.x);
  121. // tell the point where it is on the screen
  122. // we will use this info to place the tooltip
  123. e.resize( sc );
  124. if (!e.visible)
  125. {
  126. // Creates a gap in the plot and closes out the current area if defined
  127. if ((isArea) && (i > 0))
  128. {
  129. // draw an invisible line back to the base and close the fill
  130. areaX = isNaN(areaBaseX) ? last_x : areaBaseX;
  131. areaY = isNaN(areaBaseY) ? last_y : areaBaseY;
  132. this.graphics.lineStyle( 0, areaColour, 0 );
  133. this.graphics.lineTo(areaX, areaY);
  134. this.graphics.endFill();
  135. areaClosed = true;
  136. }
  137. first = true;
  138. }
  139. else if( first )
  140. {
  141. if (isArea)
  142. {
  143. // draw an invisible line from the base to the point
  144. var areaX:Number = isNaN(areaBaseX) ? e.x : areaBaseX;
  145. var areaY:Number = isNaN(areaBaseY) ? e.y : areaBaseY;
  146. // Begin the fill for the area
  147. this.graphics.beginFill(areaColour, areaAlpha);
  148. this.graphics.lineStyle( 0, areaColour, 0 );
  149. this.graphics.moveTo(areaX, areaY);
  150. this.graphics.lineTo(e.x, e.y);
  151. areaClosed = false;
  152. // change the line style back to normal
  153. this.graphics.lineStyle( this.style.width, this.style.colour, 1.0 );
  154. }
  155. else
  156. {
  157. // just move to the point
  158. this.graphics.moveTo(e.x, e.y);
  159. }
  160. first = false;
  161. }
  162. else
  163. {
  164. if (this.stepgraph == STEP_HORIZONTAL)
  165. this.graphics.lineTo(e.x, last_y);
  166. else if (this.stepgraph == STEP_VERTICAL)
  167. this.graphics.lineTo(last_x, e.y);
  168. this.graphics.lineTo(e.x, e.y);
  169. }
  170. last_x = e.x;
  171. last_y = e.y;
  172. }
  173. }
  174. // Close out the area if defined
  175. if (isArea && !areaClosed)
  176. {
  177. // draw an invisible line back to the base and close the fill
  178. areaX = isNaN(areaBaseX) ? last_x : areaBaseX;
  179. areaY = isNaN(areaBaseY) ? last_y : areaBaseY;
  180. this.graphics.lineStyle( 0, areaColour, 0 );
  181. this.graphics.lineTo(areaX, areaY);
  182. this.graphics.endFill();
  183. }
  184. }
  185. }
  186. }