📄 bamboobarchart.as
字号:
drawRoundRect(vAxis_mc, 50-leftBlockW, lineY, leftBlockW, 1, 0, 0xFFFFFF, 100);
// Increment layoutY
layoutY += layoutIncrement;
}
/*
Line boundaries:
x: 50,
y: topPadding
w: w-50
h: h
*/
var dif:Number = upperBoundary - lowerBoundary;
var lowerBoundaryEquivalentPlotY:Number = -((h * lowerBoundary) / dif);
var upperBoundaryEquivalentPlotY:Number = -((h * upperBoundary) / dif); // h/dif = ?/upperBoundary || h*upperBoundary=dif*? || ?=(h*upperBoundary)/dif;
var plotOffset:Number = topPadding - upperBoundaryEquivalentPlotY;
//trace("plotOffset: " + plotOffset + " - lower: " + lowerBoundaryEquivalentPlotY + " - upper: " + upperBoundaryEquivalentPlotY + " - h: " + h);
// Declare function to get plotY
//Actually, the relative coordinate was located at the x-axis, and the absolute coordinate was the left top corner of the chart
var getPlotY:Function = function(plotNumber:Number):Number
{
return plotOffset + (-((h * plotNumber) / dif)); //the plotOffset is the relative coordinate offset value, so we can caculate the temporary value in the relative axis freely, when get the realy value, we must plus the offset.
}
/*
/added by roland Zhu 2006.8.3
append a function to caculate the height of every bar according to the point data
*/
var getPlotHeight:Function = function(plotNumber:Number):Number{
return h* plotNumber / dif;
}
// ----------------------------
// Finally ready to plot values
// ----------------------------
var lineThickness:Number = 3;
var dropShadowColor:Number = 0x666666;
var dropShadowAlpha:Number = 50;
var dropShadowOffset:Number = 2;
var lastPlotX:Number;
var lastPlotY:Number;
//Added by Roland Zhu 2006.8.3
var plotHeightArray:Array = new Array(); //define a storage to store all the height of every point
for (var i:Number=0; i<__lines.length; i++)
{
var tempLine:Object = __lines[i];
trace("dot in this "+tempLine.points.toString());
var linePoints:Array = tempLine.points;
var lineLabel:String = tempLine.label;
var tempLineColor:Number = tempLine.color;
// Loop thru points to plot - DROP SHADOW THIS TIME
vAxis_mc.lineStyle(lineThickness, dropShadowColor, dropShadowAlpha);
//Added by Roland Zhu 2006.8.3
var unitHeightArray:Array = new Array(); //define the temp storage to hold the height values for current unit
for (var j:Number=0; j<linePoints.length; j++)
{
var tempPlotValue:Number = linePoints[j];
// Prepare layout values - reference hPoints position
var tempPlotX:Number = __hPoints[j].hAxisX;
var tempPlotY:Number = getPlotY(tempPlotValue);
/*
if (j!=0)
{
// Actually draw drop shadow if not first item
// vAxis_mc.moveTo(lastPlotX, lastPlotY + dropShadowOffset);
vAxis_mc.lineTo(tempPlotX, tempPlotY + dropShadowOffset);
}
else
{
// Move to starting position for dropshadow
vAxis_mc.moveTo(tempPlotX, tempPlotY + dropShadowOffset);
}
*/
/*Added by Roland Zhu 2006.8.3
/Caculte all the height of the bar, and record it to get the positions of them when splice them in later time.
*/
var tempPlotHeight = getPlotHeight(tempPlotValue);
unitHeightArray.push(tempPlotHeight); //store the values into unit heights storage
lastPlotX = tempPlotX;
lastPlotY = tempPlotY;
}
plotHeightArray.push(unitHeightArray); //store every unit's height values
// Loop thru points to plot - ACTUAL LINE THIS TIME
vAxis_mc.lineStyle(lineThickness, tempLineColor, 100);
for (var j:Number=0; j<linePoints.length; j++)
{
var tempPlotValue:Number = linePoints[j];
// Prepare layout values - reference hPoints position
var tempPlotX:Number = __hPoints[j].hAxisX;
var tempColumnName:String = __hPoints[j].label;
var tempPlotY:Number = getPlotY(tempPlotValue);
/*Modified by Roland Zhu
if (j!=0)
{
// Actually draw line if not first item
// vAxis_mc.moveTo(lastPlotX, lastPlotY);
vAxis_mc.lineTo(tempPlotX, tempPlotY);
}
else
{
// Move to starting position for line
vAxis_mc.moveTo(tempPlotX, tempPlotY);
}
*/
//Draw the bar rectangle according to the xAxis_Step, itemCount [The items count inner a x axis section]
var w:Number = width;
w -= 100; //decrease the left margin and right margin
var numMarkers:Number = __hPoints.length;
var sectionW:Number = w / (numMarkers - 1) ;
trace("The width of the section"+sectionW);
var barSpace:Number = sectionW/(itemCount*2+1); //keep the space half of the bar's width
var barWidth = (sectionW-(itemCount+1)*barSpace)/itemCount;
//barWidth = (barWidth > 16)? 16 : barWidth;
trace("value:"+__hPoints.length+"------"+sectionW+"barWidth"+ barWidth+"itemCount:" + itemCount);
var startX = tempPlotX + barWidth;
var layoutY:Number = topPadding;
//var startY:Number = Math.round(layoutY - 0.5);
trace(startX+","+startY +","+barWidth );
// -----------------
// Add mouseover box
// -----------------
var mouseOverBoxName:String = "mouseoverbox_" + i + "_" + j + "_mc";
var mouseOverBox:MovieClip =vAxis_mc.createEmptyObject(mouseOverBoxName, vAxis_mc.getNextHighestDepth());
trace("The var mc name in the vaxis_mc"+vAxis_mc["mouseoverbox_" + i + "_" + j + "_mc"]._alpha);
/*Added by Roland Zhu 2006.8.3
*caculate the start Y coordinate of every point when splice them in vertical
*detailed method: sum all the heights in i-1 cycles at this j section.
*/
var startYBase:Number = 0;
for(var m=0;m<i;m++){
startYBase += plotHeightArray[m][j];
}
/*Modified by Roland Zhu
Put the bar instance into a container, and define the mouse event upon it, in later time, we will control its visible
Modified 2006.8.3
put every bar splice in vertical
*/
trace(plotHeightArray.toString());
var startY = Math.round(height - hAxis_mc._height) - 5 - startYBase;
trace("startX"+startX);
trace("StartY"+startY);
trace("End Y"+tempPlotY-startYBase);
var endY = Math.round(startY - getPlotHeight(tempPlotValue)); //get the height of current bar, and then get its y coordinate value
//draw the viewable bar, but it has not the mouse event upon it
drawThickBox(vAxis_mc,startX, startY,startX+barWidth,endY,tempLineColor,1,0);
//mouseOverBox._x = _parent._x;
mouseOverBox._y = _parent._y; //keep the bar's relative postion equal to the v axis
/*Modified by Roland Zhu
Put the bar instance into a container, and define the mouse event upon it, in later time, we will control its visible
*/
mouseOverBox.createEmptyObject("hover_mc", 1);
//draw the invisible one, but there are mouse event defined on it.
drawThickBox(mouseOverBox.hover_mc,startX, startY,startX+barWidth,endY,tempLineColor,0,0x00AAFF,0,0);
drawThickBox(mouseOverBox.hover_mc,startX-2,startY-2,startX+2,startY+2,0x000000,0,1,0);
drawThickBox(mouseOverBox.hover_mc,startX+barWidth-2,startY-2,startX+barWidth+2,startY+2,0x000000,0,1,0);
drawThickBox(mouseOverBox.hover_mc,startX-2,endY-2,startX+2,endY+2,0x000000,0,1,0);
drawThickBox(mouseOverBox.hover_mc,startX+barWidth-2,endY-2,startX+barWidth+2,endY+2,0x000000,0,1,0);
mouseOverBox.hover_mc._alpha =0; //hide the hover_mc in init time,only show it as the mouse roll over it
mouseOverBox.createEmptyObject("content_mc", this.getNextHighestDepth());
mouseOverBox.hover_mc.useHandCursor = false;
mouseOverBox.content_mc._visible = false;
// Invisible hoverbox
//drawRoundRect(mouseOverBox.hover_mc, 8, 8, 5, 5, 0, 0xFFD400, 100); //modified by Roland Zhu to show the vertex upon the line.
// Tooltip hover dot
var mouseOverDotDiameter:Number = 10;
mouseOverBox.content_mc.lineStyle(1, tempLineColor, 100);
//drawRoundRect(mouseOverBox.content_mc, 5, 5, 10, 10, 5, 0xFFFFFF, 100);
//mouseOverBox.content_mc.lineStyle(0, tempLineColor, 0);
//drawRoundRect(mouseOverBox.content_mc, 8, 8, 4, 4, 2, tempLineColor, 100);
// Tooltip message
var mouseOverMessage:String = (lineLabel!=undefined && lineLabel != "") ? "<b>" + lineLabel + "</b><br>" : "";
mouseOverMessage += __hTitle +": "+ tempColumnName + "<br>" + __vTitle +": "+ tempPlotValue + numberPostfix;
mouseOverBox.content_mc.createTextField("label_txt", 2, 22, -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;
tf._y -= tf._height;
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
//Added by Roland Zhu
mouseOverBox.content_mc._x = startX - mouseOverBox.content_mc._width; //put the popup pane at the center-top of the current bar relatively
mouseOverBox.content_mc._y = endY -3;
/*Added by Roland Zhu 2006.9.19
*Control the coordinate of the float pane when it is near from the stage boundary
*/
if(j == linePoints.length-1){ //this is the last point, then move the position of the float pane to make it may show in the stage area.
trace("The original postion"+mouseOverBox.content_mc._x);
var offset = mouseOverBox.content_mc._width/2;
mouseOverBox.content_mc.label_txt._x -= offset;
mouseOverBox.content_mc.labelbg_mc._x -= offset;
trace("after moved"+mouseOverBox.content_mc._x);
}
/*
//do not define the mouse event upon the real bar any more, but on the dummy bar
// Mouse events
vAxis_mc["mouseoverbox_" + i + "_" + j + "_mc"].onRollOver = function():Void
{
this.content_mc._visible = true;
}
vAxis_mc["mouseoverbox_" + i + "_" + j + "_mc"].onRollOut = vAxis_mc["mouseoverbox_" + i + "_" + j + "_mc"].onDragOut = function():Void
{
this.content_mc._visible = false;
}
*/
mouseOverBox.hover_mc.onRollOver = function():Void{
this._alpha = 100;
_parent.content_mc._visible = true;
}
mouseOverBox.hover_mc.onRollOut = mouseOverBox.hover_mc.onDragOut = function():Void{
this._alpha = 0;
_parent.content_mc._visible = false;
}
// -- Done with mouseoverbox --
// Update lastPlot values
lastPlotX = tempPlotX;
lastPlotY = tempPlotY;
}
}
}
function convertLineObj(obj:Object):Array
{
// Create reference object
var referenceObj:Object = {};
for (var i:Number=0; i<__hPoints.length; i++) {
var tempItem:Object = __hPoints[i];
referenceObj[tempItem.id] = i;
}
// Create ordered array
var returnArray:Array = [];
for (var i:String in obj)
{
var tempOrder = referenceObj[i];
var tempVal:Number = obj[i];
returnArray[tempOrder] = tempVal;
}
return returnArray;
}
//function plotBar(xScale,yScale,backColor,lineColor,barColor){
function plotBar(bar:Object,label:String,color:Number,count:Number):Void{
var plotValues:Array = convertLineObj(bar);
var labelValue:String = label; //label!=undefined ? label : "(None)";
var colorValue:Number;
itemCount = count;
trace("itemcount in plotBar function:"+itemCount);
if (color!=undefined)
{
colorValue = color;
}
else
{
var colorIndex:Number;
if (__defaultColors.length > __lines.length)
{
colorIndex = __lines.length;
}
else
{
colorIndex = __lines.length - (Math.floor(__lines.length / __defaultColors.length) * __defaultColors.length);
}
colorValue = __defaultColors[colorIndex];
}
__lines.push({points:plotValues, label:labelValue, color:colorValue});
// Tell to draw in future
invalidate();
}
function drawLegend(o:MovieClip, pad:Number,spacing:Number):Void
{
var padding:Number = pad!=undefined ? pad : 5;
//var spacing:Number = 100;
var layoutY:Number = 0;
__spacing = spacing;
// Remove previous legend remains
o.clear();
for (var i:String 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 < width){
padding += __spacing;
}
else{ //jump to next 'line'
layoutY += 20;
//reset the padding
padding = pad!=undefined ? pad : 5;
}
}
}
function drawChart():Void
{
drawHAxis();
drawVAxis();
}
function toDeg(rad:Number):Number
{
// 2PI RAD = 360deg
var deg:Number = (180 / Math.PI) * rad;
return deg;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -