summaryrefslogtreecommitdiff
path: root/colordate.js
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-03-14 18:18:31 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2018-03-17 13:49:41 -0400
commitb54a1c9686eec3c1114e9b58cb67679ba59c45bd (patch)
tree0bdb2f3ed51ff077a8c3e337e4bc556aacec108e /colordate.js
parent54feeb027d6e5a760b49769dfe695ea2591dc6fe (diff)
directories
Diffstat (limited to 'colordate.js')
-rw-r--r--colordate.js41
1 files changed, 0 insertions, 41 deletions
diff --git a/colordate.js b/colordate.js
deleted file mode 100644
index e5331eb..0000000
--- a/colordate.js
+++ /dev/null
@@ -1,41 +0,0 @@
-(function() {
- // in milliseconds
- var now = Date.now();
- var oneday = 1000*60*60*24;
-
- // maps from a point on iRange to a point on oRange
- var mapRange = function(iRange, oRange, iPoint) {
- var pct = (iPoint - iRange[0])/(iRange[1]-iRange[0]);
- if (pct < 0) {
- pct = 0;
- } else if (pct > 1) {
- pct = 1;
- }
- var oPoint = oRange[0] + (pct * (oRange[1]-oRange[0]));
- return oPoint;
- }
-
-
- var rgb = function(r, g, b) {
- return "rgb(" + Math.trunc(r) + "," + Math.trunc(g) + "," + Math.trunc(b) + ")";
- };
-
- var date2color = function(t) {
- var max = 0xFF;
- var red = mapRange([now-oneday, now-(oneday/2)],
- [max, 0],
- t);
- var green = mapRange([now-(oneday/2), now],
- [0, max],
- t);
- return rgb(max-green, max-red, max-green-red);
- };
-
- var main = function() {
- document.querySelectorAll('time.daily').forEach(function(time) {
- time.style.backgroundColor = date2color(Date.parse(time.dateTime));
- });
- };
-
- document.addEventListener("DOMContentLoaded", main, false);
-})();