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 * cut : after this meany items - do not show a pie element?
28 function Piesectorchart(paper, width, height, cx, cy, r, values, opts) {
35 angle = opts.start_angle || 90,
41 opts.barwidth = opts.barwidth || 80;
43 paper.rect(0, 0, width, height).attr({ stroke: "none", fill: (opts.background || "#F0F4F7") });
45 paper.customAttributes.sector = function (cx, cy, startAngle, endAngle, color, R) {
47 var rad = Math.PI / 180,
48 x1 = cx + r * Math.cos(-startAngle * rad),
49 x2 = cx + r * Math.cos(-endAngle * rad),
50 y1 = cy + r * Math.sin(-startAngle * rad),
51 y2 = cy + r * Math.sin(-endAngle * rad),
54 path = [["M", x1, y1], ["A", R, R, 0, +(Math.abs(endAngle - startAngle) > 180), 1, x2, y2]];
56 return {path: path, stroke: color};
61 paper.circle(cx, cy, r + opts.barwidth / 2).attr({ fill: opts.colors && opts.colors[0] || chartinst.colors[0] || "#3E66BC" });
62 paper.circle(cx, cy, r - opts.barwidth / 2).attr({ fill: opts.background || "#F0F4F7" });
66 for (var i = 0; i < len; i++) {
67 total += values[i] * 1;
70 valueOf: function () { return this.value; }
75 values.sort(function (a, b) {
76 return b.value - a.value;
80 for (i = 0; i < len; i++) {
81 if (defcut && values[i] * 360 / total <= 1.5) {
88 values[cut].value += values[i];
89 values[cut].others = true;
93 len = Math.min(cut + 1, values.length);
95 for (i = 0; i < len; i++) {
97 var p = paper.path().attr({
99 "stroke-width": opts.barwidth
100 }).attr({sector: [cx, cy, angle, angle -= 360 * values[i] / total, opts.colors && opts.colors[i] || chartinst.colors[i], r]});
106 var ix = cx + r + opts.barwidth / 2 + 30,
109 for (var i = 0; i < len; i++) {
111 paper.circle(ix, iy, 6).attr({ fill: opts.colors && opts.colors[i] || chartinst.colors[i] || "#3E66BC" });
113 var text = (values[i].others) ? opts.others : opts.legend[i] || values[i];
115 if(text.indexOf('#%#') !== -1) {
116 text = text.replace('#%#', Math.round(values[i] / total * 100) + '%');
119 paper.text(ix + 20, iy, text).attr({
121 "font-family": "'Fontin Sans', Fontin-Sans, sans-serif",
122 "text-anchor": "start",
137 var F = function() {};
138 F.prototype = Raphael.g;
139 Piesectorchart.prototype = new F;
142 Raphael.fn.piesectorchart = function(width, height, cx, cy, r, values, opts) {
143 return new Piesectorchart(this, width, height, cx, cy, r, values, opts);