Skip to content

Commit

Permalink
Another fix for descending domains.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Sep 2, 2019
1 parent 903f39d commit cdd3452
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/diverging.js
Expand Up @@ -42,7 +42,7 @@ function transformer() {
};

return function(t) {
transform = t, t0 = t(x0), t1 = t(x1), t2 = t(x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1);
transform = t, t0 = t(x0), t1 = t(x1), t2 = t(x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1;
return scale;
};
}
Expand Down
24 changes: 21 additions & 3 deletions test/diverging-test.js
Expand Up @@ -60,9 +60,27 @@ tape("diverging.domain() handles a degenerate domain", function(test) {
tape("diverging.domain() handles a descending domain", function(test) {
var s = scale.scaleDiverging().domain([4, 2, 1]);
test.deepEqual(s.domain(), [4, 2, 1]);
test.equal(s( 1.2), 0.9);
test.equal(s( 2.0), 0.5);
test.equal(s( 3.0), 0.25);
test.equal(s(1.2), 0.9);
test.equal(s(2.0), 0.5);
test.equal(s(3.0), 0.25);
test.end();
});

tape("divergingLog.domain() handles a descending domain", function(test) {
var s = scale.scaleDivergingLog().domain([3, 2, 1]);
test.deepEqual(s.domain(), [3, 2, 1]);
test.equal(s(1.2), 1 - 0.1315172029168969);
test.equal(s(2.0), 1 - 0.5000000000000000);
test.equal(s(2.8), 1 - 0.9149213210862197);
test.end();
});

tape("divergingLog.domain() handles a descending negative domain", function(test) {
var s = scale.scaleDivergingLog().domain([-1, -2, -3]);
test.deepEqual(s.domain(), [-1, -2, -3]);
test.equal(s(-1.2), 0.1315172029168969);
test.equal(s(-2.0), 0.5000000000000000);
test.equal(s(-2.8), 0.9149213210862197);
test.end();
});

Expand Down

0 comments on commit cdd3452

Please sign in to comment.