]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
hue() complete but undebugged.
authorChristopher Weiss <cmweiss@gmail.com>
Tue, 21 Oct 2014 02:18:50 +0000 (22:18 -0400)
committerChristopher Weiss <cmweiss@gmail.com>
Tue, 21 Oct 2014 02:18:50 +0000 (22:18 -0400)
src/Chart.Doughnut.js

index 0dab405c8c3ccf73c450e387bb1ada0d011136e9..dc69cd53fbca731d7c1ffc46ca9104b4d113379d 100644 (file)
        };
 
        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({