Raphael Pie Demo
This Demo is taken without any changes from Raphael Example page - http://raphaeljs.com/pie.html
by kuyabiye
HTML
<script src="http://piotr.zalewa.info/downloads/raphael.js"></script>
<table>
<tr>
<th>Ruby</th>
<td>40%</td>
</tr>
<tr>
<th>JavaScript</th>
<td>26%</td>
</tr>
<tr>
<th>Shell</th>
<td>5%</td>
</tr>
<tr>
<th>Python</th>
<td>5%</td>
</tr>
<tr>
<th>PHP</th>
<td>4%</td>
</tr>
<tr>
<th>C</th>
<td>4%</td>
</tr>
<tr>
<th>Perl</th>
<td>3%</td>
</tr>
<tr>
<th>C++</th>
<td>2%</td>
</tr>
<tr>
<th>Java</th>
<td>2%</td>
</tr>
<tr>
<th>Objective-C</th>
<td>2%</td>
</tr>
</table>
<div id="holder"></div>
<p id="copy">Demo of <a href="http://raphaeljs.com/" target="_blank">Raphaël</a>—JavaScript Vector Library</p>
CSS
/* A font by Jos Buivenga (exljbris) -> www.exljbris.nl */
@font-face {
font-family: "Fontin-Sans";
src: url(fontin-sans.otf) format("opentype");
}
body {
background: #000 url(images/black.png);
color: #fff;
font: 300 100.1% Fontin-Sans, "Gill Sans", Calibri, "Trebuchet MS", sans-serif;
}
#holder {
height: 480px;
left: 50%;
margin: -240px 0 0 -320px;
position: absolute;
top: 50%;
width: 640px;
}
#copy {
bottom: 0;
font: 300 .7em Fontin-Sans, "Gill Sans", Calibri, "Trebuchet MS", sans-serif;
position: absolute;
right: 1em;
text-align: right;
}
#copy a {
color: #fff;
}
#holder {
margin: -350px 0 0 -350px;
width: 700px;
height: 700px;
}
JavaScript
/**
This Demo is taken without any changes from
Raphael Example page - http://raphaeljs.com/pie.html
*/
Raphael.fn.pieChart = function (cx, cy, r, values, labels, stroke) {
var paper = this,
rad = Math.PI / 180,
chart = this.set();
function sector(cx, cy, r, startAngle, endAngle, params) {
var x1 = cx + r * Math.cos(-startAngle * rad),
x2 = cx + r * Math.cos(-endAngle * rad),
y1 = cy + r * Math.sin(-startAngle * rad),
y2 = cy + r * Math.sin(-endAngle * rad);
return paper.path(["M", cx, cy, "L", x1, y1, "A", r, r, 0, +(endAngle - startAngle > 180), 0, x2, y2, "z"]).attr(params);
}
var angle = 0,
total = 0,
start = 0,
process = function (j) {
var value = values[j],
angleplus = 360 * value / total,
popangle = angle + (angleplus / 2),
color = "hsb(" + start + ", 1, .5)",
ms = 500,
delta = 30,
bcolor = "hsb(" + start + ", 1, 1)",
p = sector(cx, cy, r, angle, angle + angleplus, {gradient: "90-" + bcolor + "-" + color, stroke: stroke, "stroke-width": 3}),
txt = paper.text(cx + (r + delta + 55) * Math.cos(-popangle * rad), cy + (r + delta + 25) * Math.sin(-popangle * rad), labels[j]).attr({fill: bcolor, stroke: "none", opacity: 0, "font-family": 'Fontin-Sans, Arial', "font-size": "20px"});
p.mouseover(function () {
p.animate({scale: [1.1, 1.1, cx, cy]}, ms, "elastic");
txt.animate({opacity: 1}, ms, "elastic");
}).mouseout(function () {
p.animate({scale: [1, 1, cx, cy]}, ms, "elastic");
txt.animate({opacity: 0}, ms);
});
angle += angleplus;
chart.push(p);
chart.push(txt);
start += .1;
};
for (var i = 0, ii = values.length; i < ii; i++) {
total +=...