Skip to content

Commit 0edad18

Browse files
committed
Return undefined, not NaN.
Since the quantile scale allows arbitrary values in the range, there’s no reason the return value for unorderable input needs to be a number.
1 parent 538108b commit 0edad18

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

d3.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7022,8 +7022,7 @@ d3 = function() {
70227022
return scale;
70237023
}
70247024
function scale(x) {
7025-
if (isNaN(x = +x)) return NaN;
7026-
return range[d3.bisect(thresholds, x)];
7025+
if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
70277026
}
70287027
scale.domain = function(x) {
70297028
if (!arguments.length) return domain;

d3.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/scale/quantile.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ function d3_scale_quantile(domain, range) {
1919
}
2020

2121
function scale(x) {
22-
if (isNaN(x = +x)) return NaN;
23-
return range[d3.bisect(thresholds, x)];
22+
if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
2423
}
2524

2625
scale.domain = function(x) {

test/scale/quantile-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ suite.addBatch({
5353
assert.deepEqual([8, 8.9].map(x), [b, b]);
5454
assert.deepEqual([9, 9.1, 10, 13].map(x), [c, c, c, c]);
5555
assert.deepEqual([14.9, 15, 15.1, 16, 20].map(x), [a, a, a, a, a]);
56+
},
57+
"returns undefined if the input value is NaN": function(quantile) {
58+
var x = quantile().domain([3, 6, 7, 8, 8, 10, 13, 15, 16, 20]).range([0, 1, 2, 3]);
59+
assert.isUndefined(x(NaN));
5660
}
5761
}
5862
});

0 commit comments

Comments
 (0)