D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
BenHeubl
Full window
Github gist
function_minutes_into_Time
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } svg { width:100%; height: 100% } </style> </head> <body> <script> function minutesToTime(m) { var minutes = (m + 4*60) % 1440; var hh = Math.floor(minutes / 60); var ampm; if (hh > 12) { hh = hh - 12; ampm = "pm"; } else if (hh == 12) { ampm = "pm"; } else if (hh == 0) { hh = 12; ampm = "am"; } else { ampm = "am"; } var mm = minutes % 60; if (mm < 10) { mm = "0" + mm; } return hh + ":" + mm + ampm } console.log(minutesToTime(10000)) function readablePercent(n) { var pct = 100 * n / 1000; if (pct < 1 && pct > 0) { pct = "<1%"; } else { pct = Math.round(pct) + "%"; } return pct; } console.log(readablePercent(132)) // 13% function color(activity) { var colorByActivity = { "0": "#e0d400", "1": "#1c8af9", "2": "#51BC05", "3": "#FF7F00", "4": "#DB32A4", "5": "#00CDF8", "6": "#E63B60", "7": "#8E5649", "8": "#68c99e", "9": "#a477c8", "10": "#5C76EC", "11": "#E773C3", "12": "#799fd2", "13": "#038a6c", "14": "#cc87fa", "15": "#ee8e76", "16": "#bbbbbb", } return colorByActivity[activity]; } console.log(color("Sleeping")) </script> </body>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js