Created
January 17, 2017 00:32
-
-
Save gunn/49919c316ebea97d56c31955a607f11f to your computer and use it in GitHub Desktop.
D3 nest.sortKeys example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Nest Test</title> | |
</head> | |
<body> | |
<h3>Sorted?</h3> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script> | |
var dates = Array(10).fill(0).map((_, i)=> new Date(i*10000000000 + +new Date())) | |
var itemsWithDates = dates.map(d=> ({date: d})) | |
const nest = d3.nest() | |
.key(d=> d.date) | |
.sortKeys(d3.descending) | |
.entries(itemsWithDates) | |
var sortedDates = nest.map(d=>d.values[0].date) | |
d3.select("body").append("ul") | |
.data(sortedDates) | |
.enter() | |
.append("li") | |
.text(d=> d.toLocaleDateString()) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment