client/js/main.js
changeset 472 6dcff4438175
parent 471 e0c7be5dc02c
parent 461 48235ed6b07d
child 482 a55c33989404
--- a/client/js/main.js	Wed Jun 03 17:27:46 2015 +0200
+++ b/client/js/main.js	Fri Jun 05 12:17:16 2015 +0200
@@ -562,6 +562,25 @@
                 top: (_options.tooltip_padding + _top)
             });
             return _path;
+        },
+        // from http://stackoverflow.com/a/6444043
+        increaseBrightness: function (hex, percent){
+            // strip the leading # if it's there
+            hex = hex.replace(/^\s*#|\s*$/g, '');
+
+            // convert 3 char codes --> 6, e.g. `E0F` --> `EE00FF`
+            if(hex.length === 3){
+                hex = hex.replace(/(.)/g, '$1$1');
+            }
+
+            var r = parseInt(hex.substr(0, 2), 16),
+                g = parseInt(hex.substr(2, 2), 16),
+                b = parseInt(hex.substr(4, 2), 16);
+
+            return '#' +
+               ((0|(1<<8) + r + (256 - r) * percent / 100).toString(16)).substr(1) +
+               ((0|(1<<8) + g + (256 - g) * percent / 100).toString(16)).substr(1) +
+               ((0|(1<<8) + b + (256 - b) * percent / 100).toString(16)).substr(1);
         }
     };
 })(window);