Commit 90b6c0b9 authored by Mike Bostock's avatar Mike Bostock
Browse files

Instead of bisectBy, replace bisector.

For backwards-compatibility, bisector checks the arity of the specified
function, and if the function only takes a single argument, it is wrapped with a
suitable comparator.
parent 3c7cc81b
......@@ -130,13 +130,13 @@
}
};
}
var d3_bisect = (d3.bisectBy = d3_bisector)(d3_ascending);
var d3_bisect = d3_bisector(d3_ascending);
d3.bisectLeft = d3_bisect.left;
d3.bisect = d3.bisectRight = d3_bisect.right;
d3.bisector = function(f) {
return d3_bisector(function(d, x) {
return d3_bisector(f.length === 1 ? function(d, x) {
return d3_ascending(f(d), x);
});
} : f);
};
d3.shuffle = function(array) {
var m = array.length, t, i;
......
This diff is collapsed.
......@@ -25,12 +25,12 @@ function d3_bisector(compare) {
};
}
var d3_bisect = (d3.bisectBy = d3_bisector)(d3_ascending);
var d3_bisect = d3_bisector(d3_ascending);
d3.bisectLeft = d3_bisect.left;
d3.bisect = d3.bisectRight = d3_bisect.right;
d3.bisector = function(f) {
return d3_bisector(function(d, x) {
return d3_ascending(f(d), x);
});
return d3_bisector(f.length === 1
? function(d, x) { return d3_ascending(f(d), x); }
: f);
};
......@@ -132,11 +132,11 @@ suite.addBatch({
}
},
"bisectBy(comparator)": {
topic: load("arrays/bisect").expression("d3.bisectBy"),
"bisector(comparator)": {
topic: load("arrays/bisect").expression("d3.bisector"),
"left": {
topic: function(bisectBy) {
return bisectBy(function(d, x) { return _.descending(d.key, x); }).left;
topic: function(bisector) {
return bisector(function(d, x) { return _.descending(d.key, x); }).left;
},
"finds the index of an exact match": function(bisect) {
var array = [{key: 3}, {key: 2}, {key: 1}];
......@@ -195,8 +195,8 @@ suite.addBatch({
}
},
"right": {
topic: function(bisectBy) {
return bisectBy(function(d, x) { return _.ascending(d.key, x); }).right;
topic: function(bisector) {
return bisector(function(d, x) { return _.ascending(d.key, x); }).right;
},
"finds the index after an exact match": function(bisect) {
var array = [{key: 1}, {key: 2}, {key: 3}];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment