wholepie.lzx
<library>
<include href="piepiece.lzx"/>
<class name="wholepie" extends="view" visible="${parent.selectedpie == this || parent.selectedpie == null}">
<attribute name="drawbg" type="color" value="$once{null}"/>
<attribute name="drawbgborder" type="color" value="$once{null}"/>
<attribute name="bgborderwidth" type="number" value="1
"/>
<attribute name="piecevalues" value="$once{[]}"/>
<attribute name="colorvalues" value="$once{[]}"/>
<attribute name="bordercolors" value="$once{[]}"/>
<attribute name="borderwidths" value="$once{[]}"/>
<attribute name="opacvalues" value="$once{[]}"/>
<attribute name="legendvalues" value="$once{[]}"/>
<attribute name="radiusvalues" value="$once{[]}"/>
<attribute name="labelvalues" value="$once{[]}"/>
<attribute name="labelcolors" value="$once{[]}"/>
<attribute name="labelborders" value="$once{[]}"/>
<attribute name="labelbwidth" value="$once{[]}"/>
<attribute name="labeltsize" value="$once{[]}"/>
<attribute name="labeltcolor" value="$once{[]}"/>
<attribute name="explode" type="boolean" value="false
"/>
<attribute name="legend" type="string" value="$once{null}"/>
<attribute name="lborder" type="color" value="$once{null}"/>
<attribute name="lborderwidth" type="number" value="1
"/>
<attribute name="lbgcolor" type="color" value="$once{null}"/>
<attribute name="lhlcolor" type="color" value="$once{null}"/>
<attribute name="ltitle" type="string" value="$once{null}"/>
<attribute name="legendx" type="number" value="0
"/>
<attribute name="legendy" type="number" value="0
"/>
<attribute name="legendwidth" type="number" value="0
"/>
<attribute name="legendheight" type="number" value="0
"/>
<attribute name="showlegendminimized" type="boolean" value="true
"/>
<attribute name="legendtitleposition" type="string" value="left
"/>
<attribute name="pienumber" type="number" value="0
"/>
<attribute name="allpies" type="number" value="0
"/>
<attribute name="pievalue" type="number" value="0
"/>
<attribute name="corrvalues" value="$once{[]}"/>
<attribute name="corrcolors" value="$once{[]}"/>
<attribute name="corrborder" value="$once{[]}"/>
<attribute name="corrbwidth" value="$once{[]}"/>
<attribute name="corropac" value="$once{[]}"/>
<attribute name="corrlegend" value="$once{[]}"/>
<attribute name="corrrad" value="$once{[]}"/>
<attribute name="corrlabel" value="$once{[]}"/>
<attribute name="corrlabelcolor" value="$once{[]}"/>
<attribute name="corrlabelborder" value="$once{[]}"/>
<attribute name="corrlabelbwidth" value="$once{[]}"/>
<attribute name="corrlabeltsize" value="$once{[]}"/>
<attribute name="corrlabeltcolor" value="$once{[]}"/>
<attribute name="origx" type="number" value="$once{this.x}"/>
<attribute name="origy" type="number" value="$once{this.y}"/>
<attribute name="origwidth" type="number" value="$once{this.width}"/>
<attribute name="origheight" type="number" value="$once{this.height}"/>
<attribute name="expanded" type="boolean" value="false
"/>
<attribute name="checkwedgeoverdel" value="$once{new LzDelegate(this, 'checkWedgeOver')}"/>
<attribute name="wedgeover" value="$once{null}"/>
<handler name="oninit">
this.buildPie();
</handler>
<handler name="onclick">
if(this.wedgeover != null){
this.wedgeover.onclick.sendEvent();
} else {
if(!this.expanded){
this.setAttribute('expanded', true);
this.setAttribute('width', parent.width);
this.setAttribute('height', parent.height);
this.setAttribute('x', 0);
this.setAttribute('y', 0);
this.eatPie();
this.buildPie();
parent.setAttribute('selectedpie', this);
} else {
this.setAttribute('expanded', false);
this.setAttribute('width', this.origwidth);
this.setAttribute('height', this.origheight);
this.setAttribute('x', this.origx);
this.setAttribute('y', this.origy);
this.eatPie();
this.buildPie();
parent.setAttribute('selectedpie', null);
}
}
</handler>
<handler name="onmouseover">
this.checkwedgeoverdel.register(lz.Idle, "onidle");
</handler>
<handler name="onmouseout">
this.checkwedgeoverdel.unregisterAll();
//Clear out our wedgeover attribute
if(this.wedgeover != null){
this.wedgeover.onmouseout.sendEvent();
}
this.setAttribute('wedgeover', null);
</handler>
<method name="checkWedgeOver">
var pieradius = (this.width < this.height ? this.width * .9 : this.height * .9) / 2;
var ctrx = this.width / 2;
var ctry = this.height / 2;
if(this.legend != null){
if(this.legend == 'top'){
ctrx = this.width / 2;
ctry = this.height / 2 + (this.height * .1);
pieradius = pieradius - (this.height * .1);
} else if(this.legend == 'bottom'){
ctrx = this.width / 2;
ctry = this.height / 2 - (this.height * .1);
pieradius = pieradius - (this.height * .1);
} else if(this.legend == 'left'){
ctrx = this.width / 2 + (this.width * .1);
ctry = this.height / 2;
pieradius = pieradius - (this.width * .05);
} else if(this.legend == 'right'){
ctrx = this.width / 2 - (this.width * .1);
ctry = this.height / 2;
pieradius = pieradius - (this.width * .05);
}
}
var mx = ctrx - this.getMouse("x");
var my = ctry - this.getMouse("y");
var dist = Math.sqrt(mx * mx + my * my);
//if mouse dist is outside the circle we're no longer over a
//wedge
if (dist > pieradius) {
if(this.wedgeover != null){
this.wedgeover.onmouseout.sendEvent();
}
this.setAttribute('wedgeover', null);
return;
}
//normalize so 0 is at zeroang degrees and preserve the unit square
//in a counterclockwise direction (we render the wedges counterclockwise)
var ang = Math.acos(mx/dist);
if(my < 0){
ang = (2 * Math.PI) - ang;
}
ang = ((2 * Math.PI) / 2) - ang;
if(ang < 0){
ang += (2 * Math.PI);
}
var piecelist = this.subviews;
//find wedge that contains this angle if any
for (var i = 0; i < piecelist.length; i++) {
if(piecelist[i].name != 'bgcircle' && piecelist[i].name != 'legend' &&
(piecelist[i] instanceof lz.label != true) &&
typeof piecelist[i].startpercent != 'undefined'){
var startpos = (2 * Math.PI) * piecelist[i].startpercent;
var endpos = startpos + ((2 * Math.PI) * piecelist[i].piecepercent);
if (ang < endpos && ang > startpos) {
if (this.wedgeover != piecelist[i]) {
this.setAttribute('wedgeover', piecelist[i]);
piecelist[i].onmouseover.sendEvent();
}
break;
}
}
}
</method>
<method name="buildPie">
var pieradius = (this.width < this.height ? this.width * .9 : this.height * .9) / 2;
var piecenumbers = 0;
// Corrects for any null piece values.
for(var i = 0; i < this.piecevalues.length; i++){
if(this.piecevalues[i] != null){
this.corrvalues[piecenumbers] = this.piecevalues[i];
this.corropac[piecenumbers] = this.opacvalues != null ?
(typeof(this.opacvalues) == 'string' ? this.opacvalues :
(typeof this.opacvalues[i] != 'undefined' ? this.opacvalues[i] : null)) : null;
this.corrcolors[piecenumbers] = this.colorvalues != null ?
(typeof(this.colorvalues) == 'string' ? this.colorvalues :
(typeof this.colorvalues[i] != 'undefined' ? this.colorvalues[i] : null)) : null;
this.corrborder[piecenumbers] = this.bordercolors != null ?
(typeof(this.bordercolors) == 'string' ? this.bordercolors :
(typeof this.bordercolors[i] != 'undefined' ? this.bordercolors[i] : null)) : null;
this.corrlegend[piecenumbers] = this.legendvalues != null ?
(typeof(this.legendvalues) == 'string' ? this.legendvalues :
(typeof this.legendvalues[i] != 'undefined' ? this.legendvalues[i] : null)) : null;
this.corrbwidth[piecenumbers] = this.borderwidths != null ?
(typeof(this.borderwidths) == 'string' ? this.borderwidths :
(typeof this.borderwidths[i] != 'undefined' ? this.borderwidths[i] : null)) : null;
this.corrrad[piecenumbers] = this.radiusvalues != null ?
(typeof(this.radiusvalues) == 'string' ? this.radiusvalues :
(typeof this.radiusvalues[i] != 'undefined' ? this.radiusvalues[i] : 0)) : 0;
this.corrlabel[piecenumbers] = this.labelvalues != null ?
(typeof this.labelvalues[i] != 'undefined' ? this.labelvalues[i] : null) : null;
this.corrlabelcolor[piecenumbers] = this.labelcolors != null ?
(typeof(this.labelcolors) != 'object' ? this.labelcolors :
(typeof this.labelcolors[i] != 'undefined' ? this.labelcolors[i] : null)) : null;
this.corrlabelborder[piecenumbers] = this.labelborders != null ?
(typeof(this.labelborders) == 'string' ? this.labelborders :
(typeof this.labelborders[i] != 'undefined' ? this.labelborders[i] : null)) : null;
this.corrlabelbwidth[piecenumbers] = this.labelbwidth != null ?
(typeof(this.labelbwidth) == 'string' ? this.labelbwidth :
(typeof this.labelbwidth[i] != 'undefined' ? this.labelbwidth[i] : null)) : null;
this.corrlabeltsize[piecenumbers] = this.labeltsize != null ?
(typeof(this.labeltsize) == 'string' ? this.labeltsize :
(typeof this.labeltsize[i] != 'undefined' ? this.labeltsize[i] : 12)) : 12;
this.corrlabeltcolor[piecenumbers] = this.labeltcolor != null ?
(typeof(this.labeltcolor) != 'object' ? this.labeltcolor :
(typeof this.labeltcolor[i] != 'undefined' ? this.labeltcolor[i] : null)) : null;
piecenumbers++;
}
}
var ctrx = this.width / 2;
var ctry = this.height / 2;
if(this.legend != null){
if(this.legend == 'top'){
ctrx = this.width / 2;
ctry = this.height / 2 + (this.height * .1);
pieradius = pieradius - (this.height * .1);
} else if(this.legend == 'bottom'){
ctrx = this.width / 2;
ctry = this.height / 2 - (this.height * .1);
pieradius = pieradius - (this.height * .1);
} else if(this.legend == 'left'){
ctrx = this.width / 2 + (this.width * .1);
ctry = this.height / 2;
pieradius = pieradius - (this.width * .05);
} else if(this.legend == 'right'){
ctrx = this.width / 2 - (this.width * .1);
ctry = this.height / 2;
pieradius = pieradius - (this.width * .05);
} else if(this.legend == 'manualtop'){
ctrx = this.width / 2;
ctry = this.width / 2 + this.legendheight + 8;
pieradius = pieradius - (this.legendheight / 2) - 8;
} else if(this.legend == 'manualbottom'){
ctrx = this.width / 2;
ctry = this.width / 2 - this.legendheight - 8;
pieradius = pieradius - (this.legendheight / 2) - 8;
} else if(this.legend == 'manualleft'){
ctrx = this.width / 2 + this.legendwidth + 8;
ctry = this.width / 2;
pieradius = pieradius - (this.legendwidth / 2) - 8;
} else if(this.legend == 'manualright'){
ctrx = this.width / 2 - this.legendwidth - 8;
ctry = this.width / 2;
pieradius = pieradius - (this.legendwidth / 2) - 8;
}
}
if(this.drawbg != null){
new lz.backcircle(this, {name:'bgcircle', drawbg:this.drawbg,
drawbgborder:this.drawbgborder, bgborderwidth:this.bgborderwidth,
ctrx:ctrx, ctry:ctry, pieradius:pieradius})
}
for(var k = 0; k < this.corrvalues.length; k++){
var pieceperc = (this.corrvalues[k] / this.pievalue);
var totaltonow = 0;
var piecestart = 0;
if(k > 0){
for(var l = 0; l < k; l++){
totaltonow = totaltonow + Number(this.corrvalues[l]);
}
var piecestart = (totaltonow / this.pievalue);
}
var adjradius = pieradius + (pieradius * (this.corrrad[k] / 100));
new lz.piepiece(this, {centerx:ctrx, centery:ctry, piececolor:this.corrcolors[k],
bordercolor:this.corrborder[k], pieceradius:adjradius, piecepercent:pieceperc, startpercent:piecestart,
borderwidth:this.corrbwidth[k], pieceopacity:this.corropac[k], explode:this.explode, name:'pp'+k,
piecevalue:corrvalues[k]});
if(this.corrlabel != null && typeof this.corrlabel[k] != 'undefined' &&
this.corrlabel[k] != null){
var sposit = (2 * Math.PI) * piecestart;
var eposit = sposit + ((2 * Math.PI) * (pieceperc / 2));
var sx = ctrx - (adjradius * .7) * Math.cos(((2 * Math.PI) / 2) - eposit);
var sy = ctry - (adjradius * .7) * Math.sin(eposit);
new lz.label(this, {height:16,
y:sy, x:sx, bgcolor:this.corrlabelcolor[k],
ltext:this.corrlabel[k], labelnumber:k,
ltextsize:(this.expanded ? this.corrlabeltsize[k] : 10),
lborder:this.corrlabelborder[k],
lbwidth:this.corrlabelbwidth[k], ltcolor:this.corrlabeltcolor[k],
charttype:"pie"});
}
}
// Bring labels to the front, since they might've gotten partially
// covered by pie slices.
for(var j = 0; j <= this.subviews.length; j++){
if(this.subviews[j] instanceof lz.label){
this.subviews[j].bringToFront();
}
}
if(this.legend != null){
if(this.showlegendminimized == true ||
(this.showlegendminimized == false && this.expanded)){
var litems = this.corrvalues.length;
var ppc = new Array;
var ppccount = 0;
for(var i = 0; i <= this.subviews.length; i++){
if(typeof this.subviews[i] != 'undefined' && this.subviews[i].name != 'bgcircle' &&
(this.subviews[i] instanceof lz.label == false)){
ppc[ppccount] = this.subviews[i].name;
ppccount++;
}
}
new lz.chartlegend(this, {border:this.lborder, borderwidth:this.lborderwidth, backcolor:this.lbgcolor,
hlcolor:this.lhlcolor, itemnums:litems, charttype:'pie', posit:this.legend, piepieces:ppc,
ltitle:this.ltitle, pieradius:pieradius, centerx:ctrx, centery:ctry, piececolors:corrcolors,
legendvalues:this.corrlegend, legendx:this.legendx, legendy:this.legendy,
legendwidth:this.legendwidth, legendheight:this.legendheight,
titleposition:this.legendtitleposition});
} else {
var lholder = this.legend;
var lwid = 80;
var lhigh = 16;
var lx = this.legendx;
var ly = this.legendy;
if(this.legend == 'top' || this.legend == 'manualtop'){
lx = (this.width - lwid) / 2;
ly = (ctry - pieradius - lhigh) / 2;
lholder = 'manualtop';
} else if(this.legend == 'bottom' || this.legend == 'manualbottom'){
lx = (this.width - lwid) / 2;
ly = (ctry + pieradius) + (this.height - ctry - pieradius - lhigh) / 2;
lholder = 'manualbottom';
} else if(this.legend == 'left' || this.legend == 'manualleft'){
ly = (this.height - lhigh) / 2;
lx = (ctrx - pieradius - lwid) / 2;
lholder = 'manualleft';
} else if(this.legend == 'right' || this.legend == 'manualright'){
ly = (this.height - lhigh) / 2;
lx = (ctrx + pieradius) + (this.width - ctrx - pieradius - lwid) / 2;
lholder = 'manualright';
}
new lz.chartlegend(this, {border:this.lborder, borderwidth:this.lborderwidth, backcolor:this.lbgcolor,
itemnums:0, charttype:'pie', posit:lholder, ltitle:this.ltitle, pieradius:pieradius,
centerx:ctrx, centery:ctry, legendvalues:this.corrlegend, legendx:lx,
legendy:ly, legendwidth:lwid, legendheight:lhigh, titleposition:this.legendtitleposition})
}
}
</method>
<method name="eatPie">
while(this.subviews.length > 0){
var piecesleft = this.subviews.length;
for(var i = 0; i <= piecesleft; i++){
if(typeof this.subviews[i] != 'undefined'){
this.subviews[i].destroy();
}
}
}
</method>
<doc>
<tag name="shortdesc">
<text>
(See piechart for an example.)
</text>
</tag>
</doc>
</class>
</library>
Cross References
Includes
Classes