Skip to content

Commit 90b6c0b

Browse files
committed
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.
1 parent 3c7cc81 commit 90b6c0b

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

d3.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@
130130
}
131131
};
132132
}
133-
var d3_bisect = (d3.bisectBy = d3_bisector)(d3_ascending);
133+
var d3_bisect = d3_bisector(d3_ascending);
134134
d3.bisectLeft = d3_bisect.left;
135135
d3.bisect = d3.bisectRight = d3_bisect.right;
136136
d3.bisector = function(f) {
137-
return d3_bisector(function(d, x) {
137+
return d3_bisector(f.length === 1 ? function(d, x) {
138138
return d3_ascending(f(d), x);
139-
});
139+
} : f);
140140
};
141141
d3.shuffle = function(array) {
142142
var m = array.length, t, i;

d3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/arrays/bisect.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ function d3_bisector(compare) {
2525
};
2626
}
2727

28-
var d3_bisect = (d3.bisectBy = d3_bisector)(d3_ascending);
28+
var d3_bisect = d3_bisector(d3_ascending);
2929
d3.bisectLeft = d3_bisect.left;
3030
d3.bisect = d3.bisectRight = d3_bisect.right;
3131

3232
d3.bisector = function(f) {
33-
return d3_bisector(function(d, x) {
34-
return d3_ascending(f(d), x);
35-
});
33+
return d3_bisector(f.length === 1
34+
? function(d, x) { return d3_ascending(f(d), x); }
35+
: f);
3636
};

test/arrays/bisect-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ suite.addBatch({
132132
}
133133
},
134134

135-
"bisectBy(comparator)": {
136-
topic: load("arrays/bisect").expression("d3.bisectBy"),
135+
"bisector(comparator)": {
136+
topic: load("arrays/bisect").expression("d3.bisector"),
137137
"left": {
138-
topic: function(bisectBy) {
139-
return bisectBy(function(d, x) { return _.descending(d.key, x); }).left;
138+
topic: function(bisector) {
139+
return bisector(function(d, x) { return _.descending(d.key, x); }).left;
140140
},
141141
"finds the index of an exact match": function(bisect) {
142142
var array = [{key: 3}, {key: 2}, {key: 1}];
@@ -195,8 +195,8 @@ suite.addBatch({
195195
}
196196
},
197197
"right": {
198-
topic: function(bisectBy) {
199-
return bisectBy(function(d, x) { return _.ascending(d.key, x); }).right;
198+
topic: function(bisector) {
199+
return bisector(function(d, x) { return _.ascending(d.key, x); }).right;
200200
},
201201
"finds the index after an exact match": function(bisect) {
202202
var array = [{key: 1}, {key: 2}, {key: 3}];

0 commit comments

Comments
 (0)