* Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com)
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
*/
+Raphael = typeof(Raphael) != 'undefined' ? Raphael : (imports ? imports.seed.Raphael.Raphael : {});
+Roo = typeof(Roo) != 'undefined' ? Roo: (imports ? imports.seed.Roo.Roo: {});
+//chartinst = typeof(chartinst) != 'undefined' ? chartinst: (imports ? imports.chartinst.chartinst : {});
+
+
+
(function () {
+ /**
+ * @param {Raphael} paper to draw on
+ * @param {int} cx - centre X
+ * @param {int} cy - centre Y
+ * @param {int} r - radius
+ * @param {Array} values
+ * @param {Object} opts options
+ * cut : after this meany items - do not show a pie element?
+ *
+ *
+ *
+ */
+
function Piechart(paper, cx, cy, r, values, opts) {
+
opts = opts || {};
var chartinst = this,
others = 0,
cut = opts.cut || 9,
defcut = true;
-
+
function sector(cx, cy, r, startAngle, endAngle, fill) {
var rad = Math.PI / 180,
x1 = cx + r * Math.cos(-startAngle * rad),
"A", r, r, 0, +(Math.abs(endAngle - startAngle) > 180), 1, x2, y2,
"z"
];
- Roo.log(cx);
- Roo.log(cy);
- Roo.log(r);
- Roo.log(startAngle);
- Roo.log(endAngle);
-
- Roo.log(Math.cos(-startAngle * rad));
- Roo.log(Math.cos(-endAngle * rad));
- Roo.log(Math.cos(-(startAngle + (endAngle - startAngle) / 2) * rad));
-
- Roo.log(Math.sin(-startAngle * rad));
- Roo.log(Math.sin(-endAngle * rad));
-
+
res.middle = { x: xm, y: ym };
return res;
}
chart.covers = covers;
-
+
if (len == 1) {
- series.push(paper.circle(cx, cy, r).attr({ fill: chartinst.colors[0], stroke: opts.stroke || "#fff", "stroke-width": opts.strokewidth == null ? 1 : opts.strokewidth }));
+ series.push(paper.circle(cx, cy, r).attr({ fill: opts.colors && opts.colors[0] || chartinst.colors[0] || "#666", stroke: opts.stroke || "#fff", "stroke-width": opts.strokewidth == null ? 1 : opts.strokewidth }));
covers.push(paper.circle(cx, cy, r).attr(chartinst.shim));
- total = values[0];
+ total = values[0] * 1;
values[0] = { value: values[0], order: 0, valueOf: function () { return this.value; } };
series[0].middle = {x: cx, y: cy};
series[0].mangle = 180;
} else {
for (var i = 0; i < len; i++) {
- total += values[i];
- values[i] = { value: values[i], order: i, valueOf: function () { return this.value; } };
+ total += values[i] * 1;
+ values[i] = {
+ value: values[i],
+ order: i,
+ valueOf: function () { return this.value; }
+ };
}
+ //Roo.log(total);
if (!opts.no_sort) {
values.sort(function (a, b) {
return b.value - a.value;
others = values[cut].value;
}
}
-
+
len = Math.min(cut + 1, values.length);
others && values.splice(len) && (values[cut].others = true);
angle = opts.start_angle;
}
- Roo.log('start angle: ' + angle);
+ //Roo.log('start angle: ' + angle);
mangle = angle - 360 * values[i] / total / 2;
}
var x = cx + r + r / 5,
y = cy,
h = y + 10;
-
+
labels = labels || [];
dir = (dir && dir.toLowerCase && dir.toLowerCase()) || "east";
mark = paper[mark && mark.toLowerCase()] || "circle";
labels[j] = chartinst.labelise(labels[j], values[i], total);
chart.labels.push(paper.set());
chart.labels[i].push(paper[mark](x + 5, h, 5).attr({ fill: clr, stroke: "none" }));
- chart.labels[i].push(txt = paper.text(x + 20, h, labels[j] || values[j]).attr(chartinst.txtattr).attr({ fill: opts.legendcolor || "#000", "text-anchor": "start"}));
+ chart.labels[i].push(
+ txt = paper.text(x + 20, h, labels[j] || values[j]).attr(chartinst.txtattr).attr({ fill: opts.legendcolor || "#000", "text-anchor": "start"}));
covers[i].label = chart.labels[i];
+ // Roo.log(JSON.stringify(txt.getBBox()));
h += txt.getBBox().height * 1.2;
}