-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's like selection.sort, except it assumes that the data is already sorted; the elements are reordered to match the selection.
- Loading branch information
Showing
7 changed files
with
83 additions
and
19 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> | ||
</head> | ||
<body> | ||
<script type="text/javascript" src="../../d3.js"></script> | ||
<script type="text/javascript"> | ||
|
||
var div = d3.select("body").selectAll("div") | ||
.data(["a", "b", "f"]) | ||
.enter().append("div") | ||
.text(String); | ||
|
||
var div = d3.select("body").selectAll("div") | ||
.data(["a", "b", "c", "d", "e", "f"], String); | ||
|
||
div.enter().append("div") | ||
.text(String); | ||
|
||
div.order(); | ||
|
||
</script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
d3_selectionPrototype.order = function() { | ||
for (var j = -1, m = this.length; ++j < m;) { | ||
for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0;) { | ||
if (node = group[i]) { | ||
if (next) next.parentNode.insertBefore(node, next); | ||
next = node; | ||
} | ||
} | ||
} | ||
return this; | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require("../env"); | ||
require("../../d3"); | ||
|
||
var vows = require("vows"), | ||
assert = require("assert"); | ||
|
||
var suite = vows.describe("selection.order"); | ||
|
||
suite.addBatch({ | ||
"selectAll(div)": { | ||
topic: function() { | ||
return d3.select("body").html("").selectAll("div") | ||
.data([1, 2, 10, 20]) | ||
.enter().append("div") | ||
.attr("id", String); | ||
}, | ||
"orders elements by data": function(div) { | ||
div = div.data([1, 10, 20, 2], String).order(); | ||
assert.domNull(div[0][0].previousSibling); | ||
assert.domEqual(div[0][1].previousSibling, div[0][0]); | ||
assert.domEqual(div[0][2].previousSibling, div[0][1]); | ||
assert.domEqual(div[0][3].previousSibling, div[0][2]); | ||
assert.domNull(div[0][3].nextSibling); | ||
}, | ||
"returns the current selection": function(span) { | ||
span = d3.select("body"); // https://github.com/tmpvar/jsdom/issues/277 | ||
assert.isTrue(span.order() === span); | ||
} | ||
} | ||
}); | ||
|
||
suite.export(module); |