Skip to content

Instantly share code, notes, and snippets.

@jimmyjacobson
Created March 7, 2013 23:37
Show Gist options
  • Save jimmyjacobson/5112891 to your computer and use it in GitHub Desktop.
Save jimmyjacobson/5112891 to your computer and use it in GitHub Desktop.
var _draw = function() {
var angle = 90,
total = 0,
start = 0,
stroke = Raphael.rgb(52,125,168),
process = function (j) {
if(j == voted){
color = Raphael.rgb(235,194,0);
} else {
color = Raphael.rgb(200,200,200);
}
var value = values[j],
angleplus = 360 * value / total,
popangle = angle + (angleplus / 2),
ms = 800,
delta = 30,
p = _sector(cx, cy, r, angle, angle + angleplus, {fill: color, stroke: stroke, "stroke-width": 4}),
txt = paper.text(cx + (r + delta - 70) * Math.cos(-popangle * rad), cy + (r + delta - 70) * Math.sin(-popangle * rad), values[j]).attr({fill: stroke, stroke: "none", opacity: 1, "font-size": 24, "font-family": "futura-pt"});
p.mouseover(function () {
p.stop().animate({transform: "s1.1 1.1 " + cx + " " + cy}, ms, "elastic");
txt.stop().animate({opacity: 1}, ms / 4, "ease-in-out");
}).mouseout(function () {
p.stop().animate({transform: ""}, ms / 2, "ease-in-out");
txt.stop().animate({opacity: 1}, ms);
});
angle += angleplus;
chart.push(p);
chart.push(txt);
};
for (var i = 0, ii = values.length; i < ii; i++) {
total += values[i];
}
for (i = 0; i < ii; i++) {
process(i);
}
return chart;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment