| 1 | package charts.series.bars {
|
|---|
| 2 |
|
|---|
| 3 | import flash.filters.DropShadowFilter;
|
|---|
| 4 | import flash.geom.Matrix;
|
|---|
| 5 | import charts.series.bars.Base;
|
|---|
| 6 |
|
|---|
| 7 | public class RoundGlass extends Base
|
|---|
| 8 | {
|
|---|
| 9 |
|
|---|
| 10 | public function RoundGlass( index:Number, props:Properties, group:Number ) {
|
|---|
| 11 |
|
|---|
| 12 | super(index, props, group);
|
|---|
| 13 | //super(index, {'top':props.get('top')}, props.get_colour('colour'), props.get('tip'), props.get('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 connecting rectangle */
|
|---|
| 62 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 63 | this.graphics.moveTo(0, w/2);
|
|---|
| 64 | this.graphics.lineTo(0, h);
|
|---|
| 65 | this.graphics.lineTo(w, h);
|
|---|
| 66 | this.graphics.lineTo(w, w / 2);
|
|---|
| 67 |
|
|---|
| 68 | /* draw top ellipse */
|
|---|
| 69 | //this.graphics.beginFill(this.colour, 1);
|
|---|
| 70 | x = w / 2;
|
|---|
| 71 | y = w / 2;
|
|---|
| 72 | xRadius = w / 2;
|
|---|
| 73 | yRadius = xRadius;
|
|---|
| 74 | halfEllipse(x, y, xRadius, yRadius, 100, true);
|
|---|
| 75 |
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | else
|
|---|
| 79 |
|
|---|
| 80 | { /* bar is too short for normal draw */
|
|---|
| 81 |
|
|---|
| 82 | /* draw top ellipse */
|
|---|
| 83 | x = w / 2;
|
|---|
| 84 | y = h;
|
|---|
| 85 | xRadius = w / 2;
|
|---|
| 86 | yRadius = h;
|
|---|
| 87 | halfEllipse(x, y, xRadius, yRadius, 100, true);
|
|---|
| 88 |
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | else
|
|---|
| 93 |
|
|---|
| 94 | { /*draw bar downward */
|
|---|
| 95 |
|
|---|
| 96 | if ( h >= w / 2)
|
|---|
| 97 | { /* bar is tall enough for normal draw */
|
|---|
| 98 |
|
|---|
| 99 | /* draw connecting rectangle */
|
|---|
| 100 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 101 | this.graphics.moveTo(0, 0);
|
|---|
| 102 | this.graphics.lineTo(0, h - w / 2);
|
|---|
| 103 | this.graphics.lineTo(w, h - w / 2);
|
|---|
| 104 | this.graphics.lineTo(w, 0);
|
|---|
| 105 |
|
|---|
| 106 | /* draw bottom ellipse */
|
|---|
| 107 | //this.graphics.beginFill(this.colour, 1);
|
|---|
| 108 | x = w / 2;
|
|---|
| 109 | y = h - w / 2;
|
|---|
| 110 | xRadius = w / 2;
|
|---|
| 111 | yRadius = xRadius;
|
|---|
| 112 | halfEllipse(x, y, xRadius, yRadius, 100, false);
|
|---|
| 113 |
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | else
|
|---|
| 117 |
|
|---|
| 118 | { /* bar is too short for normal draw */
|
|---|
| 119 |
|
|---|
| 120 | if (h > 0)
|
|---|
| 121 |
|
|---|
| 122 | { /* bar greater than zero */
|
|---|
| 123 |
|
|---|
| 124 | /* draw bottom ellipse */
|
|---|
| 125 | x = w / 2;
|
|---|
| 126 | y = 0;
|
|---|
| 127 | xRadius = w / 2;
|
|---|
| 128 | yRadius = h;
|
|---|
| 129 | halfEllipse(x, y, xRadius, yRadius, 100, false);
|
|---|
| 130 |
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | else
|
|---|
| 134 |
|
|---|
| 135 | { /* bar is zero */
|
|---|
| 136 |
|
|---|
| 137 | /* draw line */
|
|---|
| 138 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 139 | this.graphics.moveTo(0, - 0.05*w);
|
|---|
| 140 | this.graphics.lineTo(0, h + 0.05*w);
|
|---|
| 141 | this.graphics.lineTo(w, h + 0.05*w);
|
|---|
| 142 | this.graphics.lineTo(w, - 0.05*w);
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | this.graphics.endFill();
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | private function glass( w:Number, h:Number, upside_down:Boolean ): void {
|
|---|
| 155 |
|
|---|
| 156 | /* if this section is commented out, the white shine overlay will not be drawn */
|
|---|
| 157 |
|
|---|
| 158 | this.graphics.lineStyle(0, 0, 0);
|
|---|
| 159 | var bgcolors:Array = GetColours(this.colour);
|
|---|
| 160 | var bgalphas:Array = [1, 1];
|
|---|
| 161 | var bgratios:Array = [0, 255];
|
|---|
| 162 | var bgmatrix:Matrix = new Matrix();
|
|---|
| 163 |
|
|---|
| 164 | bgmatrix.createGradientBox(w, h, (180 / 180) * Math.PI );
|
|---|
| 165 |
|
|---|
| 166 | /* set gradient fill */
|
|---|
| 167 | var colors:Array = [0xFFFFFF, 0xFFFFFF];
|
|---|
| 168 | var alphas:Array = [0, 0.75];
|
|---|
| 169 | var ratios:Array = [100,255];
|
|---|
| 170 | var xRadius:Number;
|
|---|
| 171 | var yRadius:Number;
|
|---|
| 172 | var x:Number;
|
|---|
| 173 | var y:Number;
|
|---|
| 174 | var matrix:Matrix = new Matrix();
|
|---|
| 175 | matrix.createGradientBox(width, height, (180 / 180) * Math.PI );
|
|---|
| 176 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 177 | var rad:Number = w / 3;
|
|---|
| 178 |
|
|---|
| 179 | if (!upside_down && h > 0)
|
|---|
| 180 | { /* draw shine upward */
|
|---|
| 181 |
|
|---|
| 182 | if (h >= w / 2)
|
|---|
| 183 | { /* bar is tall enough for normal draw */
|
|---|
| 184 |
|
|---|
| 185 | /*draw connecting rectangle shine */
|
|---|
| 186 | this.graphics.moveTo(0 + (0.05 * w), w/2);
|
|---|
| 187 | this.graphics.lineTo(0 + (0.05 * w), h - (0.05 * w));
|
|---|
| 188 | this.graphics.lineTo(w - (0.05 * w), h - (0.05 * w));
|
|---|
| 189 | this.graphics.lineTo(w - (0.05 * w), w/2);
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 | /* redraw top ellipse (to overwrite connecting rectangle shine overlap)*/
|
|---|
| 193 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 194 | x = w / 2;
|
|---|
| 195 | y = w / 2;
|
|---|
| 196 | xRadius = w / 2;
|
|---|
| 197 | yRadius = xRadius;
|
|---|
| 198 | halfEllipse(x, y, xRadius, yRadius, 100, true);
|
|---|
| 199 |
|
|---|
| 200 | /* draw top ellipse shine */
|
|---|
| 201 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 202 | x = w / 3;
|
|---|
| 203 | y = w / 2;
|
|---|
| 204 | xRadius = w / 3 - (0.05 * w);
|
|---|
| 205 | yRadius = xRadius + (0.05 * w);
|
|---|
| 206 | halfEllipse(x, y, xRadius, yRadius, 100, true);
|
|---|
| 207 |
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | else
|
|---|
| 211 |
|
|---|
| 212 | { /* bar is not tall enough for normal draw */
|
|---|
| 213 |
|
|---|
| 214 | /* draw top ellipse shine */
|
|---|
| 215 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 216 | x = w / 3;
|
|---|
| 217 | y = h - (0.05 * w);
|
|---|
| 218 | xRadius = w / 3 - (0.05 * w);
|
|---|
| 219 | yRadius = h - 2.5*(0.05 * w);
|
|---|
| 220 | halfEllipse(x, y, xRadius, yRadius, 100, true);
|
|---|
| 221 |
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | else
|
|---|
| 227 |
|
|---|
| 228 | { /* draw shine downward */
|
|---|
| 229 |
|
|---|
| 230 | if ( h >= w / 2)
|
|---|
| 231 | { /* bar is tall enough for normal draw */
|
|---|
| 232 |
|
|---|
| 233 | /*draw connecting rectangle shine */
|
|---|
| 234 | this.graphics.moveTo(0 + (0.05 * w), 0 + (0.05 * w));
|
|---|
| 235 | this.graphics.lineTo(0 + (0.05 * w), h - w / 2);
|
|---|
| 236 | this.graphics.lineTo(w - (0.05 * w), h - w / 2);
|
|---|
| 237 | this.graphics.lineTo(w - (0.05 * w), 0 + (0.05 * w));
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 | /* redraw bottom ellipse (to overwrite connecting rectangle shine overlap)*/
|
|---|
| 241 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 242 | x = w / 2;
|
|---|
| 243 | y = h - w / 2;
|
|---|
| 244 | xRadius = w / 2;
|
|---|
| 245 | yRadius = xRadius;
|
|---|
| 246 | halfEllipse(x, y, xRadius, yRadius, 100, false);
|
|---|
| 247 |
|
|---|
| 248 | /* draw bottom ellipse shine */
|
|---|
| 249 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 250 | x = w / 3;
|
|---|
| 251 | y = h - w / 2;
|
|---|
| 252 | xRadius = w / 3 - (0.05 * w);
|
|---|
| 253 | yRadius = xRadius + (0.05 * w);
|
|---|
| 254 | halfEllipse(x, y, xRadius, yRadius, 100, false);
|
|---|
| 255 |
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | else
|
|---|
| 259 |
|
|---|
| 260 | { /* bar is not tall enough for normal draw */
|
|---|
| 261 |
|
|---|
| 262 | if (h > 0)
|
|---|
| 263 | { /* bar is greater than zero */
|
|---|
| 264 |
|
|---|
| 265 | /* draw bottom ellipse shine */
|
|---|
| 266 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 267 | x = w / 3;
|
|---|
| 268 | y = 0 + (0.05 * w);
|
|---|
| 269 | xRadius = w / 3 - (0.05 * w);
|
|---|
| 270 | yRadius = h - 2.5*(0.05 * w);
|
|---|
| 271 | halfEllipse(x, y, xRadius, yRadius, 100, false);
|
|---|
| 272 |
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | else
|
|---|
| 276 |
|
|---|
| 277 | { /* bar is zero */
|
|---|
| 278 |
|
|---|
| 279 | /* draw line */
|
|---|
| 280 | this.graphics.moveTo(0 + 0.025*w, - 0.025*w);
|
|---|
| 281 | this.graphics.lineTo(0 + 0.025*w, h + 0.025*w);
|
|---|
| 282 | this.graphics.lineTo(w, h + 0.025*w);
|
|---|
| 283 | this.graphics.lineTo(w, - 0.025*w);
|
|---|
| 284 |
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | this.graphics.endFill();
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | /* function to process colors */
|
|---|
| 295 | /* returns a base color and a highlight color for the gradients based on the color passed in */
|
|---|
| 296 | public static function GetColours( col:Number ):Array {
|
|---|
| 297 | var rgb:Number = col; /* decimal value for color */
|
|---|
| 298 | var red:Number = (rgb & 16711680) >> 16; /* extacts the red channel */
|
|---|
| 299 | var green:Number = (rgb & 65280) >> 8; /* extacts the green channel */
|
|---|
| 300 | var blue:Number = rgb & 255; /* extacts the blue channel */
|
|---|
| 301 | var shift:Number = 2; /* shift factor */
|
|---|
| 302 | var basecolor:Number = col; /* base color to be returned */
|
|---|
| 303 | var highlight:Number = col; /* highlight color to be returned */
|
|---|
| 304 | var bgred:Number = (rgb & 16711680) >> 16; /* red channel for highlight */
|
|---|
| 305 | var bggreen:Number = (rgb & 65280) >> 8; /* green channel for highlight */
|
|---|
| 306 | var bgblue:Number = rgb & 255; /* blue channel for highlight */
|
|---|
| 307 | var hired:Number = (rgb & 16711680) >> 16; /* red channel for highlight */
|
|---|
| 308 | var higreen:Number = (rgb & 65280) >> 8; /* green channel for highlight */
|
|---|
| 309 | var hiblue:Number = rgb & 255; /* blue channel for highlight */
|
|---|
| 310 |
|
|---|
| 311 | /* set base color components based on ability to shift lighter */
|
|---|
| 312 | if (red + red / shift > 255 || green + green / shift > 255 || blue + blue / shift > 255)
|
|---|
| 313 | {
|
|---|
| 314 | bgred = red - red / shift;
|
|---|
| 315 | bggreen = green - green / shift;
|
|---|
| 316 | bgblue = blue - blue / shift;
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | /* set highlight components based on base colors */
|
|---|
| 320 | hired = bgred + red / shift;
|
|---|
| 321 | hiblue = bgblue + blue / shift;
|
|---|
| 322 | higreen = bggreen + green / shift;
|
|---|
| 323 |
|
|---|
| 324 | /* reconstruct base and highlight */
|
|---|
| 325 | basecolor = bgred << 16 | bggreen << 8 | bgblue;
|
|---|
| 326 | highlight = hired << 16 | higreen << 8 | hiblue;
|
|---|
| 327 |
|
|---|
| 328 | /* return base and highlight */
|
|---|
| 329 | return [highlight, basecolor];
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | /* ellipse cos helper function */
|
|---|
| 333 | public static function magicTrigFunctionX (pointRatio:Number):Number{
|
|---|
| 334 | return Math.cos(pointRatio*2*Math.PI);
|
|---|
| 335 | }
|
|---|
| 336 |
|
|---|
| 337 | /* ellipse sin helper function */
|
|---|
| 338 | public static function magicTrigFunctionY (pointRatio:Number):Number{
|
|---|
| 339 | return Math.sin(pointRatio*2*Math.PI);
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | /* ellipse function */
|
|---|
| 343 | /* draws an ellipse from passed center coordinates, x and y radii, and number of sides */
|
|---|
| 344 | public function Ellipse(centerX:Number, centerY:Number, xRadius:Number, yRadius:Number, sides:Number):Number{
|
|---|
| 345 |
|
|---|
| 346 | /* move to first point on ellipse */
|
|---|
| 347 | this.graphics.moveTo(centerX + xRadius, centerY);
|
|---|
| 348 |
|
|---|
| 349 | /* loop through sides and draw curves */
|
|---|
| 350 | for(var i:Number=0; i<=sides; i++){
|
|---|
| 351 | var pointRatio:Number = i/sides;
|
|---|
| 352 | var xSteps:Number = magicTrigFunctionX(pointRatio);
|
|---|
| 353 | var ySteps:Number = magicTrigFunctionY(pointRatio);
|
|---|
| 354 | var pointX:Number = centerX + xSteps * xRadius;
|
|---|
| 355 | var pointY:Number = centerY + ySteps * yRadius;
|
|---|
| 356 | this.graphics.lineTo(pointX, pointY);
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 | /* return 1 */
|
|---|
| 360 | return 1;
|
|---|
| 361 | }
|
|---|
| 362 |
|
|---|
| 363 | /* half ellipse function */
|
|---|
| 364 | /* draws half of an ellipse from passed center coordinates, x and y radii, number of sides , and top/bottom */
|
|---|
| 365 | public function halfEllipse(centerX:Number, centerY:Number, xRadius:Number, yRadius:Number, sides:Number, top:Boolean):Number{
|
|---|
| 366 |
|
|---|
| 367 | var loopStart:Number;
|
|---|
| 368 | var loopEnd:Number;
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 | if (top == true)
|
|---|
| 372 | { /* drawing top half of ellipse */
|
|---|
| 373 |
|
|---|
| 374 | loopStart = sides / 2;
|
|---|
| 375 | loopEnd = sides;
|
|---|
| 376 |
|
|---|
| 377 | }
|
|---|
| 378 | else
|
|---|
| 379 | { /* drawing bottom half of ellipse */
|
|---|
| 380 |
|
|---|
| 381 | loopStart = 0;
|
|---|
| 382 | loopEnd = sides / 2;
|
|---|
| 383 |
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 | /* move to first point on ellipse */
|
|---|
| 387 | this.graphics.moveTo(centerX + xRadius, centerY);
|
|---|
| 388 |
|
|---|
| 389 | /* loop through sides and draw curves */
|
|---|
| 390 | for(var i:Number=loopStart; i<=loopEnd; i++){
|
|---|
| 391 | var pointRatio:Number = i/sides;
|
|---|
| 392 | var xSteps:Number = magicTrigFunctionX(pointRatio);
|
|---|
| 393 | var ySteps:Number = magicTrigFunctionY(pointRatio);
|
|---|
| 394 | var pointX:Number = centerX + xSteps * xRadius;
|
|---|
| 395 | var pointY:Number = centerY + ySteps * yRadius;
|
|---|
| 396 | this.graphics.lineTo(pointX, pointY);
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | /* return 1 */
|
|---|
| 400 | return 1;
|
|---|
| 401 | }
|
|---|
| 402 |
|
|---|
| 403 | }
|
|---|
| 404 | }
|
|---|