source: code/Website/open-flash-chart/charts/series/dots/scat.as@ 7849

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