2 * g.Raphael 0.5 - Charting library, based on Raphaƫl
4 * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com)
5 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
7 Raphael = typeof(Raphael) != 'undefined' ? Raphael : (imports ? imports.seed.Raphael.Raphael : {});
8 Roo = typeof(Roo) != 'undefined' ? Roo: (imports ? imports.seed.Roo.Roo: {});
9 //chartinst = typeof(chartinst) != 'undefined' ? chartinst: (imports ? imports.chartinst.chartinst : {});
16 * @param {Raphael} paper to draw on
17 * @param {int} cx - centre X
18 * @param {int} cy - centre Y
19 * @param {int} r - radius
20 * @param {Array} values
21 * @param {Object} opts options
22 * background (string) : background color
23 * colors (array) : colors of the pies
24 * borderwidth (number) : width of circle border
25 * labelfont (string) : font family of labels
26 * labelsize (number) : font size of labels
27 * labelweight (string) (number) : font weight of labels
28 * labelcolor (string) : font color of the labels
29 * linewidth (number) : width of the lines connecting the legend and the circles
30 * lineheight (number) : height of the lines connecting the legend and the circles
31 * legend (array) : legend
32 * legendfont (string) : font family of the legend labels
33 * legendfontsize (number) : font size of the legend labels
34 * legendfontcolor (string) : font color of the legend colors
38 function Piecircularchart(paper, width, height, cx, cy, r, values, opts) {
45 borderWidth = typeof(opts.borderwidth) != 'undefined' ? opts.borderwidth : 2, // width can be 0 (no border)
46 labelFont = opts.labelfont || "'Fontin Sans', Fontin-Sans, sans-serif",
47 labelSize = opts.labelsize || 18,
48 labelWeight = opts.labelweight || 'bold',
49 labelColor = opts.labelcolor || '#FFFFFF',
50 lineWidth = opts.linewidth || 200,
51 lineHeight = opts.lineheight || 2,
52 lineColor = opts.linecolor || '#FFFFFF',
53 legendFont = opts.legendfont || "'Fontin Sans', Fontin-Sans, sans-serif",
54 legendFontSize = opts.legendfontsize || 18,
55 legendFontColor = opts.legendfontcolor || '#0C024B';
57 paper.rect(0, 0, width, height).attr({ stroke: "none", fill: (opts.background || "#F0F4F7") });
59 for (var i = 0; i < len; i++) {
63 valueOf: function () { return this.value; }
67 values.sort(function (a, b) {
68 return b.value - a.value;
71 // dx, dy: position of the center of the circle
72 // dr: radius of the circle
77 for (i = 0; i < len; i++) {
79 paper.circle(dx, dy, dr).attr({ fill: opts.colors && opts.colors[i] || chartinst.colors[i] || "#3E66BC", stroke: "#fff", "stroke-width": borderWidth });
81 // nx, ny: position of the label
89 paper.text(nx, ny, Roo.util.Format.number(values[i], 0)).attr({
90 "font-size": labelSize,
91 "font-family": labelFont,
92 "font-weight": labelWeight,
93 "text-anchor": "middle",
97 paper.path(["M", dx, dy - dr, "l", lineWidth, 0]).attr({ stroke: lineColor, "stroke-width": lineHeight });
99 paper.text(dx + lineWidth + 10, dy - dr, opts.legend[values[i].origin]).attr({
100 "font-size": legendFontSize,
101 "font-family": legendFont,
102 "text-anchor": "start",
103 fill : legendFontColor
107 dr = Math.round(dr / 4);
118 var F = function() {};
119 F.prototype = Raphael.g;
120 Piecircularchart.prototype = new F;
123 Raphael.fn.piecircularchart = function(width, height, cx, cy, r, values, opts) {
124 return new Piecircularchart(this, width, height, cx, cy, r, values, opts);