1 //@class wso2vis.s.chart.protovis.PieChart : wso2vis.s.chart.WedgeChart 2 3 //Constructor 4 wso2vis.s.chart.protovis.PieChart = function(canvas, chartTitle, chartDesc) { 5 wso2vis.s.chart.protovis.WedgeChart.call(this, canvas, chartTitle, chartDesc); 6 } 7 8 // this makes c.protovis.PieChart.prototype inherits from wso2vis.s.chart.WedgeChart 9 wso2vis.extend(wso2vis.s.chart.protovis.PieChart, wso2vis.s.chart.protovis.WedgeChart); 10 11 //Public function load 12 //Loads the chart inside the given HTML element 13 wso2vis.s.chart.protovis.PieChart.prototype.load = function (w) { 14 if ( w !== undefined ) { 15 this.width(w); 16 } 17 /*if ( h !== undefined ) { //not using height for the Wedge 18 this.height(h); 19 }*/ 20 //var r = this.width() / 2.5; 21 22 var thisObject = this; 23 24 this.vis = new pv.Panel() 25 .canvas(function() { return thisObject.divEl(); }) 26 .width(function() { return thisObject.width(); }) 27 .height(function() { return thisObject.height(); }); 28 29 var chart = this.vis.add(pv.Panel) 30 .width(function() { return (thisObject.width() - thisObject.paddingLeft() - thisObject.paddingRight()); }) 31 .height(function() { return (thisObject.height() - thisObject.paddingTop() - thisObject.paddingBottom()); }) 32 .top(thisObject.paddingTop()) 33 .bottom(thisObject.paddingBottom()) 34 .left(thisObject.paddingLeft()) 35 .right(thisObject.paddingRight()); 36 37 var wedge = chart.add(pv.Wedge) 38 .data(function() { return pv.normalize(thisObject.getData(thisObject)); }) 39 .left((thisObject.width() - thisObject.paddingLeft() - thisObject.paddingRight()) / 2) 40 .bottom((thisObject.height() - thisObject.paddingTop() - thisObject.paddingBottom()) / 2) 41 .innerRadius(0) 42 .outerRadius(function() { return (thisObject.width() - thisObject.paddingLeft() - thisObject.paddingRight()) / 2.5; }) 43 .angle(function(d) { return (d * 2 * Math.PI); }) 44 .title(function() { 45 var dataObj = thisObject.traverseToDataField(thisObject.data, thisObject.dataField()); 46 if( dataObj instanceof Array ) { 47 return thisObject.onTooltip(dataObj[this.index]); 48 } 49 else { 50 return thisObject.onTooltip(dataObj); 51 } 52 }) 53 .event("click", function() { 54 var dataObj = thisObject.traverseToDataField(thisObject.data, thisObject.dataField()); 55 if( dataObj instanceof Array ) { 56 return thisObject.onClick(dataObj[this.index]); 57 } 58 else { 59 return thisObject.onClick(dataObj); 60 } 61 }); 62 63 wedge.anchor("center").add(pv.Label) 64 .visible(function(d) { return (thisObject.marks() && (d > 0.10)); }) 65 .textAngle(0) 66 .text(function(d) { return (d*100).toFixed() + "%"; }) 67 .textStyle("#fff"); 68 69 //wedge.anchor("end").add(pv.Label) 70 //.visible(function(d) { return (d > 0.05); }) 71 //.textMargin(0) //function(){ return thisObject.thickness() + 5; } 72 //.text(function(d) { var lbl=thisObject.getDataLabel(this.index); return (lbl.length > thisObject.labelLength() ? lbl.substring(0,thisObject.labelLength())+"..." : lbl); }) 73 //.font(function() { return thisObject.labelFont(); }); 74 // .textStyle(function() { return wedge.fillStyle(); }); 75 76 /* Legend */ 77 /* var legend = chart.add(pv.Panel) 78 .top(function() { return thisObject.legendTop(); }) 79 .left(function() { return thisObject.legendLeft(); }) 80 .right(function() { return thisObject.legendRight(); }) 81 .bottom(function() { return thisObject.legendBottom(); })*/ 82 83 84 chart.add(pv.Dot) 85 .data(function() { return pv.normalize(thisObject.getData(thisObject)); }) 86 .visible(function() { return thisObject.legend(); }) 87 .fillStyle(function() { return wedge.fillStyle(); }) 88 .right(function() { return (thisObject.width() - thisObject.legendX()); }) 89 .bottom(function() { return (this.index * 15) + (thisObject.height() - thisObject.legendY()); }) 90 .size(20) 91 .lineWidth(1) 92 .strokeStyle("#000") 93 .anchor("right").add(pv.Label) 94 .text(function() { return thisObject.getDataLabel(this.index); }); 95 96 this.vis.add(pv.Label) 97 .left(this.width() / 2) 98 .visible(function() { return !(thisObject.title() === ""); }) 99 .top(16) 100 .textAlign("center") 101 .text(function() { return thisObject.title(); }) 102 .font(function() { return thisObject.titleFont(); }); 103 }; 104 105