?? piechart.as
字號:
?class Scene.Manage.Panels.Group1.SubPanels.PieChart extends MovieClip {
var chartHolder:MovieClip;
var chartShadow:MovieClip;
var __total:Number = 0;
var __items:Array = new Array();
var __radius:Number = 50;
var heightSet = false;
var tt:MovieClip;
function PieChart() {
createEmptyMovieClip("chartShadow", getNextHighestDepth());
createEmptyMovieClip("chartHolder", getNextHighestDepth());
drawCircle(chartShadow, __radius+1, __radius+12, __radius);
chartShadow._height -= 25;
}
//Chart Skeleton Code
function addItem(value, color) {
__total += value;
__items.push({value:value, color:color});
redraw();
}
function removeItemAt(id) {
var itm = __items[id];
__total -= itm.value;
__items.splice(id, 1);
redraw();
}
function replaceItemAt(id, value) {
__total -= __items[id].value;
__items[id].value = value;
__total += value;
redraw();
}
function getItemAt(id) {
}
//UI Code
function redraw() {
var InsertPoint = 0;
for (var i = 0; i<__items.length; i++) {
var item = __items[i];
var percent = ((item.value/__total)*100);
var degree = ((360/100)*percent);
//Draw Line
var mc = chartHolder["wedge"+i];
mc.clear();
mc.removeMovieClip();
var mc = chartHolder.createEmptyMovieClip("wedge"+i, chartHolder.getNextHighestDepth());
drawSegmant(mc, __radius, __radius, __radius, degree, InsertPoint, item.color);
//
var ntt = tt;
//mc.attachMovie("Poll_TT", "_tt", getNextHighestDepth())
mc.p1 = item.value;
mc.p2 = __total;
InsertPoint += degree;
}
if(chartHolder._height >= __radius*2){
if(heightSet == false){
chartHolder._height -= 20;
heightSet = true;
}
}
}
function drawSegmant(mc, radius, x, y, angle, rotation, color) {
drawWedge(mc, radius, x, y, angle, rotation, color, 100);
var place = drawWedge(mc, radius, x, y, angle, rotation, 0x000000, 20);
drawWedge(mc, radius-2, x-1, y-1, angle, rotation, color, 100);
var colors = [0xFFFFFF, 0xFFFFFF];
var alphas = [25, 0];
var ratios = [10, 255];
var matrix = {matrixType:"box", x:0-(radius-2), y:0-(radius-2), w:(radius-2)*2, h:(radius-2)*2, r:0};
drawWedge(mc, radius-2, x+1, y+1, angle, rotation, ["radial", colors, alphas, ratios, matrix], 100, true);
mc.lineStyle(2, 0x000000, 10);
mc.moveTo(0, 0);
mc.lineTo(radius-2, 0);
mc.moveTo(0, 0);
mc.lineTo(place.x, place.y-2);
}
function drawWedge(mc, r, x, y, angle, rotation, color, alpha, grad) {
mc.lineStyle(0, 0x000000, 0);
if (grad != true) {
mc.beginFill(color, alpha);
} else {
mc.beginGradientFill(color[0], color[1], color[2], color[3], color[4]);
}
var rad = Math.PI/180;
// start at 0,0 so rotation will be around the point of the wedge
mc.moveTo(0, 0);
mc.lineTo(r, 0);
// draw in 30-degree segments for accuracy
var nSeg = Math.floor(angle/30);
// eg 2 if angle is 80
var pSeg = angle-nSeg*30;
// eg 20 degrees if angle is 80
//trace(nSeg + " " + pSeg);
var a = 0.268;
// tan(15)
for (var i = 0; i<nSeg; i++) {
var endx = r*Math.cos((i+1)*30*rad);
var endy = r*Math.sin((i+1)*30*rad);
var ax = endx+r*a*Math.cos(((i+1)*30-90)*rad);
var ay = endy+r*a*Math.sin(((i+1)*30-90)*rad);
mc.curveTo(ax, ay, endx, endy);
}
if (pSeg>0) {
a = Math.tan(pSeg/2*rad);
endx = r*Math.cos((i*30+pSeg)*rad);
endy = r*Math.sin((i*30+pSeg)*rad);
ax = endx+r*a*Math.cos((i*30+pSeg-90)*rad);
ay = endy+r*a*Math.sin((i*30+pSeg-90)*rad);
mc.curveTo(ax, ay, endx, endy);
}
mc.lineTo(0, 0);
mc._rotation = rotation;
mc._x = x;
mc._y = y;
mc.endFill();
return {x:endx, y:endy};
}
function drawCircle(mc:MovieClip, x:Number, y:Number, r:Number):Void {
mc.lineStyle(0, 0x000000, 0);
mc.beginFill(0xCCCCCC, 70);
mc.moveTo(x+r, y);
mc.curveTo(r+x, Math.tan(Math.PI/8)*r+y, Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y);
mc.curveTo(Math.tan(Math.PI/8)*r+x, r+y, x, r+y);
mc.curveTo(-Math.tan(Math.PI/8)*r+x, r+y, -Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y);
mc.curveTo(-r+x, Math.tan(Math.PI/8)*r+y, -r+x, y);
mc.curveTo(-r+x, -Math.tan(Math.PI/8)*r+y, -Math.sin(Math.PI/4)*r+x, -Math.sin(Math.PI/4)*r+y);
mc.curveTo(-Math.tan(Math.PI/8)*r+x, -r+y, x, -r+y);
mc.curveTo(Math.tan(Math.PI/8)*r+x, -r+y, Math.sin(Math.PI/4)*r+x, -Math.sin(Math.PI/4)*r+y);
mc.curveTo(r+x, -Math.tan(Math.PI/8)*r+y, r+x, y);
}
function get preferedWidth(){
return 124;
}
function get preferedHeight(){
return 99;
}
function setSize(width, height){
if(width < height){
__radius = width/2;
}else{
__radius = height/2;
}
if(width == undefined){
__radius = height/2;
}else if(height == undefined){
__radius = width/2;
}
chartShadow.clear();
drawCircle(chartShadow, __radius+1, __radius+12, __radius);
redraw();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -