1 | package charts.series.bars {
|
---|
2 |
|
---|
3 | import charts.series.bars.Base;
|
---|
4 | import flash.filters.DropShadowFilter;
|
---|
5 | import flash.geom.Matrix;
|
---|
6 |
|
---|
7 | public class Cylinder extends Base
|
---|
8 | {
|
---|
9 |
|
---|
10 | public function Cylinder( index:Number, props:Properties, group:Number ) {
|
---|
11 |
|
---|
12 | super(index, props, group);
|
---|
13 | // MASSIVE HACK:
|
---|
14 | //super(index, {'top':props.get('top')}, props.get_colour('colour'), props.get('tip'), props.get('alpha'), group);
|
---|
15 |
|
---|
16 | //super(index, style, style.colour, style.tip, style.alpha, group);
|
---|
17 |
|
---|
18 | var dropShadow:DropShadowFilter = new flash.filters.DropShadowFilter();
|
---|
19 | dropShadow.blurX = 5;
|
---|
20 | dropShadow.blurY = 5;
|
---|
21 | dropShadow.distance = 3;
|
---|
22 | dropShadow.angle = 45;
|
---|
23 | dropShadow.quality = 2;
|
---|
24 | dropShadow.alpha = 0.4;
|
---|
25 | // apply shadow filter
|
---|
26 | this.filters = [dropShadow];
|
---|
27 | }
|
---|
28 |
|
---|
29 | public override function resize( sc:ScreenCoordsBase ):void {
|
---|
30 |
|
---|
31 | this.graphics.clear();
|
---|
32 | var h:Object = this.resize_helper( sc as ScreenCoords );
|
---|
33 |
|
---|
34 | this.bg( h.width, h.height, h.upside_down );
|
---|
35 | this.glass( h.width, h.height, h.upside_down );
|
---|
36 | }
|
---|
37 |
|
---|
38 | private function bg( w:Number, h:Number, upside_down:Boolean ):void {
|
---|
39 |
|
---|
40 | var rad:Number = w/3;
|
---|
41 | if ( rad > ( w / 2 ) )
|
---|
42 | rad = w / 2;
|
---|
43 |
|
---|
44 | this.graphics.lineStyle(0, 0, 0);// this.outline_colour, 100);
|
---|
45 |
|
---|
46 | var bgcolors:Array = GetColours(this.colour);
|
---|
47 | var bgalphas:Array = [1, 1];
|
---|
48 | var bgratios:Array = [0, 255];
|
---|
49 | var bgmatrix:Matrix = new Matrix();
|
---|
50 | var xRadius:Number;
|
---|
51 | var yRadius:Number;
|
---|
52 | var x:Number;
|
---|
53 | var y:Number;
|
---|
54 |
|
---|
55 | bgmatrix.createGradientBox(w, h, (180 / 180) * Math.PI );
|
---|
56 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
|
---|
57 |
|
---|
58 | /* draw bottom half ellipse */
|
---|
59 | x = w/2;
|
---|
60 | y = h;
|
---|
61 | xRadius = w / 2;
|
---|
62 | yRadius = rad / 2;
|
---|
63 | halfEllipse(x, y, xRadius, yRadius, 100);
|
---|
64 |
|
---|
65 | /* draw connecting rectangle */
|
---|
66 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
|
---|
67 | this.graphics.moveTo(0, 0);
|
---|
68 | this.graphics.lineTo(0, h);
|
---|
69 | this.graphics.lineTo(w, h);
|
---|
70 | this.graphics.lineTo(w, 0);
|
---|
71 |
|
---|
72 | /* draw top ellipse */
|
---|
73 | this.graphics.beginFill(this.colour, 1);
|
---|
74 | x = w / 2;
|
---|
75 | y = 0;
|
---|
76 | xRadius = w / 2;
|
---|
77 | yRadius = rad / 2;
|
---|
78 | Ellipse(x, y, xRadius, yRadius, 100);
|
---|
79 |
|
---|
80 | this.graphics.endFill();
|
---|
81 | }
|
---|
82 |
|
---|
83 | private function glass( w:Number, h:Number, upside_down:Boolean ): void {
|
---|
84 |
|
---|
85 | /* if this section is commented out, the white shine overlay will not be drawn */
|
---|
86 |
|
---|
87 | this.graphics.lineStyle(0, 0, 0);
|
---|
88 | //set gradient fill
|
---|
89 | var colors:Array = [0xFFFFFF, 0xFFFFFF];
|
---|
90 | var alphas:Array = [0, 0.5];
|
---|
91 | var ratios:Array = [150,255];
|
---|
92 | var xRadius:Number;
|
---|
93 | var yRadius:Number;
|
---|
94 | var x:Number;
|
---|
95 | var y:Number;
|
---|
96 | var matrix:Matrix = new Matrix();
|
---|
97 | matrix.createGradientBox(width, height, (180 / 180) * Math.PI );
|
---|
98 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
|
---|
99 | var rad:Number = w / 3;
|
---|
100 |
|
---|
101 | /* draw bottom half ellipse shine */
|
---|
102 | x = w/2;
|
---|
103 | y = h;
|
---|
104 | xRadius = w / 2;
|
---|
105 | yRadius = rad / 2;
|
---|
106 | halfEllipse(x, y, xRadius, yRadius, 100);
|
---|
107 |
|
---|
108 | /*draw connecting rectangle shine */
|
---|
109 | this.graphics.moveTo(0, 0);
|
---|
110 | this.graphics.lineTo(0, h);
|
---|
111 | this.graphics.lineTo(w, h);
|
---|
112 | this.graphics.lineTo(w, 0);
|
---|
113 |
|
---|
114 |
|
---|
115 | /* redraw top ellipse (to overwrite connecting rectangle shine overlap)*/
|
---|
116 | this.graphics.beginFill(this.colour, 1);
|
---|
117 | x = w / 2;
|
---|
118 | y = 0;
|
---|
119 | xRadius = w / 2;
|
---|
120 | yRadius = rad / 2;
|
---|
121 | Ellipse(x, y, xRadius, yRadius, 100);
|
---|
122 |
|
---|
123 | /* draw top ellipse shine */
|
---|
124 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, [25,255], matrix, 'pad'/*SpreadMethod.PAD*/ );
|
---|
125 | x = w / 2;
|
---|
126 | y = 0;
|
---|
127 | xRadius = w / 2;
|
---|
128 | yRadius = rad / 2;
|
---|
129 | Ellipse(x, y, xRadius, yRadius, 100);
|
---|
130 |
|
---|
131 | this.graphics.endFill();
|
---|
132 | }
|
---|
133 |
|
---|
134 | /* function to process colors */
|
---|
135 | /* returns a base color and a highlight color for the gradients based on the color passed in */
|
---|
136 | public static function GetColours( col:Number ):Array {
|
---|
137 | var rgb:Number = col; /* decimal value for color */
|
---|
138 | var red:Number = (rgb & 16711680) >> 16; /* extacts the red channel */
|
---|
139 | var green:Number = (rgb & 65280) >> 8; /* extacts the green channel */
|
---|
140 | var blue:Number = rgb & 255; /* extacts the blue channel */
|
---|
141 | var shift:Number = 2; /* shift factor */
|
---|
142 | var basecolor:Number = col; /* base color to be returned */
|
---|
143 | var highlight:Number = col; /* highlight color to be returned */
|
---|
144 | var bgred:Number = (rgb & 16711680) >> 16; /* red channel for highlight */
|
---|
145 | var bggreen:Number = (rgb & 65280) >> 8; /* green channel for highlight */
|
---|
146 | var bgblue:Number = rgb & 255; /* blue channel for highlight */
|
---|
147 | var hired:Number = (rgb & 16711680) >> 16; /* red channel for highlight */
|
---|
148 | var higreen:Number = (rgb & 65280) >> 8; /* green channel for highlight */
|
---|
149 | var hiblue:Number = rgb & 255; /* blue channel for highlight */
|
---|
150 |
|
---|
151 | /* set base color components based on ability to shift lighter */
|
---|
152 | if (red + red / shift > 255 || green + green / shift > 255 || blue + blue / shift > 255)
|
---|
153 | {
|
---|
154 | bgred = red - red / shift;
|
---|
155 | bggreen = green - green / shift;
|
---|
156 | bgblue = blue - blue / shift;
|
---|
157 | }
|
---|
158 |
|
---|
159 | /* set highlight components based on base colors */
|
---|
160 | hired = bgred + red / shift;
|
---|
161 | hiblue = bgblue + blue / shift;
|
---|
162 | higreen = bggreen + green / shift;
|
---|
163 |
|
---|
164 | /* reconstruct base and highlight */
|
---|
165 | basecolor = bgred << 16 | bggreen << 8 | bgblue;
|
---|
166 | highlight = hired << 16 | higreen << 8 | hiblue;
|
---|
167 |
|
---|
168 | /* return base and highlight */
|
---|
169 | return [highlight, basecolor];
|
---|
170 | }
|
---|
171 |
|
---|
172 | /* ellipse cos helper function */
|
---|
173 | public static function magicTrigFunctionX (pointRatio:Number):Number{
|
---|
174 | return Math.cos(pointRatio*2*Math.PI);
|
---|
175 | }
|
---|
176 |
|
---|
177 | /* ellipse sin helper function */
|
---|
178 | public static function magicTrigFunctionY (pointRatio:Number):Number{
|
---|
179 | return Math.sin(pointRatio*2*Math.PI);
|
---|
180 | }
|
---|
181 |
|
---|
182 | /* ellipse function */
|
---|
183 | /* draws an ellipse from passed center coordinates, x and y radii, and number of sides */
|
---|
184 | public function Ellipse(centerX:Number, centerY:Number, xRadius:Number, yRadius:Number, sides:Number):Number{
|
---|
185 |
|
---|
186 | /* move to first point on ellipse */
|
---|
187 | this.graphics.moveTo(centerX + xRadius, centerY);
|
---|
188 |
|
---|
189 | /* loop through sides and draw curves */
|
---|
190 | for(var i:Number=0; i<=sides; i++){
|
---|
191 | var pointRatio:Number = i/sides;
|
---|
192 | var xSteps:Number = magicTrigFunctionX(pointRatio);
|
---|
193 | var ySteps:Number = magicTrigFunctionY(pointRatio);
|
---|
194 | var pointX:Number = centerX + xSteps * xRadius;
|
---|
195 | var pointY:Number = centerY + ySteps * yRadius;
|
---|
196 | this.graphics.lineTo(pointX, pointY);
|
---|
197 | }
|
---|
198 |
|
---|
199 | /* return 1 */
|
---|
200 | return 1;
|
---|
201 | }
|
---|
202 |
|
---|
203 | /* (bottom) half ellipse function */
|
---|
204 | /* draws the bottom half of an ellipse from passed center coordinates, x and y radii, and number of sides */
|
---|
205 | public function halfEllipse(centerX:Number, centerY:Number, xRadius:Number, yRadius:Number, sides:Number):Number{
|
---|
206 |
|
---|
207 | /* move to first point on ellipse */
|
---|
208 | this.graphics.moveTo(centerX + xRadius, centerY);
|
---|
209 |
|
---|
210 | /* loop through sides and draw curves */
|
---|
211 | for(var i:Number=0; i<=sides/2; i++){
|
---|
212 | var pointRatio:Number = i/sides;
|
---|
213 | var xSteps:Number = magicTrigFunctionX(pointRatio);
|
---|
214 | var ySteps:Number = magicTrigFunctionY(pointRatio);
|
---|
215 | var pointX:Number = centerX + xSteps * xRadius;
|
---|
216 | var pointY:Number = centerY + ySteps * yRadius;
|
---|
217 | this.graphics.lineTo(pointX, pointY);
|
---|
218 | }
|
---|
219 |
|
---|
220 | /* return 1 */
|
---|
221 | return 1;
|
---|
222 | }
|
---|
223 | }
|
---|
224 | }
|
---|