Skip to content

Instantly share code, notes, and snippets.

@gordonwoodhull
Last active September 13, 2016 08:06
Show Gist options
  • Save gordonwoodhull/0cf07401e336e3453cfeb343cc30ef10 to your computer and use it in GitHub Desktop.
Save gordonwoodhull/0cf07401e336e3453cfeb343cc30ef10 to your computer and use it in GitHub Desktop.
fresh block
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.12/crossfilter.js"></script>
<script src="http://dc-js.github.io/dc.js/js/d3.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
test_data = [{date: d3.time.format("%Y-%m-%dT%H:%M:%S+0100").parse("2014-11-24T12:00:00+0100").getTime(), cnt: 1},
{date: d3.time.format("%Y-%m-%dT%H:%M:%S+0100").parse("2014-11-24T11:00:00+0100").getTime(), cnt: 2},
{date: d3.time.format("%Y-%m-%dT%H:%M:%S+0100").parse("2014-11-24T12:00:00+0100").getTime(), cnt: 3}],
test_ndx = crossfilter(test_data),
test_dim = test_ndx.dimension(function(d) { return d.date; }),
test_grp = test_dim.group(function(d) { return -new Date(d).getHours(); });
console.log(test_grp.all())
simp_grp = test_dim.group();
console.log(simp_grp.all().map(function(kv) { return new Date(kv.key)}))
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment