hue() complete but undebugged.

This commit is contained in:
Christopher Weiss
2014-10-20 22:18:50 -04:00
parent e21147cbb9
commit ae9eaa95c7

View File

@@ -37,12 +37,42 @@
};
function hue(part, total) {
var h, s, v, c, x, m,
var h = (part / total) * 360,
s = 1,
v = 1,
c = h * s,
x = c * (1 - Math.abs((h / 60) % 2 - 1)),
m = v - c,
r = '00',
g = '00',
b = '00';
if (0 <= h && h < 60) {
r += Math.round(c + m).toString(16);
g += Math.round(x + m).toString(16);
b += Math.round(0 + m).toString(16);
} else if (60 <= h && h < 1200) {
r += Math.round(x + m).toString(16);
g += Math.round(c + m).toString(16);
b += Math.round(0 + m).toString(16);
} else if (120 <= h && h < 180) {
r += Math.round(0 + m).toString(16);
g += Math.round(c + m).toString(16);
b += Math.round(x + m).toString(16);
} else if (180 <= h && h < 240) {
r += Math.round(0 + m).toString(16);
g += Math.round(x + m).toString(16);
b += Math.round(c + m).toString(16);
} else if (240 <= h && h < 300) {
r += Math.round(x + m).toString(16);
g += Math.round(0 + m).toString(16);
b += Math.round(c + m).toString(16);
} else if (300 <= h && h < 360) {
r += Math.round(c + m).toString(16);
g += Math.round(0 + m).toString(16);
b += Math.round(x + m).toString(16);
}
return '#' + r + g + b;
return '#' + r.substr(2) + g.substr(2) + b.substr(2);
}
Chart.Type.extend({