source: code/Website/open-flash-chart/charts/series/bars/Bar3D.as

Last change on this file was 7849, checked in by dennisw, 15 years ago
File size: 4.0 KB
Line 
1package charts.series.bars {
2
3 import flash.display.Sprite;
4 import flash.geom.Matrix;
5 import flash.filters.DropShadowFilter;
6 import charts.series.bars.Base;
7
8 public class Bar3D extends Base {
9
10 public function Bar3D( index:Number, props:Properties, group:Number ) {
11
12 super(index, props, group);
13 //super(index, style, style.colour, style.tip, style.alpha, group);
14 //super(index, {'top':props.get('top')}, props.get_colour('colour'), props.get('tip'), props.get('alpha'), group);
15
16 var dropShadow:DropShadowFilter = new flash.filters.DropShadowFilter();
17 dropShadow.blurX = 5;
18 dropShadow.blurY = 5;
19 dropShadow.distance = 3;
20 dropShadow.angle = 45;
21 dropShadow.quality = 2;
22 dropShadow.alpha = 0.4;
23 // apply shadow filter
24 this.filters = [dropShadow];
25 }
26
27 public override function resize( sc:ScreenCoordsBase ):void {
28
29 var h:Object = this.resize_helper( sc as ScreenCoords );
30
31 this.graphics.clear();
32
33 this.draw_top( h.width, h.height );
34 this.draw_front( h.width, h.height );
35 this.draw_side( h.width, h.height );
36 }
37
38 private function draw_top( w:Number, h:Number ):void {
39
40 this.graphics.lineStyle(0, 0, 0);
41 //set gradient fill
42
43 var lighter:Number = Bar3D.Lighten( this.colour );
44
45 var colors:Array = [this.colour,lighter];
46 var alphas:Array = [1,1];
47 var ratios:Array = [0,255];
48 var matrix:Matrix = new Matrix();
49 matrix.createGradientBox(w + 12, 12, (270 / 180) * Math.PI );
50 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
51
52
53 var y:Number = 0;
54 if( h<0 )
55 y = h;
56
57 this.graphics.moveTo(0, y);
58 this.graphics.lineTo(w, y);
59 this.graphics.lineTo(w-12, y+12);
60 this.graphics.lineTo(-12, y+12);
61 this.graphics.endFill();
62 }
63
64 private function draw_front( w:Number, h:Number ):void {
65 //
66 var rad:Number = 7;
67
68 var lighter:Number = Bar3D.Lighten( this.colour );
69
70 // Darken a light color
71 //var darker:Number = this.colour;
72 //darker &= 0x7F7F7F;
73
74 var colors:Array = [lighter,this.colour];
75 var alphas:Array = [1,1];
76 var ratios:Array = [0, 127];
77
78 var matrix:Matrix = new Matrix();
79 matrix.createGradientBox(w - 12, h+12, (90 / 180) * Math.PI );
80 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
81
82 this.graphics.moveTo(-12, 12);
83 this.graphics.lineTo(-12, h+12);
84 this.graphics.lineTo(w-12, h+12);
85 this.graphics.lineTo(w-12, 12);
86 this.graphics.endFill();
87 }
88
89 private function draw_side( w:Number, h:Number ):void {
90 //
91 var rad:Number = 7;
92
93 var lighter:Number = Bar3D.Lighten( this.colour );
94
95 var colors:Array = [this.colour,lighter];
96 var alphas:Array = [1,1];
97 var ratios:Array = [0,255];
98 var matrix:Matrix = new Matrix();
99 matrix.createGradientBox(w, h+12, (270 / 180) * Math.PI );
100 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
101
102
103 this.graphics.lineStyle(0, 0, 0);
104 this.graphics.moveTo(w, 0);
105 this.graphics.lineTo(w, h);
106 this.graphics.lineTo(w-12, h+12);
107 this.graphics.lineTo(w-12, 12);
108 this.graphics.endFill();
109 }
110
111 //
112 // JG: lighten a colour by splitting it
113 // into RGB, then adding a bit to each
114 // value...
115 //
116 public static function Lighten( col:Number ):Number {
117 var rgb:Number = col; //decimal value for a purple color
118 var red:Number = (rgb & 16711680) >> 16; //extacts the red channel
119 var green:Number = (rgb & 65280) >> 8; //extacts the green channel
120 var blue:Number = rgb & 255; //extacts the blue channel
121 var p:Number = 2;
122 red += red/p;
123 if( red > 255 )
124 red = 255;
125
126 green += green/p;
127 if( green > 255 )
128 green = 255;
129
130 blue += blue/p;
131 if( blue > 255 )
132 blue = 255;
133
134 return red << 16 | green << 8 | blue;
135 }
136 }
137}
Note: See TracBrowser for help on using the repository browser.