Protovis.Pie.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Protovis.Pie = new Class({
  2. Extends : Protovis,
  3. options : {
  4. },
  5. initialize : function(el,options){
  6. this.parent(el,options);
  7. this.prepData();
  8. this.setScale();
  9. this.makeGraph();
  10. this.render();
  11. },
  12. prepData : function(){
  13. this.data = []; var d = this.options.data, x = [], y = [];
  14. var len = d[0].length - 1;
  15. for(var i = 0; i < d.length; i++){
  16. this.data.push( parseFloat(d[i][0]) );
  17. x.push(parseFloat(d[i][0]));
  18. }
  19. this.limits = { xmin : pv.min(x), xmax : pv.max(x), ymin : 0, ymax: x.length};
  20. this.data = this.data.sort(pv.reverseOrder)
  21. },
  22. setScale : function(){
  23. this.parent();
  24. this.r = this.width / 2;
  25. this.angle = pv.Scale.linear(0, pv.sum(this.data)).range(0, 2 * Math.PI);
  26. console.debug(this.data);
  27. },
  28. makeGraph : function(){
  29. this.parent();
  30. this.graph.add(pv.Wedge)
  31. .data(this.data)
  32. .bottom(this.height / 2)
  33. .left(this.width / 2)
  34. .outerRadius(this.r / 2.2)
  35. .angle(this.angle)
  36. .title(function(d){ return d.toFixed(2);})
  37. .add(pv.Wedge)
  38. .visible(function(d){ return d > .15; })
  39. .innerRadius(2 * this.r / 6.2)
  40. .outerRadius(this.r / 2.2)
  41. .fillStyle(null)
  42. .anchor("center").add(pv.Label)
  43. .textAngle(0)
  44. .text(function(d){ return d.toFixed(2); });
  45. }
  46. })