diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-02-06 19:24:36 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-02-06 19:24:36 -0500 |
commit | e2b6ec92921a2d43f77015f0e75c362a03430e76 (patch) | |
tree | 9eaabf1e7d1f17c575d6156da8f93aadd807ed5f /colordate.js | |
parent | 2692e95db86b454a92e760446bb4e1424f79e461 (diff) |
Move some go stuff into a shared 'util'.
Diffstat (limited to 'colordate.js')
-rw-r--r-- | colordate.js | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/colordate.js b/colordate.js index a228eb5..22be25b 100644 --- a/colordate.js +++ b/colordate.js @@ -3,7 +3,8 @@ var now = Date.now(); var oneday = 1000*60*60*24; - var mapTo = function(iRange, oRange, iPoint) { + // 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; @@ -21,17 +22,17 @@ var date2color = function(t) { var max = 0xF3; - var red = mapTo([now-oneday, now-(oneday/2)], + var red = mapRange([now-oneday, now-(oneday/2)], [max, 0], t); - var green = mapTo([now-(oneday/2), now], + 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.colordate').forEach(function(time) { + document.querySelectorAll('time.daily').forEach(function(time) { time.style.backgroundColor = date2color(Date.parse(time.dateTime)); }); }; |