Skip to content

Commit a0fa7a0

Browse files
committed
Tolerate empty domains. Fixes d3#115.
1 parent 770b24c commit a0fa7a0

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

d3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,12 +844,12 @@ d3.interpolators = [
844844
function(a, b) { return (typeof b === "number") && d3.interpolateNumber(+a, b); }
845845
];
846846
function d3_uninterpolateNumber(a, b) {
847-
b = 1 / (b - (a = +a));
847+
b = b - (a = +a) ? 1 / (b - a) : 0;
848848
return function(x) { return (x - a) * b; };
849849
}
850850

851851
function d3_uninterpolateClamp(a, b) {
852-
b = 1 / (b - (a = +a));
852+
b = b - (a = +a) ? 1 / (b - a) : 0;
853853
return function(x) { return Math.max(0, Math.min(1, (x - a) * b)); };
854854
}
855855
d3.rgb = function(r, g, b) {

d3.min.js

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

src/core/uninterpolate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
function d3_uninterpolateNumber(a, b) {
2-
b = 1 / (b - (a = +a));
2+
b = b - (a = +a) ? 1 / (b - a) : 0;
33
return function(x) { return (x - a) * b; };
44
}
55

66
function d3_uninterpolateClamp(a, b) {
7-
b = 1 / (b - (a = +a));
7+
b = b - (a = +a) ? 1 / (b - a) : 0;
88
return function(x) { return Math.max(0, Math.min(1, (x - a) * b)); };
99
}

test/scale/linear-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ suite.addBatch({
4242
assert.equal(x(-5), "rgb(255,128,128)");
4343
assert.equal(x(50), "rgb(128,192,128)");
4444
assert.equal(x(75), "rgb(64,160,64)");
45+
},
46+
"an empty domain maps to the range start": function(linear) {
47+
var x = linear().domain([0, 0]).range(["red", "green"]);
48+
assert.equal(x(0), "rgb(255,0,0)");
49+
assert.equal(x(-1), "rgb(255,0,0)");
50+
assert.equal(x(1), "rgb(255,0,0)");
4551
}
4652
},
4753

0 commit comments

Comments
 (0)