/** * Copyright (c) 2009 Chris Leonello * jqPlot is currently available for use in all personal or commercial projects * under both the MIT and GPL version 2.0 licenses. This means that you can * choose the license that best suits your project and use it accordingly. * * The author would appreciate an email letting him know of any substantial * use of jqPlot. You can reach the author at: chris dot leonello at gmail * dot com or see http://www.jqplot.com/info.php . This is, of course, * not required. * * If you are feeling kind and generous, consider supporting the project by * making a donation at: http://www.jqplot.com/donate.php . * * Thanks for using jqPlot! * */ (function($) { /** * Class: $.jqplot.PieRenderer * Plugin renderer to draw a pie chart. * Pie charts will draw only the first series. Other series are ignored. * x values, if present, will be used as slice labels. * y values give slice size. */ $.jqplot.PieRenderer = function(){ $.jqplot.LineRenderer.call(this); }; $.jqplot.PieRenderer.prototype = new $.jqplot.LineRenderer(); $.jqplot.PieRenderer.prototype.constructor = $.jqplot.PieRenderer; // called with scope of a series $.jqplot.PieRenderer.prototype.init = function(options) { // Group: Properties // // prop: diameter // diameter of the pie, auto computed by default this.diameter = null; // prop: padding // padding between the pie and plot edges, legend, etc. this.padding = 20; // prop: sliceMargin // pixels spacing between pie slices. this.sliceMargin = 0; // prop: fill // true or false, wether to fil the slices. this.fill = true; // prop: shadowOffset // offset of the shadow from the slice and offset of // each succesive stroke of the shadow from the last. this.shadowOffset = 2; // prop: shadowAlpha // transparency of the shadow (0 = transparent, 1 = opaque) this.shadowAlpha = 0.07; // prop: shadowDepth // number of strokes to apply to the shadow, // each stroke offset shadowOffset from the last. this.shadowDepth = 5; this.tickRenderer = $.jqplot.PieTickRenderer; $.extend(true, this, options); if (this.diameter != null) { this.diameter = this.diameter - this.sliceMargin; } this._diameter = null; }; $.jqplot.PieRenderer.prototype.setGridData = function(plot) { // this is a no-op }; $.jqplot.PieRenderer.prototype.makeGridData = function(data, plot) { var stack = []; var td = []; for (var i=0; i0) { stack[i] += stack[i-1]; } } var fact = Math.PI*2/stack[stack.length - 1]; for (var i=0; i 6.282) { ang2 = 6.282; if (ang1 > ang2) { ang1 = 6.281; } } ctx.beginPath(); ctx.moveTo(0, 0); ctx.fillStyle = color; ctx.strokeStyle = color; ctx.lineWidth = lineWidth; ctx.arc(0, 0, r, ang1, ang2, false); ctx.closePath(); if (fill) { ctx.fill(); } else { ctx.stroke(); } } if (isShadow) { for (var i=0; i'); var pad = false; var s = series[0]; var colorGenerator = new s.colorGenerator(s.seriesColors); if (s.show) { var pd = s.data; for (var i=0; i