<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script>
<script type="text/javascript" src="//d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/cal-heatmap/3.3.10/cal-heatmap.min.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/cal-heatmap/3.3.10/cal-heatmap.css" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Calendar Flip</title>
</head>
<body>
<button id="example-g-PreviousDomain-selector" style="margin-bottom: 10px;" class="btn"><i class="icon icon-chevron-left"></i></button>
<button id="example-g-NextDomain-selector" style="margin-bottom: 10px;" class="btn"><i class="icon icon-chevron-right"></i></button>
<div id="cal"></div>
</body>
</html>
// global data variable
var data = null;
// Convert running log JSON data into readable format for heatmap calendar
function convertRunningLog() {
// set get URL
var json_url = "https://raw.githubusercontent.com/kylesb/static/master/JSON/running_log.json";
// declare object variable
var ob = {};
// Get running log file from repository
$.getJSON(json_url, function(result){
// for each data entry
for (var i = 0; i < result.data.length; i++) {
// get date and miles
var apoche = date_to_epoch(result['data'][i]['date']).toString();
var miles = parseFloat(result['data'][i]['miles']);
// set date and miles
ob[apoche.toString()] = miles;
}
var json_string = JSON.stringify(ob);
data = JSON.parse(json_string);
console.log(data);
return data;
});
}
// Convert strings to date objects
function date_to_epoch(key) {
var epoch_seconds = new Date(key).getTime();
return Math.floor (epoch_seconds / 1000);
}
// initilize the calendar
// ------------------------
var cal = new CalHeatMap();
cal.init({
itemSelector: "#cal",
domain: "month",
subDomain: "x_day",
data: convertRunningLog(),
start: new Date(2016, 0, 5),
cellSize: 20,
cellPadding: 5,
domainGutter: 20,
range: 1,
domainDynamicDimension: false,
previousSelector: "#example-g-PreviousDomain-selector",
nextSelector: "#example-g-NextDomain-selector",
subDomainTextFormat: "%d",
legend: [0.5, 1, 1.5, 2]
});
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |