Skip to content

Commit

Permalink
Fix #117 - use midpoint when collapsed.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jan 26, 2019
1 parent 30876a5 commit b0bdca4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/continuous.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function identity(x) {
function normalize(a, b) {
return (b -= (a = +a))
? function(x) { return (x - a) / b; }
: constant(b);
: constant(isNaN(b) ? NaN : 0.5);
}

function clamper(domain) {
Expand Down
12 changes: 6 additions & 6 deletions test/linear-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ tape("linear(x) ignores extra domain values if the range is smaller than the dom
test.end();
});

tape("linear(x) maps an empty domain to the range start", function(test) {
test.equal(scale.scaleLinear().domain([0, 0]).range([1, 2])(0), 1);
test.equal(scale.scaleLinear().domain([0, 0]).range([2, 1])(1), 2);
tape("linear(x) maps an empty domain to the middle of the range", function(test) {
test.equal(scale.scaleLinear().domain([0, 0]).range([1, 2])(0), 1.5);
test.equal(scale.scaleLinear().domain([0, 0]).range([2, 1])(1), 1.5);
test.end();
});

Expand Down Expand Up @@ -91,9 +91,9 @@ tape("linear.invert(y) maps a range value y to a domain value x", function(test)
test.end();
});

tape("linear.invert(y) maps an empty range to the domain start", function(test) {
test.equal(scale.scaleLinear().domain([1, 2]).range([0, 0]).invert(0), 1);
test.equal(scale.scaleLinear().domain([2, 1]).range([0, 0]).invert(1), 2);
tape("linear.invert(y) maps an empty range to the middle of the domain", function(test) {
test.equal(scale.scaleLinear().domain([1, 2]).range([0, 0]).invert(0), 1.5);
test.equal(scale.scaleLinear().domain([2, 1]).range([0, 0]).invert(1), 1.5);
test.end();
});

Expand Down
12 changes: 6 additions & 6 deletions test/pow-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ tape("pow(x) ignores extra domain values if the range is smaller than the domain
test.end();
});

tape("pow(x) maps an empty domain to the range start", function(test) {
test.equal(scale.scalePow().domain([0, 0]).range([1, 2])(0), 1);
test.equal(scale.scalePow().domain([0, 0]).range([2, 1])(1), 2);
tape("pow(x) maps an empty domain to the middle of the range", function(test) {
test.equal(scale.scalePow().domain([0, 0]).range([1, 2])(0), 1.5);
test.equal(scale.scalePow().domain([0, 0]).range([2, 1])(1), 1.5);
test.end();
});

Expand Down Expand Up @@ -77,9 +77,9 @@ tape("pow.invert(y) maps a range value y to a domain value x", function(test) {
test.end();
});

tape("pow.invert(y) maps an empty range to the domain start", function(test) {
test.equal(scale.scalePow().domain([1, 2]).range([0, 0]).invert(0), 1);
test.equal(scale.scalePow().domain([2, 1]).range([0, 0]).invert(1), 2);
tape("pow.invert(y) maps an empty range to the middle of the domain", function(test) {
test.equal(scale.scalePow().domain([1, 2]).range([0, 0]).invert(0), 1.5);
test.equal(scale.scalePow().domain([2, 1]).range([0, 0]).invert(1), 1.5);
test.end();
});

Expand Down

0 comments on commit b0bdca4

Please sign in to comment.