From: Christopher Weiss Date: Tue, 21 Oct 2014 02:18:50 +0000 (-0400) Subject: hue() complete but undebugged. X-Git-Tag: v2.0-alpha~47^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae9eaa95c7634fcdb7684f650a050692a3f96b3c;p=thirdparty%2FChart.js.git hue() complete but undebugged. --- diff --git a/src/Chart.Doughnut.js b/src/Chart.Doughnut.js index 0dab405c8..dc69cd53f 100644 --- a/src/Chart.Doughnut.js +++ b/src/Chart.Doughnut.js @@ -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({