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