source: code/Website/open-flash-chart/charts/series/bars/Dome.as@ 7849

Last change on this file since 7849 was 7849, checked in by dennisw, 15 years ago
File size: 19.5 KB
Line 
1package charts.series.bars {
2 import flash.filters.DropShadowFilter;
3 import flash.geom.Matrix;
4 import charts.series.bars.Base;
5
6 public class Dome extends Base
7 {
8
9 public function Dome( index:Number, props:Properties, group:Number ) {
10
11 super(index, props, group);
12 //super(index, {'top':props.get('top')}, props.get_colour('colour'), props.get('tip'), props.get('alpha'), group);
13 //super(index, style, style.colour, style.tip, style.alpha, group);
14
15 var dropShadow:DropShadowFilter = new flash.filters.DropShadowFilter();
16 dropShadow.blurX = 5;
17 dropShadow.blurY = 5;
18 dropShadow.distance = 3;
19 dropShadow.angle = 45;
20 dropShadow.quality = 2;
21 dropShadow.alpha = 0.4;
22 // apply shadow filter
23 this.filters = [dropShadow];
24 }
25
26 public override function resize( sc:ScreenCoordsBase ):void {
27
28 this.graphics.clear();
29 var h:Object = this.resize_helper( sc as ScreenCoords );
30
31 this.bg( h.width, h.height, h.upside_down );
32 this.glass( h.width, h.height, h.upside_down );
33 }
34
35 private function bg( w:Number, h:Number, upside_down:Boolean ):void {
36
37 var rad:Number = w/3;
38 if ( rad > ( w / 2 ) )
39 rad = w / 2;
40
41 this.graphics.lineStyle(0, 0, 0);// this.outline_colour, 100);
42
43 var bgcolors:Array = GetColours(this.colour);
44 var bgalphas:Array = [1, 1];
45 var bgratios:Array = [0, 255];
46 var bgmatrix:Matrix = new Matrix();
47 var xRadius:Number;
48 var yRadius:Number;
49 var x:Number;
50 var y:Number;
51
52 bgmatrix.createGradientBox(w, h, (180 / 180) * Math.PI );
53 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
54
55 if (!upside_down && h > 0)
56 { /* draw bar upward */
57
58 if ( h >= w / 2)
59 { /* bar is tall enough for normal draw */
60
61 /* draw bottom half ellipse */
62 x = w/2;
63 y = h;
64 xRadius = w / 2;
65 yRadius = rad / 2;
66 halfEllipse(x, y, xRadius, yRadius, 100, false);
67
68 /* draw connecting rectangle */
69 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
70 this.graphics.moveTo(0, w/2);
71 this.graphics.lineTo(0, h);
72 this.graphics.lineTo(w, h);
73 this.graphics.lineTo(w, w / 2);
74
75 /* draw top ellipse */
76 //this.graphics.beginFill(this.colour, 1);
77 x = w / 2;
78 y = w / 2;
79 xRadius = w / 2;
80 yRadius = xRadius;
81 halfEllipse(x, y, xRadius, yRadius, 100, true);
82
83 }
84
85 else
86
87 { /* bar is too short for normal draw */
88
89 /* draw bottom half ellipse */
90 x = w/2;
91 y = h;
92 xRadius = w / 2;
93 yRadius = rad / 2;
94 halfEllipse(x, y, xRadius, yRadius, 100, false);
95
96 /* draw top ellipse */
97 x = w / 2;
98 y = h;
99 xRadius = w / 2;
100 yRadius = h;
101 halfEllipse(x, y, xRadius, yRadius, 100, true);
102
103 }
104 }
105
106 else
107
108 { /*draw bar downward */
109
110 if ( h >= w / 2)
111 { /* bar is tall enough for normal draw */
112
113 /* draw top half ellipse */
114 x = w/2;
115 y = 0;
116 xRadius = w / 2;
117 yRadius = rad / 2;
118 halfEllipse(x, y, xRadius, yRadius, 100, true);
119
120 /* draw connecting rectangle */
121 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
122 this.graphics.moveTo(0, 0);
123 this.graphics.lineTo(0, h - w / 2);
124 this.graphics.lineTo(w, h - w / 2);
125 this.graphics.lineTo(w, 0);
126
127 /* draw bottom ellipse */
128 //this.graphics.beginFill(this.colour, 1);
129 x = w / 2;
130 y = h - w / 2;
131 xRadius = w / 2;
132 yRadius = xRadius;
133 halfEllipse(x, y, xRadius, yRadius, 100, false);
134
135 }
136
137 else
138
139 { /* bar is too short for normal draw */
140
141 if (h > 0)
142
143 { /* bar greater than zero */
144
145 /* draw top half ellipse */
146 x = w/2;
147 y = 0;
148 xRadius = w / 2;
149 yRadius = rad / 2;
150 halfEllipse(x, y, xRadius, yRadius, 100, true);
151
152 /* draw bottom ellipse */
153 x = w / 2;
154 y = 0;
155 xRadius = w / 2;
156 yRadius = h;
157 halfEllipse(x, y, xRadius, yRadius, 100, false);
158
159 }
160
161 else
162
163 { /* bar is zero */
164
165 /* draw top ellipse */
166 x = w/2;
167 y = h;
168 xRadius = w / 2;
169 yRadius = rad / 4;
170 Ellipse(x, y, xRadius, yRadius, 100);
171
172 }
173
174 }
175
176 }
177
178 this.graphics.endFill();
179 }
180
181 private function glass( w:Number, h:Number, upside_down:Boolean ): void {
182
183 /* if this section is commented out, the white shine overlay will not be drawn */
184
185 this.graphics.lineStyle(0, 0, 0);
186 var bgcolors:Array = GetColours(this.colour);
187 var bgalphas:Array = [1, 1];
188 var bgratios:Array = [0, 255];
189 var bgmatrix:Matrix = new Matrix();
190
191 bgmatrix.createGradientBox(w, h, (180 / 180) * Math.PI );
192
193 /* set gradient fill */
194 var colors:Array = [0xFFFFFF, 0xFFFFFF];
195 var alphas:Array = [0, 0.75];
196 var ratios:Array = [100,255];
197 var xRadius:Number;
198 var yRadius:Number;
199 var x:Number;
200 var y:Number;
201 var matrix:Matrix = new Matrix();
202 matrix.createGradientBox(width, height, (180 / 180) * Math.PI );
203 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
204 var rad:Number = w / 3;
205
206 if (!upside_down && h > 0)
207 { /* draw shine upward */
208
209 if (h >= w / 2)
210 { /* bar is tall enough for normal draw */
211
212 /* draw bottom half ellipse shine */
213 x = w/2;
214 y = h;
215 xRadius = w / 2 - (0.05 * w);
216 yRadius = rad / 2 - (0.05 * w);
217 halfEllipse(x, y, xRadius, yRadius, 100, false);
218
219 /*draw connecting rectangle shine */
220 this.graphics.moveTo(0 + (0.05 * w), w/2);
221 this.graphics.lineTo(0 + (0.05 * w), h);
222 this.graphics.lineTo(w - (0.05 * w), h);
223 this.graphics.lineTo(w - (0.05 * w), w/2);
224
225
226 /* redraw top ellipse (to overwrite connecting rectangle shine overlap)*/
227 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
228 x = w / 2;
229 y = w / 2;
230 xRadius = w / 2;
231 yRadius = xRadius;
232 halfEllipse(x, y, xRadius, yRadius, 100, true);
233
234 /* draw top ellipse shine */
235 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
236 x = w / 3;
237 y = w / 2;
238 xRadius = w / 3 - (0.05 * w);
239 yRadius = xRadius + (0.05 * w);
240 halfEllipse(x, y, xRadius, yRadius, 100, true);
241
242 }
243
244 else
245
246 { /* bar is not tall enough for normal draw */
247
248 /* draw bottom half ellipse shine */
249 x = w/2;
250 y = h;
251 xRadius = w / 2 - (0.05 * w);
252 yRadius = rad / 2 - (0.05 * w);
253 halfEllipse(x, y, xRadius, yRadius, 100, false);
254
255 /* draw top ellipse shine */
256 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
257 x = w / 3;
258 y = h;
259 xRadius = w / 3 - (0.05 * w);
260 yRadius = h - 2.5*(0.05 * w);
261 halfEllipse(x, y, xRadius, yRadius, 100, true);
262
263 }
264
265 }
266
267 else
268
269 { /* draw shine downward */
270
271 if ( h >= w / 2)
272 { /* bar is tall enough for normal draw */
273
274 /* draw top half ellipse shine */
275 x = w/2;
276 y = 0;
277 xRadius = w / 2 - (0.05 * w);
278 yRadius = rad / 2 - (0.05 * w);
279 halfEllipse(x, y, xRadius, yRadius, 100, true);
280
281 /*draw connecting rectangle shine */
282 this.graphics.moveTo(0 + (0.05 * w), 0);
283 this.graphics.lineTo(0 + (0.05 * w), h - w / 2);
284 this.graphics.lineTo(w - (0.05 * w), h - w / 2);
285 this.graphics.lineTo(w - (0.05 * w), 0);
286
287
288 /* redraw bottom ellipse (to overwrite connecting rectangle shine overlap)*/
289 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
290 x = w / 2;
291 y = h - w / 2;
292 xRadius = w / 2;
293 yRadius = xRadius;
294 halfEllipse(x, y, xRadius, yRadius, 100, false);
295
296 /* draw bottom ellipse shine */
297 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
298 x = w / 3;
299 y = h - w / 2;
300 xRadius = w / 3 - (0.05 * w);
301 yRadius = xRadius + (0.05 * w);
302 halfEllipse(x, y, xRadius, yRadius, 100, false);
303
304 }
305
306 else
307
308 { /* bar is not tall enough for normal draw */
309
310 if (h > 0)
311 { /* bar is greater than zero */
312
313 /* draw top half ellipse shine */
314 x = w/2;
315 y = 0;
316 xRadius = w / 2 - (0.05 * w);
317 yRadius = rad / 2 - (0.05 * w);
318 halfEllipse(x, y, xRadius, yRadius, 100, true);
319
320 /* draw bottom ellipse shine */
321 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
322 x = w / 3;
323 y = 0;
324 xRadius = w / 3 - (0.05 * w);
325 yRadius = h - 2.5*(0.05 * w);
326 halfEllipse(x, y, xRadius, yRadius, 100, false);
327
328 }
329
330 else
331
332 { /* bar is zero */
333
334 /* draw top ellipse shine */
335 x = w/2;
336 y = h;
337 xRadius = w / 2 - (0.05 * w);
338 yRadius = rad / 4 - (0.05 * w);
339 Ellipse(x, y, xRadius, yRadius, 100);
340
341 }
342
343 }
344
345 }
346
347 this.graphics.endFill();
348 }
349
350 /* function to process colors */
351 /* returns a base color and a highlight color for the gradients based on the color passed in */
352 public static function GetColours( col:Number ):Array {
353 var rgb:Number = col; /* decimal value for color */
354 var red:Number = (rgb & 16711680) >> 16; /* extacts the red channel */
355 var green:Number = (rgb & 65280) >> 8; /* extacts the green channel */
356 var blue:Number = rgb & 255; /* extacts the blue channel */
357 var shift:Number = 2; /* shift factor */
358 var basecolor:Number = col; /* base color to be returned */
359 var highlight:Number = col; /* highlight color to be returned */
360 var bgred:Number = (rgb & 16711680) >> 16; /* red channel for highlight */
361 var bggreen:Number = (rgb & 65280) >> 8; /* green channel for highlight */
362 var bgblue:Number = rgb & 255; /* blue channel for highlight */
363 var hired:Number = (rgb & 16711680) >> 16; /* red channel for highlight */
364 var higreen:Number = (rgb & 65280) >> 8; /* green channel for highlight */
365 var hiblue:Number = rgb & 255; /* blue channel for highlight */
366
367 /* set base color components based on ability to shift lighter */
368 if (red + red / shift > 255 || green + green / shift > 255 || blue + blue / shift > 255)
369 {
370 bgred = red - red / shift;
371 bggreen = green - green / shift;
372 bgblue = blue - blue / shift;
373 }
374
375 /* set highlight components based on base colors */
376 hired = bgred + red / shift;
377 hiblue = bgblue + blue / shift;
378 higreen = bggreen + green / shift;
379
380 /* reconstruct base and highlight */
381 basecolor = bgred << 16 | bggreen << 8 | bgblue;
382 highlight = hired << 16 | higreen << 8 | hiblue;
383
384 /* return base and highlight */
385 return [highlight, basecolor];
386 }
387
388 /* ellipse cos helper function */
389 public static function magicTrigFunctionX (pointRatio:Number):Number{
390 return Math.cos(pointRatio*2*Math.PI);
391 }
392
393 /* ellipse sin helper function */
394 public static function magicTrigFunctionY (pointRatio:Number):Number{
395 return Math.sin(pointRatio*2*Math.PI);
396 }
397
398 /* ellipse function */
399 /* draws an ellipse from passed center coordinates, x and y radii, and number of sides */
400 public function Ellipse(centerX:Number, centerY:Number, xRadius:Number, yRadius:Number, sides:Number):Number{
401
402 /* move to first point on ellipse */
403 this.graphics.moveTo(centerX + xRadius, centerY);
404
405 /* loop through sides and draw curves */
406 for(var i:Number=0; i<=sides; i++){
407 var pointRatio:Number = i/sides;
408 var xSteps:Number = magicTrigFunctionX(pointRatio);
409 var ySteps:Number = magicTrigFunctionY(pointRatio);
410 var pointX:Number = centerX + xSteps * xRadius;
411 var pointY:Number = centerY + ySteps * yRadius;
412 this.graphics.lineTo(pointX, pointY);
413 }
414
415 /* return 1 */
416 return 1;
417 }
418
419 /* half ellipse function */
420 /* draws half of an ellipse from passed center coordinates, x and y radii, number of sides , and top/bottom */
421 public function halfEllipse(centerX:Number, centerY:Number, xRadius:Number, yRadius:Number, sides:Number, top:Boolean):Number{
422
423 var loopStart:Number;
424 var loopEnd:Number;
425
426 if (top == true)
427 {
428 loopStart = sides / 2;
429 loopEnd = sides;
430 }
431 else
432 {
433 loopStart = 0;
434 loopEnd = sides / 2;
435 }
436
437 /* move to first point on ellipse */
438 this.graphics.moveTo(centerX + xRadius, centerY);
439
440 /* loop through sides and draw curves */
441 for(var i:Number=loopStart; i<=loopEnd; i++){
442 var pointRatio:Number = i/sides;
443 var xSteps:Number = magicTrigFunctionX(pointRatio);
444 var ySteps:Number = magicTrigFunctionY(pointRatio);
445 var pointX:Number = centerX + xSteps * xRadius;
446 var pointY:Number = centerY + ySteps * yRadius;
447 this.graphics.lineTo(pointX, pointY);
448 }
449
450 /* return 1 */
451 return 1;
452 }
453
454 }
455 }
Note: See TracBrowser for help on using the repository browser.