| 1 | package charts.series.bars {
|
|---|
| 2 | import flash.filters.DropShadowFilter;
|
|---|
| 3 | import flash.geom.Matrix;
|
|---|
| 4 | import charts.series.bars.Base;
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 | public class Round extends Base
|
|---|
| 8 | {
|
|---|
| 9 |
|
|---|
| 10 | public function Round( 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 (h > 0)
|
|---|
| 56 | {
|
|---|
| 57 |
|
|---|
| 58 | if ( h >= w)
|
|---|
| 59 | { /* bar is tall enough for normal draw */
|
|---|
| 60 |
|
|---|
| 61 | /* draw bottom half ellipse */
|
|---|
| 62 | x = w/2;
|
|---|
| 63 | y = h - w / 2;
|
|---|
| 64 | xRadius = w / 2;
|
|---|
| 65 | yRadius = xRadius;
|
|---|
| 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 - w/2);
|
|---|
| 72 | this.graphics.lineTo(w, h - w/2);
|
|---|
| 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 / 2;
|
|---|
| 92 | xRadius = w / 2;
|
|---|
| 93 | yRadius = h / 2;
|
|---|
| 94 | halfEllipse(x, y, xRadius, yRadius, 100, false);
|
|---|
| 95 |
|
|---|
| 96 | /* draw top ellipse */
|
|---|
| 97 | x = w / 2;
|
|---|
| 98 | y = h / 2;
|
|---|
| 99 | xRadius = w / 2;
|
|---|
| 100 | yRadius = h / 2;
|
|---|
| 101 | halfEllipse(x, y, xRadius, yRadius, 100, true);
|
|---|
| 102 |
|
|---|
| 103 | }
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | else
|
|---|
| 107 |
|
|---|
| 108 | {
|
|---|
| 109 |
|
|---|
| 110 | { /* bar is zero */
|
|---|
| 111 |
|
|---|
| 112 | /* draw top ellipse */
|
|---|
| 113 | x = w/2;
|
|---|
| 114 | y = h;
|
|---|
| 115 | xRadius = w / 2;
|
|---|
| 116 | yRadius = rad / 4;
|
|---|
| 117 | Ellipse(x, y, xRadius, yRadius, 100);
|
|---|
| 118 |
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | this.graphics.endFill();
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | private function glass( w:Number, h:Number, upside_down:Boolean ): void {
|
|---|
| 127 |
|
|---|
| 128 | /* if this section is commented out, the white shine overlay will not be drawn */
|
|---|
| 129 |
|
|---|
| 130 | this.graphics.lineStyle(0, 0, 0);
|
|---|
| 131 | var bgcolors:Array = GetColours(this.colour);
|
|---|
| 132 | var bgalphas:Array = [1, 1];
|
|---|
| 133 | var bgratios:Array = [0, 255];
|
|---|
| 134 | var bgmatrix:Matrix = new Matrix();
|
|---|
| 135 |
|
|---|
| 136 | bgmatrix.createGradientBox(w, h, (180 / 180) * Math.PI );
|
|---|
| 137 |
|
|---|
| 138 | /* set gradient fill */
|
|---|
| 139 | var colors:Array = [0xFFFFFF, 0xFFFFFF];
|
|---|
| 140 | var alphas:Array = [0, 0.75];
|
|---|
| 141 | var ratios:Array = [100,255];
|
|---|
| 142 | var xRadius:Number;
|
|---|
| 143 | var yRadius:Number;
|
|---|
| 144 | var x:Number;
|
|---|
| 145 | var y:Number;
|
|---|
| 146 | var matrix:Matrix = new Matrix();
|
|---|
| 147 | matrix.createGradientBox(width, height, (180 / 180) * Math.PI );
|
|---|
| 148 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 149 | var rad:Number = w / 3;
|
|---|
| 150 |
|
|---|
| 151 | if (h > 0)
|
|---|
| 152 | { /* draw shine upward */
|
|---|
| 153 |
|
|---|
| 154 | if (h >= w)
|
|---|
| 155 | { /* bar is tall enough for normal draw */
|
|---|
| 156 |
|
|---|
| 157 | /* draw bottom half ellipse shine */
|
|---|
| 158 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 159 | x = w / 3;
|
|---|
| 160 | y = h - w / 2;
|
|---|
| 161 | xRadius = w / 3 - (0.05 * w);
|
|---|
| 162 | yRadius = xRadius + (0.05 * w);
|
|---|
| 163 | halfEllipse(x, y, xRadius, yRadius, 100, false);
|
|---|
| 164 |
|
|---|
| 165 | /*draw connecting rectangle shine */
|
|---|
| 166 | this.graphics.moveTo(0 + (0.05 * w), w/2);
|
|---|
| 167 | this.graphics.lineTo(0 + (0.05 * w), h - w/2);
|
|---|
| 168 | this.graphics.lineTo(w - (0.05 * w), h - w/2);
|
|---|
| 169 | this.graphics.lineTo(w - (0.05 * w), w/2);
|
|---|
| 170 |
|
|---|
| 171 | /* draw top ellipse shine */
|
|---|
| 172 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 173 | x = w / 3;
|
|---|
| 174 | y = w / 2;
|
|---|
| 175 | xRadius = w / 3 - (0.05 * w);
|
|---|
| 176 | yRadius = xRadius + (0.05 * w);
|
|---|
| 177 | halfEllipse(x, y, xRadius, yRadius, 100, true);
|
|---|
| 178 |
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | else
|
|---|
| 182 |
|
|---|
| 183 | { /* bar is not tall enough for normal draw */
|
|---|
| 184 |
|
|---|
| 185 | this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
|
|---|
| 186 | x = w / 3;
|
|---|
| 187 | y = h / 2;
|
|---|
| 188 | xRadius = w / 3 - (0.05 * w);
|
|---|
| 189 | yRadius = h/2 - 3*(0.05 * w);
|
|---|
| 190 | Ellipse(x, y, xRadius, yRadius, 100);
|
|---|
| 191 |
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | else
|
|---|
| 197 |
|
|---|
| 198 | { /* bar is zero */
|
|---|
| 199 |
|
|---|
| 200 | /* draw top ellipse shine*/
|
|---|
| 201 | x = w/2;
|
|---|
| 202 | y = h;
|
|---|
| 203 | xRadius = w / 2 - (0.05 * w);
|
|---|
| 204 | yRadius = rad / 4 - (0.05 * w);
|
|---|
| 205 | Ellipse(x, y, xRadius, yRadius, 100);
|
|---|
| 206 |
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | this.graphics.endFill();
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | /* function to process colors */
|
|---|
| 213 | /* returns a base color and a highlight color for the gradients based on the color passed in */
|
|---|
| 214 | public static function GetColours( col:Number ):Array {
|
|---|
| 215 | var rgb:Number = col; /* decimal value for color */
|
|---|
| 216 | var red:Number = (rgb & 16711680) >> 16; /* extacts the red channel */
|
|---|
| 217 | var green:Number = (rgb & 65280) >> 8; /* extacts the green channel */
|
|---|
| 218 | var blue:Number = rgb & 255; /* extacts the blue channel */
|
|---|
| 219 | var shift:Number = 2; /* shift factor */
|
|---|
| 220 | var basecolor:Number = col; /* base color to be returned */
|
|---|
| 221 | var highlight:Number = col; /* highlight color to be returned */
|
|---|
| 222 | var bgred:Number = (rgb & 16711680) >> 16; /* red channel for highlight */
|
|---|
| 223 | var bggreen:Number = (rgb & 65280) >> 8; /* green channel for highlight */
|
|---|
| 224 | var bgblue:Number = rgb & 255; /* blue channel for highlight */
|
|---|
| 225 | var hired:Number = (rgb & 16711680) >> 16; /* red channel for highlight */
|
|---|
| 226 | var higreen:Number = (rgb & 65280) >> 8; /* green channel for highlight */
|
|---|
| 227 | var hiblue:Number = rgb & 255; /* blue channel for highlight */
|
|---|
| 228 |
|
|---|
| 229 | /* set base color components based on ability to shift lighter */
|
|---|
| 230 | if (red + red / shift > 255 || green + green / shift > 255 || blue + blue / shift > 255)
|
|---|
| 231 | {
|
|---|
| 232 | bgred = red - red / shift;
|
|---|
| 233 | bggreen = green - green / shift;
|
|---|
| 234 | bgblue = blue - blue / shift;
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | /* set highlight components based on base colors */
|
|---|
| 238 | hired = bgred + red / shift;
|
|---|
| 239 | hiblue = bgblue + blue / shift;
|
|---|
| 240 | higreen = bggreen + green / shift;
|
|---|
| 241 |
|
|---|
| 242 | /* reconstruct base and highlight */
|
|---|
| 243 | basecolor = bgred << 16 | bggreen << 8 | bgblue;
|
|---|
| 244 | highlight = hired << 16 | higreen << 8 | hiblue;
|
|---|
| 245 |
|
|---|
| 246 | /* return base and highlight */
|
|---|
| 247 | return [highlight, basecolor];
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | /* ellipse cos helper function */
|
|---|
| 251 | public static function magicTrigFunctionX (pointRatio:Number):Number{
|
|---|
| 252 | return Math.cos(pointRatio*2*Math.PI);
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | /* ellipse sin helper function */
|
|---|
| 256 | public static function magicTrigFunctionY (pointRatio:Number):Number{
|
|---|
| 257 | return Math.sin(pointRatio*2*Math.PI);
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | /* ellipse function */
|
|---|
| 261 | /* draws an ellipse from passed center coordinates, x and y radii, and number of sides */
|
|---|
| 262 | public function Ellipse(centerX:Number, centerY:Number, xRadius:Number, yRadius:Number, sides:Number):Number{
|
|---|
| 263 |
|
|---|
| 264 | /* move to first point on ellipse */
|
|---|
| 265 | this.graphics.moveTo(centerX + xRadius, centerY);
|
|---|
| 266 |
|
|---|
| 267 | /* loop through sides and draw curves */
|
|---|
| 268 | for(var i:Number=0; i<=sides; i++){
|
|---|
| 269 | var pointRatio:Number = i/sides;
|
|---|
| 270 | var xSteps:Number = magicTrigFunctionX(pointRatio);
|
|---|
| 271 | var ySteps:Number = magicTrigFunctionY(pointRatio);
|
|---|
| 272 | var pointX:Number = centerX + xSteps * xRadius;
|
|---|
| 273 | var pointY:Number = centerY + ySteps * yRadius;
|
|---|
| 274 | this.graphics.lineTo(pointX, pointY);
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | /* return 1 */
|
|---|
| 278 | return 1;
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | /* half ellipse function */
|
|---|
| 282 | /* draws half of an ellipse from passed center coordinates, x and y radii, number of sides , and top/bottom */
|
|---|
| 283 | public function halfEllipse(centerX:Number, centerY:Number, xRadius:Number, yRadius:Number, sides:Number, top:Boolean):Number{
|
|---|
| 284 |
|
|---|
| 285 | var loopStart:Number;
|
|---|
| 286 | var loopEnd:Number;
|
|---|
| 287 |
|
|---|
| 288 | if (top == true)
|
|---|
| 289 | {
|
|---|
| 290 | loopStart = sides / 2;
|
|---|
| 291 | loopEnd = sides;
|
|---|
| 292 | }
|
|---|
| 293 | else
|
|---|
| 294 | {
|
|---|
| 295 | loopStart = 0;
|
|---|
| 296 | loopEnd = sides / 2;
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | /* move to first point on ellipse */
|
|---|
| 300 | this.graphics.moveTo(centerX + xRadius, centerY);
|
|---|
| 301 |
|
|---|
| 302 | /* loop through sides and draw curves */
|
|---|
| 303 | for(var i:Number=loopStart; i<=loopEnd; i++){
|
|---|
| 304 | var pointRatio:Number = i/sides;
|
|---|
| 305 | var xSteps:Number = magicTrigFunctionX(pointRatio);
|
|---|
| 306 | var ySteps:Number = magicTrigFunctionY(pointRatio);
|
|---|
| 307 | var pointX:Number = centerX + xSteps * xRadius;
|
|---|
| 308 | var pointY:Number = centerY + ySteps * yRadius;
|
|---|
| 309 | this.graphics.lineTo(pointX, pointY);
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | /* return 1 */
|
|---|
| 313 | return 1;
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | }
|
|---|
| 317 | }
|
|---|