📄 piechart.as
字号:
//drawThickBox(mouseOverBox.content_mc.anchor_mc1,arcAnchorPoint[i].x-2,arcAnchorPoint[i].y-2,arcAnchorPoint[i].x+2,arcAnchorPoint[i].y+2,0x000000,0,1,0);
drawThickBox(mouseOverBox.content_mc.anchor_mc2,arcAnchorPoint[i+1].x-2,arcAnchorPoint[i+1].y-2,arcAnchorPoint[i+1].x+2,arcAnchorPoint[i+1].y+2,0x000000,0,1,0);
//var prevArcDegree = currentDegrees - sliceDegrees;
//mouseOverBox.content_mc.anchor_mc1._rotation = prevArcDegree; //make this mc's relative position consistency with the hover_mc
mouseOverBox.content_mc.anchor_mc2._rotation = currentDegrees;
drawThickBox(mouseOverBox.content_mc,-2,-2,2,2,0x000000,0,1,0); //the content_mc's reg-point is just at the plotCenter position
*/
mouseOverBox.content_mc.lineStyle(1, tempLineColor, 100);
var mouseOverMessage:String = "CB: ";
var legendName = (lineLabel != undefined && lineLabel != "") ? "<b>"+lineLabel+"</b><br>" : "";
mouseOverMessage += legendName;
mouseOverMessage += "Usage: "+Math.round(fraction*1000)/1000*100+"%";
mouseOverBox.content_mc.createTextField("label_txt", 2, 2, -2, 0, 0);
var tf:TextField = mouseOverBox.content_mc.label_txt;
tf.selectable = false;
tf.html = true;
tf.multiline = true;
tf.htmlText = "<font face='Verdana' size='10'>"+mouseOverMessage+"</font>";
tf._width = tf.textWidth+5;
tf._height = tf.textHeight+5;
var o:MovieClip = mouseOverBox.content_mc.createEmptyObject("labelbg_mc", 1);
o._x = tf._x-2;
o._y = tf._y-1;
o.lineStyle(1, tempLineColor, 100);
drawRoundRect(o, 0, 0, tf._width+4, tf._height+3, 0, 0xFFFFFF, 80);
// bg
o.lineStyle(0, tempLineColor, 0);
drawRoundRect(o, 1, tf._height+3.5, tf._width+4.5, 1, 0, 0x666666, 50);
// inner shad horiz
drawRoundRect(o, tf._width+4.5, 1, 1, tf._height+2.5, 0, 0x666666, 50);
// inner shad vert
drawRoundRect(o, 2, tf._height+4.5, tf._width+4.5, 1, 0, 0x666666, 20);
// outer shad horiz
drawRoundRect(o, tf._width+5.5, 2, 1, tf._height+2.5, 0, 0x666666, 20);
// outer shad vert
//define the event handler
mouseOverBox.hover_mc.onRollOver = function():Void {
this._parent.content_mc._visible = true;
//Todo: draw the highlight selected point when mouse roll over the hover_mc dynamically
var hotMc:String = this._parent._name;
var tpStr = hotMc.substr(hotMc.indexOf("_")+1, hotMc.length);
var index = Number(tpStr.substring(0, tpStr.indexOf("_")))+1;
trace(hotMc+"--------"+index);
this._parent.content_mc.createEmptyObject("anchor_mc1", this._parent.content_mc.getNextHighestDepth());
this._parent.content_mc.createEmptyObject("anchor_mc2", this._parent.content_mc.getNextHighestDepth());
//drawThickBox(mouseOverBox.content_mc.anchor_mc,arcAnchorPoint.x*Math.cos(currentDegrees)-2,arcAnchorPoint.y*Math.sin(currentDegrees)-2,arcAnchorPoint.x*Math.cos(currentDegrees)+2,arcAnchorPoint.y*Math.sin(currentDegrees)+2,0x000000,0,1,0);
this.delegator.drawThickBox(this._parent.content_mc.anchor_mc1, this.delegator.arcAnchorPoint[index].x-2, this.delegator.arcAnchorPoint[index].y-2, this.delegator.arcAnchorPoint[index].x+2, this.delegator.arcAnchorPoint[index].y+2, 0x000000, 0, 1, 0);
this.delegator.drawThickBox(this._parent.content_mc.anchor_mc2, this.delegator.arcAnchorPoint[index+1].x-2, this.delegator.arcAnchorPoint[index+1].y-2, this.delegator.arcAnchorPoint[index+1].x+2, this.delegator.arcAnchorPoint[index+1].y+2, 0x000000, 0, 1, 0);
//var prevArcDegree = currentDegrees - sliceDegrees;
this._parent.content_mc.anchor_mc1._rotation = this.delegator.arcRotationDegrees[index-1];
//make this mc's relative position consistency with the hover_mc
this._parent.content_mc.anchor_mc2._rotation = this.delegator.arcRotationDegrees[index];
this.delegator.drawThickBox(this._parent.content_mc, -2, -2, 2, 2, 0x000000, 0, 1, 0);
//the content_mc's reg-point is just at the plotCenter position
trace("rotate degreee1:"+this.delegator.arcRotationDegrees[index]+"rotate degreee2:"+this.delegator.arcRotationDegrees[index+1]);
//set the float pane's position according to the anchor coordinate
this._parent.content_mc.label_txt._x = this._parent.content_mc._xmouse -20;
this._parent.content_mc.label_txt._y = this._parent.content_mc._ymouse +20; //set the offset to 20 px.
this._parent.content_mc.labelbg_mc._x = this._parent.content_mc._xmouse -20;
this._parent.content_mc.labelbg_mc._y = this._parent.content_mc._ymouse +20;;
//tf._y -= tf._height;
};
mouseOverBox.hover_mc.onRollOut = mouseOverBox.hover_mc.onDragOut=function ():Void {
this._parent.content_mc._visible = false;
};
}
}
//Important: After drew the last arc, the anchor postion just the first anchor, because the pie is close in any time.
arcAnchorPoint.push({x:radius, y:0});
var tp:String;
for (var i = 0; i<arcAnchorPoint.length; i++) {
tp += arcAnchorPoint[i].x+"/"+arcAnchorPoint[i].y;
}
_root.test.text = tp;
_root.test2.text = arcRotationDegrees.toString();
}
/**Method; draws the legend on the specified MovieClip.
*/
function drawLegend(o:MovieClip, pad:Number, spacing:Number,w:Number):Void {
var padding:Number = pad != undefined ? pad : 5;
__spacing = spacing;
var layoutY:Number = padding;
// Remove previous legend remains
o.clear();
for (var i in o) {
if (i.substr(0, 13) == "legend_label_") {
o[i].removeTextField();
}
}
// Loop through lines and draw legend
for (var i:Number = 0; i<__lines.length; i++) {
// Prepare vars
var tempLine:Object = __lines[i];
var tempLabel:String = tempLine.label;
var tempColor:Number = tempLine.color;
// Draw box
drawRoundRect(o, padding, layoutY, 10, 15, 0, tempColor, 100);
// Draw label
var labelName:String = "legend_label_"+i;
o.createTextField(labelName, o.getNextHighestDepth(), padding+15, layoutY, 0, 10);
var t:TextField = o[labelName];
t.selectable = false;
t.autoSize = "left";
t.setNewTextFormat(labelFormatBold);
t.text = tempLabel;
// Increment layoutY
//layoutY += spacing;
//Modified by Roland Zhu Indrement padding, so the legend icon will be put horizontally
if (padding+__spacing<w) {
padding += __spacing;
} else {
//jump to next 'line'
layoutY += 20;
//reset the padding
padding = pad != undefined ? pad : 5;
}
}
}
/*Method
*Draw a acr in specified movie clip, and record the end anchor coordinate.
*Parameters
*src The mc to be drewn.
*x the start anchor point x coordinate.
*y the start anchor point's y coordinate.
*r the radius of the arc.
*a1 the degree of the arc
*arc
*obj the data storage to record the end anchor's coordinate, this value will be used to indicate the border and then hightlight this arc.
*/
function arcTo(src, x, y, r, a1, arc, obj):Void {
var remainder, theta, halftheta, angle, angleMid, segs, ax, ay, bx, by, cx, cy, remainder, lastArc;
src.lineTo(x, y);
if (a1<0) {
a1 += 360;
}
if (Math.abs(arc)>360) {
arc = 360;
}
segs = Math.floor(Math.abs(arc)/45);
remainder = Math.abs(arc)%45;
theta = -0.785398163397448;
//-PI /4 it is the angle of the 45 degree.
halftheta = -0.392699081698724;
angle = -(a1/180)*Math.PI;
ax = x-Math.cos(angle)*r;
ay = y-Math.sin(angle)*r;
if (arc<0) {
theta *= -1;
halftheta *= -1;
}
if (segs>0) {
angleMid = angle-halftheta;
for (var i = 0; i<segs; i++) {
angle += theta;
angleMid += theta;
bx = ax+Math.cos(angle)*r;
by = ay+Math.sin(angle)*r;
cx = ax+Math.cos(angleMid)*(r/Math.cos(halftheta));
cy = ay+Math.sin(angleMid)*(r/Math.cos(halftheta));
src.curveTo(cx, cy, bx, by);
}
}
if (remainder>0) {
lastArc = Math.abs(arc)-(segs*45);
if (arc<0) {
lastArc *= -1;
}
angle = -((a1+arc)/180)*Math.PI;
angleMid = angle-(-(lastArc/360)*Math.PI);
bx = ax+Math.cos(angle)*r;
by = ay+Math.sin(angle)*r;
cx = ax+Math.cos(angleMid)*(r/Math.cos(angle-angleMid));
cy = ay+Math.sin(angleMid)*(r/Math.cos(angle-angleMid));
src.curveTo(cx, cy, bx, by);
}
if (obj != undefined) {
this[obj].push({x:bx, y:by});
//this[obj].y= by;
}
}
/*
function drawCircle(mc:MovieClip, x:Number, y:Number, r:Number):Void {
mc.beginFill(0xff0000, 100);
mc.moveTo(x, y);
mc.lineTo(Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y);
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);
mc.lineTo(x, y);
mc.endFill();
}
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -