forked from mbostock's block: selection.order
Created
January 21, 2016 15:35
-
-
Save anonymous/8ad986db8b3f5cc82e69 to your computer and use it in GitHub Desktop.
selection.order
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> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> | |
</head> | |
<body> | |
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.6.0"></script> | |
<script type="text/javascript"> | |
d3.selection.prototype.order = function() { | |
for (var j = 0, m = this.length; j < m; j++) { | |
for (var group = this[j], i = 1, n = group.length, prev = group[0]; i < n; i++) { | |
var node = group[i]; | |
if (node) { | |
if (prev) prev.parentNode.insertBefore(node, prev.nextSibling); | |
prev = node; | |
} | |
} | |
} | |
return this; | |
}; | |
var div = d3.select("body").selectAll("div") | |
.data([0, 10, 11, 4, 6, 12]) | |
.enter().append("div") | |
.text(String); | |
var div = d3.select("body").selectAll("div") | |
.data([0, 1, 2, 10, 11, 12], String); | |
div.enter().append("div") | |
.text(String); | |
div.order().exit().remove(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment