Skip to content

Instantly share code, notes, and snippets.

@adamgreenhall
Forked from mbostock/.block
Created August 8, 2012 17:50
Show Gist options
  • Save adamgreenhall/3297039 to your computer and use it in GitHub Desktop.
Save adamgreenhall/3297039 to your computer and use it in GitHub Desktop.
D3 and Custom Data Attributes
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.4.6"></script>
</head>
<body>
<ul id="list">
<li data-username="shawnbot">Shawn Allen</li>
<li data-username="mbostock">Mike Bostock</li>
</ul>
<script type="text/javascript">
d3.selectAll("#list li")
.map(function() { return this.dataset; })
.sort(function(a, b) { return d3.ascending(a.username, b.username); });
console.log( d3.selectAll("#list li").map(function() { return this.dataset; }) );
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment